Avoid double-printing dag nodes.

This commit is contained in:
Bill Currie 2012-07-16 18:17:30 +09:00
parent 7b2e426545
commit d9354255a3
2 changed files with 7 additions and 0 deletions

View file

@ -45,6 +45,7 @@ typedef struct daglabel_s {
typedef struct dagnode_s {
struct dagnode_s *next;
int print_count; ///< used to avoid double printing nodes
daglabel_t *label; ///< ident/const if leaf node, or operator
/// \name child nodes
/// All three child nodes will be null if this node is a leaf

View file

@ -48,9 +48,14 @@
#include "symtab.h"
#include "type.h"
static int print_count;
static void
print_node (dstring_t *dstr, dagnode_t *node)
{
if (node->print_count == print_count)
return;
node->print_count = print_count;
if (!node->a && (node->b || node->c)) {
dasprintf (dstr, " \"dag_%p\" [label=\"bad node\"];\n", node);
return;
@ -94,6 +99,7 @@ print_dag (dagnode_t *dag, const char *filename)
{
dstring_t *dstr = dstring_newstr();
print_count++;
dasprintf (dstr, "digraph dag_%p {\n", dag);
dasprintf (dstr, " layout=dot; rankdir=TB;\n");
print_node (dstr, dag);