diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-16 22:55:45 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-16 22:55:45 -0400 |
commit | 47fed2c5d43d7689b745640473a6959042284c55 (patch) | |
tree | 0cc08d419a00c69a37c5d190bcf69fd3cdf749c1 | |
parent | 88cc707876ff3299f36e290aa4f691adeb13450a (diff) |
Optimize away literal nodes followed by to_string
-rw-r--r-- | dump-tree.c | 5 | ||||
-rw-r--r-- | examples/switch.nl | 1 | ||||
-rw-r--r-- | optimize.c | 16 |
3 files changed, 18 insertions, 4 deletions
diff --git a/dump-tree.c b/dump-tree.c index 60a8ca8..fbbed7f 100644 --- a/dump-tree.c +++ b/dump-tree.c @@ -477,7 +477,6 @@ dump_type_spec (ast_type_spec_t *type_spec) g_print (")"); g_print (" -> "); dump_type_spec (type_spec->function.return_); - break; } } @@ -490,8 +489,6 @@ dump_program (ast_program_t *program) g_print ("\n"); } - - static void real_dump_graph (node_t *node) { @@ -537,7 +534,7 @@ real_dump_graph (node_t *node) node->literal.type_spec)); break; case NODE_PRINT: - g_print (" print\n"); + g_print (" print %d\n", node->print.n_exprs); break; case NODE_TO_STRING: g_print (" to_string\n"); diff --git a/examples/switch.nl b/examples/switch.nl index ed353af..13e2d17 100644 --- a/examples/switch.nl +++ b/examples/switch.nl @@ -41,6 +41,7 @@ default: break; } +print "asdf", 1234345; print 1234; print !false; print ~123; @@ -440,6 +440,22 @@ peephole (node_t *node, *changed = TRUE; } + else if (node_is (node0, NODE_LITERAL) && + node_is (node1, NODE_TO_STRING)) + { + value_t value; + + value.pointer_val = value_to_string ( + &node0->literal.value, node0->literal.type_spec); + + node_new_literal ( + value, ast_type_spec_new (AST_STRING_TYPE), node1, node0->common.ast); + + nop_node (node0, 0); + nop_node (node1, 0); + + *changed = TRUE; + } node->common.next = peephole (node->common.next, changed); |