2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of all program known entities.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
43 #include "irgraph_t.h"
44 #include "callgraph.h"
46 #include "compound_path.h"
48 /*-----------------------------------------------------------------*/
50 /*-----------------------------------------------------------------*/
52 ir_entity *unknown_entity = NULL;
54 ir_entity *get_unknown_entity(void) { return unknown_entity; }
56 /** The name of the unknown entity. */
57 #define UNKNOWN_ENTITY_NAME "unknown_entity"
59 /*-----------------------------------------------------------------*/
61 /*-----------------------------------------------------------------*/
64 * Add an entity to it's already set owner type.
66 static inline void insert_entity_in_owner(ir_entity *ent)
68 ir_type *owner = ent->owner;
69 switch (get_type_tpop_code(owner)) {
71 add_class_member(owner, ent);
74 add_struct_member(owner, ent);
77 add_union_member(owner, ent);
80 set_array_element_entity(owner, ent);
83 panic("Unsupported type kind");
85 } /* insert_entity_in_owner */
88 * Creates a new entity. This entity is NOT inserted in the owner type.
90 * @param db debug info for this entity
91 * @param owner the owner type of the new entity
92 * @param name the name of the new entity
93 * @param type the type of the new entity
95 * @return the new created entity
97 static inline ir_entity *
98 new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type)
103 assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
105 res = XMALLOCZ(ir_entity);
107 res->kind = k_entity;
113 res->volatility = volatility_non_volatile;
114 res->aligned = align_is_aligned;
115 res->usage = ir_usage_unknown;
116 res->compiler_gen = 0;
117 res->visibility = ir_visibility_default;
119 res->offset_bit_remainder = 0;
122 res->repr_class = NULL;
124 if (is_Method_type(type)) {
126 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
128 rem = current_ir_graph;
129 current_ir_graph = get_const_code_irg();
130 set_atomic_ent_value(res, new_SymConst(mode, sym, symconst_addr_ent));
131 current_ir_graph = rem;
132 res->linkage = IR_LINKAGE_CONSTANT;
133 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
134 res->attr.mtd_attr.vtable_number = VTABLE_NUM_NOT_SET;
135 res->attr.mtd_attr.param_access = NULL;
136 res->attr.mtd_attr.param_weight = NULL;
137 res->attr.mtd_attr.irg = NULL;
138 } else if (is_compound_type(type)) {
139 res->attr.cmpd_attr.values = NULL;
140 res->attr.cmpd_attr.val_paths = NULL;
141 } else if (is_code_type(type)) {
142 res->attr.code_attr.label = (ir_label_t) -1;
145 if (is_Class_type(owner)) {
146 res->overwrites = NEW_ARR_F(ir_entity *, 0);
147 res->overwrittenby = NEW_ARR_F(ir_entity *, 0);
149 res->overwrites = NULL;
150 res->overwrittenby = NULL;
154 res->nr = get_irp_new_node_nr();
155 #endif /* DEBUG_libfirm */
158 set_entity_dbg_info(res, db);
161 } /* new_rd_entity */
164 new_d_entity(ir_type *owner, ident *name, ir_type *type, dbg_info *db)
168 assert(is_compound_type(owner));
169 res = new_rd_entity(db, owner, name, type);
170 /* Remember entity in it's owner. */
171 insert_entity_in_owner(res);
173 hook_new_entity(res);
178 new_entity(ir_type *owner, ident *name, ir_type *type)
180 return new_d_entity(owner, name, type, NULL);
184 * Free entity attributes.
186 * @param ent the entity
188 static void free_entity_attrs(ir_entity *ent)
191 if (get_type_tpop(get_entity_owner(ent)) == type_class) {
192 DEL_ARR_F(ent->overwrites); ent->overwrites = NULL;
193 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
195 assert(ent->overwrites == NULL);
196 assert(ent->overwrittenby == NULL);
198 if (ent->initializer != NULL) {
199 /* TODO: free initializers */
200 } else if (entity_has_compound_ent_values(ent)) {
201 if (ent->attr.cmpd_attr.val_paths) {
202 for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i)
203 if (ent->attr.cmpd_attr.val_paths[i]) {
204 /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */
205 /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
206 /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */
208 ent->attr.cmpd_attr.val_paths = NULL;
211 if (is_compound_entity(ent)) {
212 if (ent->attr.cmpd_attr.values) {
213 /*DEL_ARR_F(ent->attr.cmpd_attr.values)*/;
215 ent->attr.cmpd_attr.values = NULL;
216 } else if (is_method_entity(ent)) {
217 if (ent->attr.mtd_attr.param_access) {
218 DEL_ARR_F(ent->attr.mtd_attr.param_access);
219 ent->attr.mtd_attr.param_access = NULL;
221 if (ent->attr.mtd_attr.param_weight) {
222 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
223 ent->attr.mtd_attr.param_weight = NULL;
226 } /* free_entity_attrs */
229 * Creates a deep copy of an entity.
231 static ir_entity *deep_entity_copy(ir_entity *old)
233 ir_entity *newe = XMALLOC(ir_entity);
236 if (old->initializer != NULL) {
237 /* FIXME: the initializers are NOT copied */
238 } else if (entity_has_compound_ent_values(old)) {
239 newe->attr.cmpd_attr.values = NULL;
240 newe->attr.cmpd_attr.val_paths = NULL;
241 if (old->attr.cmpd_attr.values)
242 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
244 /* FIXME: the compound graph paths are NOT copied */
245 if (old->attr.cmpd_attr.val_paths)
246 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
247 } else if (is_method_entity(old)) {
248 /* do NOT copy them, reanalyze. This might be the best solution */
249 newe->attr.mtd_attr.param_access = NULL;
250 newe->attr.mtd_attr.param_weight = NULL;
254 newe->nr = get_irp_new_node_nr();
259 * Copies the entity if the new_owner is different from the
260 * owner of the old entity, else returns the old entity.
263 copy_entity_own(ir_entity *old, ir_type *new_owner)
266 assert(is_entity(old));
267 assert(is_compound_type(new_owner));
268 assert(get_type_state(new_owner) != layout_fixed);
270 if (old->owner == new_owner)
273 /* create a deep copy so we are safe of aliasing and double-freeing. */
274 newe = deep_entity_copy(old);
275 newe->owner = new_owner;
277 if (is_Class_type(new_owner)) {
278 newe->overwrites = NEW_ARR_F(ir_entity *, 0);
279 newe->overwrittenby = NEW_ARR_F(ir_entity *, 0);
282 insert_entity_in_owner(newe);
284 } /* copy_entity_own */
287 copy_entity_name(ir_entity *old, ident *new_name)
290 assert(old && old->kind == k_entity);
292 if (old->name == new_name) return old;
293 newe = deep_entity_copy(old);
294 newe->name = new_name;
295 newe->ld_name = NULL;
297 if (is_Class_type(newe->owner)) {
298 newe->overwrites = DUP_ARR_F(ir_entity *, old->overwrites);
299 newe->overwrittenby = DUP_ARR_F(ir_entity *, old->overwrittenby);
301 insert_entity_in_owner(newe);
304 } /* copy_entity_name */
307 free_entity(ir_entity *ent)
309 assert(ent && ent->kind == k_entity);
310 free_entity_attrs(ent);
315 /* Outputs a unique number for this node */
317 get_entity_nr(const ir_entity *ent)
319 assert(ent && ent->kind == k_entity);
323 return (long)PTR_TO_INT(ent);
325 } /* get_entity_nr */
328 (get_entity_name)(const ir_entity *ent) {
329 return _get_entity_name(ent);
333 (get_entity_ident)(const ir_entity *ent) {
334 return _get_entity_ident(ent);
338 (set_entity_ident)(ir_entity *ent, ident *id) {
339 _set_entity_ident(ent, id);
343 (get_entity_owner)(const ir_entity *ent) {
344 return _get_entity_owner(ent);
348 set_entity_owner(ir_entity *ent, ir_type *owner)
350 assert(is_entity(ent));
351 assert(is_compound_type(owner));
355 ident *(get_entity_ld_ident)(const ir_entity *ent)
357 return _get_entity_ld_ident(ent);
361 (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident) {
362 _set_entity_ld_ident(ent, ld_ident);
365 const char *(get_entity_ld_name)(const ir_entity *ent)
367 return _get_entity_ld_name(ent);
371 (get_entity_type)(const ir_entity *ent) {
372 return _get_entity_type(ent);
376 (set_entity_type)(ir_entity *ent, ir_type *type) {
377 _set_entity_type(ent, type);
381 (get_entity_volatility)(const ir_entity *ent) {
382 return _get_entity_volatility(ent);
386 (set_entity_volatility)(ir_entity *ent, ir_volatility vol) {
387 _set_entity_volatility(ent, vol);
390 /* Return the name of the volatility. */
391 const char *get_volatility_name(ir_volatility var)
393 #define X(a) case a: return #a
395 X(volatility_non_volatile);
396 X(volatility_is_volatile);
397 default: return "BAD VALUE";
400 } /* get_volatility_name */
403 (get_entity_aligned)(const ir_entity *ent) {
404 return _get_entity_aligned(ent);
408 (set_entity_aligned)(ir_entity *ent, ir_align a) {
409 _set_entity_aligned(ent, a);
413 (get_entity_alignment)(const ir_entity *ent) {
414 return _get_entity_alignment(ent);
418 (set_entity_alignment)(ir_entity *ent, unsigned alignment) {
419 _set_entity_alignment(ent, alignment);
422 /* Return the name of the alignment. */
423 const char *get_align_name(ir_align a)
425 #define X(a) case a: return #a
427 X(align_non_aligned);
429 default: return "BAD VALUE";
432 } /* get_align_name */
435 set_entity_label(ir_entity *ent, ir_label_t label)
437 ent->attr.code_attr.label = label;
440 ir_label_t get_entity_label(const ir_entity *ent)
442 return ent->attr.code_attr.label;
445 static void verify_visibility(const ir_entity *entity)
447 if (get_entity_visibility(entity) == ir_visibility_external
448 && !is_method_entity(entity)) {
449 assert(!entity_has_definition(entity));
453 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
455 entity->visibility = visibility;
456 verify_visibility(entity);
459 ir_visibility get_entity_visibility(const ir_entity *entity)
461 return entity->visibility;
464 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
466 entity->linkage = linkage;
469 ir_linkage (get_entity_linkage)(const ir_entity *entity)
471 return get_entity_linkage(entity);
474 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
476 entity->linkage |= linkage;
479 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
481 entity->linkage &= ~linkage;
484 /* Checks if an entity is compiler generated */
485 int (is_entity_compiler_generated)(const ir_entity *ent)
487 return _is_entity_compiler_generated(ent);
488 } /* is_entity_compiler_generated */
490 /* Sets/resets the compiler generated flag */
491 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
493 _set_entity_compiler_generated(ent, flag);
494 } /* set_entity_compiler_generated */
496 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
498 return _get_entity_usage(ent);
501 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
503 _set_entity_usage(ent, flags);
506 /* Set has no effect for existent entities of type method. */
507 ir_node *get_atomic_ent_value(ir_entity *entity)
509 ir_initializer_t *initializer = get_entity_initializer(entity);
511 assert(entity && is_atomic_entity(entity));
512 if (initializer == NULL) {
513 ir_type *type = get_entity_type(entity);
514 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
517 switch (get_initializer_kind(initializer)) {
518 case IR_INITIALIZER_NULL: {
519 ir_type *type = get_entity_type(entity);
520 ir_mode *mode = get_type_mode(type);
521 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
523 case IR_INITIALIZER_TARVAL: {
524 tarval *tv = get_initializer_tarval_value(initializer);
525 return new_r_Const(get_const_code_irg(), tv);
527 case IR_INITIALIZER_CONST:
528 return get_initializer_const_value(initializer);
529 case IR_INITIALIZER_COMPOUND:
530 panic("compound initializer in atomic entity not allowed (%+F)", entity);
533 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
536 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
538 ir_initializer_t *initializer;
540 assert(is_atomic_entity(entity));
541 assert(get_entity_peculiarity(entity) != peculiarity_description);
543 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
544 initializer = create_initializer_const(val);
545 entity->initializer = initializer;
548 /* Returns true if the the node is representable as code on
550 int is_irn_const_expression(ir_node *n)
554 /* we are in danger iff an exception will arise. TODO: be more precisely,
555 * for instance Div. will NOT rise if divisor != 0
557 if (is_binop(n) && !is_fragile_op(n))
558 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
561 switch (get_irn_opcode(n)) {
568 return is_irn_const_expression(get_irn_n(n, 0));
573 } /* is_irn_const_expression */
576 * Copies a firm subgraph that complies to the restrictions for
577 * constant expressions to current_block in current_ir_graph.
579 ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
584 /* @@@ GL I think we should implement this using the routines from irgopt for
585 dead node elimination/inlineing. */
588 switch (get_irn_opcode(n)) {
590 nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n));
593 nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n),
594 get_SymConst_value_type(n));
597 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
598 copy_const_value(dbg, get_Add_right(n)), m); break;
600 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
601 copy_const_value(dbg, get_Sub_right(n)), m); break;
603 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
604 copy_const_value(dbg, get_Mul_right(n)), m); break;
606 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
607 copy_const_value(dbg, get_And_right(n)), m); break;
609 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
610 copy_const_value(dbg, get_Or_right(n)), m); break;
612 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
613 copy_const_value(dbg, get_Eor_right(n)), m); break;
615 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
617 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
619 nn = new_Unknown(m); break;
621 assert(0 && "opcode invalid or not implemented");
626 } /* copy_const_value */
628 /** Return the name of the initializer kind. */
629 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
631 #define X(a) case a: return #a
633 X(IR_INITIALIZER_CONST);
634 X(IR_INITIALIZER_TARVAL);
635 X(IR_INITIALIZER_NULL);
636 X(IR_INITIALIZER_COMPOUND);
637 default: return "BAD VALUE";
642 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
644 ir_initializer_t *get_initializer_null(void)
646 return &null_initializer;
649 ir_initializer_t *create_initializer_const(ir_node *value)
651 struct obstack *obst = get_irg_obstack(get_const_code_irg());
653 ir_initializer_t *initializer
654 = obstack_alloc(obst, sizeof(ir_initializer_const_t));
655 initializer->kind = IR_INITIALIZER_CONST;
656 initializer->consti.value = value;
661 ir_initializer_t *create_initializer_tarval(tarval *tv)
663 struct obstack *obst = get_irg_obstack(get_const_code_irg());
665 ir_initializer_t *initializer
666 = obstack_alloc(obst, sizeof(ir_initializer_tarval_t));
667 initializer->kind = IR_INITIALIZER_TARVAL;
668 initializer->tarval.value = tv;
673 ir_initializer_t *create_initializer_compound(unsigned n_entries)
675 struct obstack *obst = get_irg_obstack(get_const_code_irg());
678 size_t size = sizeof(ir_initializer_compound_t)
679 + (n_entries-1) * sizeof(ir_initializer_t*);
681 ir_initializer_t *initializer = obstack_alloc(obst, size);
682 initializer->kind = IR_INITIALIZER_COMPOUND;
683 initializer->compound.n_initializers = n_entries;
685 for (i = 0; i < n_entries; ++i) {
686 initializer->compound.initializers[i] = get_initializer_null();
692 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
694 assert(initializer->kind == IR_INITIALIZER_CONST);
695 return skip_Id(initializer->consti.value);
698 tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
700 assert(initializer->kind == IR_INITIALIZER_TARVAL);
701 return initializer->tarval.value;
704 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer)
706 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
707 return initializer->compound.n_initializers;
710 void set_initializer_compound_value(ir_initializer_t *initializer,
711 unsigned index, ir_initializer_t *value)
713 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
714 assert(index < initializer->compound.n_initializers);
716 initializer->compound.initializers[index] = value;
719 ir_initializer_t *get_initializer_compound_value(
720 const ir_initializer_t *initializer, unsigned index)
722 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
723 assert(index < initializer->compound.n_initializers);
725 return initializer->compound.initializers[index];
728 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
730 return initializer->kind;
733 static void check_entity_initializer(ir_entity *entity)
736 ir_initializer_t *initializer = entity->initializer;
737 switch (initializer->kind) {
738 case IR_INITIALIZER_COMPOUND:
739 assert(is_compound_entity(entity));
741 case IR_INITIALIZER_CONST:
742 case IR_INITIALIZER_TARVAL:
743 assert(is_atomic_entity(entity));
745 case IR_INITIALIZER_NULL:
751 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
753 entity->initializer = initializer;
754 check_entity_initializer(entity);
757 int has_entity_initializer(const ir_entity *entity)
759 return entity->initializer != NULL;
762 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
764 return entity->initializer;
767 int (get_entity_offset)(const ir_entity *ent)
769 return _get_entity_offset(ent);
772 void (set_entity_offset)(ir_entity *ent, int offset)
774 _set_entity_offset(ent, offset);
777 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
779 return _get_entity_offset_bits_remainder(ent);
782 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
784 _set_entity_offset_bits_remainder(ent, offset);
787 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
790 ir_type *owner = get_entity_owner(ent);
791 ir_type *ovw_ovner = get_entity_owner(overwritten);
792 assert(is_Class_type(owner));
793 assert(is_Class_type(ovw_ovner));
794 assert(! is_class_final(ovw_ovner));
796 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
797 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
800 int get_entity_n_overwrites(const ir_entity *ent)
802 assert(is_Class_type(get_entity_owner(ent)));
803 return (ARR_LEN(ent->overwrites));
806 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
809 assert(is_Class_type(get_entity_owner(ent)));
810 n = get_entity_n_overwrites(ent);
811 for (i = 0; i < n; ++i) {
812 if (get_entity_overwrites(ent, i) == overwritten)
818 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
820 assert(is_Class_type(get_entity_owner(ent)));
821 assert(pos < get_entity_n_overwrites(ent));
822 return ent->overwrites[pos];
825 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
827 assert(is_Class_type(get_entity_owner(ent)));
828 assert(pos < get_entity_n_overwrites(ent));
829 ent->overwrites[pos] = overwritten;
832 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
835 assert(is_Class_type(get_entity_owner(ent)));
836 n = ARR_LEN(ent->overwrites);
837 for (i = 0; i < n; ++i) {
838 if (ent->overwrites[i] == overwritten) {
839 for (; i < n - 1; i++)
840 ent->overwrites[i] = ent->overwrites[i+1];
841 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
847 void add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
849 add_entity_overwrites(overwrites, ent);
852 int get_entity_n_overwrittenby(const ir_entity *ent)
854 assert(is_Class_type(get_entity_owner(ent)));
855 return ARR_LEN(ent->overwrittenby);
858 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
861 assert(is_Class_type(get_entity_owner(ent)));
862 n = get_entity_n_overwrittenby(ent);
863 for (i = 0; i < n; ++i) {
864 if (get_entity_overwrittenby(ent, i) == overwrites)
870 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
872 assert(is_Class_type(get_entity_owner(ent)));
873 assert(pos < get_entity_n_overwrittenby(ent));
874 return ent->overwrittenby[pos];
877 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
879 assert(is_Class_type(get_entity_owner(ent)));
880 assert(pos < get_entity_n_overwrittenby(ent));
881 ent->overwrittenby[pos] = overwrites;
884 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
887 assert(is_Class_type(get_entity_owner(ent)));
889 n = ARR_LEN(ent->overwrittenby);
890 for (i = 0; i < n; ++i) {
891 if (ent->overwrittenby[i] == overwrites) {
892 for (; i < n - 1; ++i)
893 ent->overwrittenby[i] = ent->overwrittenby[i+1];
894 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
900 void *(get_entity_link)(const ir_entity *ent)
902 return _get_entity_link(ent);
905 void (set_entity_link)(ir_entity *ent, void *l)
907 _set_entity_link(ent, l);
910 ir_graph *(get_entity_irg)(const ir_entity *ent)
912 return _get_entity_irg(ent);
915 void set_entity_irg(ir_entity *ent, ir_graph *irg)
917 assert(is_method_entity(ent));
918 assert(get_entity_peculiarity(ent) == peculiarity_existent);
919 ent->attr.mtd_attr.irg = irg;
922 unsigned get_entity_vtable_number(const ir_entity *ent)
924 assert(is_method_entity((ir_entity *)ent));
925 return ent->attr.mtd_attr.vtable_number;
928 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
930 assert(is_method_entity(ent));
931 ent->attr.mtd_attr.vtable_number = vtable_number;
934 int (is_entity)(const void *thing)
936 return _is_entity(thing);
939 int is_atomic_entity(const ir_entity *ent)
941 ir_type *t = get_entity_type(ent);
942 const tp_op *op = get_type_tpop(t);
943 return (op == type_primitive || op == type_pointer ||
944 op == type_enumeration || op == type_method);
947 int is_compound_entity(const ir_entity *ent)
949 ir_type *t = get_entity_type(ent);
950 const tp_op *op = get_type_tpop(t);
951 return (op == type_class || op == type_struct ||
952 op == type_array || op == type_union);
955 int is_method_entity(const ir_entity *ent)
957 ir_type *t = get_entity_type(ent);
958 return is_Method_type(t);
961 ir_visited_t (get_entity_visited)(const ir_entity *ent)
963 return _get_entity_visited(ent);
966 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
968 _set_entity_visited(ent, num);
971 void (mark_entity_visited)(ir_entity *ent)
973 _mark_entity_visited(ent);
976 int (entity_visited)(const ir_entity *ent)
978 return _entity_visited(ent);
981 int (entity_not_visited)(const ir_entity *ent)
983 return _entity_not_visited(ent);
986 unsigned get_entity_additional_properties(const ir_entity *ent)
990 assert(is_method_entity(ent));
992 /* first check, if the graph has additional properties */
993 irg = get_entity_irg(ent);
996 return get_irg_additional_properties(irg);
998 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
999 return get_method_additional_properties(get_entity_type(ent));
1001 return ent->attr.mtd_attr.irg_add_properties;
1004 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
1008 assert(is_method_entity(ent));
1010 /* first check, if the graph exists */
1011 irg = get_entity_irg(ent);
1013 set_irg_additional_properties(irg, property_mask);
1015 /* do not allow to set the mtp_property_inherited flag or
1016 * the automatic inheritance of flags will not work */
1017 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1021 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
1025 assert(is_method_entity(ent));
1027 /* first check, if the graph exists */
1028 irg = get_entity_irg(ent);
1030 set_irg_additional_property(irg, flag);
1032 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
1034 if (mask & mtp_property_inherited)
1035 mask = get_method_additional_properties(get_entity_type(ent));
1037 /* do not allow to set the mtp_property_inherited flag or
1038 * the automatic inheritance of flags will not work */
1039 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
1043 /* Returns the class type that this type info entity represents or NULL
1044 if ent is no type info entity. */
1045 ir_type *(get_entity_repr_class)(const ir_entity *ent)
1047 return _get_entity_repr_class(ent);
1050 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
1052 return _get_entity_dbg_info(ent);
1055 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
1057 _set_entity_dbg_info(ent, db);
1060 int entity_is_externally_visible(const ir_entity *entity)
1062 return get_entity_visibility(entity) != ir_visibility_local
1063 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1066 int entity_has_definition(const ir_entity *entity)
1068 return entity->initializer != NULL
1069 || get_entity_irg(entity) != NULL
1070 || entity_has_compound_ent_values(entity);
1073 void firm_init_entity(void)
1075 symconst_symbol sym;
1077 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1078 assert(!unknown_entity && "Call firm_init_entity() only once!");
1080 unknown_entity = new_rd_entity(NULL, firm_unknown_type, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type);
1081 set_entity_visibility(unknown_entity, ir_visibility_external);
1083 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1085 current_ir_graph = get_const_code_irg();
1086 sym.entity_p = unknown_entity;
1089 ir_allocation get_entity_allocation(const ir_entity *entity)
1091 return entity->allocation;
1094 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1096 entity->allocation = allocation;
1099 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1101 return entity->peculiarity;
1104 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1106 entity->peculiarity = peculiarity;
1109 void set_entity_final(ir_entity *entity, int final)
1111 entity->final = final;
1114 int is_entity_final(const ir_entity *entity)
1116 return entity->final;