ref: c903ba47cf1e54d18727f493a5beca2ccf5e33fc
parent: ac3c0bd121fac595ebaeb9c364929697bb05cfe1
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 30 20:15:31 EDT 2012
Fix more x64 issues.
--- a/8/isel.c
+++ b/8/isel.c
@@ -86,7 +86,7 @@
stkoff = (size_t)htget(s->locs, n);
l = locmem(-stkoff, locphysreg(Rrbp), NULL, mode(n));
} else if (hthas(s->globls, n)) {
- l = locstrlbl(htget(s->globls, n));
+ l = locmeml(htget(s->globls, n), NULL, NULL, mode(n));
} else {
die("%s (id=%ld) not found", namestr(n->expr.args[0]), n->expr.did);
}
@@ -388,7 +388,7 @@
argoff += size(n->expr.args[i]);
}
fn = selexpr(s, n->expr.args[0]);
- if (fn->type == Loclbl)
+ if (fn->type == Loclbl || fn->type == Locmeml)
g(s, Icall, fn, NULL);
else
g(s, Icallind, fn, NULL);
@@ -618,16 +618,20 @@
if (l->mem.lbldisp)
fprintf(fd, "%s", l->mem.lbldisp);
}
- fprintf(fd, "(");
- locprint(fd, l->mem.base, 'r');
- if (l->mem.idx) {
- fprintf(fd, ",");
- locprint(fd, l->mem.idx, 'r');
+ if (l->mem.base) {
+ fprintf(fd, "(");
+ locprint(fd, l->mem.base, 'r');
+ if (l->mem.idx) {
+ fprintf(fd, ",");
+ locprint(fd, l->mem.idx, 'r');
+ }
+ if (l->mem.scale > 1)
+ fprintf(fd, ",%d", l->mem.scale);
+ if (l->mem.base)
+ fprintf(fd, ")");
+ } else if (l->type != Locmeml) {
+ die("Only locmeml can have unspecified base reg");
}
- if (l->mem.scale > 1)
- fprintf(fd, ",%d", l->mem.scale);
- if (l->mem.base)
- fprintf(fd, ")");
break;
case Loclit:
assert(spec == 'i' || spec == 'x' || spec == 'u');
--- a/8/locs.c
+++ b/8/locs.c
@@ -156,7 +156,7 @@
Loc *l;
l = zalloc(sizeof(Loc));
- l->type = Locmem;
+ l->type = Locmeml;
l->mode = mode;
l->mem.lbldisp = strdup(disp);
l->mem.base = base;
--- a/8/ra.c
+++ b/8/ra.c
@@ -167,8 +167,9 @@
m = insn->args[i];
if (m->type != Locmem && m->type != Locmeml)
continue;
- if (!isfixreg(m->mem.base))
- u[j++] = m->mem.base->reg.id;
+ if (m->mem.base)
+ if (!isfixreg(m->mem.base))
+ u[j++] = m->mem.base->reg.id;
if (m->mem.idx)
if (!isfixreg(m->mem.base))
u[j++] = m->mem.idx->reg.id;
--- a/8/simp.c
+++ b/8/simp.c
@@ -427,7 +427,7 @@
return disp(uc->line, uc->id);
}
-static Node *uval(Node *n, size_t off)
+static Node *uval(Node *n, size_t off, Type *t)
{
if (exprop(n) == Ocons)
return n->expr.args[1];
@@ -434,9 +434,7 @@
else if (exprop(n) == Olit)
return n;
else
- /* FIXME: WRONG WRONG WRONG. Union vals
- * aren't only disps. */
- return load(add(addr(n, tyintptr), disp(n->line, off)));
+ return load(addk(addr(n, t), off));
}
static Node *ucompare(Simp *s, Node *a, Node *b, Type *t, size_t off)
@@ -459,8 +457,8 @@
case Tyint8: case Tyint16: case Tyint32: case Tyint:
case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint:
case Typtr: case Tyfunc:
- x = uval(a, off);
- y = uval(b, off);
+ x = uval(a, off, t);
+ y = uval(b, off, t);
r = mkexpr(a->line, Oeq, x, y, NULL);
r->expr.type = tyintptr;
break;
@@ -639,6 +637,7 @@
default: die("Unslicable type %s", tystr(n->expr.type));
}
/* safe: all types we allow here have a sub[0] that we want to grab */
+ off = ptrsized(s, off);
sz = tysize(n->expr.type->sub[0]);
v = mul(off, disp(n->line, sz));
return add(u, v);
@@ -646,7 +645,7 @@
static Node *slicelen(Simp *s, Node *sl)
{
- /* *(&sl + 4) */
+ /* *(&sl + sizeof(size_t)) */
return load(addk(addr(sl, tyintptr), Ptrsz));
}
@@ -700,8 +699,8 @@
t = temp(s, n);
/* *(&slice) = (void*)base + off*sz */
base = slicebase(s, n->expr.args[0], n->expr.args[1]);
- start = rval(s, n->expr.args[1], NULL);
- end = rval(s, n->expr.args[2], NULL);
+ start = ptrsized(s, rval(s, n->expr.args[1], NULL));
+ end = ptrsized(s, rval(s, n->expr.args[2], NULL));
len = sub(end, start);
stbase = store(addr(t, tyintptr), base);
/* *(&slice + ptrsz) = len */
--
⑨