2012-05-08 02:44:16 +00:00
|
|
|
/*
|
|
|
|
dot_dag.c
|
|
|
|
|
|
|
|
Output dags to dot (graphvis).
|
|
|
|
|
|
|
|
Copyright (C) 2012 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2012/05/08
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <QF/dstring.h>
|
|
|
|
#include <QF/quakeio.h>
|
|
|
|
#include <QF/va.h>
|
|
|
|
|
|
|
|
#include "dags.h"
|
|
|
|
#include "statements.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "type.h"
|
|
|
|
|
2012-07-16 09:17:30 +00:00
|
|
|
static int print_count;
|
|
|
|
|
2012-05-08 02:44:16 +00:00
|
|
|
static void
|
|
|
|
print_node (dstring_t *dstr, dagnode_t *node)
|
|
|
|
{
|
2012-07-16 09:17:30 +00:00
|
|
|
if (node->print_count == print_count)
|
|
|
|
return;
|
|
|
|
node->print_count = print_count;
|
2012-05-08 13:05:14 +00:00
|
|
|
if (!node->a && (node->b || node->c)) {
|
2012-05-08 02:44:16 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" [label=\"bad node\"];\n", node);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-15 12:09:13 +00:00
|
|
|
if (node->a) {
|
2012-05-08 13:05:14 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=a];\n", node,
|
|
|
|
node->a);
|
2012-07-15 12:09:13 +00:00
|
|
|
print_node (dstr, node->a);
|
|
|
|
}
|
|
|
|
if (node->b) {
|
2012-05-08 13:05:14 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=b];\n", node,
|
|
|
|
node->b);
|
2012-07-15 12:09:13 +00:00
|
|
|
print_node (dstr, node->b);
|
|
|
|
}
|
|
|
|
if (node->c) {
|
2012-05-08 13:05:14 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [label=c];\n", node,
|
|
|
|
node->c);
|
2012-07-15 12:09:13 +00:00
|
|
|
print_node (dstr, node->c);
|
|
|
|
}
|
2012-07-19 02:38:02 +00:00
|
|
|
if (node->next)
|
|
|
|
dasprintf (dstr, " \"dag_%p\" -> \"dag_%p\" [style=dashed];\n", node,
|
|
|
|
node->next);
|
2012-05-08 02:44:16 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" [%slabel=\"%s\"];\n", node,
|
2012-05-08 13:05:14 +00:00
|
|
|
node->a ? "" : "shape=none,", daglabel_string (node->label));
|
2012-05-08 02:44:16 +00:00
|
|
|
if (node->identifiers) {
|
|
|
|
daglabel_t *id;
|
|
|
|
|
2012-07-17 05:01:15 +00:00
|
|
|
dasprintf (dstr, " \"dag_%p\" -> \"dagid_%p\" "
|
|
|
|
"[style=dashed,dir=none];\n", node, node);
|
2012-07-15 12:09:13 +00:00
|
|
|
dasprintf (dstr, " \"dagid_%p\" [shape=none,label=<\n", node);
|
2012-05-08 02:44:16 +00:00
|
|
|
dasprintf (dstr, " <table border=\"0\" cellborder=\"1\" "
|
|
|
|
"cellspacing=\"0\">\n");
|
|
|
|
dasprintf (dstr, " <tr>\n");
|
|
|
|
dasprintf (dstr, " <td>");
|
|
|
|
for (id = node->identifiers; id; id = id->next)
|
|
|
|
dasprintf (dstr, "%s%s", daglabel_string(id), id->next ? " " : "");
|
|
|
|
dasprintf (dstr, " </td>");
|
|
|
|
dasprintf (dstr, " </tr>\n");
|
|
|
|
dasprintf (dstr, " </table>>];\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-18 06:29:30 +00:00
|
|
|
print_dag (dstring_t *dstr, dagnode_t *dag)
|
2012-05-08 02:44:16 +00:00
|
|
|
{
|
2012-07-16 09:17:30 +00:00
|
|
|
print_count++;
|
2012-07-18 07:03:08 +00:00
|
|
|
for (; dag; dag = dag->next)
|
|
|
|
print_node (dstr, dag);
|
2012-05-08 02:44:16 +00:00
|
|
|
}
|