[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 <acme@mandriva.com>
This commit is contained in:
parent
460c5d91f4
commit
6a3cc448d1
42
classes.c
42
classes.c
|
@ -600,10 +600,10 @@ static struct function *function__new(uint64_t id, uint64_t type,
|
||||||
tag__init(&self->tag, DW_TAG_subprogram,
|
tag__init(&self->tag, DW_TAG_subprogram,
|
||||||
id, type, decl_file, decl_line);
|
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->parameters);
|
||||||
INIT_LIST_HEAD(&self->variables);
|
INIT_LIST_HEAD(&self->lexblock.variables);
|
||||||
INIT_LIST_HEAD(&self->inline_expansions);
|
INIT_LIST_HEAD(&self->lexblock.inline_expansions);
|
||||||
|
|
||||||
self->name = strings__add(name);
|
self->name = strings__add(name);
|
||||||
self->inlined = inlined;
|
self->inlined = inlined;
|
||||||
|
@ -626,22 +626,22 @@ static void function__add_parameter(struct function *self,
|
||||||
static void function__add_inline_expansion(struct function *self,
|
static void function__add_inline_expansion(struct function *self,
|
||||||
struct inline_expansion *exp)
|
struct inline_expansion *exp)
|
||||||
{
|
{
|
||||||
++self->nr_inline_expansions;
|
++self->lexblock.nr_inline_expansions;
|
||||||
exp->function = self;
|
exp->function = self;
|
||||||
self->size_inline_expansions += exp->size;
|
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)
|
static void function__add_variable(struct function *self, struct variable *var)
|
||||||
{
|
{
|
||||||
++self->nr_variables;
|
++self->lexblock.nr_variables;
|
||||||
list_add_tail(&var->tag.node, &self->variables);
|
list_add_tail(&var->tag.node, &self->lexblock.variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void function__add_label(struct function *self, struct label *label)
|
static void function__add_label(struct function *self, struct label *label)
|
||||||
{
|
{
|
||||||
++self->nr_labels;
|
++self->lexblock.nr_labels;
|
||||||
list_add_tail(&label->tag.node, &self->labels);
|
list_add_tail(&label->tag.node, &self->lexblock.labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void class__find_holes(struct class *self)
|
void class__find_holes(struct class *self)
|
||||||
|
@ -706,10 +706,10 @@ static void function__account_inline_expansions(struct function *self)
|
||||||
struct function *type;
|
struct function *type;
|
||||||
struct inline_expansion *pos;
|
struct inline_expansion *pos;
|
||||||
|
|
||||||
if (self->nr_inline_expansions == 0)
|
if (self->lexblock.nr_inline_expansions == 0)
|
||||||
return;
|
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);
|
type = cu__find_function_by_id(self->cu, pos->tag.type);
|
||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
type->cu_total_nr_inline_expansions++;
|
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) {
|
list_for_each_entry(pos, &self->functions, tag.node) {
|
||||||
function__account_inline_expansions(pos);
|
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;
|
self->size_inline_expansions += pos->size_inline_expansions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -808,21 +808,21 @@ static void function__print_body(const struct function *self,
|
||||||
struct tag *pos;
|
struct tag *pos;
|
||||||
|
|
||||||
if (show_variables)
|
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 */
|
/* FIXME! this test shouln't be needed at all */
|
||||||
if (pos->decl_line >= self->tag.decl_line)
|
if (pos->decl_line >= self->tag.decl_line)
|
||||||
tags__add(&tags, pos);
|
tags__add(&tags, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_inline_expansions)
|
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 */
|
/* FIXME! this test shouln't be needed at all */
|
||||||
if (pos->decl_line >= self->tag.decl_line)
|
if (pos->decl_line >= self->tag.decl_line)
|
||||||
tags__add(&tags, pos);
|
tags__add(&tags, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_labels)
|
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 */
|
/* FIXME! this test shouln't be needed at all */
|
||||||
if (pos->decl_line >= self->tag.decl_line)
|
if (pos->decl_line >= self->tag.decl_line)
|
||||||
tags__add(&tags, pos);
|
tags__add(&tags, pos);
|
||||||
|
@ -881,13 +881,13 @@ void function__print(const struct function *self, int show_stats,
|
||||||
|
|
||||||
if (show_stats) {
|
if (show_stats) {
|
||||||
printf("/* size: %llu", self->high_pc - self->low_pc);
|
printf("/* size: %llu", self->high_pc - self->low_pc);
|
||||||
if (self->nr_variables > 0)
|
if (self->lexblock.nr_variables > 0)
|
||||||
printf(", variables: %u", self->nr_variables);
|
printf(", variables: %u", self->lexblock.nr_variables);
|
||||||
if (self->nr_labels > 0)
|
if (self->lexblock.nr_labels > 0)
|
||||||
printf(", goto labels: %u", self->nr_labels);
|
printf(", goto labels: %u", self->lexblock.nr_labels);
|
||||||
if (self->nr_inline_expansions > 0)
|
if (self->lexblock.nr_inline_expansions > 0)
|
||||||
printf(", inline expansions: %u (%u bytes)",
|
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);
|
fputs(" */\n\n", stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
classes.h
16
classes.h
|
@ -72,21 +72,25 @@ struct class_member {
|
||||||
one (or the end of the struct) */
|
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 function {
|
||||||
struct tag tag;
|
struct tag tag;
|
||||||
struct cu *cu;
|
struct cu *cu;
|
||||||
|
struct lexblock lexblock;
|
||||||
struct list_head parameters;
|
struct list_head parameters;
|
||||||
struct list_head inline_expansions;
|
|
||||||
struct list_head variables;
|
|
||||||
struct list_head labels;
|
|
||||||
const char *name;
|
const char *name;
|
||||||
uint64_t low_pc;
|
uint64_t low_pc;
|
||||||
uint64_t high_pc;
|
uint64_t high_pc;
|
||||||
unsigned short nr_parameters;
|
unsigned short nr_parameters;
|
||||||
unsigned short nr_labels;
|
|
||||||
unsigned short nr_variables;
|
|
||||||
unsigned short inlined;
|
unsigned short inlined;
|
||||||
unsigned short nr_inline_expansions;
|
|
||||||
unsigned char external:1;
|
unsigned char external:1;
|
||||||
unsigned char unspecified_parameters;
|
unsigned char unspecified_parameters;
|
||||||
unsigned int refcnt;
|
unsigned int refcnt;
|
||||||
|
|
12
pfunct.c
12
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)
|
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 ?: "",
|
printf("%s: %u\n", function->name ?: "",
|
||||||
function->nr_variables);
|
function->lexblock.nr_variables);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ static int goto_labels_iterator(struct function *function, void *cookie)
|
||||||
if (function->inlined)
|
if (function->inlined)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (function->nr_labels > 0)
|
if (function->lexblock.nr_labels > 0)
|
||||||
printf("%s: %u\n", function->name ?: "", function->nr_labels);
|
printf("%s: %u\n", function->name ?: "", function->lexblock.nr_labels);
|
||||||
return 0;
|
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)
|
static int function_iterator(struct function *function, void *cookie)
|
||||||
{
|
{
|
||||||
if (cookie == NULL) {
|
if (cookie == NULL) {
|
||||||
if (function->nr_inline_expansions > 0)
|
if (function->lexblock.nr_inline_expansions > 0)
|
||||||
printf("%s: %u %u\n", function->name ?: "",
|
printf("%s: %u %u\n", function->name ?: "",
|
||||||
function->nr_inline_expansions,
|
function->lexblock.nr_inline_expansions,
|
||||||
function->size_inline_expansions);
|
function->size_inline_expansions);
|
||||||
} else if (function->name != NULL &&
|
} else if (function->name != NULL &&
|
||||||
strcmp(function->name, cookie) == 0) {
|
strcmp(function->name, cookie) == 0) {
|
||||||
|
|
|
@ -103,10 +103,10 @@ static void refcnt_function(struct function *function)
|
||||||
list_for_each_entry(parameter, &function->parameters, tag.node)
|
list_for_each_entry(parameter, &function->parameters, tag.node)
|
||||||
refcnt_parameter(parameter);
|
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);
|
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);
|
refcnt_inline_expansion(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue