X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fentity.c;h=380ee1ef0ea3e0a51f17ec4ec9b4c1e461b5c2da;hb=d6a4592afc658544100e136acaf09902b710b7e7;hp=3acca6937e0b0b6709704195dd5b4286a8a26c47;hpb=8ca297d3fa1c84b58d71a9ec102061239159f9a7;p=libfirm diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 3acca6937..380ee1ef0 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -23,47 +23,38 @@ * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STDDEF_H -# include -#endif +#include +#include +#include #include "firm_common_t.h" #include "xmalloc.h" #include "entity_t.h" -#include "mangle.h" -#include "typegmod.h" #include "array.h" #include "irtools.h" #include "irhooks.h" #include "irprintf.h" -/* All this is needed to build the constant node for methods: */ #include "irprog_t.h" #include "ircons.h" #include "tv_t.h" -#include "irdump.h" /* for output if errors occur. */ +#include "irdump.h" +#include "irgraph_t.h" +#include "callgraph.h" +#include "error.h" -#include "callgraph.h" /* for dumping debug output */ - -/*******************************************************************/ +/*-----------------------------------------------------------------*/ /** general **/ -/*******************************************************************/ +/*-----------------------------------------------------------------*/ ir_entity *unknown_entity = NULL; ir_entity *get_unknown_entity(void) { return unknown_entity; } +/** The name of the unknown entity. */ #define UNKNOWN_ENTITY_NAME "unknown_entity" /*-----------------------------------------------------------------*/ @@ -73,7 +64,7 @@ ir_entity *get_unknown_entity(void) { return unknown_entity; } /** * Add an entity to it's already set owner type. */ -static INLINE void insert_entity_in_owner(ir_entity *ent) { +static inline void insert_entity_in_owner(ir_entity *ent) { ir_type *owner = ent->owner; switch (get_type_tpop_code(owner)) { case tpo_class: @@ -88,7 +79,8 @@ static INLINE void insert_entity_in_owner(ir_entity *ent) { case tpo_array: set_array_element_entity(owner, ent); break; - default: assert(0); + default: + panic("Unsupported type kind"); } } /* insert_entity_in_owner */ @@ -102,7 +94,7 @@ static INLINE void insert_entity_in_owner(ir_entity *ent) { * * @return the new created entity */ -static INLINE ir_entity * +static inline ir_entity * new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) { ir_entity *res; @@ -110,8 +102,7 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) assert(!id_contains_char(name, ' ') && "entity name should not contain spaces"); - res = xmalloc(sizeof(*res)); - memset(res, 0, sizeof(*res)); + res = XMALLOCZ(ir_entity); res->kind = k_entity; res->name = name; @@ -122,11 +113,13 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) res->allocation = allocation_automatic; res->visibility = visibility_local; res->volatility = volatility_non_volatile; + res->align = align_is_aligned; res->stickyness = stickyness_unsticky; res->peculiarity = peculiarity_existent; - res->address_taken = ir_address_taken_unknown; + res->usage = ir_usage_unknown; res->final = 0; res->compiler_gen = 0; + res->backend_marked = 0; res->offset = -1; res->offset_bit_remainder = 0; res->link = NULL; @@ -134,10 +127,11 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) if (is_Method_type(type)) { symconst_symbol sym; + ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data; sym.entity_p = res; rem = current_ir_graph; current_ir_graph = get_const_code_irg(); - res->value = new_SymConst(sym, symconst_addr_ent); + res->value = new_SymConst(mode, sym, symconst_addr_ent); current_ir_graph = rem; res->allocation = allocation_static; res->variability = variability_constant; @@ -146,7 +140,6 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) res->attr.mtd_attr.param_access = NULL; res->attr.mtd_attr.param_weight = NULL; res->attr.mtd_attr.irg = NULL; - res->attr.mtd_attr.section = section_text; } else if (is_compound_type(type)) { res->variability = variability_uninitialized; res->value = NULL; @@ -208,17 +201,23 @@ static void free_entity_attrs(ir_entity *ent) { assert(ent->overwrittenby == NULL); } if (is_compound_entity(ent)) { - if (ent->attr.cmpd_attr.val_paths) { - for (i = 0; i < get_compound_ent_n_values(ent); i++) - if (ent->attr.cmpd_attr.val_paths[i]) { - /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */ - /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ - /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */ - } - ent->attr.cmpd_attr.val_paths = NULL; + if (ent->has_initializer) { + /* TODO: free initializers */ + } else { + if (ent->attr.cmpd_attr.val_paths) { + for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) + if (ent->attr.cmpd_attr.val_paths[i]) { + /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */ + /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ + /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */ + } + ent->attr.cmpd_attr.val_paths = NULL; + } + if (ent->attr.cmpd_attr.values) { + /*DEL_ARR_F(ent->attr.cmpd_attr.values)*/; + } + ent->attr.cmpd_attr.values = NULL; } - /* if (ent->attr.cmpd_attr.values) DEL_ARR_F(ent->attr.cmpd_attr.values); *//* @@@ warum nich? */ - ent->attr.cmpd_attr.values = NULL; } else if (is_method_entity(ent)) { if (ent->attr.mtd_attr.param_access) { DEL_ARR_F(ent->attr.mtd_attr.param_access); @@ -231,26 +230,62 @@ static void free_entity_attrs(ir_entity *ent) { } } /* free_entity_attrs */ +/** + * Creates a deep copy of an entity. + */ +static ir_entity *deep_entity_copy(ir_entity *old) +{ + ir_entity *newe = XMALLOC(ir_entity); + + *newe = *old; + if (is_compound_entity(old)) { + if (old->has_initializer) { + /* FIXME: the initializers are NOT copied */ + } else { + newe->attr.cmpd_attr.values = NULL; + newe->attr.cmpd_attr.val_paths = NULL; + if (old->attr.cmpd_attr.values) + newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values); + + /* FIXME: the compound graph paths are NOT copied */ + if (old->attr.cmpd_attr.val_paths) + newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths); + } + } else 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; + } + +#ifdef DEBUG_libfirm + newe->nr = get_irp_new_node_nr(); +#endif + return newe; +} +/* + * Copies the entity if the new_owner is different from the + * owner of the old entity, else returns the old entity. + */ ir_entity * copy_entity_own(ir_entity *old, ir_type *new_owner) { ir_entity *newe; assert(is_entity(old)); assert(is_compound_type(new_owner)); + assert(get_type_state(new_owner) != layout_fixed); + + if (old->owner == new_owner) + return old; - if (old->owner == new_owner) return old; - newe = xmalloc(sizeof(*newe)); - memcpy(newe, old, sizeof(*newe)); + /* create a deep copy so we are safe of aliasing and double-freeing. */ + newe = deep_entity_copy(old); newe->owner = new_owner; + if (is_Class_type(new_owner)) { newe->overwrites = NEW_ARR_F(ir_entity *, 0); newe->overwrittenby = NEW_ARR_F(ir_entity *, 0); } -#ifdef DEBUG_libfirm - newe->nr = get_irp_new_node_nr(); -#endif insert_entity_in_owner(newe); - return newe; } /* copy_entity_own */ @@ -260,24 +295,19 @@ copy_entity_name(ir_entity *old, ident *new_name) { assert(old && old->kind == k_entity); if (old->name == new_name) return old; - newe = xmalloc(sizeof(*newe)); - memcpy(newe, old, sizeof(*newe)); + newe = deep_entity_copy(old); newe->name = new_name; newe->ld_name = NULL; + if (is_Class_type(newe->owner)) { newe->overwrites = DUP_ARR_F(ir_entity *, old->overwrites); newe->overwrittenby = DUP_ARR_F(ir_entity *, old->overwrittenby); } -#ifdef DEBUG_libfirm - newe->nr = get_irp_new_node_nr(); -#endif - insert_entity_in_owner(newe); return newe; } /* copy_entity_name */ - void free_entity(ir_entity *ent) { assert(ent && ent->kind == k_entity); @@ -459,7 +489,7 @@ void _set_entity_volatility(ent, vol); } /* set_entity_volatility */ -/* return the name of the volatility */ +/* Return the name of the volatility. */ const char *get_volatility_name(ir_volatility var) { #define X(a) case a: return #a @@ -471,6 +501,28 @@ const char *get_volatility_name(ir_volatility var) #undef X } /* get_volatility_name */ +ir_align +(get_entity_align)(const ir_entity *ent) { + return _get_entity_align(ent); +} /* get_entity_align */ + +void +(set_entity_align)(ir_entity *ent, ir_align a) { + _set_entity_align(ent, a); +} /* set_entity_align */ + +/* Return the name of the alignment. */ +const char *get_align_name(ir_align a) +{ +#define X(a) case a: return #a + switch (a) { + X(align_non_aligned); + X(align_is_aligned); + default: return "BAD VALUE"; + } +#undef X +} /* get_align_name */ + ir_peculiarity (get_entity_peculiarity)(const ir_entity *ent) { return _get_entity_peculiarity(ent); @@ -501,27 +553,23 @@ void (set_entity_compiler_generated)(ir_entity *ent, int flag) { _set_entity_compiler_generated(ent, flag); } /* set_entity_compiler_generated */ -/* Checks if the address of an entity was taken. */ -ir_address_taken_state (get_entity_address_taken)(const ir_entity *ent) { - return _get_entity_address_taken(ent); -} /* is_entity_address_taken */ +/* Checks if an entity is marked by the backend */ +int (is_entity_backend_marked)(const ir_entity *ent) { + return _is_entity_backend_marked(ent); +} /* is_entity_backend_marked */ + +/* Sets/resets the compiler generated flag */ +void (set_entity_backend_marked)(ir_entity *ent, int flag) { + _set_entity_backend_marked(ent, flag); +} /* set_entity_backend_marked */ -/* Sets/resets the address taken flag. */ -void (set_entity_address_taken)(ir_entity *ent, ir_address_taken_state flag) { - _set_entity_address_taken(ent, flag); -} /* set_entity_address_taken */ +ir_entity_usage (get_entity_usage)(const ir_entity *ent) { + return _get_entity_usage(ent); +} -/* Return the name of the address_taken state. */ -const char *get_address_taken_state_name(ir_address_taken_state state) { -#define X(a) case a: return #a - switch (state) { - X(ir_address_not_taken); - X(ir_address_taken_unknown); - X(ir_address_taken); - default: return "BAD VALUE"; - } -#undef X -} /* get_address_taken_state_name */ +void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags) { + _set_entity_usage(ent, flags); +} /* Get the entity's stickyness */ ir_stickyness @@ -549,6 +597,7 @@ set_atomic_ent_value(ir_entity *ent, ir_node *val) { assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized)); if (is_Method_type(ent->type) && (ent->peculiarity == peculiarity_existent)) return; + assert(get_irn_mode(val) == get_type_mode(ent->type)); ent->value = val; } /* set_atomic_ent_value */ @@ -592,10 +641,10 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n) { m = get_irn_mode(n); switch (get_irn_opcode(n)) { case iro_Const: - nn = new_d_Const_type(dbg, m, get_Const_tarval(n), get_Const_type(n)); + nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n)); break; case iro_SymConst: - nn = new_d_SymConst_type(dbg, get_SymConst_symbol(n), get_SymConst_kind(n), + nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n), get_SymConst_value_type(n)); break; case iro_Add: @@ -623,7 +672,6 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n) { case iro_Unknown: nn = new_d_Unknown(m); break; default: - DDMN(n); assert(0 && "opcode invalid or not implemented"); nn = NULL; break; @@ -631,6 +679,116 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n) { return nn; } /* copy_const_value */ +static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL }; + +ir_initializer_t *get_initializer_null(void) +{ + return &null_initializer; +} + +ir_initializer_t *create_initializer_const(ir_node *value) +{ + struct obstack *obst = get_irg_obstack(get_const_code_irg()); + + ir_initializer_t *initializer + = obstack_alloc(obst, sizeof(ir_initializer_const_t)); + initializer->kind = IR_INITIALIZER_CONST; + initializer->consti.value = value; + + return initializer; +} + +ir_initializer_t *create_initializer_tarval(tarval *tv) +{ + struct obstack *obst = get_irg_obstack(get_const_code_irg()); + + ir_initializer_t *initializer + = obstack_alloc(obst, sizeof(ir_initializer_tarval_t)); + initializer->kind = IR_INITIALIZER_TARVAL; + initializer->tarval.value = tv; + + return initializer; +} + +ir_initializer_t *create_initializer_compound(unsigned n_entries) +{ + struct obstack *obst = get_irg_obstack(get_const_code_irg()); + + size_t i; + size_t size = sizeof(ir_initializer_compound_t) + + (n_entries-1) * sizeof(ir_initializer_t*); + + ir_initializer_t *initializer = obstack_alloc(obst, size); + initializer->kind = IR_INITIALIZER_COMPOUND; + initializer->compound.n_initializers = n_entries; + + for(i = 0; i < n_entries; ++i) { + initializer->compound.initializers[i] = get_initializer_null(); + } + + return initializer; +} + +ir_node *get_initializer_const_value(const ir_initializer_t *initializer) +{ + assert(initializer->kind == IR_INITIALIZER_CONST); + return skip_Id(initializer->consti.value); +} + +tarval *get_initializer_tarval_value(const ir_initializer_t *initializer) +{ + assert(initializer->kind == IR_INITIALIZER_TARVAL); + return initializer->tarval.value; +} + +unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer) +{ + assert(initializer->kind == IR_INITIALIZER_COMPOUND); + return initializer->compound.n_initializers; +} + +void set_initializer_compound_value(ir_initializer_t *initializer, + unsigned index, ir_initializer_t *value) +{ + assert(initializer->kind == IR_INITIALIZER_COMPOUND); + assert(index < initializer->compound.n_initializers); + + initializer->compound.initializers[index] = value; +} + +ir_initializer_t *get_initializer_compound_value( + const ir_initializer_t *initializer, unsigned index) +{ + assert(initializer->kind == IR_INITIALIZER_COMPOUND); + assert(index < initializer->compound.n_initializers); + + return initializer->compound.initializers[index]; +} + +ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer) +{ + return initializer->kind; +} + +static void check_entity_initializer(ir_entity *entity) +{ + /* TODO */ + (void) entity; +} + +void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer) +{ + entity->attr.initializer = initializer; + entity->has_initializer = 1; + check_entity_initializer(entity); +} + +ir_initializer_t *get_entity_initializer(const ir_entity *entity) +{ + assert(entity->has_initializer); + return entity->attr.initializer; +} + /* Creates a new compound graph path. */ compound_graph_path * new_compound_graph_path(ir_type *tp, int length) { @@ -718,6 +876,12 @@ set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index) gr->list[pos].index = index; } /* set_compound_graph_path_array_index */ +ir_type * +get_compound_graph_path_type(const compound_graph_path *gr) { + assert(gr && is_compound_graph_path(gr)); + return gr->tp; +} + /* A value of a compound entity is a pair of value and the corresponding path to a member of the compound. */ void @@ -739,6 +903,7 @@ set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path int get_compound_ent_n_values(ir_entity *ent) { + assert(!ent->has_initializer); assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); return ARR_LEN(ent->attr.cmpd_attr.values); } /* get_compound_ent_n_values */ @@ -746,6 +911,7 @@ get_compound_ent_n_values(ir_entity *ent) { ir_node * get_compound_ent_value(ir_entity *ent, int pos) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); + assert(!ent->has_initializer); assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values)); return ent->attr.cmpd_attr.values[pos]; } /* get_compound_ent_value */ @@ -753,6 +919,7 @@ get_compound_ent_value(ir_entity *ent, int pos) { compound_graph_path * get_compound_ent_value_path(ir_entity *ent, int pos) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); + assert(!ent->has_initializer); assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths)); return ent->attr.cmpd_attr.val_paths[pos]; } /* get_compound_ent_value_path */ @@ -761,10 +928,9 @@ get_compound_ent_value_path(ir_entity *ent, int pos) { * Returns non-zero, if two compound_graph_pathes are equal * * @param path1 the first path - * @param visited_indices * @param path2 the second path */ -static int equal_paths(compound_graph_path *path1, int *visited_indices, compound_graph_path *path2) { +static int equal_paths(compound_graph_path *path1, compound_graph_path *path2) { int i; int len1 = get_compound_graph_path_length(path1); int len2 = get_compound_graph_path_length(path2); @@ -778,20 +944,12 @@ static int equal_paths(compound_graph_path *path1, int *visited_indices, compoun if (node1 != node2) return 0; - /* FIXME: Strange code. What is it good for? */ tp = get_entity_owner(node1); if (is_Array_type(tp)) { - long low; - - /* Compute the index of this node. */ - assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented"); - - low = get_array_lower_bound_int(tp, 0); - if (low + visited_indices[i] < get_compound_graph_path_array_index(path2, i)) { - visited_indices[i]++; + int index1 = get_compound_graph_path_array_index(path1, i); + int index2 = get_compound_graph_path_array_index(path2, i); + if (index1 != index2) return 0; - } else - assert(low + visited_indices[i] == get_compound_graph_path_array_index(path2, i)); } } return 1; @@ -801,60 +959,46 @@ static int equal_paths(compound_graph_path *path1, int *visited_indices, compoun * Returns the position of a value with the given path. * The path must contain array indices for all array element entities. * - * @todo This implementation is very low and should be replaced when the new tree oriented + * @todo This implementation is very slow (O(number of initializers * |path|) + * and should be replaced when the new tree oriented * value representation is finally implemented. */ static int get_compound_ent_pos_by_path(ir_entity *ent, compound_graph_path *path) { int i, n_paths = get_compound_ent_n_values(ent); - int *visited_indices; - int path_len = get_compound_graph_path_length(path); - NEW_ARR_A(int *, visited_indices, path_len); - memset(visited_indices, 0, sizeof(*visited_indices) * path_len); for (i = 0; i < n_paths; i ++) { - if (equal_paths(get_compound_ent_value_path(ent, i), visited_indices, path)) + compound_graph_path *gr = get_compound_ent_value_path(ent, i); + if (equal_paths(gr, path)) return i; } - -#if 0 - { - int j; - printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); - printf("Entity %s : ", get_entity_name(ent)); - for (j = 0; j < get_compound_graph_path_length(path); ++j) { - ir_entity *node = get_compound_graph_path_node(path, j); - printf("%s", get_entity_name(node)); - if (is_Array_type(get_entity_owner(node))) - printf("[%d]", get_compound_graph_path_array_index(path, j)); - } - printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); - } -#endif - - assert(0 && "path not found"); return -1; } /* get_compound_ent_pos_by_path */ /* Returns a constant value given the access path. * The path must contain array indices for all array element entities. */ ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path) { - return get_compound_ent_value(ent, get_compound_ent_pos_by_path(ent, path)); + int pos = get_compound_ent_pos_by_path(ent, path); + if (pos >= 0) + return get_compound_ent_value(ent, pos); + return NULL; } /* get_compound_ent_value_by_path */ void remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent) { - int i; + int i, n; assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - for (i = 0; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths)); ++i) { + + n = ARR_LEN(ent->attr.cmpd_attr.val_paths); + for (i = 0; i < n; ++i) { compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i]; if (path->list[path->len-1].node == value_ent) { - for (; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths))-1; ++i) { + for (; i < n - 1; ++i) { ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1]; ent->attr.cmpd_attr.values[i] = ent->attr.cmpd_attr.values[i+1]; } - ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, ARR_LEN(ent->attr.cmpd_attr.val_paths) - 1); - ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, ARR_LEN(ent->attr.cmpd_attr.values) - 1); + ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, n - 1); + ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, n - 1); break; } } @@ -928,57 +1072,58 @@ set_array_entity_values(ir_entity *ent, tarval **values, int num_vals) { } /* set_array_entity_values */ /* Return the overall offset of value at position pos in bytes. */ -int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { +unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { compound_graph_path *path; int path_len, i; - int offset = 0; + unsigned offset = 0; ir_type *curr_tp; assert(get_type_state(get_entity_type(ent)) == layout_fixed); - path = get_compound_ent_value_path(ent, pos); + path = get_compound_ent_value_path(ent, pos); path_len = get_compound_graph_path_length(path); - curr_tp = path->tp; + curr_tp = path->tp; for (i = 0; i < path_len; ++i) { - ir_entity *node = get_compound_graph_path_node(path, i); - ir_type *node_tp = get_entity_type(node); - if (is_Array_type(curr_tp)) { - int size = get_type_size_bits(node_tp); - int align = get_type_alignment_bits(node_tp); - int idx; + ir_type *elem_type = get_array_element_type(curr_tp); + unsigned size = get_type_size_bytes(elem_type); + unsigned align = get_type_alignment_bytes(elem_type); + int idx; assert(size > 0); if(size % align > 0) { size += align - (size % align); } - assert(size % 8 == 0); - size /= 8; idx = get_compound_graph_path_array_index(path, i); assert(idx >= 0); offset += size * idx; + curr_tp = elem_type; } else { + ir_entity *node = get_compound_graph_path_node(path, i); offset += get_entity_offset(node); + curr_tp = get_entity_type(node); } - curr_tp = node_tp; } return offset; } /* get_compound_ent_value_offset_bytes */ /* Return the offset in bits from the last byte address. */ -int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) { +unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) { compound_graph_path *path; int path_len; ir_entity *last_node; assert(get_type_state(get_entity_type(ent)) == layout_fixed); - path = get_compound_ent_value_path(ent, pos); - path_len = get_compound_graph_path_length(path); + path = get_compound_ent_value_path(ent, pos); + path_len = get_compound_graph_path_length(path); last_node = get_compound_graph_path_node(path, path_len - 1); + if(last_node == NULL) + return 0; + return get_entity_offset_bits_remainder(last_node); } /* get_compound_ent_value_offset_bit_remainder */ @@ -1023,11 +1168,13 @@ get_entity_n_overwrites(ir_entity *ent) { int get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten) { - int i; + int i, n; assert(is_Class_type(get_entity_owner(ent))); - for (i = 0; i < get_entity_n_overwrites(ent); i++) + n = get_entity_n_overwrites(ent); + for (i = 0; i < n; ++i) { if (get_entity_overwrites(ent, i) == overwritten) return i; + } return -1; } /* get_entity_overwrites_index */ @@ -1047,15 +1194,17 @@ set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten) { void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten) { - int i; + int i, n; assert(is_Class_type(get_entity_owner(ent))); - for (i = 0; i < (ARR_LEN (ent->overwrites)); i++) + n = ARR_LEN(ent->overwrites); + for (i = 0; i < n; ++i) { if (ent->overwrites[i] == overwritten) { - for(; i < (ARR_LEN (ent->overwrites))-1; i++) + for (; i < n - 1; i++) ent->overwrites[i] = ent->overwrites[i+1]; - ARR_SETLEN(ir_entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1); + ARR_SETLEN(ir_entity*, ent->overwrites, n - 1); break; } + } } /* remove_entity_overwrites */ void @@ -1066,16 +1215,18 @@ add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) { int get_entity_n_overwrittenby(ir_entity *ent) { assert(is_Class_type(get_entity_owner(ent))); - return (ARR_LEN (ent->overwrittenby)); + return ARR_LEN(ent->overwrittenby); } /* get_entity_n_overwrittenby */ int get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites) { - int i; + int i, n; assert(is_Class_type(get_entity_owner(ent))); - for (i = 0; i < get_entity_n_overwrittenby(ent); i++) + n = get_entity_n_overwrittenby(ent); + for (i = 0; i < n; ++i) { if (get_entity_overwrittenby(ent, i) == overwrites) return i; + } return -1; } /* get_entity_overwrittenby_index */ @@ -1093,16 +1244,19 @@ set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites) { ent->overwrittenby[pos] = overwrites; } /* set_entity_overwrittenby */ -void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) { - int i; +void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) { + int i, n; assert(is_Class_type(get_entity_owner(ent))); - for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++) + + n = ARR_LEN(ent->overwrittenby); + for (i = 0; i < n; ++i) { if (ent->overwrittenby[i] == overwrites) { - for(; i < (ARR_LEN (ent->overwrittenby))-1; i++) + for(; i < n - 1; ++i) ent->overwrittenby[i] = ent->overwrittenby[i+1]; - ARR_SETLEN(ir_entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1); + ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1); break; } + } } /* remove_entity_overwrittenby */ /* A link to store intermediate information */ @@ -1147,18 +1301,6 @@ void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number) { ent->attr.mtd_attr.vtable_number = vtable_number; } /* set_entity_vtable_number */ -/* Returns the section of a method. */ -ir_img_section get_method_img_section(const ir_entity *ent) { - assert(is_method_entity((ir_entity *)ent)); - return ent->attr.mtd_attr.section; -} /* get_method_img_section */ - -/* Sets the section of a method. */ -void set_method_img_section(ir_entity *ent, ir_img_section section) { - assert(is_method_entity(ent)); - ent->attr.mtd_attr.section = section; -} /* set_method_img_section */ - int (is_entity)(const void *thing) { return _is_entity(thing); @@ -1186,16 +1328,18 @@ int is_method_entity(ir_entity *ent) { /** * @todo not implemented!!! */ int equal_entity(ir_entity *ent1, ir_entity *ent2) { + (void) ent1; + (void) ent2; fprintf(stderr, " calling unimplemented equal entity!!! \n"); return 1; } /* equal_entity */ -unsigned long (get_entity_visited)(ir_entity *ent) { +ir_visited_t (get_entity_visited)(ir_entity *ent) { return _get_entity_visited(ent); } /* get_entity_visited */ -void (set_entity_visited)(ir_entity *ent, unsigned long num) { +void (set_entity_visited)(ir_entity *ent, ir_visited_t num) { _set_entity_visited(ent, num); } /* set_entity_visited */ @@ -1277,6 +1421,14 @@ ir_type *(get_entity_repr_class)(const ir_entity *ent) { return _get_entity_repr_class(ent); } /* get_entity_repr_class */ +dbg_info *(get_entity_dbg_info)(const ir_entity *ent) { + return _get_entity_dbg_info(ent); +} /* get_entity_dbg_info */ + +void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db) { + _set_entity_dbg_info(ent, db); +} /* set_entity_dbg_info */ + /* Initialize entity module. */ void firm_init_entity(void) { @@ -1291,5 +1443,6 @@ void firm_init_entity(void) current_ir_graph = get_const_code_irg(); sym.entity_p = unknown_entity; - unknown_entity->value = new_SymConst(sym, symconst_addr_ent); + /* TODO: we need two unknown_entities here, one for code and one for data */ + unknown_entity->value = new_SymConst(mode_P_data, sym, symconst_addr_ent); } /* firm_init_entity */