X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fentity.c;h=5cf9e2ecc1dbeb19e63a46885bb9cc89e6afe79e;hb=6449e683c808a19471a7b2362b73e4dfb4c248d3;hp=c4bbdf10c679af78fa2ad0dbd797ace4e0a67053;hpb=5c27107154d63252e27639ebb34e98022f9b3358;p=libfirm diff --git a/ir/tr/entity.c b/ir/tr/entity.c index c4bbdf10c..5cf9e2ecc 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -1,8 +1,8 @@ /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe -** All rights reserved. -** -** Authors: Martin Trapp, Christian Schaefer -** +* All rights reserved. +* +* Authors: Martin Trapp, Christian Schaefer +* */ /* $Id$ */ @@ -20,7 +20,7 @@ # include "typegmod_t.h" # include "array.h" /* All this is needed to build the constant node for methods: */ -# include "irprog.h" +# include "irprog_t.h" # include "ircons.h" /*******************************************************************/ @@ -36,6 +36,11 @@ init_entity (void) /** ENTITY **/ /*******************************************************************/ +/* redeclared to declare INLINE. */ +INLINE entity *get_entity_overwrites (entity *ent, int pos); +INLINE entity *get_entity_overwrittenby (entity *ent, int pos); +INLINE type *get_entity_owner (entity *ent); + INLINE void insert_entity_in_owner (entity *ent) { type *owner = ent->owner; switch (get_type_tpop_code(owner)) { @@ -61,6 +66,8 @@ new_entity (type *owner, ident *name, type *type) entity *res; ir_graph *rem; + assert(!id_contains_char(name, ' ') && "entity name should not contain spaces"); + res = (entity *) malloc (sizeof (entity)); res->kind = k_entity; assert_legal_owner_of_ent(owner); @@ -77,10 +84,12 @@ new_entity (type *owner, ident *name, type *type) res->variability = constant; rem = current_ir_graph; current_ir_graph = get_const_code_irg(); - res->value = new_Const(mode_p, tarval_p_from_entity(res)); + res->value = new_Const(mode_P, tarval_P_from_entity(res)); current_ir_graph = rem; } else { res->variability = uninitialized; + res->value = NULL; + res->values = NULL; } res->peculiarity = existent; res->volatility = non_volatile; @@ -90,16 +99,28 @@ new_entity (type *owner, ident *name, type *type) res->irg = NULL; +#ifdef DEBUG_libfirm + res->nr = get_irp_new_node_nr(); +#endif + res->visit = 0; /* Remember entity in it's owner. */ insert_entity_in_owner (res); return res; } +entity * +new_d_entity (type *owner, ident *name, type *type, dbg_info *db) { + entity *res = new_entity(owner, name, type); + set_entity_dbg_info(res, db); + return res; +} INLINE void free_entity_attrs(entity *ent) { assert(ent); - DEL_ARR_F(ent->overwrites); - DEL_ARR_F(ent->overwrittenby); + if (get_type_tpop(get_entity_owner(ent)) == type_class) { + DEL_ARR_F(ent->overwrites); + DEL_ARR_F(ent->overwrittenby); + } } entity * @@ -111,8 +132,24 @@ copy_entity_own (entity *old, type *new_owner) { new = (entity *) malloc (sizeof (entity)); memcpy (new, old, sizeof (entity)); new->owner = new_owner; - new->overwrites = DUP_ARR_F(entity *, old->overwrites); - new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + /* + if ((get_type_tpop(get_entity_owner(old)) == type_class) && + (get_type_tpop(new_owner) == type_class)) { + new->overwrites = DUP_ARR_F(entity *, old->overwrites); + new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + } else if ((get_type_tpop(get_entity_owner(old)) != type_class) && + (get_type_tpop(new_owner) == type_class)) { + new->overwrites = NEW_ARR_F(entity *, 1); + new->overwrittenby = NEW_ARR_F(entity *, 1); + } + */ + if (is_class_type(new_owner)) { + new->overwrites = NEW_ARR_F(entity *, 1); + new->overwrittenby = NEW_ARR_F(entity *, 1); + } +#ifdef DEBUG_libfirm + new->nr = get_irp_new_node_nr(); +#endif insert_entity_in_owner (new); @@ -128,14 +165,38 @@ copy_entity_name (entity *old, ident *new_name) { memcpy (new, old, sizeof (entity)); new->name = new_name; new->ld_name = NULL; - new->overwrites = DUP_ARR_F(entity *, old->overwrites); - new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + if (is_class_type(new->owner)) { + new->overwrites = DUP_ARR_F(entity *, old->overwrites); + new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + } +#ifdef DEBUG_libfirm + new->nr = get_irp_new_node_nr(); +#endif insert_entity_in_owner (new); return new; } + +void +free_entity (entity *ent) { + free_tv_entity(ent); + free_entity_attrs(ent); + free(ent); +} + +/* Outputs a unique number for this node */ +INLINE long +get_entity_nr(entity *ent) { + assert(ent); +#ifdef DEBUG_libfirm + return ent->nr; +#else + return 0; +#endif +} + INLINE const char * get_entity_name (entity *ent) { assert (ent); @@ -225,7 +286,11 @@ get_entity_visibility (entity *ent) { INLINE void set_entity_visibility (entity *ent, ent_visibility vis) { - if (vis != local) assert(ent->allocation == static_allocated); + if (vis != local) + assert((ent->allocation == static_allocated) || + (ent->allocation == automatic_allocated)); + // @@@ Test that the owner type is not local, but how?? + // && get_class_visibility(get_entity_owner(ent)) != local)); ent->visibility = vis; } @@ -256,11 +321,13 @@ set_entity_variability (entity *ent, ent_variability var){ INLINE ent_volatility get_entity_volatility (entity *ent) { + assert (ent); return ent->volatility; } INLINE void set_entity_volatility (entity *ent, ent_volatility vol) { + assert (ent); ent->volatility = vol; } @@ -273,6 +340,7 @@ get_entity_peculiarity (entity *ent) { INLINE void set_entity_peculiarity (entity *ent, peculiarity pec) { assert (ent); + /* @@@ why peculiarity only for methods? */ assert (is_method_type(ent->type)); ent->peculiarity = pec; } @@ -311,13 +379,6 @@ ir_node *copy_const_value(ir_node *n) { return nn; } -/* Copies the value represented by the entity to current_block - in current_ir_graph. */ -ir_node *copy_atomic_ent_value(entity *ent) { - assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized)); - return copy_const_value(ent->value); -} - /* A value of a compound entity is a pair of value and the corresponding member of the compound. */ INLINE void @@ -329,7 +390,7 @@ add_compound_ent_value(entity *ent, ir_node *val, entity *member) { /* Copies the firm subgraph referenced by val to const_code_irg and adds the node as constant initialization to ent. - The subgraph may not contain control flow operations. */ + The subgraph may not contain control flow operations. INLINE void copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) { ir_graph *rem = current_ir_graph; @@ -340,7 +401,7 @@ copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) { val = copy_const_value(val); add_compound_ent_value(ent, val, member); current_ir_graph = rem; -} + }*/ INLINE int get_compound_ent_n_values(entity *ent) { @@ -354,12 +415,12 @@ get_compound_ent_value(entity *ent, int pos) { return ent->values[pos+1]; } -/* Copies the value i of the entity to current_block in current_ir_graph. */ +/* Copies the value i of the entity to current_block in current_ir_graph. ir_node * copy_compound_ent_value(entity *ent, int pos) { assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized)); return copy_const_value(ent->values[pos+1]); -} + }*/ INLINE entity * get_compound_ent_value_member(entity *ent, int pos) { @@ -374,6 +435,23 @@ set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) { ent->val_ents[pos+1] = member; } +void +remove_compound_ent_value(entity *ent, entity *value_ent) { + int i; + assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized)); + for (i = 1; i < (ARR_LEN (ent->val_ents)); i++) { + if (ent->val_ents[i] == value_ent) { + for(; i < (ARR_LEN (ent->val_ents))-1; i++) { + ent->val_ents[i] = ent->val_ents[i+1]; + ent->values[i] = ent->values[i+1]; + } + ARR_SETLEN(entity*, ent->val_ents, ARR_LEN(ent->val_ents) - 1); + ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1); + break; + } + } +} + void set_array_entity_values(entity *ent, tarval **values, int num_vals) { int i; @@ -421,6 +499,16 @@ get_entity_n_overwrites (entity *ent) { return (ARR_LEN (ent->overwrites))-1; } +int +get_entity_overwrites_index(entity *ent, entity *overwritten) { + int i; + assert(ent && is_class_type(get_entity_owner(ent))); + for (i = 0; i < get_entity_n_overwrites(ent); i++) + if (get_entity_overwrites(ent, i) == overwritten) + return i; + return -1; +} + INLINE entity * get_entity_overwrites (entity *ent, int pos) { assert(ent); @@ -437,6 +525,19 @@ set_entity_overwrites (entity *ent, int pos, entity *overwritten) { ent->overwrites[pos+1] = overwritten; } +void +remove_entity_overwrites(entity *ent, entity *overwritten) { + int i; + assert(ent && is_class_type(get_entity_owner(ent))); + for (i = 1; i < (ARR_LEN (ent->overwrites)); i++) + if (ent->overwrites[i] == overwritten) { + for(; i < (ARR_LEN (ent->overwrites))-1; i++) + ent->overwrites[i] = ent->overwrites[i+1]; + ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1); + break; + } +} + INLINE void add_entity_overwrittenby (entity *ent, entity *overwrites) { assert(ent); @@ -451,6 +552,16 @@ get_entity_n_overwrittenby (entity *ent) { return (ARR_LEN (ent->overwrittenby))-1; } +int +get_entity_overwrittenby_index(entity *ent, entity *overwrites) { + int i; + assert(ent && is_class_type(get_entity_owner(ent))); + for (i = 0; i < get_entity_n_overwrittenby(ent); i++) + if (get_entity_overwrittenby(ent, i) == overwrites) + return i; + return -1; +} + INLINE entity * get_entity_overwrittenby (entity *ent, int pos) { assert(ent); @@ -467,6 +578,18 @@ set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) { ent->overwrittenby[pos+1] = overwrites; } +void remove_entity_overwrittenby(entity *ent, entity *overwrites) { + int i; + assert(ent && is_class_type(get_entity_owner(ent))); + for (i = 1; i < (ARR_LEN (ent->overwrittenby)); i++) + if (ent->overwrittenby[i] == overwrites) { + for(; i < (ARR_LEN (ent->overwrittenby))-1; i++) + ent->overwrittenby[i] = ent->overwrittenby[i+1]; + ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1); + break; + } +} + /* A link to store intermediate information */ void * get_entity_link(entity *ent) { @@ -499,6 +622,14 @@ set_entity_irg(entity *ent, ir_graph *irg) { ent->irg = irg; } +int is_entity (void *thing) { + assert(thing); + if (get_kind(thing) == k_entity) + return 1; + else + return 0; +} + int is_atomic_entity(entity *ent) { type* t = get_entity_type(ent); return (is_primitive_type(t) || is_pointer_type(t) || @@ -510,3 +641,32 @@ int is_compound_entity(entity *ent) { return (is_class_type(t) || is_struct_type(t) || is_array_type(t) || is_union_type(t)); } + +/* @@@ not implemnted!!! */ +bool equal_entity(entity *ent1, entity *ent2) { + printf(" calling unimplemented equal entity!!! \n"); + return true; +} + + +unsigned long get_entity_visited(entity *ent) { + assert (ent); + return ent->visit; +} +void set_entity_visited(entity *ent, unsigned long num) { + assert (ent); + ent->visit = num; +} +/* Sets visited field in entity to entity_visited. */ +void mark_entity_visited(entity *ent) { + assert (ent); + ent->visit = type_visited; +} + + +INLINE bool entity_visited(entity *ent) { + return get_entity_visited(ent) >= type_visited; +} +INLINE bool entity_not_visited(entity *ent) { + return get_entity_visited(ent) < type_visited; +}