ref: d4b87f186552008f45bb413e423e05523f1857f4
parent: a53b68479664f176614fa259484145eb4583fd71
author: Ori Bernstein <[email protected]>
date: Tue May 8 10:41:29 EDT 2012
Add (and use) declaration ids.
--- a/8/isel.c
+++ b/8/isel.c
@@ -146,7 +146,7 @@
switch (exprop(n)) {
case Ovar:
- stkoff = (size_t)htget(s->locs, n->expr.args[0]);
+ stkoff = (size_t)htget(s->locs, (void*)n->expr.did);
locmem(&l, stkoff, Resp, Rnone, ModeL);
break;
case Olit:
@@ -361,9 +361,6 @@
args = n->expr.args;
r = (Loc){Locnone, };
- printf("===================\n");
- dump(n, stdout);
- printf("===================\n");
switch (exprop(n)) {
case Oadd: r = binop(s, Iadd, args[0], args[1]); break;
case Osub: r = binop(s, Isub, args[0], args[1]); break;
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -335,8 +335,9 @@
{
Fn *f;
+ assert(n->type == Ndecl);
f = s->fn;
- htput(f->locs, n, (void*)f->stksz);
+ htput(f->locs, (void*)n->decl.sym->id, (void*)f->stksz);
f->stksz += size(n);
}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -318,6 +318,7 @@
fatal(n->line, "Undeclared var %s", args[0]->name.parts[args[0]->name.nparts - 1]);
else
settype(n, s->type);
+ n->expr.did = s->id;
break;
case Olit: /* <lit>:@a::tyclass -> @a */
switch (args[0]->lit.littype) {
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -86,6 +86,7 @@
};
struct Sym {
+ long id;
int line;
int isconst;
Node *name;
@@ -136,6 +137,7 @@
Op op;
Type *type;
int isconst;
+ long did; /* for Ovar, we want a mapping to the decl id */
size_t nargs;
Node **args;
} expr;
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -55,9 +55,11 @@
Sym *mksym(int line, Node *name, Type *ty)
{
+ static int nextid;
Sym *sym;
sym = zalloc(sizeof(Sym));
+ sym->id = nextid++;
sym->name = name;
sym->type = ty;
sym->line = line;