summaryrefslogtreecommitdiff
path: root/mi/cfg.c
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-10-17 18:05:26 -0400
committerOri Bernstein <orib@google.com>2012-10-17 18:05:26 -0400
commit1ad08d5fdee3b975722f692e9222da1a0126d632 (patch)
treeb0570cb473899e5c5f7dffe3fd79260f301cf8ac /mi/cfg.c
parent62f7dc8a82a51b9b043587ee0ca52c62c7420999 (diff)
downloadmc-1ad08d5fdee3b975722f692e9222da1a0126d632.tar.gz
Labels are now Lit values, not their own toplev nodes.
Diffstat (limited to 'mi/cfg.c')
-rw-r--r--mi/cfg.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/mi/cfg.c b/mi/cfg.c
index 3387014..50be90b 100644
--- a/mi/cfg.c
+++ b/mi/cfg.c
@@ -26,10 +26,18 @@ static Bb *mkbb(Cfg *cfg)
return bb;
}
+static char *lblstr(Node *n)
+{
+ assert(exprop(n) == Olit);
+ assert(n->expr.args[0]->type == Nlit);
+ assert(n->expr.args[0]->lit.littype == Llbl);
+ return n->expr.args[0]->lit.lblval;
+}
+
static void label(Cfg *cfg, Node *lbl, Bb *bb)
{
- htput(cfg->lblmap, lbl->lbl.name, bb);
- lappend(&bb->lbls, &bb->nlbls, lbl->lbl.name);
+ htput(cfg->lblmap, lblstr(lbl), bb);
+ lappend(&bb->lbls, &bb->nlbls, lblstr(lbl));
}
static int addnode(Cfg *cfg, Bb *bb, Node *n)
@@ -49,6 +57,34 @@ static int addnode(Cfg *cfg, Bb *bb, Node *n)
return 0;
}
+static int islabel(Node *n)
+{
+ Node *l;
+ if (n->type != Nexpr)
+ return 0;
+ if (exprop(n) != Olit)
+ return 0;
+ l = n->expr.args[0];
+ if (l->type != Nlit)
+ return 0;
+ if (l->lit.littype != Llbl)
+ return 0;
+ return 1;
+}
+
+static Bb *addlabel(Cfg *cfg, Bb *bb, Node **nl, size_t i)
+{
+ /* if the current block assumes fall-through, insert an explicit jump */
+ if (i > 0 && nl[i - 1]->type == Nexpr) {
+ if (exprop(nl[i - 1]) != Ocjmp && exprop(nl[i - 1]) != Ojmp)
+ addnode(cfg, bb, mkexpr(-1, Ojmp, mklbl(-1, lblstr(nl[i])), NULL));
+ }
+ if (bb->nnl)
+ bb = mkbb(cfg);
+ label(cfg, nl[i], bb);
+ return bb;
+}
+
Cfg *mkcfg(Node **nl, size_t nn)
{
Cfg *cfg;
@@ -63,20 +99,13 @@ Cfg *mkcfg(Node **nl, size_t nn)
bb = mkbb(cfg);
for (i = 0; i < nn; i++) {
switch (nl[i]->type) {
- case Nlbl:
- /* if the current block assumes fall-through, insert an explicit jump */
- if (i > 0 && nl[i - 1]->type == Nexpr) {
- if (exprop(nl[i - 1]) != Ocjmp && exprop(nl[i - 1]) != Ojmp)
- addnode(cfg, bb, mkexpr(-1, Ojmp, mklbl(-1, nl[i]->lbl.name), NULL));
- }
- if (bb->nnl)
- bb = mkbb(cfg);
- label(cfg, nl[i], bb);
- break;
case Nexpr:
- if (addnode(cfg, bb, nl[i]))
+ if (islabel(nl[i]))
+ bb = addlabel(cfg, bb, nl, i);
+ else if (addnode(cfg, bb, nl[i]))
bb = mkbb(cfg);
break;
+ break;
case Ndecl:
break;
default:
@@ -104,16 +133,16 @@ Cfg *mkcfg(Node **nl, size_t nn)
break;
}
if (a) {
- targ = htget(cfg->lblmap, a->lbl.name);
+ targ = htget(cfg->lblmap, lblstr(a));
if (!targ)
- die("No bb with label %s", a->lbl.name);
+ die("No bb with label %s", lblstr(a));
bsput(bb->succ, targ->id);
bsput(targ->pred, bb->id);
}
if (b) {
- targ = htget(cfg->lblmap, b->lbl.name);
+ targ = htget(cfg->lblmap, lblstr(b));
if (!targ)
- die("No bb with label %s", b->lbl.name);
+ die("No bb with label %s", lblstr(b));
bsput(bb->succ, targ->id);
bsput(targ->pred, bb->id);
}