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 *new_rd_entity(dbg_info *db, ir_type *owner,
98 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 */
163 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type, dbg_info *db)
167 assert(is_compound_type(owner));
168 res = new_rd_entity(db, owner, name, type);
169 /* Remember entity in it's owner. */
170 insert_entity_in_owner(res);
172 hook_new_entity(res);
176 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
178 return new_d_entity(owner, name, type, NULL);
182 * Free entity attributes.
184 * @param ent the entity
186 static void free_entity_attrs(ir_entity *ent)
189 if (get_type_tpop(get_entity_owner(ent)) == type_class) {
190 DEL_ARR_F(ent->overwrites); ent->overwrites = NULL;
191 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
193 assert(ent->overwrites == NULL);
194 assert(ent->overwrittenby == NULL);
196 if (ent->initializer != NULL) {
197 /* TODO: free initializers */
198 } else if (entity_has_compound_ent_values(ent)) {
199 if (ent->attr.cmpd_attr.val_paths) {
200 for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i)
201 if (ent->attr.cmpd_attr.val_paths[i]) {
202 /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */
203 /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
204 /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */
206 ent->attr.cmpd_attr.val_paths = NULL;
209 if (is_compound_entity(ent)) {
210 if (ent->attr.cmpd_attr.values) {
211 /*DEL_ARR_F(ent->attr.cmpd_attr.values)*/;
213 ent->attr.cmpd_attr.values = NULL;
214 } else if (is_method_entity(ent)) {
215 if (ent->attr.mtd_attr.param_access) {
216 DEL_ARR_F(ent->attr.mtd_attr.param_access);
217 ent->attr.mtd_attr.param_access = NULL;
219 if (ent->attr.mtd_attr.param_weight) {
220 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
221 ent->attr.mtd_attr.param_weight = NULL;
224 } /* free_entity_attrs */
227 * Creates a deep copy of an entity.
229 static ir_entity *deep_entity_copy(ir_entity *old)
231 ir_entity *newe = XMALLOC(ir_entity);
234 if (old->initializer != NULL) {
235 /* FIXME: the initializers are NOT copied */
236 } else if (entity_has_compound_ent_values(old)) {
237 newe->attr.cmpd_attr.values = NULL;
238 newe->attr.cmpd_attr.val_paths = NULL;
239 if (old->attr.cmpd_attr.values)
240 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
242 /* FIXME: the compound graph paths are NOT copied */
243 if (old->attr.cmpd_attr.val_paths)
244 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
245 } else if (is_method_entity(old)) {
246 /* do NOT copy them, reanalyze. This might be the best solution */
247 newe->attr.mtd_attr.param_access = NULL;
248 newe->attr.mtd_attr.param_weight = NULL;
252 newe->nr = get_irp_new_node_nr();
257 * Copies the entity if the new_owner is different from the
258 * owner of the old entity, else returns the old entity.
260 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
263 assert(is_entity(old));
264 assert(is_compound_type(new_owner));
265 assert(get_type_state(new_owner) != layout_fixed);
267 if (old->owner == new_owner)
270 /* create a deep copy so we are safe of aliasing and double-freeing. */
271 newe = deep_entity_copy(old);
272 newe->owner = new_owner;
274 if (is_Class_type(new_owner)) {
275 newe->overwrites = NEW_ARR_F(ir_entity *, 0);
276 newe->overwrittenby = NEW_ARR_F(ir_entity *, 0);
279 insert_entity_in_owner(newe);
281 } /* copy_entity_own */
283 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
286 assert(old && old->kind == k_entity);
288 if (old->name == new_name) return old;
289 newe = deep_entity_copy(old);
290 newe->name = new_name;
291 newe->ld_name = NULL;
293 if (is_Class_type(newe->owner)) {
294 newe->overwrites = DUP_ARR_F(ir_entity *, old->overwrites);
295 newe->overwrittenby = DUP_ARR_F(ir_entity *, old->overwrittenby);
297 insert_entity_in_owner(newe);
300 } /* copy_entity_name */
302 void free_entity(ir_entity *ent)
304 assert(ent && ent->kind == k_entity);
305 free_entity_attrs(ent);
310 /* Outputs a unique number for this node */
311 long get_entity_nr(const ir_entity *ent)
313 assert(ent && ent->kind == k_entity);
317 return (long)PTR_TO_INT(ent);
319 } /* get_entity_nr */
321 const char *(get_entity_name)(const ir_entity *ent)
323 return _get_entity_name(ent);
326 ident *(get_entity_ident)(const ir_entity *ent)
328 return _get_entity_ident(ent);
331 void (set_entity_ident)(ir_entity *ent, ident *id)
333 _set_entity_ident(ent, id);
336 ir_type *(get_entity_owner)(const ir_entity *ent)
338 return _get_entity_owner(ent);
341 void set_entity_owner(ir_entity *ent, ir_type *owner)
343 assert(is_entity(ent));
344 assert(is_compound_type(owner));
348 ident *(get_entity_ld_ident)(const ir_entity *ent)
350 return _get_entity_ld_ident(ent);
353 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
355 _set_entity_ld_ident(ent, ld_ident);
358 const char *(get_entity_ld_name)(const ir_entity *ent)
360 return _get_entity_ld_name(ent);
363 ir_type *(get_entity_type)(const ir_entity *ent)
365 return _get_entity_type(ent);
368 void (set_entity_type)(ir_entity *ent, ir_type *type)
370 _set_entity_type(ent, type);
373 ir_volatility (get_entity_volatility)(const ir_entity *ent)
375 return _get_entity_volatility(ent);
378 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
380 _set_entity_volatility(ent, vol);
383 /* Return the name of the volatility. */
384 const char *get_volatility_name(ir_volatility var)
386 #define X(a) case a: return #a
388 X(volatility_non_volatile);
389 X(volatility_is_volatile);
390 default: return "BAD VALUE";
393 } /* get_volatility_name */
395 ir_align (get_entity_aligned)(const ir_entity *ent)
397 return _get_entity_aligned(ent);
400 void (set_entity_aligned)(ir_entity *ent, ir_align a)
402 _set_entity_aligned(ent, a);
405 unsigned (get_entity_alignment)(const ir_entity *ent)
407 return _get_entity_alignment(ent);
410 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
412 _set_entity_alignment(ent, alignment);
415 /* Return the name of the alignment. */
416 const char *get_align_name(ir_align a)
418 #define X(a) case a: return #a
420 X(align_non_aligned);
422 default: return "BAD VALUE";
425 } /* get_align_name */
427 void set_entity_label(ir_entity *ent, ir_label_t label)
429 ent->attr.code_attr.label = label;
432 ir_label_t get_entity_label(const ir_entity *ent)
434 return ent->attr.code_attr.label;
437 static void verify_visibility(const ir_entity *entity)
439 if (get_entity_visibility(entity) == ir_visibility_external
440 && !is_method_entity(entity)) {
441 assert(!entity_has_definition(entity));
445 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
447 entity->visibility = visibility;
448 verify_visibility(entity);
451 ir_visibility get_entity_visibility(const ir_entity *entity)
453 return entity->visibility;
456 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
458 entity->linkage = linkage;
461 ir_linkage (get_entity_linkage)(const ir_entity *entity)
463 return get_entity_linkage(entity);
466 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
468 entity->linkage |= linkage;
471 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
473 entity->linkage &= ~linkage;
476 /* Checks if an entity is compiler generated */
477 int (is_entity_compiler_generated)(const ir_entity *ent)
479 return _is_entity_compiler_generated(ent);
480 } /* is_entity_compiler_generated */
482 /* Sets/resets the compiler generated flag */
483 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
485 _set_entity_compiler_generated(ent, flag);
486 } /* set_entity_compiler_generated */
488 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
490 return _get_entity_usage(ent);
493 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
495 _set_entity_usage(ent, flags);
498 /* Set has no effect for existent entities of type method. */
499 ir_node *get_atomic_ent_value(ir_entity *entity)
501 ir_initializer_t *initializer = get_entity_initializer(entity);
503 assert(entity && is_atomic_entity(entity));
504 if (initializer == NULL) {
505 ir_type *type = get_entity_type(entity);
506 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
509 switch (get_initializer_kind(initializer)) {
510 case IR_INITIALIZER_NULL: {
511 ir_type *type = get_entity_type(entity);
512 ir_mode *mode = get_type_mode(type);
513 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
515 case IR_INITIALIZER_TARVAL: {
516 tarval *tv = get_initializer_tarval_value(initializer);
517 return new_r_Const(get_const_code_irg(), tv);
519 case IR_INITIALIZER_CONST:
520 return get_initializer_const_value(initializer);
521 case IR_INITIALIZER_COMPOUND:
522 panic("compound initializer in atomic entity not allowed (%+F)", entity);
525 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
528 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
530 ir_initializer_t *initializer;
532 assert(is_atomic_entity(entity));
534 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
535 initializer = create_initializer_const(val);
536 entity->initializer = initializer;
539 /* Returns true if the the node is representable as code on
541 int is_irn_const_expression(ir_node *n)
545 /* we are in danger iff an exception will arise. TODO: be more precisely,
546 * for instance Div. will NOT rise if divisor != 0
548 if (is_binop(n) && !is_fragile_op(n))
549 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
552 switch (get_irn_opcode(n)) {
559 return is_irn_const_expression(get_irn_n(n, 0));
564 } /* is_irn_const_expression */
567 * Copies a firm subgraph that complies to the restrictions for
568 * constant expressions to current_block in current_ir_graph.
570 ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
575 /* @@@ GL I think we should implement this using the routines from irgopt for
576 dead node elimination/inlineing. */
579 switch (get_irn_opcode(n)) {
581 nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n));
584 nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n),
585 get_SymConst_value_type(n));
588 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
589 copy_const_value(dbg, get_Add_right(n)), m); break;
591 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
592 copy_const_value(dbg, get_Sub_right(n)), m); break;
594 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
595 copy_const_value(dbg, get_Mul_right(n)), m); break;
597 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
598 copy_const_value(dbg, get_And_right(n)), m); break;
600 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
601 copy_const_value(dbg, get_Or_right(n)), m); break;
603 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
604 copy_const_value(dbg, get_Eor_right(n)), m); break;
606 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
608 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
610 nn = new_Unknown(m); break;
612 assert(0 && "opcode invalid or not implemented");
617 } /* copy_const_value */
619 /** Return the name of the initializer kind. */
620 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
622 #define X(a) case a: return #a
624 X(IR_INITIALIZER_CONST);
625 X(IR_INITIALIZER_TARVAL);
626 X(IR_INITIALIZER_NULL);
627 X(IR_INITIALIZER_COMPOUND);
628 default: return "BAD VALUE";
633 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
635 ir_initializer_t *get_initializer_null(void)
637 return &null_initializer;
640 ir_initializer_t *create_initializer_const(ir_node *value)
642 struct obstack *obst = get_irg_obstack(get_const_code_irg());
644 ir_initializer_t *initializer
645 = obstack_alloc(obst, sizeof(ir_initializer_const_t));
646 initializer->kind = IR_INITIALIZER_CONST;
647 initializer->consti.value = value;
652 ir_initializer_t *create_initializer_tarval(tarval *tv)
654 struct obstack *obst = get_irg_obstack(get_const_code_irg());
656 ir_initializer_t *initializer
657 = obstack_alloc(obst, sizeof(ir_initializer_tarval_t));
658 initializer->kind = IR_INITIALIZER_TARVAL;
659 initializer->tarval.value = tv;
664 ir_initializer_t *create_initializer_compound(unsigned n_entries)
666 struct obstack *obst = get_irg_obstack(get_const_code_irg());
669 size_t size = sizeof(ir_initializer_compound_t)
670 + (n_entries-1) * sizeof(ir_initializer_t*);
672 ir_initializer_t *initializer = obstack_alloc(obst, size);
673 initializer->kind = IR_INITIALIZER_COMPOUND;
674 initializer->compound.n_initializers = n_entries;
676 for (i = 0; i < n_entries; ++i) {
677 initializer->compound.initializers[i] = get_initializer_null();
683 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
685 assert(initializer->kind == IR_INITIALIZER_CONST);
686 return skip_Id(initializer->consti.value);
689 tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
691 assert(initializer->kind == IR_INITIALIZER_TARVAL);
692 return initializer->tarval.value;
695 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer)
697 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
698 return initializer->compound.n_initializers;
701 void set_initializer_compound_value(ir_initializer_t *initializer,
702 unsigned index, ir_initializer_t *value)
704 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
705 assert(index < initializer->compound.n_initializers);
707 initializer->compound.initializers[index] = value;
710 ir_initializer_t *get_initializer_compound_value(
711 const ir_initializer_t *initializer, unsigned index)
713 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
714 assert(index < initializer->compound.n_initializers);
716 return initializer->compound.initializers[index];
719 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
721 return initializer->kind;
724 static void check_entity_initializer(ir_entity *entity)
727 ir_initializer_t *initializer = entity->initializer;
728 switch (initializer->kind) {
729 case IR_INITIALIZER_COMPOUND:
730 assert(is_compound_entity(entity));
732 case IR_INITIALIZER_CONST:
733 case IR_INITIALIZER_TARVAL:
734 assert(is_atomic_entity(entity));
736 case IR_INITIALIZER_NULL:
742 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
744 entity->initializer = initializer;
745 check_entity_initializer(entity);
748 int has_entity_initializer(const ir_entity *entity)
750 return entity->initializer != NULL;
753 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
755 return entity->initializer;
758 int (get_entity_offset)(const ir_entity *ent)
760 return _get_entity_offset(ent);
763 void (set_entity_offset)(ir_entity *ent, int offset)
765 _set_entity_offset(ent, offset);
768 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
770 return _get_entity_offset_bits_remainder(ent);
773 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
775 _set_entity_offset_bits_remainder(ent, offset);
778 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
781 ir_type *owner = get_entity_owner(ent);
782 ir_type *ovw_ovner = get_entity_owner(overwritten);
783 assert(is_Class_type(owner));
784 assert(is_Class_type(ovw_ovner));
785 assert(! is_class_final(ovw_ovner));
787 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
788 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
791 int get_entity_n_overwrites(const ir_entity *ent)
793 assert(is_Class_type(get_entity_owner(ent)));
794 return (ARR_LEN(ent->overwrites));
797 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
800 assert(is_Class_type(get_entity_owner(ent)));
801 n = get_entity_n_overwrites(ent);
802 for (i = 0; i < n; ++i) {
803 if (get_entity_overwrites(ent, i) == overwritten)
809 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
811 assert(is_Class_type(get_entity_owner(ent)));
812 assert(pos < get_entity_n_overwrites(ent));
813 return ent->overwrites[pos];
816 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
818 assert(is_Class_type(get_entity_owner(ent)));
819 assert(pos < get_entity_n_overwrites(ent));
820 ent->overwrites[pos] = overwritten;
823 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
826 assert(is_Class_type(get_entity_owner(ent)));
827 n = ARR_LEN(ent->overwrites);
828 for (i = 0; i < n; ++i) {
829 if (ent->overwrites[i] == overwritten) {
830 for (; i < n - 1; i++)
831 ent->overwrites[i] = ent->overwrites[i+1];
832 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
838 void add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
840 add_entity_overwrites(overwrites, ent);
843 int get_entity_n_overwrittenby(const ir_entity *ent)
845 assert(is_Class_type(get_entity_owner(ent)));
846 return ARR_LEN(ent->overwrittenby);
849 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
852 assert(is_Class_type(get_entity_owner(ent)));
853 n = get_entity_n_overwrittenby(ent);
854 for (i = 0; i < n; ++i) {
855 if (get_entity_overwrittenby(ent, i) == overwrites)
861 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
863 assert(is_Class_type(get_entity_owner(ent)));
864 assert(pos < get_entity_n_overwrittenby(ent));
865 return ent->overwrittenby[pos];
868 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
870 assert(is_Class_type(get_entity_owner(ent)));
871 assert(pos < get_entity_n_overwrittenby(ent));
872 ent->overwrittenby[pos] = overwrites;
875 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
878 assert(is_Class_type(get_entity_owner(ent)));
880 n = ARR_LEN(ent->overwrittenby);
881 for (i = 0; i < n; ++i) {
882 if (ent->overwrittenby[i] == overwrites) {
883 for (; i < n - 1; ++i)
884 ent->overwrittenby[i] = ent->overwrittenby[i+1];
885 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
891 void *(get_entity_link)(const ir_entity *ent)
893 return _get_entity_link(ent);
896 void (set_entity_link)(ir_entity *ent, void *l)
898 _set_entity_link(ent, l);
901 ir_graph *(get_entity_irg)(const ir_entity *ent)
903 return _get_entity_irg(ent);
906 void set_entity_irg(ir_entity *ent, ir_graph *irg)
908 assert(is_method_entity(ent));
909 assert(get_entity_peculiarity(ent) == peculiarity_existent);
910 ent->attr.mtd_attr.irg = irg;
913 unsigned get_entity_vtable_number(const ir_entity *ent)
915 assert(is_method_entity((ir_entity *)ent));
916 return ent->attr.mtd_attr.vtable_number;
919 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
921 assert(is_method_entity(ent));
922 ent->attr.mtd_attr.vtable_number = vtable_number;
925 int (is_entity)(const void *thing)
927 return _is_entity(thing);
930 int is_atomic_entity(const ir_entity *ent)
932 ir_type *t = get_entity_type(ent);
933 const tp_op *op = get_type_tpop(t);
934 return (op == type_primitive || op == type_pointer ||
935 op == type_enumeration || op == type_method);
938 int is_compound_entity(const ir_entity *ent)
940 ir_type *t = get_entity_type(ent);
941 const tp_op *op = get_type_tpop(t);
942 return (op == type_class || op == type_struct ||
943 op == type_array || op == type_union);
946 int is_method_entity(const ir_entity *ent)
948 ir_type *t = get_entity_type(ent);
949 return is_Method_type(t);
952 ir_visited_t (get_entity_visited)(const ir_entity *ent)
954 return _get_entity_visited(ent);
957 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
959 _set_entity_visited(ent, num);
962 void (mark_entity_visited)(ir_entity *ent)
964 _mark_entity_visited(ent);
967 int (entity_visited)(const ir_entity *ent)
969 return _entity_visited(ent);
972 int (entity_not_visited)(const ir_entity *ent)
974 return _entity_not_visited(ent);
977 unsigned get_entity_additional_properties(const ir_entity *ent)
981 assert(is_method_entity(ent));
983 /* first check, if the graph has additional properties */
984 irg = get_entity_irg(ent);
987 return get_irg_additional_properties(irg);
989 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
990 return get_method_additional_properties(get_entity_type(ent));
992 return ent->attr.mtd_attr.irg_add_properties;
995 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
999 assert(is_method_entity(ent));
1001 /* first check, if the graph exists */
1002 irg = get_entity_irg(ent);
1004 set_irg_additional_properties(irg, property_mask);
1006 /* do not allow to set the mtp_property_inherited flag or
1007 * the automatic inheritance of flags will not work */
1008 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1012 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
1016 assert(is_method_entity(ent));
1018 /* first check, if the graph exists */
1019 irg = get_entity_irg(ent);
1021 set_irg_additional_property(irg, flag);
1023 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
1025 if (mask & mtp_property_inherited)
1026 mask = get_method_additional_properties(get_entity_type(ent));
1028 /* do not allow to set the mtp_property_inherited flag or
1029 * the automatic inheritance of flags will not work */
1030 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
1034 /* Returns the class type that this type info entity represents or NULL
1035 if ent is no type info entity. */
1036 ir_type *(get_entity_repr_class)(const ir_entity *ent)
1038 return _get_entity_repr_class(ent);
1041 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
1043 return _get_entity_dbg_info(ent);
1046 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
1048 _set_entity_dbg_info(ent, db);
1051 int entity_is_externally_visible(const ir_entity *entity)
1053 return get_entity_visibility(entity) != ir_visibility_local
1054 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1057 int entity_has_definition(const ir_entity *entity)
1059 return entity->initializer != NULL
1060 || get_entity_irg(entity) != NULL
1061 || entity_has_compound_ent_values(entity);
1064 void firm_init_entity(void)
1066 symconst_symbol sym;
1068 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1069 assert(!unknown_entity && "Call firm_init_entity() only once!");
1071 unknown_entity = new_rd_entity(NULL, firm_unknown_type, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type);
1072 set_entity_visibility(unknown_entity, ir_visibility_external);
1074 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1076 current_ir_graph = get_const_code_irg();
1077 sym.entity_p = unknown_entity;
1080 ir_allocation get_entity_allocation(const ir_entity *entity)
1082 return entity->allocation;
1085 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1087 entity->allocation = allocation;
1090 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1092 return entity->peculiarity;
1095 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1097 entity->peculiarity = peculiarity;
1100 void set_entity_final(ir_entity *entity, int final)
1102 entity->final = final;
1105 int is_entity_final(const ir_entity *entity)
1107 return entity->final;