From dbf1aa8f722cf2b47675c474a624612367e07466 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 18 Jul 2012 15:29:30 +0900 Subject: [PATCH] Attach dags to statement blocks. Now, if a dag is attached to a statement block, it will be included in the flowgraph with that statement block. --- tools/qfcc/include/dags.h | 3 ++- tools/qfcc/include/options.h | 1 + tools/qfcc/include/statements.h | 1 + tools/qfcc/source/dot_dag.c | 18 +----------------- tools/qfcc/source/dot_flow.c | 5 +++++ tools/qfcc/source/options.c | 3 +++ tools/qfcc/source/statements.c | 8 ++++---- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tools/qfcc/include/dags.h b/tools/qfcc/include/dags.h index 72b1e562d..4dedab1c4 100644 --- a/tools/qfcc/include/dags.h +++ b/tools/qfcc/include/dags.h @@ -64,7 +64,8 @@ typedef struct dagnode_s { } dagnode_t; const char *daglabel_string (daglabel_t *label); -void print_dag (dagnode_t *node, const char *filename); +struct dstring_s; +void print_dag (struct dstring_s *dstr, dagnode_t *node); struct sblock_s; /** Make a dag for a single basic block. diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index 4dc5e0bd6..9b244bee8 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -72,6 +72,7 @@ typedef struct { qboolean thread; qboolean dead; qboolean final; + qboolean dags; } blockdot_options_t; typedef struct { diff --git a/tools/qfcc/include/statements.h b/tools/qfcc/include/statements.h index 084fcb886..da4479a06 100644 --- a/tools/qfcc/include/statements.h +++ b/tools/qfcc/include/statements.h @@ -74,6 +74,7 @@ typedef struct sblock_s { struct sblock_s *next; struct reloc_s *relocs; struct ex_label_s *labels; + struct dagnode_s *dag; int offset; ///< offset of first statement of block int reachable; statement_t *statements; diff --git a/tools/qfcc/source/dot_dag.c b/tools/qfcc/source/dot_dag.c index c536dca93..67bdcf4ad 100644 --- a/tools/qfcc/source/dot_dag.c +++ b/tools/qfcc/source/dot_dag.c @@ -96,24 +96,8 @@ print_node (dstring_t *dstr, dagnode_t *node) } void -print_dag (dagnode_t *dag, const char *filename) +print_dag (dstring_t *dstr, dagnode_t *dag) { - 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); - dasprintf (dstr, "}\n"); - - if (filename) { - QFile *file; - - file = Qopen (filename, "wt"); - Qwrite (file, dstr->str, dstr->size - 1); - Qclose (file); - } else { - fputs (dstr->str, stdout); - } - dstring_delete (dstr); } diff --git a/tools/qfcc/source/dot_flow.c b/tools/qfcc/source/dot_flow.c index 76245de55..8be766069 100644 --- a/tools/qfcc/source/dot_flow.c +++ b/tools/qfcc/source/dot_flow.c @@ -43,6 +43,7 @@ #include #include +#include "dags.h" #include "expr.h" #include "statements.h" #include "strpool.h" @@ -95,6 +96,10 @@ flow_sblock (dstring_t *dstr, sblock_t *sblock, int blockno) sblock_t *target; ex_label_t *l; + if (sblock->dag) { + dasprintf (dstr, " sb_%p -> dag_%p;", sblock, sblock->dag); + print_dag (dstr, sblock->dag); + } dasprintf (dstr, " sb_%p [shape=none,label=<\n", sblock); dasprintf (dstr, " \n"); diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index ce00efd01..1811b9ebb 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -389,6 +389,8 @@ DecodeArgs (int argc, char **argv) options.block_dot.dead = flag; } else if (!(strcasecmp (temp, "final"))) { options.block_dot.final = flag; + } else if (!(strcasecmp (temp, "dags"))) { + options.block_dot.dags = flag; } temp = strtok (NULL, ","); } @@ -398,6 +400,7 @@ DecodeArgs (int argc, char **argv) options.block_dot.thread = true; options.block_dot.dead = true; options.block_dot.final = true; + options.block_dot.dags = true; } break; case 'c': diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index ab3216f96..484aab16b 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -1411,9 +1411,9 @@ make_statements (expr_t *e) if (options.block_dot.final) dump_flow (sblock, "final"); - for (s = sblock; s; s = s->next) { - dagnode_t *dag = make_dag (s); - print_dag (dag, 0); - } + for (s = sblock; s; s = s->next) + s->dag = make_dag (s); + if (options.block_dot.dags) + dump_flow (sblock, "dags"); return sblock; }