Skip to content

Commit ed1a5e5

Browse files
committed
Implement sym operands for global asm
1 parent df6b067 commit ed1a5e5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/global_asm.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,20 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
3939
);
4040
global_asm.push_str(&string);
4141
}
42-
InlineAsmOperand::SymFn { anon_const: _ } => todo!(),
43-
InlineAsmOperand::SymStatic { path: _, def_id: _ } => todo!(),
42+
InlineAsmOperand::SymFn { anon_const } => {
43+
let ty = tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
44+
let instance = match ty.kind() {
45+
&ty::FnDef(def_id, substs) => Instance::new(def_id, substs),
46+
_ => span_bug!(op_sp, "asm sym is not a function"),
47+
};
48+
let symbol = tcx.symbol_name(instance);
49+
global_asm.push_str(symbol.name);
50+
}
51+
InlineAsmOperand::SymStatic { path: _, def_id } => {
52+
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
53+
let symbol = tcx.symbol_name(instance);
54+
global_asm.push_str(symbol.name);
55+
}
4456
InlineAsmOperand::In { .. }
4557
| InlineAsmOperand::Out { .. }
4658
| InlineAsmOperand::InOut { .. }

0 commit comments

Comments
 (0)