Skip to content

Commit 620d453

Browse files
committed
transpile: assembly: use () rather than [] for indirect operands with AT&T syntax
1 parent 8cf9fca commit 620d453

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

c2rust-transpile/src/translator/assembly.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ fn tied_output_operand_idx(
559559
/// {0:y} (and wrapping mem-only references in square brackets).
560560
fn rewrite_asm<F: Fn(&str) -> bool, M: Fn(usize) -> usize>(
561561
asm: &str,
562+
att_syntax: bool,
562563
input_op_mapper: M,
563564
is_mem_only: F,
564565
arch: Arch,
@@ -647,7 +648,10 @@ fn rewrite_asm<F: Fn(&str) -> bool, M: Fn(usize) -> usize>(
647648
}
648649
let mem_only = is_mem_only(index_str);
649650
// Push the reference wrapped in {}, or in [{}] if mem-only
650-
out.push_str(if mem_only { "[{" } else { "{" });
651+
if mem_only {
652+
out.push(if att_syntax { '(' } else { '[' });
653+
};
654+
out.push('{');
651655
let idx: usize = index_str
652656
.parse()
653657
.map_err(|_| TranslationError::generic("could not parse operand idx"))?;
@@ -656,7 +660,10 @@ fn rewrite_asm<F: Fn(&str) -> bool, M: Fn(usize) -> usize>(
656660
out.push(':');
657661
out.push_str(&new_modifiers);
658662
}
659-
out.push_str(if mem_only { "}]" } else { "}" });
663+
out.push('}');
664+
if mem_only {
665+
out.push(if att_syntax { ')' } else { ']' });
666+
};
660667
// Push the rest of the chunk
661668
out.push_str(&chunk[end_idx..]);
662669
continue;
@@ -832,6 +839,7 @@ impl<'c> Translation<'c> {
832839
// Rewrite arg references in assembly template
833840
let rewritten_asm = rewrite_asm(
834841
asm,
842+
att_syntax,
835843
|idx: usize| {
836844
new_idx_for_orig(tied_output_operand_idx(idx, outputs.len(), &tied_operands))
837845
},

c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub unsafe extern "C" fn VM_CallCompiled(
5858
*opStack = 0 as core::ffi::c_int;
5959
opStackOfs = 0 as core::ffi::c_int;
6060
asm!(
61-
"movq [{2}], %rax\n", "movq [{0}], %r8\n", "movq [{1}], %r9\n", "push %r15\n",
61+
"movq ({2}), %rax\n", "movq ({0}), %r8\n", "movq ({1}), %r9\n", "push %r15\n",
6262
"push %r14\n", "push %r13\n", "push %r12\n", "callq *%rax\n", "pop %r12\n",
6363
"pop %r13\n", "pop %r14\n", "pop %r15\n", "\n", "mov {restmp0:x}, %bx\n", in
6464
(reg) & (* vm).instructionPointers, in (reg) & (* vm).dataBase, in (reg) &

0 commit comments

Comments
 (0)