From 6a3cc448d111bde8802eca3c5b453f31769bd7c7 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 20 Nov 2006 16:38:47 -0200 Subject: [PATCH] [CLASSES]: Introduce struct lexblock To represent DW_TAG_lexical_block, for now just group the lists of labels, inline expansions and variables, struct function now has the root of the tree as ->lexblock. Signed-off-by: Arnaldo Carvalho de Melo --- classes.c | 42 +++++++++++++++++++++--------------------- classes.h | 16 ++++++++++------ pfunct.c | 12 ++++++------ prefcnt.c | 4 ++-- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/classes.c b/classes.c index 25b8272..7022bce 100644 --- a/classes.c +++ b/classes.c @@ -600,10 +600,10 @@ static struct function *function__new(uint64_t id, uint64_t type, tag__init(&self->tag, DW_TAG_subprogram, id, type, decl_file, decl_line); - INIT_LIST_HEAD(&self->labels); + INIT_LIST_HEAD(&self->lexblock.labels); INIT_LIST_HEAD(&self->parameters); - INIT_LIST_HEAD(&self->variables); - INIT_LIST_HEAD(&self->inline_expansions); + INIT_LIST_HEAD(&self->lexblock.variables); + INIT_LIST_HEAD(&self->lexblock.inline_expansions); self->name = strings__add(name); self->inlined = inlined; @@ -626,22 +626,22 @@ static void function__add_parameter(struct function *self, static void function__add_inline_expansion(struct function *self, struct inline_expansion *exp) { - ++self->nr_inline_expansions; + ++self->lexblock.nr_inline_expansions; exp->function = self; self->size_inline_expansions += exp->size; - list_add_tail(&exp->tag.node, &self->inline_expansions); + list_add_tail(&exp->tag.node, &self->lexblock.inline_expansions); } static void function__add_variable(struct function *self, struct variable *var) { - ++self->nr_variables; - list_add_tail(&var->tag.node, &self->variables); + ++self->lexblock.nr_variables; + list_add_tail(&var->tag.node, &self->lexblock.variables); } static void function__add_label(struct function *self, struct label *label) { - ++self->nr_labels; - list_add_tail(&label->tag.node, &self->labels); + ++self->lexblock.nr_labels; + list_add_tail(&label->tag.node, &self->lexblock.labels); } void class__find_holes(struct class *self) @@ -706,10 +706,10 @@ static void function__account_inline_expansions(struct function *self) struct function *type; struct inline_expansion *pos; - if (self->nr_inline_expansions == 0) + if (self->lexblock.nr_inline_expansions == 0) return; - list_for_each_entry(pos, &self->inline_expansions, tag.node) { + list_for_each_entry(pos, &self->lexblock.inline_expansions, tag.node) { type = cu__find_function_by_id(self->cu, pos->tag.type); if (type != NULL) { type->cu_total_nr_inline_expansions++; @@ -725,7 +725,7 @@ void cu__account_inline_expansions(struct cu *self) list_for_each_entry(pos, &self->functions, tag.node) { function__account_inline_expansions(pos); - self->nr_inline_expansions += pos->nr_inline_expansions; + self->nr_inline_expansions += pos->lexblock.nr_inline_expansions; self->size_inline_expansions += pos->size_inline_expansions; } } @@ -808,21 +808,21 @@ static void function__print_body(const struct function *self, struct tag *pos; if (show_variables) - list_for_each_entry(pos, &self->variables, node) { + list_for_each_entry(pos, &self->lexblock.variables, node) { /* FIXME! this test shouln't be needed at all */ if (pos->decl_line >= self->tag.decl_line) tags__add(&tags, pos); } if (show_inline_expansions) - list_for_each_entry(pos, &self->inline_expansions, node) { + list_for_each_entry(pos, &self->lexblock.inline_expansions, node) { /* FIXME! this test shouln't be needed at all */ if (pos->decl_line >= self->tag.decl_line) tags__add(&tags, pos); } if (show_labels) - list_for_each_entry(pos, &self->labels, node) { + list_for_each_entry(pos, &self->lexblock.labels, node) { /* FIXME! this test shouln't be needed at all */ if (pos->decl_line >= self->tag.decl_line) tags__add(&tags, pos); @@ -881,13 +881,13 @@ void function__print(const struct function *self, int show_stats, if (show_stats) { printf("/* size: %llu", self->high_pc - self->low_pc); - if (self->nr_variables > 0) - printf(", variables: %u", self->nr_variables); - if (self->nr_labels > 0) - printf(", goto labels: %u", self->nr_labels); - if (self->nr_inline_expansions > 0) + if (self->lexblock.nr_variables > 0) + printf(", variables: %u", self->lexblock.nr_variables); + if (self->lexblock.nr_labels > 0) + printf(", goto labels: %u", self->lexblock.nr_labels); + if (self->lexblock.nr_inline_expansions > 0) printf(", inline expansions: %u (%u bytes)", - self->nr_inline_expansions, self->size_inline_expansions); + self->lexblock.nr_inline_expansions, self->size_inline_expansions); fputs(" */\n\n", stdout); } } diff --git a/classes.h b/classes.h index 4e6c071..336631f 100644 --- a/classes.h +++ b/classes.h @@ -72,21 +72,25 @@ struct class_member { one (or the end of the struct) */ }; +struct lexblock { + struct list_head inline_expansions; + struct list_head labels; + struct list_head variables; + unsigned short nr_inline_expansions; + unsigned short nr_labels; + unsigned short nr_variables; +}; + struct function { struct tag tag; struct cu *cu; + struct lexblock lexblock; struct list_head parameters; - struct list_head inline_expansions; - struct list_head variables; - struct list_head labels; const char *name; uint64_t low_pc; uint64_t high_pc; unsigned short nr_parameters; - unsigned short nr_labels; - unsigned short nr_variables; unsigned short inlined; - unsigned short nr_inline_expansions; unsigned char external:1; unsigned char unspecified_parameters; unsigned int refcnt; diff --git a/pfunct.c b/pfunct.c index 8db8ca8..f9ebec1 100644 --- a/pfunct.c +++ b/pfunct.c @@ -202,9 +202,9 @@ static int cu_externals_iterator(struct cu *cu, void *cookie) static int variables_iterator(struct function *function, void *cookie) { - if (function->nr_variables > 0) + if (function->lexblock.nr_variables > 0) printf("%s: %u\n", function->name ?: "", - function->nr_variables); + function->lexblock.nr_variables); return 0; } @@ -218,8 +218,8 @@ static int goto_labels_iterator(struct function *function, void *cookie) if (function->inlined) return 0; - if (function->nr_labels > 0) - printf("%s: %u\n", function->name ?: "", function->nr_labels); + if (function->lexblock.nr_labels > 0) + printf("%s: %u\n", function->name ?: "", function->lexblock.nr_labels); return 0; } @@ -231,9 +231,9 @@ static int cu_goto_labels_iterator(struct cu *cu, void *cookie) static int function_iterator(struct function *function, void *cookie) { if (cookie == NULL) { - if (function->nr_inline_expansions > 0) + if (function->lexblock.nr_inline_expansions > 0) printf("%s: %u %u\n", function->name ?: "", - function->nr_inline_expansions, + function->lexblock.nr_inline_expansions, function->size_inline_expansions); } else if (function->name != NULL && strcmp(function->name, cookie) == 0) { diff --git a/prefcnt.c b/prefcnt.c index 2e919c4..08829df 100644 --- a/prefcnt.c +++ b/prefcnt.c @@ -103,10 +103,10 @@ static void refcnt_function(struct function *function) list_for_each_entry(parameter, &function->parameters, tag.node) refcnt_parameter(parameter); - list_for_each_entry(variable, &function->variables, tag.node) + list_for_each_entry(variable, &function->lexblock.variables, tag.node) refcnt_variable(variable); - list_for_each_entry(exp, &function->inline_expansions, tag.node) + list_for_each_entry(exp, &function->lexblock.inline_expansions, tag.node) refcnt_inline_expansion(exp); }