rust/src/linkage.rs

28 lines
986 B
Rust
Raw Normal View History

2019-08-31 22:58:09 +05:30
use rustc::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
2019-03-11 20:36:29 +01:00
use crate::prelude::*;
pub fn get_clif_linkage(mono_item: MonoItem, linkage: RLinkage, visibility: Visibility) -> Linkage {
match (linkage, visibility) {
(RLinkage::External, Visibility::Default) => Linkage::Export,
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
2020-03-19 12:09:21 +01:00
(RLinkage::External, Visibility::Hidden) => Linkage::Hidden,
2019-03-11 20:36:29 +01:00
_ => panic!("{:?} = {:?} {:?}", mono_item, linkage, visibility),
}
}
pub fn get_static_ref_linkage(tcx: TyCtxt, def_id: DefId) -> Linkage {
let fn_attrs = tcx.codegen_fn_attrs(def_id);
if let Some(linkage) = fn_attrs.linkage {
match linkage {
RLinkage::External => Linkage::Export,
RLinkage::Internal => Linkage::Local,
RLinkage::ExternalWeak | RLinkage::WeakAny => Linkage::Preemptible,
_ => panic!("{:?}", linkage),
}
} else {
Linkage::Import
}
}