X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fentity.c;h=89f4716f64b849b363b3721af8d7b86dbdfed305;hb=5a6371dc4b3660d968b8401fc700390a5ba20e7e;hp=b317ba60a9a059a802ecad6f7710244190c586a1;hpb=9ab3d84833ffff735112b3a08558aa83258121ba;p=libfirm diff --git a/ir/tr/entity.c b/ir/tr/entity.c index b317ba60a..89f4716f6 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,9 +23,7 @@ * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include #include @@ -40,41 +38,13 @@ #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 "callgraph.h" /* for dumping debug output */ - -/** - * An interval initializer. - */ -typedef struct interval_initializer interval_initializer; - -/** - * A value initializer. - */ -typedef struct value_initializer value_initializer; - -struct interval_initializer { - int first_index; /**< The first index of the initialized interval. */ - int last_index; /**< The last index of the initialized interval. */ - interval_initializer *next; /**< Points to the next interval initializer. */ -}; - -struct value_initializer { - ir_entity *ent; /**< The initialized entity. */ - value_initializer *next; /**< Points to the next value initializer. */ -}; - -typedef union initializer { - ir_node *value; /**< The value of the initializer. */ - ir_node **values; /**< The values of an interval. */ - value_initializer *val_init; /**< Points the the head of the next value initializers. */ - interval_initializer *int_init; /**< Points to the head of the next value initializers. */ -} initializer; +#include "irdump.h" +#include "irgraph_t.h" +#include "callgraph.h" +#include "error.h" /*-----------------------------------------------------------------*/ /** general **/ @@ -94,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: @@ -109,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 */ @@ -123,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; @@ -131,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; @@ -146,7 +116,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; @@ -170,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; @@ -232,17 +201,22 @@ 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 = 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->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); @@ -255,14 +229,19 @@ static void free_entity_attrs(ir_entity *ent) { } } /* free_entity_attrs */ +/* + * 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; - newe = xmalloc(sizeof(*newe)); + newe = XMALLOC(ir_entity); memcpy(newe, old, sizeof(*newe)); newe->owner = new_owner; if (is_Class_type(new_owner)) { @@ -284,7 +263,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; @@ -557,27 +536,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 @@ -687,6 +652,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 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) { @@ -774,6 +849,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 @@ -795,6 +876,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 */ @@ -802,6 +884,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 */ @@ -809,6 +892,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 */ @@ -817,10 +901,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); @@ -834,20 +917,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; @@ -857,45 +932,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 */ @@ -1216,18 +1274,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); @@ -1262,11 +1308,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 */