Skip to content

Commit d342a34

Browse files
committed
Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
1 parent 40a62a9 commit d342a34

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/driver/aot.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use std::path::PathBuf;
55

6+
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
67
use rustc_codegen_ssa::back::linker::LinkerInfo;
78
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
89
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -125,9 +126,19 @@ fn module_codegen(
125126
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
126127
MonoItem::GlobalAsm(item_id) => {
127128
let item = cx.tcx.hir().item(item_id);
128-
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
129-
cx.global_asm.push_str(&*asm.as_str());
130-
cx.global_asm.push_str("\n\n");
129+
if let rustc_hir::ItemKind::GlobalAsm(asm) = item.kind {
130+
if !asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
131+
cx.global_asm.push_str("\n.intel_syntax noprefix\n");
132+
} else {
133+
cx.global_asm.push_str("\n.att_syntax\n");
134+
}
135+
for piece in asm.template {
136+
match *piece {
137+
InlineAsmTemplatePiece::String(ref s) => cx.global_asm.push_str(s),
138+
InlineAsmTemplatePiece::Placeholder { .. } => todo!(),
139+
}
140+
}
141+
cx.global_asm.push_str("\n.att_syntax\n\n");
131142
} else {
132143
bug!("Expected GlobalAsm found {:?}", item);
133144
}

0 commit comments

Comments
 (0)