summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-26 13:21:11 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-26 13:21:11 -0700
commitf4a4987fb85dc9ea146146068734988bb046a3ab (patch)
tree3eac5098cdb2cd9a48996bedbeb26d52d2c0db9c /6
parente1bd55e7d0fd87b66041c1f90cc4cba370cb25ed (diff)
downloadmc-f4a4987fb85dc9ea146146068734988bb046a3ab.tar.gz
Fix up constant initialization a bit.
Diffstat (limited to '6')
-rw-r--r--6/asm.h1
-rw-r--r--6/gen.c16
-rw-r--r--6/isel.c18
-rw-r--r--6/simp.c6
4 files changed, 20 insertions, 21 deletions
diff --git a/6/asm.h b/6/asm.h
index 3f59700..6fdf6aa 100644
--- a/6/asm.h
+++ b/6/asm.h
@@ -279,6 +279,7 @@ Loc *locmemls(char *disp, Loc *base, Loc *idx, int scale, Mode mode);
Loc *loclit(long val, Mode m);
Loc *loclitl(char *lbl);
char *asmname(Node *dcl);
+int isconstfn(Node *n);
char *tydescid(char *buf, size_t bufsz, Type *ty);
Loc *coreg(Reg r, Mode m);
int isfloatmode(Mode m);
diff --git a/6/gen.c b/6/gen.c
index 6b2cb5d..19cd863 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -67,6 +67,22 @@ char *genlblstr(char *buf, size_t sz)
return buf;
}
+int isconstfn(Node *n)
+{
+ Node *d;
+
+ if (n->type == Nexpr) {
+ if (exprop(n) != Ovar)
+ return 0;
+ d = decls[n->expr.did];
+ } else {
+ d = n;
+ }
+ if (d && d->decl.isconst && d->decl.isglobl)
+ return tybase(decltype(d))->type == Tyfunc;
+ return 0;
+}
+
/*
* For x86, the assembly names are generated as follows:
* local symbols: .name
diff --git a/6/isel.c b/6/isel.c
index 22495cb..b7a5ebb 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -478,26 +478,12 @@ static void clear(Isel *s, Loc *val, size_t sz, size_t align)
}
}
-static int isconstfunc(Isel *s, Node *n)
-{
- Node *d;
-
- if (exprop(n) != Ovar)
- return 0;
- if (!hthas(s->globls, n))
- return 0;
- d = decls[n->expr.did];
- if (d && d->decl.isconst)
- return tybase(decltype(d))->type == Tyfunc;
- return 0;
-}
-
static void call(Isel *s, Node *n)
{
AsmOp op;
Loc *f;
- if (isconstfunc(s, n)) {
+ if (isconstfn(n)) {
op = Icall;
f = locmeml(htget(s->globls, n), NULL, NULL, mode(n));
} else {
@@ -810,7 +796,7 @@ Loc *selexpr(Isel *s, Node *n)
r = loc(s, n);
break;
case Ovar:
- if (isconstfunc(s, n)) {
+ if (isconstfn(n)) {
r = locreg(ModeQ);
a = loc(s, n);
g(s, Ilea, a, r, NULL);
diff --git a/6/simp.c b/6/simp.c
index 8117af6..592f8eb 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -85,11 +85,6 @@ static int ispure(Node *n)
return opispure[exprop(n)];
}
-static int isconstfn(Node *s)
-{
- return s->decl.isconst && decltype(s)->type == Tyfunc;
-}
-
size_t alignto(size_t sz, Type *t)
{
size_t a;
@@ -709,6 +704,7 @@ static Node *simpblob(Simp *s, Node *blob, Node ***l, size_t *nl)
d->decl.init = blob;
d->decl.type = blob->expr.type;
d->decl.isconst = 1;
+ d->decl.isglobl = 1;
htput(s->globls, d, asmname(d));
r->expr.did = d->decl.did;