Produce tidier dag dumps.

This commit is contained in:
Bill Currie 2012-11-06 21:50:29 +09:00
parent 04a8e19481
commit 783b4082a1
2 changed files with 59 additions and 16 deletions

View File

@ -50,40 +50,79 @@
static int print_count; static int print_count;
static void
print_node_def (dstring_t *dstr, dagnode_t *node, int recurse)
{
if (!node->a && (node->b || node->c)) {
dasprintf (dstr, " \"dagnode_%p\" [label=\"bad node\"];\n", node);
return;
}
dasprintf (dstr, " \"dagnode_%p\" [%slabel=\"%s\"];\n", node,
node->a ? "" : "shape=none,", daglabel_string (node->label));
if (recurse) {
if (node->a)
print_node_def (dstr, node->a, 1);
if (node->b)
print_node_def (dstr, node->b, 1);
if (node->c)
print_node_def (dstr, node->c, 1);
}
}
static void
print_root_nodes (dstring_t *dstr, dagnode_t *dag)
{
dasprintf (dstr, " subgraph roots_%p {", dag);
dasprintf (dstr, " rank=same;");
for (; dag; dag = dag->next)
print_node_def (dstr, dag, 0);
dasprintf (dstr, " }\n");
}
static void
print_child_nodes (dstring_t *dstr, dagnode_t *dag)
{
for (; dag; dag = dag->next) {
if (!dag->a && (dag->b || dag->c))
continue;
if (dag->a)
print_node_def (dstr, dag->a, 1);
if (dag->b)
print_node_def (dstr, dag->b, 1);
if (dag->c)
print_node_def (dstr, dag->c, 1);
}
}
static void static void
print_node (dstring_t *dstr, dagnode_t *node) print_node (dstring_t *dstr, dagnode_t *node)
{ {
if (node->print_count == print_count) if (node->print_count == print_count)
return; return;
node->print_count = print_count; node->print_count = print_count;
if (!node->a && (node->b || node->c)) {
dasprintf (dstr, " \"dag_%p\" [label=\"bad node\"];\n", node);
return;
}
if (node->a) { if (node->a) {
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=a];\n", node, dasprintf (dstr, " \"dagnode_%p\" -> \"dagnode_%p\" [label=a];\n",
node->a); node, node->a);
print_node (dstr, node->a); print_node (dstr, node->a);
} }
if (node->b) { if (node->b) {
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=b];\n", node, dasprintf (dstr, " \"dagnode_%p\" -> \"dagnode_%p\" [label=b];\n",
node->b); node, node->b);
print_node (dstr, node->b); print_node (dstr, node->b);
} }
if (node->c) { if (node->c) {
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=c];\n", node, dasprintf (dstr, " \"dagnode_%p\" -> \"dagnode_%p\" [label=c];\n",
node->c); node, node->c);
print_node (dstr, node->c); print_node (dstr, node->c);
} }
if (node->next) if (node->next)
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [style=dashed];\n", node, dasprintf (dstr,
node->next); " \"dagnode_%p\" -> \"dagnode_%p\" [style=dashed];\n",
dasprintf (dstr, " \"dag_%p\" [%slabel=\"%s\"];\n", node, node, node->next);
node->a ? "" : "shape=none,", daglabel_string (node->label));
if (node->identifiers) { if (node->identifiers) {
daglabel_t *id; daglabel_t *id;
dasprintf (dstr, " \"dag_%p\" -> \"dagid_%p\" " dasprintf (dstr, " \"dagnode_%p\" -> \"dagid_%p\" "
"[style=dashed,dir=none];\n", node, node); "[style=dashed,dir=none];\n", node, node);
dasprintf (dstr, " \"dagid_%p\" [shape=none,label=<\n", node); dasprintf (dstr, " \"dagid_%p\" [shape=none,label=<\n", node);
dasprintf (dstr, " <table border=\"0\" cellborder=\"1\" " dasprintf (dstr, " <table border=\"0\" cellborder=\"1\" "
@ -101,7 +140,11 @@ print_node (dstring_t *dstr, dagnode_t *node)
void void
print_dag (dstring_t *dstr, dagnode_t *dag) print_dag (dstring_t *dstr, dagnode_t *dag)
{ {
dasprintf (dstr, " subgraph dag_%p {", dag);
print_count++; print_count++;
print_root_nodes (dstr, dag);
print_child_nodes (dstr, dag);
for (; dag; dag = dag->next) for (; dag; dag = dag->next)
print_node (dstr, dag); print_node (dstr, dag);
dasprintf (dstr, " }\n");
} }

View File

@ -74,7 +74,7 @@ flow_sblock (dstring_t *dstr, sblock_t *sblock, int blockno)
ex_label_t *l; ex_label_t *l;
if (sblock->dag) { if (sblock->dag) {
dasprintf (dstr, " sb_%p -> dag_%p;", sblock, sblock->dag); dasprintf (dstr, " sb_%p -> dagnode_%p;", sblock, sblock->dag);
print_dag (dstr, sblock->dag); print_dag (dstr, sblock->dag);
} }
dasprintf (dstr, " sb_%p [shape=none,label=<\n", sblock); dasprintf (dstr, " sb_%p [shape=none,label=<\n", sblock);