2022-10-23 11:42:05 +03:30
|
|
|
//! Target dependent parameters needed for layouts
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2022-12-21 15:11:24 +01:00
|
|
|
use base_db::CrateId;
|
2023-01-16 22:43:27 +03:30
|
|
|
use hir_def::layout::TargetDataLayout;
|
2022-10-23 11:42:05 +03:30
|
|
|
|
|
|
|
|
use crate::db::HirDatabase;
|
|
|
|
|
|
2023-01-16 22:43:27 +03:30
|
|
|
pub fn target_data_layout_query(
|
|
|
|
|
db: &dyn HirDatabase,
|
|
|
|
|
krate: CrateId,
|
|
|
|
|
) -> Option<Arc<TargetDataLayout>> {
|
2022-10-23 11:42:05 +03:30
|
|
|
let crate_graph = db.crate_graph();
|
2023-01-19 19:21:44 +01:00
|
|
|
let target_layout = crate_graph[krate].target_layout.as_ref().ok()?;
|
|
|
|
|
let res = TargetDataLayout::parse_from_llvm_datalayout_string(&target_layout);
|
|
|
|
|
if let Err(_e) = &res {
|
|
|
|
|
// FIXME: Print the error here once it implements debug/display
|
|
|
|
|
// also logging here is somewhat wrong, but unfortunately this is the earliest place we can
|
|
|
|
|
// parse that doesn't impose a dependency to the rust-abi crate for project-model
|
|
|
|
|
tracing::error!("Failed to parse target data layout for {krate:?}");
|
|
|
|
|
}
|
|
|
|
|
res.ok().map(Arc::new)
|
2022-12-21 15:11:24 +01:00
|
|
|
}
|