summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-06-15 10:33:58 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-06-15 10:33:58 -0400
commit162ffd529a3316416b91f8c1db92fbea93b027fe (patch)
treeabaa08aa5865901f5b2b05f393e03b40df8d0738
parenta109f716fd8c002a3b5f1d4dd04050faed91d218 (diff)
Do debug spew from within compile().
Dump the goto graph after optimization if debug_spew is turned on.
-rw-r--r--ast.h3
-rw-r--r--internal-tests.c4
-rw-r--r--main.c28
3 files changed, 23 insertions, 12 deletions
diff --git a/ast.h b/ast.h
index ad532d1..7c6c4b9 100644
--- a/ast.h
+++ b/ast.h
@@ -1472,7 +1472,8 @@ void interpret (ast_t *ast);
/* Driver */
ast_t * compile (const char *input,
- gboolean do_optimize);
+ gboolean do_optimize,
+ gboolean debug_spew);
/* Debug spew */
void dump_program (ast_program_t *program);
diff --git a/internal-tests.c b/internal-tests.c
index e91de00..b027fef 100644
--- a/internal-tests.c
+++ b/internal-tests.c
@@ -25,7 +25,7 @@ interp (const char *data)
{
ast_t *ast;
- if ((ast = compile (data, TRUE)))
+ if ((ast = compile (data, TRUE, TRUE)))
interpret (ast);
}
@@ -34,7 +34,7 @@ dump (const char *data)
{
ast_t *ast;
- if ((ast = compile (data, TRUE)))
+ if ((ast = compile (data, TRUE, TRUE)))
dump_program (&ast->program);
}
diff --git a/main.c b/main.c
index 8ab9f25..61bf10a 100644
--- a/main.c
+++ b/main.c
@@ -23,7 +23,7 @@
#include "ast.h"
ast_t *
-compile (const char *input, gboolean do_optimize)
+compile (const char *input, gboolean do_optimize, gboolean debug_spew)
{
token_t *tokens;
ast_t *ast;
@@ -34,6 +34,9 @@ compile (const char *input, gboolean do_optimize)
if (!(ast = parse (tokens)))
return NULL;
+ if (debug_spew)
+ dump_program (&ast->program);
+
if (!prepare (ast))
return NULL;
@@ -51,6 +54,9 @@ compile (const char *input, gboolean do_optimize)
if (!graph (ast))
return NULL;
+
+ if (debug_spew)
+ dump_graph (&ast->program);
if (!init_check (ast))
return NULL;
@@ -61,8 +67,17 @@ compile (const char *input, gboolean do_optimize)
if (!levels (ast))
return NULL;
- if (do_optimize && !optimize (ast))
- return NULL;
+ if (do_optimize)
+ {
+ if (!optimize (ast))
+ return NULL;
+
+ if (debug_spew)
+ {
+ g_print ("-=-=-=-=- Graph after optimization -=-=-=-=-=- \n");
+ dump_graph (&ast->program);
+ }
+ }
if (!offsets (ast))
return NULL;
@@ -131,13 +146,8 @@ main (int argc, char **argv)
{
ast_t *ast;
- if ((ast = compile (contents, optimize)))
+ if ((ast = compile (contents, optimize, debug_spew)))
{
- if (debug_spew)
- {
- dump_program (&ast->program);
- dump_graph (&ast->program);
- }
interpret (ast);
}
}