summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-06-16 16:30:42 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-06-16 16:30:42 -0400
commitc684ba9a5564edf5c43ce9bcae56b9b84df340c3 (patch)
treee577595e2cf0741b8709575b683f104469aa363e
parent7109fcbe8eba5fce5055d02e15aa1ba78f51037e (diff)
Only allocate space for variables that are actually used
-rw-r--r--ast.h1
-rw-r--r--offsets.c26
2 files changed, 26 insertions, 1 deletions
diff --git a/ast.h b/ast.h
index 7c6c4b9..d8e8a97 100644
--- a/ast.h
+++ b/ast.h
@@ -935,6 +935,7 @@ struct ast_variable_definition_t
int level;
gboolean field;
+ gboolean used;
};
struct ast_label_definition_t
diff --git a/offsets.c b/offsets.c
index 93ead6f..32f3614 100644
--- a/offsets.c
+++ b/offsets.c
@@ -19,6 +19,27 @@
#include "ast.h"
static void
+mark_used (node_t *node, gpointer data)
+{
+ if (node->common.type == NODE_LOAD)
+ {
+ node->load.definition->used = TRUE;
+ }
+ else if (node->common.type == NODE_STORE)
+ {
+ node->store.definition->used = TRUE;
+ }
+ else if (node->common.type == NODE_LOAD_IND)
+ {
+ node->load_ind.definition->used = TRUE;
+ }
+ else if (node->common.type == NODE_STORE_IND)
+ {
+ node->store_ind.definition->used = TRUE;
+ }
+}
+
+static void
list_def (gpointer key, gpointer value, gpointer data)
{
GPtrArray *array = data;
@@ -38,7 +59,8 @@ assign_offsets (symbol_table_t *symbols, int offset, int *max)
{
ast_definition_t *definition = definitions->pdata[i];
- if (definition->common.type == AST_VARIABLE_DEFINITION)
+ if (definition->common.type == AST_VARIABLE_DEFINITION &&
+ definition->variable.used)
{
int size = ast_type_spec_get_size (definition->variable.type_spec);
@@ -123,6 +145,8 @@ do_offsets (ast_t *ast, int offset, int *max)
gboolean
offsets (ast_t *ast)
{
+ node_breadth_first (ast->program.enter, mark_used, NULL);
+
do_offsets (ast, 0, NULL);
/* The offsets pass can never fail */