Unify GCC and Clang ASM (#103)

* GCC-10 on Mac seems to require this syntax instead of the "+"

* update comment
This commit is contained in:
Mamy Ratsimbazafy 2020-10-11 21:36:16 +02:00 committed by GitHub
parent 1383aae105
commit 7826c40e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -286,6 +286,9 @@ func getStrOffset(a: Assembler_x86, op: Operand): string =
# Beware GCC / Clang differences with array offsets
# https://lists.llvm.org/pipermail/llvm-dev/2017-August/116202.html
# - 8+%rax works with GCC
# - 8%rax works with Clang
# - 8(%rax) works with both
if op.desc.rm in {Mem, AnyRegOrMem, MemOffsettable, AnyMemOffImm, AnyRegMemImm}:
# Directly accessing memory
@ -302,12 +305,11 @@ func getStrOffset(a: Assembler_x86, op: Operand): string =
(op.desc.rm == ElemsInReg and op.kind == kFromArray):
if op.offset == 0:
return "(%" & $op.desc.asmId & ')'
if defined(gcc):
return $(op.offset * a.wordSize) & "+(%" & $op.desc.asmId & ')'
elif defined(clang):
return $(op.offset * a.wordSize) & "(%" & $op.desc.asmId & ')'
else:
error "Unconfigured compiler"
# GCC & Clang seemed to disagree on pointer indexing
# in the past and required different codegen
# if defined(gcc):
# return $(op.offset * a.wordSize) & "+(%" & $op.desc.asmId & ')'
return $(op.offset * a.wordSize) & "(%" & $op.desc.asmId & ')'
else:
error "Unsupported: " & $op.desc.rm.ord