diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 19:03:46 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 19:03:46 -0400 |
commit | 4b1eac841bef8451be90e0b61d5574c418d073b6 (patch) | |
tree | dfb7c90cc904c51f894455a6a75c096f2db7904f | |
parent | c1417b4df5bad7e0c0c8186641af52a965e7f705 (diff) |
Also move graph dumping there
-rw-r--r-- | ast.h | 1 | ||||
-rw-r--r-- | dump-tree.c | 140 | ||||
-rw-r--r-- | main.c | 137 |
3 files changed, 141 insertions, 137 deletions
@@ -1473,3 +1473,4 @@ void interpret (ast_t *ast); void dump_program (ast_program_t *program); void dump_type_spec (ast_type_spec_t *type_spec); void dump_tokens (token_t *tokens); +void dump_graph (ast_program_t *program); diff --git a/dump-tree.c b/dump-tree.c index ccfc31c..8c60bb1 100644 --- a/dump-tree.c +++ b/dump-tree.c @@ -489,3 +489,143 @@ dump_program (ast_program_t *program) dump_statement (program->statement); g_print ("\n"); } + + + +static void +real_dump_graph (node_t *node) +{ + while (node) + { + const char *text; + + switch (node->common.type) + { + case NODE_GOTO: + g_print ("%p goto %p\n", node, node->goto_.label); + break; + case NODE_DYN_GOTO: + g_print (" dyn goto\n"); + break; + case NODE_DYN_LABEL: + g_print ("%p dyn label (%p)\n", node, + node->dyn_label.label); + break; + case NODE_IF: + if (node->if_.sense) + text = "if_true"; + else + text = "if_false"; + + g_print (" %s -> %p\n", text, node->if_.taken); + break; + case NODE_BINOP: + g_print (" binop\n"); + break; + case NODE_PROLOG: + g_print (" prolog\n"); + break; + case NODE_FUN_REF: + g_print (" fun_ref\n"); + break; + case NODE_UNARY: + g_print (" unary op\n"); + break; + case NODE_LITERAL: + g_print (" literal %s\n", + value_to_string (&node->literal.value, + node->literal.type_spec)); + break; + case NODE_PRINT: + g_print (" print\n"); + break; + case NODE_TO_STRING: + g_print (" to_string\n"); + break; + case NODE_POP: + g_print (" pop\n"); + break; + case NODE_DUP: + g_print (" dup\n"); + break; + case NODE_RETURN: + g_print (" return\n"); + break; + case NODE_STORE: + g_print (" store %s\n", node->store.definition->name); + break; + case NODE_STORE_IND: + g_print (" store_ind\n"); + break; + case NODE_STORE_ARRAY: + g_print (" store_array\n"); + break; + case NODE_LOAD: + g_print ("%p load %s\n", node, node->load.definition->name); + break; + case NODE_LOAD_IND: + g_print (" load_ind\n"); + break; + case NODE_LOAD_ARRAY: + g_print ("%p load_array\n", node); + break; + case NODE_NOP: + g_print ("%p nop\n", node); + break; + case NODE_INIT: + g_print (" init\n"); + break; + case NODE_LABEL: + g_print ("%p label", node); + if (ast_is (node->common.ast, AST_STATEMENT, AST_LABEL_STATEMENT)) + g_print (" [%s]", node->common.ast->statement.label.label); + g_print ("\n"); + break; + case NODE_CALL: + g_print (" call\n"); + break; + case NODE_CLOSURE: + g_print (" closure (%s)\n", + node->closure.function->name); + break; + case NODE_DYN_CLOSURE: + g_print (" dyn_closure (%s)\n", + node->dyn_closure.function->name); + break; + case NODE_NEW: + g_print (" new %s\n", node->new.class->name); + break; + case NODE_NEW_ARRAY: + g_print (" new "); + dump_type_spec ((ast_type_spec_t *)node->new_array.array); + g_print ("\n"); + break; + case NODE_THIS: + g_print (" this\n"); + break; + } + + node = node->common.next; + } +} + +void +dump_graph (ast_program_t *program) +{ + int i; + + g_print ("\nGraph:\n"); + + g_print ("*** main:\n"); + real_dump_graph (program->enter); + + for (i = 0; program->functions[i] != NULL; ++i) + { + ast_function_definition_t *function = program->functions[i]; + + g_print ("\n*** %s:\n", function->name); + + real_dump_graph (function->enter); + } +} + @@ -20,143 +20,6 @@ #include <glib.h> #include "ast.h" -void -real_dump_graph (node_t *node) -{ - while (node) - { - const char *text; - - switch (node->common.type) - { - case NODE_GOTO: - g_print ("%p goto %p\n", node, node->goto_.label); - break; - case NODE_DYN_GOTO: - g_print (" dyn goto\n"); - break; - case NODE_DYN_LABEL: - g_print ("%p dyn label (%p)\n", node, - node->dyn_label.label); - break; - case NODE_IF: - if (node->if_.sense) - text = "if_true"; - else - text = "if_false"; - - g_print (" %s -> %p\n", text, node->if_.taken); - break; - case NODE_BINOP: - g_print (" binop\n"); - break; - case NODE_PROLOG: - g_print (" prolog\n"); - break; - case NODE_FUN_REF: - g_print (" fun_ref\n"); - break; - case NODE_UNARY: - g_print (" unary op\n"); - break; - case NODE_LITERAL: - g_print (" literal %s\n", - value_to_string (&node->literal.value, - node->literal.type_spec)); - break; - case NODE_PRINT: - g_print (" print\n"); - break; - case NODE_TO_STRING: - g_print (" to_string\n"); - break; - case NODE_POP: - g_print (" pop\n"); - break; - case NODE_DUP: - g_print (" dup\n"); - break; - case NODE_RETURN: - g_print (" return\n"); - break; - case NODE_STORE: - g_print (" store %s\n", node->store.definition->name); - break; - case NODE_STORE_IND: - g_print (" store_ind\n"); - break; - case NODE_STORE_ARRAY: - g_print (" store_array\n"); - break; - case NODE_LOAD: - g_print ("%p load %s\n", node, node->load.definition->name); - break; - case NODE_LOAD_IND: - g_print (" load_ind\n"); - break; - case NODE_LOAD_ARRAY: - g_print ("%p load_array\n", node); - break; - case NODE_NOP: - g_print ("%p nop\n", node); - break; - case NODE_INIT: - g_print (" init\n"); - break; - case NODE_LABEL: - g_print ("%p label", node); - if (ast_is (node->common.ast, AST_STATEMENT, AST_LABEL_STATEMENT)) - g_print (" [%s]", node->common.ast->statement.label.label); - g_print ("\n"); - break; - case NODE_CALL: - g_print (" call\n"); - break; - case NODE_CLOSURE: - g_print (" closure (%s)\n", - node->closure.function->name); - break; - case NODE_DYN_CLOSURE: - g_print (" dyn_closure (%s)\n", - node->dyn_closure.function->name); - break; - case NODE_NEW: - g_print (" new %s\n", node->new.class->name); - break; - case NODE_NEW_ARRAY: - g_print (" new "); - dump_type_spec ((ast_type_spec_t *)node->new_array.array); - g_print ("\n"); - break; - case NODE_THIS: - g_print (" this\n"); - break; - } - - node = node->common.next; - } -} - -void -dump_graph (ast_program_t *program) -{ - int i; - - g_print ("\nGraph:\n"); - - g_print ("*** main:\n"); - real_dump_graph (program->enter); - - for (i = 0; program->functions[i] != NULL; ++i) - { - ast_function_definition_t *function = program->functions[i]; - - g_print ("\n*** %s:\n", function->name); - - real_dump_graph (function->enter); - } -} - static void real_dump (const char *input, gboolean interp) { |