summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2013-02-06 13:55:10 -0500
committerOri Bernstein <orib@google.com>2013-02-06 13:55:10 -0500
commitf635856c50c2a640c3765af746ee23a8d4282373 (patch)
tree2b119b07d59c2bf89de186870ce3a79e88d474d1
parent2f5f1d3d30406b78123e934998a681d90ced60a0 (diff)
downloadmc-f635856c50c2a640c3765af746ee23a8d4282373.tar.gz
Comment our data structures a bit better.
-rw-r--r--6/asm.h59
-rw-r--r--6/isel.c12
2 files changed, 38 insertions, 33 deletions
diff --git a/6/asm.h b/6/asm.h
index 6e61bb1..5564851 100644
--- a/6/asm.h
+++ b/6/asm.h
@@ -49,17 +49,22 @@ typedef enum {
Nmode,
} Mode;
+/* a register, label, or memory location */
struct Loc {
- Loctype type;
- Mode mode;
+ Loctype type; /* the type of loc */
+ Mode mode; /* the mode of this location */
union {
- char *lbl;
- struct {
+ char *lbl; /* for Loclbl, Loclitl */
+ struct { /* for Locreg */
regid id;
Reg colour;
} reg;
- long lit;
- /* disp(base + index) */
+ long lit; /* for Loclit */
+ /*
+ * for Locmem, Locmeml.
+ * address format is
+ * disp(base + index)
+ */
struct {
/* only one of lbldisp and constdisp may be used */
char *lbldisp;
@@ -78,28 +83,28 @@ struct Insn {
};
struct Func {
- char *name;
- int isexport;
- size_t stksz;
- Type *type;
- Htab *locs;
- Node *ret;
- Cfg *cfg;
+ char *name; /* function name */
+ int isexport; /* is this exported from the asm? */
+ size_t stksz; /* stack size */
+ Type *type; /* type of function */
+ Htab *stkoff; /* Loc* -> int stackoff map */
+ Node *ret; /* return value */
+ Cfg *cfg; /* flow graph */
};
struct Asmbb {
- int id;
- char **lbls;
- size_t nlbls;
- Insn **il;
- size_t ni;
-
- Bitset *pred;
- Bitset *succ;
- Bitset *use;
- Bitset *def;
- Bitset *livein;
- Bitset *liveout;
+ int id; /* unique identifier */
+ char **lbls; /* list of BB labels */
+ size_t nlbls; /* number of labels */
+ Insn **il; /* instructions */
+ size_t ni; /* number of instructions */
+
+ Bitset *pred; /* set of predecessor BB ids */
+ Bitset *succ; /* set of successor BB ids */
+ Bitset *use; /* registers used by this BB */
+ Bitset *def; /* registers defined by this BB */
+ Bitset *livein; /* variables live on entrance to BB */
+ Bitset *liveout; /* variables live on exit from BB */
};
@@ -112,10 +117,10 @@ struct Isel {
Asmbb *curbb;
Node *ret; /* we store the return into here */
- Htab *locs; /* decl id => int stkoff */
Htab *spillslots; /* reg id => int stkoff */
Htab *reglocs; /* decl id => Loc *reg */
- Htab *globls; /* decl id => char *globlname */
+ Htab *stkoff; /* decl id => int stkoff */
+ Htab *_globls; /* decl id => char *globlname */
/* increased when we spill */
Loc *stksz;
diff --git a/6/isel.c b/6/isel.c
index 78a3568..81fa419 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -78,21 +78,21 @@ static Mode mode(Node *n)
static Loc *loc(Isel *s, Node *n)
{
- size_t stkoff;
+ ssize_t stkoff;
Loc *l, *rip;
Node *v;
switch (exprop(n)) {
case Ovar:
- if (hthas(s->locs, n)) {
- stkoff = (size_t)htget(s->locs, n);
+ if (hthas(s->stkoff, n)) {
+ stkoff = (ssize_t)htget(s->stkoff, n);
l = locmem(-stkoff, locphysreg(Rrbp), NULL, mode(n));
- } else if (hthas(s->globls, n)) {
+ } else if (hthas(s->_globls, n)) {
if (tybase(exprtype(n))->type == Tyfunc)
rip = NULL;
else
rip = locphysreg(Rrip);
- l = locmeml(htget(s->globls, n), rip, NULL, mode(n));
+ l = locmeml(htget(s->_globls, n), rip, NULL, mode(n));
} else {
if (!hthas(s->reglocs, n))
htput(s->reglocs, n, locreg(mode(n)));
@@ -931,7 +931,7 @@ void genasm(FILE *fd, Func *fn, Htab *globls)
char buf[128];
is.reglocs = mkht(dclhash, dcleq);
- is.locs = fn->locs;
+ is.stkoff = fn->stkoff;
is.globls = globls;
is.ret = fn->ret;
is.cfg = fn->cfg;