ref: f2fa59d669b6e1470a3c18c545abfbb6fda39ff8
parent: 52a4d88af911ccd62125f55e72155b3d76878a66
author: Ori Bernstein <[email protected]>
date: Thu Dec 19 19:08:27 EST 2013
Take the address of const funcs.
--- a/6/isel.c
+++ b/6/isel.c
@@ -371,16 +371,26 @@
g(s, Irepmovsb, NULL);
}
+static int isfunc(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;
- Node *d;
Loc *f;
- d = NULL;
- if (exprop(n) == Ovar)
- d = decls[n->expr.did];
- if (hthas(s->globls, n) && d && d->decl.isconst && tybase(decltype(d))->type == Tyfunc) {
+ if (isfunc(s, n)) {
op = Icall;
f = locmeml(htget(s->globls, n), NULL, NULL, mode(n));
} else {
@@ -628,7 +638,13 @@
r = loc(s, n);
break;
case Ovar:
- r = loc(s, n);
+ if (isfunc(s, n)) {
+ r = locreg(ModeQ);
+ a = loc(s, n);
+ g(s, Ilea, a, r, NULL);
+ } else {
+ r = loc(s, n);
+ }
break;
case Olbl:
r = loclbl(args[0]);
--- a/6/simp.c
+++ b/6/simp.c
@@ -624,8 +624,6 @@
r->expr.did = d->decl.did;
r->expr.type = lit->expr.type;
- if (tybase(r->expr.type)->type == Tyfunc)
- r = addr(s, r, tybase(r->expr.type));
lappend(l, nl, d);
return r;