summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-19 23:06:56 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-19 23:06:56 -0700
commit88df32c77ff6806dee396803b8a9145f53c04ae3 (patch)
tree193dbed8f2c7bf65055186ab7f005c548a6e28b9 /6
parent837b2cb7b258a5a81325e521b1555b18f88eab74 (diff)
downloadmc-88df32c77ff6806dee396803b8a9145f53c04ae3.tar.gz
Store function args into the right place.
This probably means a register, but possibly a stack slot. Let loc() figure it out.
Diffstat (limited to '6')
-rw-r--r--6/isel.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/6/isel.c b/6/isel.c
index 8935d31..28454f7 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -92,41 +92,53 @@ static Mode mode(Node *n)
return ModeNone;
}
-static Loc *loc(Isel *s, Node *n)
+static Loc *varloc(Isel *s, Node *n)
{
ssize_t stkoff;
Loc *l, *rip;
+
+ if (hthas(s->globls, n)) {
+ rip = locphysreg(Rrip);
+ l = locmeml(htget(s->globls, n), rip, NULL, mode(n));
+ } else if (hthas(s->stkoff, n)) {
+ stkoff = ptoi(htget(s->stkoff, n));
+ l = locmem(-stkoff, locphysreg(Rrbp), NULL, mode(n));
+ } else {
+ l = htget(s->reglocs, n);
+ if (!l) {
+ l = locreg(mode(n));
+ htput(s->reglocs, n, l);
+ }
+ }
+ return l;
+}
+
+static Loc *loc(Isel *s, Node *n)
+{
Node *v;
+ Loc *l;
- switch (exprop(n)) {
- case Ovar:
- if (hthas(s->globls, n)) {
- rip = locphysreg(Rrip);
- l = locmeml(htget(s->globls, n), rip, NULL, mode(n));
- } else if (hthas(s->stkoff, n)) {
- stkoff = ptoi(htget(s->stkoff, n));
- l = locmem(-stkoff, locphysreg(Rrbp), NULL, mode(n));
- } else {
- l = htget(s->reglocs, n);
- if (!l) {
- l = locreg(mode(n));
- htput(s->reglocs, n, l);
+ if (n->type == Ndecl) {
+ l = varloc(s, n);
+ } else {
+ switch (exprop(n)) {
+ case Ovar:
+ l = varloc(s, n);
+ break;
+ case Olit:
+ v = n->expr.args[0];
+ switch (v->lit.littype) {
+ case Lchr: l = loclit(v->lit.chrval, mode(n)); break;
+ case Lbool: l = loclit(v->lit.boolval, mode(n)); break;
+ case Lint: l = loclit(v->lit.intval, mode(n)); break;
+ default:
+ die("Literal type %s should be blob", litstr[v->lit.littype]);
}
- }
- break;
- case Olit:
- v = n->expr.args[0];
- switch (v->lit.littype) {
- case Lchr: l = loclit(v->lit.chrval, mode(n)); break;
- case Lbool: l = loclit(v->lit.boolval, mode(n)); break;
- case Lint: l = loclit(v->lit.intval, mode(n)); break;
- default:
- die("Literal type %s should be blob", litstr[v->lit.littype]);
- }
- break;
- default:
- die("Node %s not leaf in loc()", opstr[exprop(n)]);
- break;
+ break;
+ default:
+ die("Node %s not leaf in loc()", opstr[exprop(n)]);
+ break;
+ }
}
return l;
}
@@ -921,13 +933,13 @@ void addarglocs(Isel *s, Func *fn)
argoff += size(arg);
} else if (!vararg && isfloatmode(mode(arg)) && nfloats < Nfloatregargs) {
a = coreg(floatargregs[nfloats], mode(arg));
- l = locreg(mode(arg));
+ l = loc(s, arg);
g(s, Imovs, a, l, NULL);
htput(s->reglocs, arg, l);
nfloats++;
} else if (!vararg && isintmode(mode(arg)) && nints < Nintregargs) {
a = coreg(intargregs[nints], mode(arg));
- l = locreg(mode(arg));
+ l = loc(s, arg);
g(s, Imov, a, l, NULL);
htput(s->reglocs, arg, l);
nints++;