Skip to content

Commit 178e267

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

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/global_asm.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,22 @@ 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+
// FIXME handle the case where the function was made private to the
50+
// current codegen unit
51+
global_asm.push_str(symbol.name);
52+
}
53+
InlineAsmOperand::SymStatic { path: _, def_id } => {
54+
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
55+
let symbol = tcx.symbol_name(instance);
56+
global_asm.push_str(symbol.name);
57+
}
4458
InlineAsmOperand::In { .. }
4559
| InlineAsmOperand::Out { .. }
4660
| InlineAsmOperand::InOut { .. }

0 commit comments

Comments
 (0)