X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fentity.c;h=f1fac56cb9c9f6b63ece78e4bb241ceb7ddf61c6;hb=f2edb6301aa7affb0673e76436d9b4dbaef6b9e1;hp=9af1de6a08983519575499f7c96eb2100d9bb8fc;hpb=b41ce1d070a9f7d216f024fc969ad49908098c0c;p=libfirm diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 9af1de6a0..f1fac56cb 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -45,8 +45,8 @@ #include "tv_t.h" #include "irdump.h" #include "irgraph_t.h" - #include "callgraph.h" +#include "error.h" /** * An interval initializer. @@ -109,7 +109,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 */ @@ -131,8 +132,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; @@ -146,7 +146,7 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type) 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; @@ -266,7 +266,7 @@ copy_entity_own(ir_entity *old, ir_type *new_owner) { assert(get_type_state(new_owner) != layout_fixed); if (old->owner == new_owner) return old; - newe = xmalloc(sizeof(*newe)); + newe = XMALLOC(ir_entity); memcpy(newe, old, sizeof(*newe)); newe->owner = new_owner; if (is_Class_type(new_owner)) { @@ -288,7 +288,7 @@ 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)); + newe = XMALLOC(ir_entity); memcpy(newe, old, sizeof(*newe)); newe->name = new_name; newe->ld_name = NULL; @@ -561,27 +561,13 @@ void (set_entity_backend_marked)(ir_entity *ent, int flag) { _set_entity_backend_marked(ent, flag); } /* set_entity_backend_marked */ -/* 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 */ - -/* 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 @@ -940,10 +926,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); @@ -957,20 +942,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; @@ -980,45 +957,28 @@ 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 slow (O(number of initializers^2) 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 */ @@ -1373,11 +1333,11 @@ int equal_entity(ir_entity *ent1, ir_entity *ent2) { } /* 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 */