aboutsummaryrefslogtreecommitdiff
path: root/amd64/emit.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2019-04-25 15:27:25 +0200
committerQuentin Carbonneaux <[email protected]>2019-04-25 15:27:25 +0200
commitb4a98c3fa8b880f58b04f5d632ab89ad15725bd4 (patch)
tree16d37727a7f810e0357436e533d60557c15f3547 /amd64/emit.c
parent636568dcba071e212a61c35ce994012b9cb83ec5 (diff)
cleanup amd64 constant addressing
We now emit correct code when the user refers to a specific constant address. I also made some comments clearer in the instruction selection pass and got rid of some apparently useless code.
Diffstat (limited to 'amd64/emit.c')
-rw-r--r--amd64/emit.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index 1fe141f..91223bd 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -292,10 +292,10 @@ Next:
if (m->offset.type != CUndef)
emitcon(&m->offset, f);
fputc('(', f);
- if (req(m->base, R))
- fprintf(f, "%%rip");
- else
+ if (!req(m->base, R))
fprintf(f, "%%%s", regtoa(m->base.val, SLong));
+ else if (m->offset.type == CAddr)
+ fprintf(f, "%%rip");
if (!req(m->index, R))
fprintf(f, ", %%%s, %d",
regtoa(m->index.val, SLong),
@@ -333,8 +333,10 @@ Next:
fprintf(f, "%d(%%rbp)", slot(ref.val, fn));
break;
case RCon:
- emitcon(&fn->con[ref.val], f);
- fprintf(f, "(%%rip)");
+ off = fn->con[ref.val];
+ emitcon(&off, f);
+ if (off.type == CAddr)
+ fprintf(f, "(%%rip)");
break;
case RTmp:
assert(isreg(ref));