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 /*-----------------------------------------------------------------*/
63 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
69 assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
71 res = XMALLOCZ(ir_entity);
79 res->volatility = volatility_non_volatile;
80 res->aligned = align_is_aligned;
81 res->usage = ir_usage_unknown;
82 res->compiler_gen = 0;
83 res->visibility = ir_visibility_default;
85 res->offset_bit_remainder = 0;
88 res->repr_class = NULL;
90 if (is_Method_type(type)) {
92 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
94 rem = current_ir_graph;
95 current_ir_graph = get_const_code_irg();
96 set_atomic_ent_value(res, new_SymConst(mode, sym, symconst_addr_ent));
97 current_ir_graph = rem;
98 res->linkage = IR_LINKAGE_CONSTANT;
99 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
100 res->attr.mtd_attr.vtable_number = VTABLE_NUM_NOT_SET;
101 res->attr.mtd_attr.param_access = NULL;
102 res->attr.mtd_attr.param_weight = NULL;
103 res->attr.mtd_attr.irg = NULL;
104 } else if (is_compound_type(type)) {
105 res->attr.cmpd_attr.values = NULL;
106 res->attr.cmpd_attr.val_paths = NULL;
107 } else if (is_code_type(type)) {
108 res->attr.code_attr.label = (ir_label_t) -1;
111 /* Remember entity in it's owner. */
113 add_compound_member(owner, res);
116 res->nr = get_irp_new_node_nr();
120 set_entity_dbg_info(res, db);
122 hook_new_entity(res);
127 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
129 return new_d_entity(owner, name, type, NULL);
133 * Free entity attributes.
135 * @param ent the entity
137 static void free_entity_attrs(ir_entity *ent)
139 if (ent->overwrites != NULL) {
140 DEL_ARR_F(ent->overwrites);
141 ent->overwrites = NULL;
143 if (ent->overwrittenby != NULL) {
144 DEL_ARR_F(ent->overwrittenby);
145 ent->overwrittenby = NULL;
148 if (ent->initializer != NULL) {
149 /* TODO: free initializers */
150 } else if (entity_has_compound_ent_values(ent)) {
151 /* can't free compound graph path as it might be used
153 ent->attr.cmpd_attr.val_paths = NULL;
155 if (is_compound_entity(ent)) {
156 ent->attr.cmpd_attr.values = NULL;
157 } else if (is_method_entity(ent)) {
158 if (ent->attr.mtd_attr.param_access) {
159 DEL_ARR_F(ent->attr.mtd_attr.param_access);
160 ent->attr.mtd_attr.param_access = NULL;
162 if (ent->attr.mtd_attr.param_weight) {
163 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
164 ent->attr.mtd_attr.param_weight = NULL;
170 * Creates a deep copy of an entity.
172 static ir_entity *deep_entity_copy(ir_entity *old)
174 ir_entity *newe = XMALLOC(ir_entity);
177 if (old->initializer != NULL) {
178 /* FIXME: the initializers are NOT copied */
179 } else if (entity_has_compound_ent_values(old)) {
180 newe->attr.cmpd_attr.values = NULL;
181 newe->attr.cmpd_attr.val_paths = NULL;
182 if (old->attr.cmpd_attr.values)
183 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
185 /* FIXME: the compound graph paths are NOT copied */
186 if (old->attr.cmpd_attr.val_paths)
187 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
188 } else if (is_method_entity(old)) {
189 /* do NOT copy them, reanalyze. This might be the best solution */
190 newe->attr.mtd_attr.param_access = NULL;
191 newe->attr.mtd_attr.param_weight = NULL;
193 newe->overwrites = NULL;
194 newe->overwrittenby = NULL;
197 newe->nr = get_irp_new_node_nr();
203 * Copies the entity if the new_owner is different from the
204 * owner of the old entity, else returns the old entity.
206 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
209 assert(is_entity(old));
210 assert(is_compound_type(new_owner));
211 assert(get_type_state(new_owner) != layout_fixed);
213 if (old->owner == new_owner)
216 /* create a deep copy so we are safe of aliasing and double-freeing. */
217 newe = deep_entity_copy(old);
218 newe->owner = new_owner;
219 add_compound_member(new_owner, newe);
224 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
227 assert(old && old->kind == k_entity);
229 if (old->name == new_name)
232 newe = deep_entity_copy(old);
233 newe->name = new_name;
234 newe->ld_name = NULL;
235 add_compound_member(old->owner, newe);
240 void free_entity(ir_entity *ent)
242 remove_compound_member(ent->owner, ent);
244 assert(ent && ent->kind == k_entity);
245 free_entity_attrs(ent);
250 /* Outputs a unique number for this node */
251 long get_entity_nr(const ir_entity *ent)
253 assert(ent && ent->kind == k_entity);
257 return (long)PTR_TO_INT(ent);
261 const char *(get_entity_name)(const ir_entity *ent)
263 return _get_entity_name(ent);
266 ident *(get_entity_ident)(const ir_entity *ent)
268 return _get_entity_ident(ent);
271 void (set_entity_ident)(ir_entity *ent, ident *id)
273 _set_entity_ident(ent, id);
276 ir_type *(get_entity_owner)(const ir_entity *ent)
278 return _get_entity_owner(ent);
281 void set_entity_owner(ir_entity *ent, ir_type *owner)
283 assert(is_entity(ent));
284 assert(is_compound_type(owner));
286 remove_compound_member(ent->owner, ent);
287 add_compound_member(owner, ent);
291 ident *(get_entity_ld_ident)(const ir_entity *ent)
293 return _get_entity_ld_ident(ent);
296 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
298 _set_entity_ld_ident(ent, ld_ident);
301 const char *(get_entity_ld_name)(const ir_entity *ent)
303 return _get_entity_ld_name(ent);
306 ir_type *(get_entity_type)(const ir_entity *ent)
308 return _get_entity_type(ent);
311 void (set_entity_type)(ir_entity *ent, ir_type *type)
313 _set_entity_type(ent, type);
316 ir_volatility (get_entity_volatility)(const ir_entity *ent)
318 return _get_entity_volatility(ent);
321 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
323 _set_entity_volatility(ent, vol);
326 /* Return the name of the volatility. */
327 const char *get_volatility_name(ir_volatility var)
329 #define X(a) case a: return #a
331 X(volatility_non_volatile);
332 X(volatility_is_volatile);
333 default: return "BAD VALUE";
338 ir_align (get_entity_aligned)(const ir_entity *ent)
340 return _get_entity_aligned(ent);
343 void (set_entity_aligned)(ir_entity *ent, ir_align a)
345 _set_entity_aligned(ent, a);
348 unsigned (get_entity_alignment)(const ir_entity *ent)
350 return _get_entity_alignment(ent);
353 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
355 _set_entity_alignment(ent, alignment);
358 /* Return the name of the alignment. */
359 const char *get_align_name(ir_align a)
361 #define X(a) case a: return #a
363 X(align_non_aligned);
365 default: return "BAD VALUE";
370 void set_entity_label(ir_entity *ent, ir_label_t label)
372 ent->attr.code_attr.label = label;
375 ir_label_t get_entity_label(const ir_entity *ent)
377 return ent->attr.code_attr.label;
380 static void verify_visibility(const ir_entity *entity)
382 if (get_entity_visibility(entity) == ir_visibility_external
383 && !is_method_entity(entity)) {
384 assert(!entity_has_definition(entity));
388 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
390 entity->visibility = visibility;
391 verify_visibility(entity);
394 ir_visibility get_entity_visibility(const ir_entity *entity)
396 return entity->visibility;
399 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
401 entity->linkage = linkage;
404 ir_linkage (get_entity_linkage)(const ir_entity *entity)
406 return get_entity_linkage(entity);
409 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
411 entity->linkage |= linkage;
414 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
416 entity->linkage &= ~linkage;
419 /* Checks if an entity is compiler generated */
420 int (is_entity_compiler_generated)(const ir_entity *ent)
422 return _is_entity_compiler_generated(ent);
425 /* Sets/resets the compiler generated flag */
426 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
428 _set_entity_compiler_generated(ent, flag);
431 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
433 return _get_entity_usage(ent);
436 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
438 _set_entity_usage(ent, flags);
441 /* Set has no effect for existent entities of type method. */
442 ir_node *get_atomic_ent_value(ir_entity *entity)
444 ir_initializer_t *initializer = get_entity_initializer(entity);
446 assert(entity && is_atomic_entity(entity));
447 if (initializer == NULL) {
448 ir_type *type = get_entity_type(entity);
449 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
452 switch (get_initializer_kind(initializer)) {
453 case IR_INITIALIZER_NULL: {
454 ir_type *type = get_entity_type(entity);
455 ir_mode *mode = get_type_mode(type);
456 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
458 case IR_INITIALIZER_TARVAL: {
459 tarval *tv = get_initializer_tarval_value(initializer);
460 return new_r_Const(get_const_code_irg(), tv);
462 case IR_INITIALIZER_CONST:
463 return get_initializer_const_value(initializer);
464 case IR_INITIALIZER_COMPOUND:
465 panic("compound initializer in atomic entity not allowed (%+F)", entity);
468 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
471 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
473 ir_initializer_t *initializer;
475 assert(is_atomic_entity(entity));
477 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
478 initializer = create_initializer_const(val);
479 entity->initializer = initializer;
482 /* Returns true if the the node is representable as code on
484 int is_irn_const_expression(ir_node *n)
488 /* we are in danger iff an exception will arise. TODO: be more precisely,
489 * for instance Div. will NOT rise if divisor != 0
491 if (is_binop(n) && !is_fragile_op(n))
492 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
495 switch (get_irn_opcode(n)) {
502 return is_irn_const_expression(get_irn_n(n, 0));
510 * Copies a firm subgraph that complies to the restrictions for
511 * constant expressions to current_block in current_ir_graph.
513 ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
518 /* @@@ GL I think we should implement this using the routines from irgopt for
519 dead node elimination/inlineing. */
522 switch (get_irn_opcode(n)) {
524 nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n));
527 nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n),
528 get_SymConst_value_type(n));
531 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
532 copy_const_value(dbg, get_Add_right(n)), m); break;
534 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
535 copy_const_value(dbg, get_Sub_right(n)), m); break;
537 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
538 copy_const_value(dbg, get_Mul_right(n)), m); break;
540 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
541 copy_const_value(dbg, get_And_right(n)), m); break;
543 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
544 copy_const_value(dbg, get_Or_right(n)), m); break;
546 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
547 copy_const_value(dbg, get_Eor_right(n)), m); break;
549 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
551 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
553 nn = new_Unknown(m); break;
555 panic("opcode invalid or not implemented");
560 /** Return the name of the initializer kind. */
561 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
563 #define X(a) case a: return #a
565 X(IR_INITIALIZER_CONST);
566 X(IR_INITIALIZER_TARVAL);
567 X(IR_INITIALIZER_NULL);
568 X(IR_INITIALIZER_COMPOUND);
569 default: return "BAD VALUE";
574 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
576 ir_initializer_t *get_initializer_null(void)
578 return &null_initializer;
581 ir_initializer_t *create_initializer_const(ir_node *value)
583 struct obstack *obst = get_irg_obstack(get_const_code_irg());
585 ir_initializer_t *initializer
586 = obstack_alloc(obst, sizeof(ir_initializer_const_t));
587 initializer->kind = IR_INITIALIZER_CONST;
588 initializer->consti.value = value;
593 ir_initializer_t *create_initializer_tarval(tarval *tv)
595 struct obstack *obst = get_irg_obstack(get_const_code_irg());
597 ir_initializer_t *initializer
598 = obstack_alloc(obst, sizeof(ir_initializer_tarval_t));
599 initializer->kind = IR_INITIALIZER_TARVAL;
600 initializer->tarval.value = tv;
605 ir_initializer_t *create_initializer_compound(unsigned n_entries)
607 struct obstack *obst = get_irg_obstack(get_const_code_irg());
610 size_t size = sizeof(ir_initializer_compound_t)
611 + (n_entries-1) * sizeof(ir_initializer_t*);
613 ir_initializer_t *initializer = obstack_alloc(obst, size);
614 initializer->kind = IR_INITIALIZER_COMPOUND;
615 initializer->compound.n_initializers = n_entries;
617 for (i = 0; i < n_entries; ++i) {
618 initializer->compound.initializers[i] = get_initializer_null();
624 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
626 assert(initializer->kind == IR_INITIALIZER_CONST);
627 return skip_Id(initializer->consti.value);
630 tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
632 assert(initializer->kind == IR_INITIALIZER_TARVAL);
633 return initializer->tarval.value;
636 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer)
638 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
639 return initializer->compound.n_initializers;
642 void set_initializer_compound_value(ir_initializer_t *initializer,
643 unsigned index, ir_initializer_t *value)
645 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
646 assert(index < initializer->compound.n_initializers);
648 initializer->compound.initializers[index] = value;
651 ir_initializer_t *get_initializer_compound_value(
652 const ir_initializer_t *initializer, unsigned index)
654 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
655 assert(index < initializer->compound.n_initializers);
657 return initializer->compound.initializers[index];
660 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
662 return initializer->kind;
665 static void check_entity_initializer(ir_entity *entity)
668 ir_initializer_t *initializer = entity->initializer;
669 ir_type *entity_tp = get_entity_type(entity);
670 switch (initializer->kind) {
671 case IR_INITIALIZER_COMPOUND:
672 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
674 case IR_INITIALIZER_CONST:
675 /* methods are initialized by a SymConst */
676 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
678 case IR_INITIALIZER_TARVAL:
679 assert(is_atomic_type(entity_tp));
681 case IR_INITIALIZER_NULL:
687 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
689 entity->initializer = initializer;
690 check_entity_initializer(entity);
693 int has_entity_initializer(const ir_entity *entity)
695 return entity->initializer != NULL;
698 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
700 return entity->initializer;
703 int (get_entity_offset)(const ir_entity *ent)
705 return _get_entity_offset(ent);
708 void (set_entity_offset)(ir_entity *ent, int offset)
710 _set_entity_offset(ent, offset);
713 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
715 return _get_entity_offset_bits_remainder(ent);
718 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
720 _set_entity_offset_bits_remainder(ent, offset);
723 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
725 if (ent->overwrites == NULL) {
726 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
728 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
729 if (overwritten->overwrittenby == NULL) {
730 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
732 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
735 int get_entity_n_overwrites(const ir_entity *ent)
737 if (ent->overwrites == NULL)
739 return ARR_LEN(ent->overwrites);
742 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
745 n = get_entity_n_overwrites(ent);
746 for (i = 0; i < n; ++i) {
747 if (get_entity_overwrites(ent, i) == overwritten)
753 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
755 assert(pos < get_entity_n_overwrites(ent));
756 return ent->overwrites[pos];
759 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
761 assert(pos < get_entity_n_overwrites(ent));
762 ent->overwrites[pos] = overwritten;
765 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
768 n = get_entity_n_overwrites(ent);
769 for (i = 0; i < n; ++i) {
770 if (ent->overwrites[i] == overwritten) {
771 for (; i < n - 1; i++)
772 ent->overwrites[i] = ent->overwrites[i+1];
773 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
780 int get_entity_n_overwrittenby(const ir_entity *ent)
782 if (ent->overwrittenby == NULL)
784 return ARR_LEN(ent->overwrittenby);
787 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
790 n = get_entity_n_overwrittenby(ent);
791 for (i = 0; i < n; ++i) {
792 if (get_entity_overwrittenby(ent, i) == overwrites)
798 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
800 assert(pos < get_entity_n_overwrittenby(ent));
801 return ent->overwrittenby[pos];
804 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
806 assert(pos < get_entity_n_overwrittenby(ent));
807 ent->overwrittenby[pos] = overwrites;
810 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
814 n = get_entity_n_overwrittenby(ent);
815 for (i = 0; i < n; ++i) {
816 if (ent->overwrittenby[i] == overwrites) {
817 for (; i < n - 1; ++i)
818 ent->overwrittenby[i] = ent->overwrittenby[i+1];
819 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
825 void *(get_entity_link)(const ir_entity *ent)
827 return _get_entity_link(ent);
830 void (set_entity_link)(ir_entity *ent, void *l)
832 _set_entity_link(ent, l);
835 ir_graph *(get_entity_irg)(const ir_entity *ent)
837 return _get_entity_irg(ent);
840 void set_entity_irg(ir_entity *ent, ir_graph *irg)
842 assert(is_method_entity(ent));
843 assert(get_entity_peculiarity(ent) == peculiarity_existent);
844 ent->attr.mtd_attr.irg = irg;
847 unsigned get_entity_vtable_number(const ir_entity *ent)
849 assert(is_method_entity((ir_entity *)ent));
850 return ent->attr.mtd_attr.vtable_number;
853 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
855 assert(is_method_entity(ent));
856 ent->attr.mtd_attr.vtable_number = vtable_number;
859 int (is_entity)(const void *thing)
861 return _is_entity(thing);
864 int is_atomic_entity(const ir_entity *ent)
866 ir_type *t = get_entity_type(ent);
867 const tp_op *op = get_type_tpop(t);
868 return (op == type_primitive || op == type_pointer ||
869 op == type_enumeration || op == type_method);
872 int is_compound_entity(const ir_entity *ent)
874 ir_type *t = get_entity_type(ent);
875 const tp_op *op = get_type_tpop(t);
876 return (op == type_class || op == type_struct ||
877 op == type_array || op == type_union);
880 int is_method_entity(const ir_entity *ent)
882 ir_type *t = get_entity_type(ent);
883 return is_Method_type(t);
886 ir_visited_t (get_entity_visited)(const ir_entity *ent)
888 return _get_entity_visited(ent);
891 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
893 _set_entity_visited(ent, num);
896 void (mark_entity_visited)(ir_entity *ent)
898 _mark_entity_visited(ent);
901 int (entity_visited)(const ir_entity *ent)
903 return _entity_visited(ent);
906 int (entity_not_visited)(const ir_entity *ent)
908 return _entity_not_visited(ent);
911 unsigned get_entity_additional_properties(const ir_entity *ent)
915 assert(is_method_entity(ent));
917 /* first check, if the graph has additional properties */
918 irg = get_entity_irg(ent);
921 return get_irg_additional_properties(irg);
923 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
924 return get_method_additional_properties(get_entity_type(ent));
926 return ent->attr.mtd_attr.irg_add_properties;
929 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
933 assert(is_method_entity(ent));
935 /* first check, if the graph exists */
936 irg = get_entity_irg(ent);
938 set_irg_additional_properties(irg, property_mask);
940 /* do not allow to set the mtp_property_inherited flag or
941 * the automatic inheritance of flags will not work */
942 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
946 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
950 assert(is_method_entity(ent));
952 /* first check, if the graph exists */
953 irg = get_entity_irg(ent);
955 set_irg_additional_property(irg, flag);
957 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
959 if (mask & mtp_property_inherited)
960 mask = get_method_additional_properties(get_entity_type(ent));
962 /* do not allow to set the mtp_property_inherited flag or
963 * the automatic inheritance of flags will not work */
964 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
968 /* Returns the class type that this type info entity represents or NULL
969 if ent is no type info entity. */
970 ir_type *(get_entity_repr_class)(const ir_entity *ent)
972 return _get_entity_repr_class(ent);
975 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
977 return _get_entity_dbg_info(ent);
980 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
982 _set_entity_dbg_info(ent, db);
985 int entity_is_externally_visible(const ir_entity *entity)
987 return get_entity_visibility(entity) != ir_visibility_local
988 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
991 int entity_has_definition(const ir_entity *entity)
993 return entity->initializer != NULL
994 || get_entity_irg(entity) != NULL
995 || entity_has_compound_ent_values(entity);
998 void firm_init_entity(void)
1000 symconst_symbol sym;
1002 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1003 assert(!unknown_entity && "Call firm_init_entity() only once!");
1005 unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
1006 firm_unknown_type, NULL);
1007 set_entity_visibility(unknown_entity, ir_visibility_external);
1009 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1011 current_ir_graph = get_const_code_irg();
1012 sym.entity_p = unknown_entity;
1015 ir_allocation get_entity_allocation(const ir_entity *entity)
1017 return entity->allocation;
1020 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1022 entity->allocation = allocation;
1025 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1027 return entity->peculiarity;
1030 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1032 entity->peculiarity = peculiarity;
1035 void set_entity_final(ir_entity *entity, int final)
1037 entity->final = final;
1040 int is_entity_final(const ir_entity *entity)
1042 return entity->final;