]>
git.proxmox.com Git - rustc.git/blob - compiler/rustc_codegen_ssa/src/mono_item.rs
5 use rustc_middle
::mir
::mono
::MonoItem
;
6 use rustc_middle
::mir
::mono
::{Linkage, Visibility}
;
7 use rustc_middle
::ty
::layout
::HasTyCtxt
;
8 use rustc_target
::abi
::LayoutOf
;
10 pub trait MonoItemExt
<'a
, 'tcx
> {
11 fn define
<Bx
: BuilderMethods
<'a
, 'tcx
>>(&self, cx
: &'a Bx
::CodegenCx
);
12 fn predefine
<Bx
: BuilderMethods
<'a
, 'tcx
>>(
14 cx
: &'a Bx
::CodegenCx
,
16 visibility
: Visibility
,
18 fn to_raw_string(&self) -> String
;
21 impl<'a
, 'tcx
: 'a
> MonoItemExt
<'a
, 'tcx
> for MonoItem
<'tcx
> {
22 fn define
<Bx
: BuilderMethods
<'a
, 'tcx
>>(&self, cx
: &'a Bx
::CodegenCx
) {
24 "BEGIN IMPLEMENTING '{} ({})' in cgu {}",
27 cx
.codegen_unit().name()
31 MonoItem
::Static(def_id
) => {
32 cx
.codegen_static(def_id
, cx
.tcx().is_mutable_static(def_id
));
34 MonoItem
::GlobalAsm(item_id
) => {
35 let item
= cx
.tcx().hir().item(item_id
);
36 if let hir
::ItemKind
::GlobalAsm(ref asm
) = item
.kind
{
37 let operands
: Vec
<_
> = asm
40 .map(|(op
, op_sp
)| match *op
{
41 hir
::InlineAsmOperand
::Const { ref anon_const }
=> {
42 let anon_const_def_id
=
43 cx
.tcx().hir().local_def_id(anon_const
.hir_id
).to_def_id();
45 cx
.tcx().const_eval_poly(anon_const_def_id
).unwrap_or_else(
46 |_
| span_bug
!(*op_sp
, "asm const cannot be resolved"),
50 .typeck_body(anon_const
.body
)
51 .node_type(anon_const
.hir_id
);
52 let string
= common
::asm_const_to_str(
58 GlobalAsmOperandRef
::Const { string }
60 _
=> span_bug
!(*op_sp
, "invalid operand type for global_asm!"),
64 cx
.codegen_global_asm(asm
.template
, &operands
, asm
.options
, asm
.line_spans
);
66 span_bug
!(item
.span
, "Mismatch between hir::Item type and MonoItem type")
69 MonoItem
::Fn(instance
) => {
70 base
::codegen_instance
::<Bx
>(&cx
, instance
);
75 "END IMPLEMENTING '{} ({})' in cgu {}",
78 cx
.codegen_unit().name()
82 fn predefine
<Bx
: BuilderMethods
<'a
, 'tcx
>>(
84 cx
: &'a Bx
::CodegenCx
,
86 visibility
: Visibility
,
89 "BEGIN PREDEFINING '{} ({})' in cgu {}",
92 cx
.codegen_unit().name()
95 let symbol_name
= self.symbol_name(cx
.tcx()).name
;
97 debug
!("symbol {}", &symbol_name
);
100 MonoItem
::Static(def_id
) => {
101 cx
.predefine_static(def_id
, linkage
, visibility
, &symbol_name
);
103 MonoItem
::Fn(instance
) => {
104 cx
.predefine_fn(instance
, linkage
, visibility
, &symbol_name
);
106 MonoItem
::GlobalAsm(..) => {}
110 "END PREDEFINING '{} ({})' in cgu {}",
112 self.to_raw_string(),
113 cx
.codegen_unit().name()
117 fn to_raw_string(&self) -> String
{
119 MonoItem
::Fn(instance
) => {
120 format
!("Fn({:?}, {})", instance
.def
, instance
.substs
.as_ptr() as usize)
122 MonoItem
::Static(id
) => format
!("Static({:?})", id
),
123 MonoItem
::GlobalAsm(id
) => format
!("GlobalAsm({:?})", id
),