summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-27 00:29:07 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-27 00:31:56 -0700
commitcde7e0d999cf3d56f48d830cf3149f779d86fb31 (patch)
tree1a322413d711e3b53ccb26e634f7775ddcfade8c /6
parentc74b0bc06994e9a4921131696a5714cf83642acc (diff)
downloadmc-cde7e0d999cf3d56f48d830cf3149f779d86fb31.tar.gz
Add indirect call operator.
This should allow us to split up direct calls and environment calls. Currently, it doesn't actually do anything.
Diffstat (limited to '6')
-rw-r--r--6/isel.c13
-rw-r--r--6/simp.c14
2 files changed, 18 insertions, 9 deletions
diff --git a/6/isel.c b/6/isel.c
index 928ec9d..f1c11b9 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -481,15 +481,17 @@ static void clear(Isel *s, Loc *val, size_t sz, size_t align)
static void call(Isel *s, Node *n)
{
AsmOp op;
+ Node *fn;
Loc *f;
- if (isconstfn(n)) {
+ if (exprop(n) == Ocall) {
op = Icall;
- assert(tybase(exprtype(n))->type == Tycode);
- f = locmeml(htget(s->globls, n), NULL, NULL, mode(n));
+ fn = n->expr.args[0];
+ assert(tybase(exprtype(fn))->type == Tycode);
+ f = locmeml(htget(s->globls, fn), NULL, NULL, mode(fn));
} else {
op = Icallind;
- f = selexpr(s, n);
+ f = selexpr(s, n->expr.args[0]);
}
g(s, op, f, NULL);
}
@@ -585,7 +587,7 @@ static Loc *gencall(Isel *s, Node *n)
argoff += size(n->expr.args[i]);
}
}
- call(s, n->expr.args[0]);
+ call(s, n);
if (argsz)
g(s, Iadd, stkbump, rsp, NULL);
if (retloc) {
@@ -778,6 +780,7 @@ Loc *selexpr(Isel *s, Node *n)
r = b;
break;
case Ocall:
+ case Ocallind:
r = gencall(s, n);
break;
case Oret:
diff --git a/6/simp.c b/6/simp.c
index c9911d6..1bf78a5 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1345,12 +1345,14 @@ static Node *getcode(Simp *s, Node *n)
static Node *simpcall(Simp *s, Node *n, Node *dst)
{
+ Node *r, *call, *fn;
size_t i, nargs;
Node **args;
- Node *r, *call;
Type *ft;
+ Op op;
- ft = tybase(exprtype(n->expr.args[0]));
+ fn = n->expr.args[0];
+ ft = tybase(exprtype(fn));
if (exprtype(n)->type == Tyvoid)
r = NULL;
else if (isstacktype(exprtype(n)) && dst)
@@ -1360,7 +1362,11 @@ static Node *simpcall(Simp *s, Node *n, Node *dst)
args = NULL;
nargs = 0;
- lappend(&args, &nargs, getcode(s, n->expr.args[0]));
+ if (isconstfn(fn))
+ op = Ocall;
+ else
+ op = Ocallind;
+ lappend(&args, &nargs, getcode(s, fn));
if (exprtype(n)->type != Tyvoid && isstacktype(exprtype(n)))
lappend(&args, &nargs, addr(s, r, exprtype(n)));
@@ -1379,7 +1385,7 @@ static Node *simpcall(Simp *s, Node *n, Node *dst)
if (r)
def(s, r);
- call = mkexprl(n->loc, Ocall, args, nargs);
+ call = mkexprl(n->loc, op, args, nargs);
call->expr.type = exprtype(n);
if (r && !isstacktype(exprtype(n))) {
append(s, set(r, call));