summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/main.c b/main.c
index f1665e5..d15559c 100644
--- a/main.c
+++ b/main.c
@@ -274,6 +274,10 @@ void parse_unit(Lexer *l) {
/* graph output */
void node_print(Node *n, Proc *p) {
+ if (n->walked) return;
+ const char *colors[] = {
+ "red", "blue", "cyan", "green", "orange", "magenta",
+ };
if (n->type == N_START) {
Str s = S("");
int c = n->val.tuple.len;
@@ -282,27 +286,25 @@ void node_print(Node *n, Proc *p) {
if (i > 0) str_cat(&s, S(", "), &p->arena);
str_cat(&s, type_desc(&v[i].type, &p->arena), &p->arena);
}
- printf("\t%d [label=\"start(%.*s)\"]\n", n->id, (int)s.n, s.s);
+ printf("\t%d [label=\"start(%.*s)\"]", n->id, (int)s.n, s.s);
} else if (n->type == N_LIT) {
switch (n->val.type.t) {
case T_INT:
- printf("\t%d [label=\"%ld\"]\n", n->id, n->val.i);
+ printf("\t%d [label=\"%ld\"]", n->id, n->val.i);
break;
case T_BOOL:
- printf("\t%d [label=\"%s\"]\n", n->id, n->val.i ? "true" : "false");
+ printf("\t%d [label=\"%s\"]", n->id, n->val.i ? "true" : "false");
break;
default:
- printf("\t%d [label=\"literal %d\"]\n", n->id, n->id);
+ printf("\t%d [label=\"literal %d\"]", n->id, n->id);
break;
}
} else if (n->type == N_PROJ) {
- printf("\t%d [label=\"PROJ(%ld)\", shape=record]\n", n->id, n->val.i);
+ printf("\t%d [label=\"PROJ(%ld)\", shape=record]", n->id, n->val.i);
} else {
- printf("\t%d [label=\"%s\", shape=record]\n", n->id, node_type_name(n->type));
- }
- if (n->walked) {
- return;
+ printf("\t%d [label=\"%s\", shape=record]", n->id, node_type_name(n->type));
}
+ printf(" [color=%s]\n", colors[n->id % (sizeof colors / sizeof *colors)]);
n->walked = 1;
for (int i = 0; i < n->out.len; i++) {
Node *o = n->out.data[i];
@@ -311,7 +313,7 @@ void node_print(Node *n, Proc *p) {
} else {
int j;
for (j = 0; j < o->in.len && o->in.data[j] != n; j++);
- printf("\t%d -> %d [label=%d]\n", n->id, o->id, j);
+ printf("\t%d -> %d [color=%s,headlabel=%d]\n", n->id, o->id, colors[o->id % (sizeof colors / sizeof *colors)], j);
}
}
for (int i = 0; i < n->out.len; i++) {