Commit bac025c6 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

tr: Only IR_ENTITY_NORMAL has an initializer now.

parent a1937355
......@@ -387,8 +387,7 @@ static void free_ana_walker(ir_node *node, void *env)
*
* which is sometimes used to anchor functions.
*/
static void add_method_address_inititializer(ir_initializer_t *initializer,
pset *set)
static void add_method_address_inititializer(ir_initializer_t const *const initializer, pset *const set)
{
switch (initializer->kind) {
case IR_INITIALIZER_CONST: {
......@@ -430,8 +429,10 @@ static void add_method_address_inititializer(ir_initializer_t *initializer,
*/
static void add_method_address(ir_entity *ent, pset *set)
{
if (ent->initializer != NULL) {
add_method_address_inititializer(get_entity_initializer(ent), set);
if (get_entity_kind(ent) == IR_ENTITY_NORMAL) {
ir_initializer_t const *const init = get_entity_initializer(ent);
if (init)
add_method_address_inititializer(init, set);
}
}
......
......@@ -773,8 +773,10 @@ static void check_initializer_nodes(ir_initializer_t *initializer)
*/
static void check_initializer(ir_entity *ent)
{
if (ent->initializer != NULL) {
check_initializer_nodes(ent->initializer);
if (get_entity_kind(ent) == IR_ENTITY_NORMAL) {
ir_initializer_t *const init = get_entity_initializer(ent);
if (init != NULL)
check_initializer_nodes(init);
}
}
......
......@@ -374,10 +374,11 @@ static bool entity_is_string_const(const ir_entity *ent, bool only_suffix_null)
if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
return false;
if (ent->initializer == NULL)
ir_initializer_t const *const init = get_entity_initializer(ent);
if (!init)
return false;
return initializer_is_string_const(ent->initializer, only_suffix_null);
return initializer_is_string_const(init, only_suffix_null);
}
static bool entity_is_null(const ir_entity *entity)
......@@ -1087,7 +1088,7 @@ static void emit_node_data(be_gas_decl_env_t *env, ir_node *init, ir_type *type)
static void emit_initializer(be_gas_decl_env_t *env, const ir_entity *entity)
{
const ir_initializer_t *initializer = entity->initializer;
ir_initializer_t const *const initializer = get_entity_initializer(entity);
if (initializer_is_string_const(initializer, false)) {
emit_string_initializer(initializer);
return;
......@@ -1444,7 +1445,6 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
be_emit_write_line();
}
} else {
assert(entity->initializer != NULL);
emit_initializer(env, entity);
}
}
......
......@@ -1474,16 +1474,6 @@ static void dump_entity_node(FILE *F, ir_entity *ent)
fprintf(F, "}\n");
}
/**
* Dumps a new style initializer.
*/
static void dump_entity_initializer(FILE *F, const ir_entity *ent)
{
/* TODO */
(void)F;
(void)ent;
}
/**
* type-walker: Dumps a type or entity and its edges.
*/
......@@ -1504,10 +1494,7 @@ static void dump_type_info(ir_type *const tp, ir_entity *const ent, void *const
}
/* attached subgraphs */
if (! (flags & ir_dump_flag_no_entity_values)) {
if (ent->initializer != NULL) {
/* new style initializers */
dump_entity_initializer(F, ent);
}
/* TODO dump initializer */
}
} else {
dump_type_node(F, tp);
......
......@@ -600,12 +600,14 @@ static void dump_entity_to_file_prefix(FILE *const F,
}
if (verbosity & dump_verbosity_entconsts) {
if (ent->initializer != NULL) {
const ir_initializer_t *initializer = get_entity_initializer(ent);
fprintf(F, "\n%s Initializers:", prefix);
need_nl = true;
dump_ir_initializers_to_file(F, prefix, initializer, get_entity_type(ent));
fputc('\n', F);
if (get_entity_kind(ent) == IR_ENTITY_NORMAL) {
ir_initializer_t const *const initializer = get_entity_initializer(ent);
if (initializer) {
fprintf(F, "\n%s Initializers:", prefix);
need_nl = true;
dump_ir_initializers_to_file(F, prefix, initializer, get_entity_type(ent));
fputc('\n', F);
}
}
}
......
......@@ -354,8 +354,10 @@ static void walk_entity(ir_entity *ent, void *env)
{
walk_env *my_env = (walk_env*)env;
if (ent->initializer != NULL) {
walk_initializer(ent->initializer, my_env);
if (get_entity_kind(ent) == IR_ENTITY_NORMAL) {
ir_initializer_t *const init = get_entity_initializer(ent);
if (init)
walk_initializer(init, my_env);
}
}
......
......@@ -484,7 +484,7 @@ static void write_node_ref(write_env_t *env, const ir_node *node)
write_long(env, get_irn_node_nr(node));
}
static void write_initializer(write_env_t *env, ir_initializer_t *ini)
static void write_initializer(write_env_t *const env, ir_initializer_t const *const ini)
{
FILE *f = env->file;
ir_initializer_kind_t ini_kind = get_initializer_kind(ini);
......@@ -752,14 +752,18 @@ static void write_entity(write_env_t *env, ir_entity *ent)
case IR_ENTITY_GOTENTRY:
write_entity_ref(env, ent->attr.got.referenced);
break;
case IR_ENTITY_NORMAL:
if (ent->initializer != NULL) {
case IR_ENTITY_NORMAL: {
ir_initializer_t const *const init = get_entity_initializer(ent);
if (init) {
write_symbol(env, "initializer");
write_initializer(env, get_entity_initializer(ent));
write_initializer(env, init);
} else {
write_symbol(env, "none");
}
break;
}
case IR_ENTITY_COMPOUND_MEMBER:
write_long(env, get_entity_offset(ent));
write_unsigned(env, get_entity_bitfield_offset(ent));
......
......@@ -66,19 +66,29 @@ static void visit_entity(ir_entity *entity)
return;
mark_entity_visited(entity);
if (entity->initializer != NULL) {
visit_initializer(entity->initializer);
switch (get_entity_kind(entity)) {
case IR_ENTITY_NORMAL: {
ir_initializer_t *const init = get_entity_initializer(entity);
if (init)
visit_initializer(init);
break;
}
if (is_method_entity(entity)) {
case IR_ENTITY_METHOD: {
ir_graph *irg = get_entity_irg(entity);
if (irg != NULL)
start_visit_node(get_irg_end(irg));
break;
}
if (is_alias_entity(entity)) {
case IR_ENTITY_ALIAS: {
ir_entity *aliased = get_entity_alias(entity);
visit_entity(aliased);
break;
}
default:
break;
}
}
......
......@@ -155,9 +155,8 @@ static void free_entity_attrs(ir_entity *ent)
ent->overwrittenby = NULL;
}
if (ent->initializer != NULL) {
/* TODO: free initializers */
}
/* TODO: free initializers */
if (ent->entity_kind == IR_ENTITY_METHOD) {
if (ent->attr.mtd_attr.param_access) {
DEL_ARR_F(ent->attr.mtd_attr.param_access);
......@@ -178,9 +177,8 @@ static ir_entity *deep_entity_copy(ir_entity *old)
ir_entity *newe = XMALLOC(ir_entity);
*newe = *old;
if (old->initializer != NULL) {
/* FIXME: the initializers are NOT copied */
} else if (is_method_entity(old)) {
/* FIXME: the initializers are NOT copied */
if (is_method_entity(old)) {
/* do NOT copy them, reanalyze. This might be the best solution */
newe->attr.mtd_attr.param_access = NULL;
newe->attr.mtd_attr.param_weight = NULL;
......@@ -468,7 +466,7 @@ void set_atomic_ent_value(ir_entity *entity, ir_node *val)
assert(is_atomic_entity(entity));
assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
ir_initializer_t *initializer = create_initializer_const(val);
entity->initializer = initializer;
set_entity_initializer(entity, initializer);
}
const char *get_initializer_kind_name(ir_initializer_kind_t ini)
......@@ -579,7 +577,7 @@ ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
static void check_entity_initializer(ir_entity *entity)
{
#ifndef NDEBUG
ir_initializer_t *initializer = entity->initializer;
ir_initializer_t *initializer = get_entity_initializer(entity);
if (initializer == NULL)
return;
ir_type *entity_tp = get_entity_type(entity);
......@@ -603,7 +601,7 @@ static void check_entity_initializer(ir_entity *entity)
void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
{
entity->initializer = initializer;
entity->attr.normal.initializer = initializer;
check_entity_initializer(entity);
}
......@@ -902,8 +900,10 @@ int entity_has_definition(const ir_entity *entity)
case IR_ENTITY_METHOD:
return get_entity_irg(entity) != NULL
&& (get_entity_linkage(entity) & IR_LINKAGE_NO_CODEGEN) == 0;
case IR_ENTITY_NORMAL:
return entity->initializer != NULL;
return get_entity_initializer(entity) != NULL;
case IR_ENTITY_LABEL:
case IR_ENTITY_ALIAS:
return true;
......
......@@ -95,6 +95,10 @@ union ir_initializer_t {
ir_initializer_tarval_t tarval;
};
typedef struct normal_ent_attr {
ir_initializer_t *initializer; /**< entity initializer */
} normal_ent_attr;
/** The attributes for methods. */
typedef struct method_ent_attr {
mtp_additional_properties properties; /**< Additional graph properties can
......@@ -193,13 +197,14 @@ struct ir_entity {
ir_entity **overwrittenby; /**< A list of entities that overwrite this
entity. */
ir_initializer_t *initializer; /**< entity initializer */
#ifdef DEBUG_libfirm
long nr; /**< A unique node number for each node to make output
readable. */
#endif
union {
/** attributes for normal entities */
normal_ent_attr normal;
/** attributes for method entities */
method_ent_attr mtd_attr;
/** fields for code entities */
......@@ -369,7 +374,8 @@ static inline bool is_entity_compound_member(const ir_entity *entity)
static inline ir_initializer_t *_get_entity_initializer(ir_entity const *const ent)
{
return ent->initializer;
assert(ent->entity_kind == IR_ENTITY_NORMAL);
return ent->attr.normal.initializer;
}
static inline int _get_entity_offset(const ir_entity *ent)
......
......@@ -222,11 +222,7 @@ static bool is_data_type(const ir_type *type)
int check_entity(const ir_entity *entity)
{
bool fine = true;
const ir_initializer_t *initializer = get_entity_initializer(entity);
const ir_type *type = get_entity_type(entity);
if (initializer != NULL)
fine &= check_initializer(initializer, type, entity);
bool fine = true;
ir_linkage linkage = get_entity_linkage(entity);
if (linkage & IR_LINKAGE_NO_CODEGEN) {
......@@ -247,7 +243,8 @@ int check_entity(const ir_entity *entity)
"GARBAGE_COLLECT");
check_external_linkage(entity, IR_LINKAGE_MERGE, "MERGE");
const ir_type *owner = get_entity_owner(entity);
ir_type const *const type = get_entity_type(entity);
ir_type const *const owner = get_entity_owner(entity);
switch (get_entity_kind(entity)) {
case IR_ENTITY_ALIAS:
if (!is_segment_type(owner)) {
......@@ -255,40 +252,37 @@ int check_entity(const ir_entity *entity)
owner);
fine = false;
}
if (initializer != NULL) {
report_error("alias entity %+F has initializer", entity);
fine = false;
}
break;
case IR_ENTITY_NORMAL:
case IR_ENTITY_NORMAL: {
ir_initializer_t const *const init = get_entity_initializer(entity);
if (init)
fine &= check_initializer(init, type, entity);
if (!is_data_type(type)) {
report_error("normal entity %+F has non-data type %+F", entity,
type);
fine = false;
}
break;
}
case IR_ENTITY_COMPOUND_MEMBER:
if (!is_compound_type(owner)) {
report_error("compound member entity %+F has non-compound owner %+F",
entity, owner);
fine = false;
}
if (initializer != NULL) {
report_error("compound member entity %+F has initializer", entity);
fine = false;
}
break;
case IR_ENTITY_LABEL:
if (type != get_code_type()) {
report_error("label entity %+F has non-code type %+F", entity,
type);
fine = false;
}
if (initializer != NULL) {
report_error("label entity %+F has initializer", entity);
fine = false;
}
break;
case IR_ENTITY_METHOD:
if (!is_Method_type(type)) {
report_error("method entity %+F has non-method type %+F", entity,
......@@ -316,11 +310,8 @@ int check_entity(const ir_entity *entity)
type);
fine = false;
}
if (initializer != NULL) {
report_error("parameter entity %+F has initializer", entity);
fine = false;
}
break;
case IR_ENTITY_UNKNOWN:
case IR_ENTITY_GOTENTRY:
break;
......
......@@ -101,12 +101,13 @@ static void do_type_walk(ir_type *const tp, ir_entity *const ent,
break;
}
case IR_ENTITY_NORMAL:
case IR_ENTITY_NORMAL: {
/* walk over the value types */
if (ent->initializer != NULL) {
walk_initializer(ent->initializer, pre, post, env);
}
ir_initializer_t *const init = get_entity_initializer(ent);
if (init)
walk_initializer(init, pre, post, env);
break;
}
case IR_ENTITY_METHOD:
case IR_ENTITY_UNKNOWN:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment