fix my sloppy understanding of x86 assembly!
This commit is contained in:
parent
03785fbc9a
commit
ec5042148e
2 changed files with 30 additions and 38 deletions
47
lisc/emit.c
47
lisc/emit.c
|
@ -79,11 +79,26 @@ cneg(int cmp)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
econ(Con *c, FILE *f)
|
||||
{
|
||||
switch (c->type) {
|
||||
case CAddr:
|
||||
fprintf(f, "%s", c->label);
|
||||
if (c->val)
|
||||
fprintf(f, "%+"PRId64, c->val);
|
||||
break;
|
||||
case CNum:
|
||||
fprintf(f, "%"PRId64, c->val);
|
||||
break;
|
||||
default:
|
||||
diag("econ: invalid constant");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eref(Ref r, Fn *fn, FILE *f)
|
||||
{
|
||||
Con *c;
|
||||
|
||||
switch (rtype(r)) {
|
||||
case RReg:
|
||||
fprintf(f, "%%%s", rtoa[r.val]);
|
||||
|
@ -92,19 +107,8 @@ eref(Ref r, Fn *fn, FILE *f)
|
|||
fprintf(f, "-%d(%%rbp)", 8 * r.val);
|
||||
break;
|
||||
case RCon:
|
||||
c = &fn->con[r.val];
|
||||
switch (c->type) {
|
||||
case CAddr:
|
||||
fprintf(f, "$%s", c->label);
|
||||
if (c->val)
|
||||
fprintf(f, "%+"PRId64, c->val);
|
||||
break;
|
||||
case CNum:
|
||||
fprintf(f, "$%"PRId64, c->val);
|
||||
break;
|
||||
default:
|
||||
diag("emitref: invalid constant");
|
||||
}
|
||||
fprintf(f, "$");
|
||||
econ(&fn->con[r.val], f);
|
||||
break;
|
||||
default:
|
||||
diag("emitref: invalid reference");
|
||||
|
@ -114,10 +118,17 @@ eref(Ref r, Fn *fn, FILE *f)
|
|||
static void
|
||||
emem(Ref r, Fn *fn, FILE *f)
|
||||
{
|
||||
if (rtype(r) == RSlot)
|
||||
switch (rtype(r)) {
|
||||
default:
|
||||
diag("emem: invalid memory reference");
|
||||
case RSlot:
|
||||
eref(r, fn, f);
|
||||
else {
|
||||
assert(rtype(r)!=RReg || BASE(r.val)==r.val);
|
||||
break;
|
||||
case RCon:
|
||||
econ(&fn->con[r.val], f);
|
||||
break;
|
||||
case RReg:
|
||||
assert(BASE(r.val) == r.val);
|
||||
fprintf(f, "(");
|
||||
eref(r, fn, f);
|
||||
fprintf(f, ")");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue