fix mips immediate dumper
[libfirm] / ir / tr / entity.c
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Representation of all program known entities.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stddef.h>
33
34 #include "firm_common_t.h"
35
36 #include "xmalloc.h"
37 #include "entity_t.h"
38 #include "array.h"
39 #include "irtools.h"
40 #include "irhooks.h"
41 #include "irprintf.h"
42
43 /* All this is needed to build the constant node for methods: */
44 #include "irprog_t.h"
45 #include "ircons.h"
46 #include "tv_t.h"
47 #include "irdump.h"  /* for output if errors occur. */
48
49 #include "callgraph.h"  /* for dumping debug output */
50
51 /*******************************************************************/
52 /** general                                                       **/
53 /*******************************************************************/
54
55 ir_entity *unknown_entity = NULL;
56
57 ir_entity *get_unknown_entity(void) { return unknown_entity; }
58
59 #define UNKNOWN_ENTITY_NAME "unknown_entity"
60
61 /*-----------------------------------------------------------------*/
62 /* ENTITY                                                          */
63 /*-----------------------------------------------------------------*/
64
65 /**
66  * Add an entity to it's already set owner type.
67  */
68 static INLINE void insert_entity_in_owner(ir_entity *ent) {
69         ir_type *owner = ent->owner;
70         switch (get_type_tpop_code(owner)) {
71         case tpo_class:
72                 add_class_member(owner, ent);
73                 break;
74         case tpo_struct:
75                 add_struct_member(owner, ent);
76                 break;
77         case tpo_union:
78                 add_union_member(owner, ent);
79                 break;
80         case tpo_array:
81                 set_array_element_entity(owner, ent);
82                 break;
83         default: assert(0);
84         }
85 }  /* insert_entity_in_owner */
86
87 /**
88  * Creates a new entity. This entity is NOT inserted in the owner type.
89  *
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
94  *
95  * @return the new created entity
96  */
97 static INLINE ir_entity *
98 new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type)
99 {
100         ir_entity *res;
101         ir_graph *rem;
102
103         assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
104
105         res = xmalloc(sizeof(*res));
106         memset(res, 0, sizeof(*res));
107
108         res->kind    = k_entity;
109         res->name    = name;
110         res->ld_name = NULL;
111         res->type    = type;
112         res->owner   = owner;
113
114         res->allocation           = allocation_automatic;
115         res->visibility           = visibility_local;
116         res->volatility           = volatility_non_volatile;
117         res->stickyness           = stickyness_unsticky;
118         res->peculiarity          = peculiarity_existent;
119         res->address_taken        = ir_address_taken_unknown;
120         res->final                = 0;
121         res->compiler_gen         = 0;
122         res->backend_marked       = 0;
123         res->offset               = -1;
124         res->offset_bit_remainder = 0;
125         res->link                 = NULL;
126         res->repr_class           = NULL;
127
128         if (is_Method_type(type)) {
129                 symconst_symbol sym;
130                 sym.entity_p            = res;
131                 rem                     = current_ir_graph;
132                 current_ir_graph        = get_const_code_irg();
133                 res->value              = new_SymConst(sym, symconst_addr_ent);
134                 current_ir_graph        = rem;
135                 res->allocation         = allocation_static;
136                 res->variability        = variability_constant;
137                 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
138                 res->attr.mtd_attr.vtable_number      = VTABLE_NUM_NOT_SET;
139                 res->attr.mtd_attr.param_access       = NULL;
140                 res->attr.mtd_attr.param_weight       = NULL;
141                 res->attr.mtd_attr.irg                = NULL;
142                 res->attr.mtd_attr.section            = section_text;
143         } else if (is_compound_type(type)) {
144                 res->variability = variability_uninitialized;
145                 res->value       = NULL;
146                 res->attr.cmpd_attr.values    = NULL;
147                 res->attr.cmpd_attr.val_paths = NULL;
148         } else {
149                 res->variability = variability_uninitialized;
150                 res->value       = NULL;
151         }
152
153         if (is_Class_type(owner)) {
154                 res->overwrites    = NEW_ARR_F(ir_entity *, 0);
155                 res->overwrittenby = NEW_ARR_F(ir_entity *, 0);
156         } else {
157                 res->overwrites    = NULL;
158                 res->overwrittenby = NULL;
159         }
160
161 #ifdef DEBUG_libfirm
162         res->nr = get_irp_new_node_nr();
163 #endif /* DEBUG_libfirm */
164
165         res->visit = 0;
166         set_entity_dbg_info(res, db);
167
168         return res;
169 }  /* new_rd_entity */
170
171 ir_entity *
172 new_d_entity(ir_type *owner, ident *name, ir_type *type, dbg_info *db) {
173         ir_entity *res;
174
175         assert(is_compound_type(owner));
176         res = new_rd_entity(db, owner, name, type);
177         /* Remember entity in it's owner. */
178         insert_entity_in_owner(res);
179
180         hook_new_entity(res);
181         return res;
182 }  /* new_d_entity */
183
184 ir_entity *
185 new_entity(ir_type *owner, ident *name, ir_type *type) {
186         return new_d_entity(owner, name, type, NULL);
187 }  /* new_entity */
188
189 /**
190  * Free entity attributes.
191  *
192  * @param ent  the entity
193  */
194 static void free_entity_attrs(ir_entity *ent) {
195         int i;
196         if (get_type_tpop(get_entity_owner(ent)) == type_class) {
197                 DEL_ARR_F(ent->overwrites);    ent->overwrites = NULL;
198                 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
199         } else {
200                 assert(ent->overwrites == NULL);
201                 assert(ent->overwrittenby == NULL);
202         }
203         if (is_compound_entity(ent)) {
204                 if (ent->attr.cmpd_attr.val_paths) {
205                         for (i = 0; i < get_compound_ent_n_values(ent); i++)
206                                 if (ent->attr.cmpd_attr.val_paths[i]) {
207                                         /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ;  * @@@ warum nich? */
208                                         /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
209                                         /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */
210                                 }
211                                 ent->attr.cmpd_attr.val_paths = NULL;
212                 }
213                 /* if (ent->attr.cmpd_attr.values) DEL_ARR_F(ent->attr.cmpd_attr.values); *//* @@@ warum nich? */
214                 ent->attr.cmpd_attr.values = NULL;
215         } else if (is_method_entity(ent)) {
216                 if (ent->attr.mtd_attr.param_access) {
217                         DEL_ARR_F(ent->attr.mtd_attr.param_access);
218                         ent->attr.mtd_attr.param_access = NULL;
219                 }
220                 if (ent->attr.mtd_attr.param_weight) {
221                         DEL_ARR_F(ent->attr.mtd_attr.param_weight);
222                         ent->attr.mtd_attr.param_weight = NULL;
223                 }
224         }
225 }  /* free_entity_attrs */
226
227 ir_entity *
228 copy_entity_own(ir_entity *old, ir_type *new_owner) {
229         ir_entity *newe;
230         assert(is_entity(old));
231         assert(is_compound_type(new_owner));
232
233         if (old->owner == new_owner) return old;
234         newe = xmalloc(sizeof(*newe));
235         memcpy(newe, old, sizeof(*newe));
236         newe->owner = new_owner;
237         if (is_Class_type(new_owner)) {
238                 newe->overwrites    = NEW_ARR_F(ir_entity *, 0);
239                 newe->overwrittenby = NEW_ARR_F(ir_entity *, 0);
240         }
241 #ifdef DEBUG_libfirm
242         newe->nr = get_irp_new_node_nr();
243 #endif
244
245         insert_entity_in_owner(newe);
246
247         return newe;
248 }  /* copy_entity_own */
249
250 ir_entity *
251 copy_entity_name(ir_entity *old, ident *new_name) {
252         ir_entity *newe;
253         assert(old && old->kind == k_entity);
254
255         if (old->name == new_name) return old;
256         newe = xmalloc(sizeof(*newe));
257         memcpy(newe, old, sizeof(*newe));
258         newe->name = new_name;
259         newe->ld_name = NULL;
260         if (is_Class_type(newe->owner)) {
261                 newe->overwrites    = DUP_ARR_F(ir_entity *, old->overwrites);
262                 newe->overwrittenby = DUP_ARR_F(ir_entity *, old->overwrittenby);
263         }
264 #ifdef DEBUG_libfirm
265         newe->nr = get_irp_new_node_nr();
266 #endif
267
268         insert_entity_in_owner(newe);
269
270         return newe;
271 }  /* copy_entity_name */
272
273
274 void
275 free_entity(ir_entity *ent) {
276         assert(ent && ent->kind == k_entity);
277         free_entity_attrs(ent);
278         ent->kind = k_BAD;
279         free(ent);
280 }  /* free_entity */
281
282 /* Outputs a unique number for this node */
283 long
284 get_entity_nr(const ir_entity *ent) {
285         assert(ent && ent->kind == k_entity);
286 #ifdef DEBUG_libfirm
287         return ent->nr;
288 #else
289         return (long)PTR_TO_INT(ent);
290 #endif
291 }  /* get_entity_nr */
292
293 const char *
294 (get_entity_name)(const ir_entity *ent) {
295         return _get_entity_name(ent);
296 }  /* get_entity_name */
297
298 ident *
299 (get_entity_ident)(const ir_entity *ent) {
300         return _get_entity_ident(ent);
301 }  /* get_entity_ident */
302
303 void
304 (set_entity_ident)(ir_entity *ent, ident *id) {
305         _set_entity_ident(ent, id);
306 }  /* set_entity_ident */
307
308 ir_type *
309 (get_entity_owner)(ir_entity *ent) {
310         return _get_entity_owner(ent);
311 }  /* get_entity_owner */
312
313 void
314 set_entity_owner(ir_entity *ent, ir_type *owner) {
315         assert(is_entity(ent));
316         assert(is_compound_type(owner));
317         ent->owner = owner;
318 }  /* set_entity_owner */
319
320 ident *
321 (get_entity_ld_ident)(ir_entity *ent) {
322         return _get_entity_ld_ident(ent);
323 }  /* get_entity_ld_ident */
324
325 void
326 (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident) {
327         _set_entity_ld_ident(ent, ld_ident);
328 }  /* set_entity_ld_ident */
329
330 const char *
331 (get_entity_ld_name)(ir_entity *ent) {
332         return _get_entity_ld_name(ent);
333 }  /* get_entity_ld_name */
334
335 ir_type *
336 (get_entity_type)(ir_entity *ent) {
337         return _get_entity_type(ent);
338 }  /* get_entity_type */
339
340 void
341 (set_entity_type)(ir_entity *ent, ir_type *type) {
342         _set_entity_type(ent, type);
343 }  /* set_entity_type */
344
345 ir_allocation
346 (get_entity_allocation)(const ir_entity *ent) {
347         return _get_entity_allocation(ent);
348 }  /* get_entity_allocation */
349
350 void
351 (set_entity_allocation)(ir_entity *ent, ir_allocation al) {
352         _set_entity_allocation(ent, al);
353 }  /* set_entity_allocation */
354
355 /* return the name of the visibility */
356 const char *get_allocation_name(ir_allocation all)
357 {
358 #define X(a)    case a: return #a
359         switch (all) {
360         X(allocation_automatic);
361         X(allocation_parameter);
362         X(allocation_dynamic);
363         X(allocation_static);
364     default: return "BAD VALUE";
365         }
366 #undef X
367 }  /* get_allocation_name */
368
369 ir_visibility
370 (get_entity_visibility)(const ir_entity *ent) {
371         return _get_entity_visibility(ent);
372 }  /* get_entity_visibility */
373
374 void
375 set_entity_visibility(ir_entity *ent, ir_visibility vis) {
376         assert(ent && ent->kind == k_entity);
377         if (vis != visibility_local)
378                 assert((ent->allocation == allocation_static) ||
379                 (ent->allocation == allocation_automatic));
380                 /* @@@ Test that the owner type is not local, but how??
381         && get_class_visibility(get_entity_owner(ent)) != local));*/
382         ent->visibility = vis;
383 }  /* set_entity_visibility */
384
385 /* return the name of the visibility */
386 const char *get_visibility_name(ir_visibility vis)
387 {
388 #define X(a)    case a: return #a
389         switch (vis) {
390         X(visibility_local);
391         X(visibility_external_visible);
392         X(visibility_external_allocated);
393     default: return "BAD VALUE";
394         }
395 #undef X
396 }  /* get_visibility_name */
397
398 ir_variability
399 (get_entity_variability)(const ir_entity *ent) {
400         return _get_entity_variability(ent);
401 }  /* get_entity_variability */
402
403 void
404 set_entity_variability(ir_entity *ent, ir_variability var)
405 {
406         assert(ent && ent->kind == k_entity);
407         if (var == variability_part_constant)
408                 assert(is_Class_type(ent->type) || is_Struct_type(ent->type));
409
410         if ((is_compound_type(ent->type)) &&
411                 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
412                 /* Allocate data structures for constant values */
413                 ent->attr.cmpd_attr.values    = NEW_ARR_F(ir_node *, 0);
414                 ent->attr.cmpd_attr.val_paths = NEW_ARR_F(compound_graph_path *, 0);
415         }
416         if ((is_atomic_type(ent->type)) &&
417                 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
418                 /* Set default constant value. */
419                 ent->value = new_rd_Unknown(get_const_code_irg(), get_type_mode(ent->type));
420         }
421
422         if ((is_compound_type(ent->type)) &&
423                 (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
424                 /* Free data structures for constant values */
425                 DEL_ARR_F(ent->attr.cmpd_attr.values);    ent->attr.cmpd_attr.values    = NULL;
426                 DEL_ARR_F(ent->attr.cmpd_attr.val_paths); ent->attr.cmpd_attr.val_paths = NULL;
427         }
428         ent->variability = var;
429 }  /* set_entity_variability */
430
431 /* return the name of the variability */
432 const char *get_variability_name(ir_variability var)
433 {
434 #define X(a)    case a: return #a
435         switch (var) {
436         X(variability_uninitialized);
437         X(variability_initialized);
438         X(variability_part_constant);
439         X(variability_constant);
440     default: return "BAD VALUE";
441         }
442 #undef X
443 }  /* get_variability_name */
444
445 ir_volatility
446 (get_entity_volatility)(const ir_entity *ent) {
447         return _get_entity_volatility(ent);
448 }  /* get_entity_volatility */
449
450 void
451 (set_entity_volatility)(ir_entity *ent, ir_volatility vol) {
452         _set_entity_volatility(ent, vol);
453 }  /* set_entity_volatility */
454
455 /* return the name of the volatility */
456 const char *get_volatility_name(ir_volatility var)
457 {
458 #define X(a)    case a: return #a
459         switch (var) {
460         X(volatility_non_volatile);
461         X(volatility_is_volatile);
462     default: return "BAD VALUE";
463         }
464 #undef X
465 }  /* get_volatility_name */
466
467 ir_peculiarity
468 (get_entity_peculiarity)(const ir_entity *ent) {
469         return _get_entity_peculiarity(ent);
470 }  /* get_entity_peculiarity */
471
472 void
473 (set_entity_peculiarity)(ir_entity *ent, ir_peculiarity pec) {
474         _set_entity_peculiarity(ent, pec);
475 }  /* set_entity_peculiarity */
476
477 /* Checks if an entity cannot be overridden anymore. */
478 int (is_entity_final)(const ir_entity *ent) {
479         return _is_entity_final(ent);
480 }  /* is_entity_final */
481
482 /* Sets/resets the final flag of an entity. */
483 void (set_entity_final)(ir_entity *ent, int final) {
484         _set_entity_final(ent, final);
485 }  /* set_entity_final */
486
487 /* Checks if an entity is compiler generated */
488 int (is_entity_compiler_generated)(const ir_entity *ent) {
489         return _is_entity_compiler_generated(ent);
490 }  /* is_entity_compiler_generated */
491
492 /* Sets/resets the compiler generated flag */
493 void (set_entity_compiler_generated)(ir_entity *ent, int flag) {
494         _set_entity_compiler_generated(ent, flag);
495 }  /* set_entity_compiler_generated */
496
497 /* Checks if an entity is marked by the backend */
498 int (is_entity_backend_marked)(const ir_entity *ent) {
499         return _is_entity_backend_marked(ent);
500 }  /* is_entity_backend_marked */
501
502 /* Sets/resets the compiler generated flag */
503 void (set_entity_backend_marked)(ir_entity *ent, int flag) {
504         _set_entity_backend_marked(ent, flag);
505 }  /* set_entity_backend_marked */
506
507 /* Checks if the address of an entity was taken. */
508 ir_address_taken_state (get_entity_address_taken)(const ir_entity *ent) {
509         return _get_entity_address_taken(ent);
510 }  /* is_entity_address_taken */
511
512 /* Sets/resets the address taken flag. */
513 void (set_entity_address_taken)(ir_entity *ent, ir_address_taken_state flag) {
514         _set_entity_address_taken(ent, flag);
515 }  /* set_entity_address_taken */
516
517 /* Return the name of the address_taken state. */
518 const char *get_address_taken_state_name(ir_address_taken_state state) {
519 #define X(a)    case a: return #a
520         switch (state) {
521         X(ir_address_not_taken);
522         X(ir_address_taken_unknown);
523         X(ir_address_taken);
524     default: return "BAD VALUE";
525         }
526 #undef X
527 }  /* get_address_taken_state_name */
528
529 /* Get the entity's stickyness */
530 ir_stickyness
531 (get_entity_stickyness)(const ir_entity *ent) {
532         return _get_entity_stickyness(ent);
533 }  /* get_entity_stickyness */
534
535 /* Set the entity's stickyness */
536 void
537 (set_entity_stickyness)(ir_entity *ent, ir_stickyness stickyness) {
538         _set_entity_stickyness(ent, stickyness);
539 }  /* set_entity_stickyness */
540
541 /* Set has no effect for existent entities of type method. */
542 ir_node *
543 get_atomic_ent_value(ir_entity *ent)
544 {
545         assert(ent && is_atomic_entity(ent));
546         assert(ent->variability != variability_uninitialized);
547         return skip_Id(ent->value);
548 }  /* get_atomic_ent_value */
549
550 void
551 set_atomic_ent_value(ir_entity *ent, ir_node *val) {
552         assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
553         if (is_Method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
554                 return;
555         ent->value = val;
556 }  /* set_atomic_ent_value */
557
558 /* Returns true if the the node is representable as code on
559  *  const_code_irg. */
560 int is_irn_const_expression(ir_node *n) {
561         ir_mode *m;
562
563         /* we are in danger iff an exception will arise. TODO: be more precisely,
564          * for instance Div. will NOT rise if divisor != 0
565          */
566         if (is_binop(n) && !is_fragile_op(n))
567                 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
568
569         m = get_irn_mode(n);
570         switch (get_irn_opcode(n)) {
571         case iro_Const:
572         case iro_SymConst:
573         case iro_Unknown:
574                 return 1;
575         case iro_Conv:
576         case iro_Cast:
577                 return is_irn_const_expression(get_irn_n(n, 0));
578         default:
579                 break;
580         }
581         return 0;
582 }  /* is_irn_const_expression */
583
584 /*
585  * Copies a firm subgraph that complies to the restrictions for
586  * constant expressions to current_block in current_ir_graph.
587  */
588 ir_node *copy_const_value(dbg_info *dbg, ir_node *n) {
589         ir_node *nn;
590         ir_mode *m;
591
592         /* @@@ GL I think  we should implement this using the routines from irgopt for
593                dead node elimination/inlineing. */
594
595         m = get_irn_mode(n);
596         switch (get_irn_opcode(n)) {
597         case iro_Const:
598                 nn = new_d_Const_type(dbg, m, get_Const_tarval(n), get_Const_type(n));
599                 break;
600         case iro_SymConst:
601                 nn = new_d_SymConst_type(dbg, get_SymConst_symbol(n), get_SymConst_kind(n),
602                         get_SymConst_value_type(n));
603                 break;
604         case iro_Add:
605                 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
606                         copy_const_value(dbg, get_Add_right(n)), m); break;
607         case iro_Sub:
608                 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
609                         copy_const_value(dbg, get_Sub_right(n)), m); break;
610         case iro_Mul:
611                 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
612                         copy_const_value(dbg, get_Mul_right(n)), m); break;
613         case iro_And:
614                 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
615                         copy_const_value(dbg, get_And_right(n)), m); break;
616         case iro_Or:
617                 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
618                         copy_const_value(dbg, get_Or_right(n)), m); break;
619         case iro_Eor:
620                 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
621                         copy_const_value(dbg, get_Eor_right(n)), m); break;
622         case iro_Cast:
623                 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
624         case iro_Conv:
625                 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
626         case iro_Unknown:
627                 nn = new_d_Unknown(m); break;
628         default:
629                 assert(0 && "opcode invalid or not implemented");
630                 nn = NULL;
631                 break;
632         }
633         return nn;
634 }  /* copy_const_value */
635
636 /* Creates a new compound graph path. */
637 compound_graph_path *
638 new_compound_graph_path(ir_type *tp, int length) {
639         compound_graph_path *res;
640
641         assert(is_compound_type(tp));
642         assert(length > 0);
643
644         res = xmalloc(sizeof(*res) + (length-1) * sizeof(res->list[0]));
645         memset(res, 0, sizeof(*res) + (length-1) * sizeof(res->list[0]));
646         res->kind         = k_ir_compound_graph_path;
647         res->tp           = tp;
648         res->len          = length;
649
650         return res;
651 }  /* new_compound_graph_path */
652
653 /* Frees an graph path object */
654 void free_compound_graph_path (compound_graph_path *gr) {
655         assert(gr && is_compound_graph_path(gr));
656         gr->kind = k_BAD;
657         free(gr);
658 }  /* free_compound_graph_path */
659
660 /* Returns non-zero if an object is a compound graph path */
661 int is_compound_graph_path(const void *thing) {
662         return (get_kind(thing) == k_ir_compound_graph_path);
663 }  /* is_compound_graph_path */
664
665 /* Checks whether the path up to pos is correct. If the path contains a NULL,
666  *  assumes the path is not complete and returns 'true'. */
667 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
668         int i;
669         ir_entity *node;
670         ir_type *owner = gr->tp;
671
672         for (i = 0; i <= pos; i++) {
673                 node = get_compound_graph_path_node(gr, i);
674                 if (node == NULL)
675                         /* Path not yet complete. */
676                         return 1;
677                 if (get_entity_owner(node) != owner)
678                         return 0;
679                 owner = get_entity_type(node);
680         }
681         if (pos == get_compound_graph_path_length(gr))
682                 if (!is_atomic_type(owner))
683                         return 0;
684                 return 1;
685 }  /* is_proper_compound_graph_path */
686
687 /* Returns the length of a graph path */
688 int get_compound_graph_path_length(const compound_graph_path *gr) {
689         assert(gr && is_compound_graph_path(gr));
690         return gr->len;
691 }  /* get_compound_graph_path_length */
692
693 ir_entity *
694 get_compound_graph_path_node(const compound_graph_path *gr, int pos) {
695         assert(gr && is_compound_graph_path(gr));
696         assert(pos >= 0 && pos < gr->len);
697         return gr->list[pos].node;
698 }  /* get_compound_graph_path_node */
699
700 void
701 set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node) {
702         assert(gr && is_compound_graph_path(gr));
703         assert(pos >= 0 && pos < gr->len);
704         assert(is_entity(node));
705         gr->list[pos].node = node;
706         assert(is_proper_compound_graph_path(gr, pos));
707 }  /* set_compound_graph_path_node */
708
709 int
710 get_compound_graph_path_array_index(const compound_graph_path *gr, int pos) {
711         assert(gr && is_compound_graph_path(gr));
712         assert(pos >= 0 && pos < gr->len);
713         return gr->list[pos].index;
714 }  /* get_compound_graph_path_array_index */
715
716 void
717 set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index) {
718         assert(gr && is_compound_graph_path(gr));
719         assert(pos >= 0 && pos < gr->len);
720         gr->list[pos].index = index;
721 }  /* set_compound_graph_path_array_index */
722
723 /* A value of a compound entity is a pair of value and the corresponding path to a member of
724    the compound. */
725 void
726 add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path) {
727         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
728         assert(is_compound_graph_path(path));
729         ARR_APP1(ir_node *, ent->attr.cmpd_attr.values, val);
730         ARR_APP1(compound_graph_path *, ent->attr.cmpd_attr.val_paths, path);
731 }  /* add_compound_ent_value_w_path */
732
733 void
734 set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos) {
735         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
736         assert(is_compound_graph_path(path));
737         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
738         ent->attr.cmpd_attr.values[pos]    = val;
739         ent->attr.cmpd_attr.val_paths[pos] = path;
740 }  /* set_compound_ent_value_w_path */
741
742 int
743 get_compound_ent_n_values(ir_entity *ent) {
744         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
745         return ARR_LEN(ent->attr.cmpd_attr.values);
746 }  /* get_compound_ent_n_values */
747
748 ir_node *
749 get_compound_ent_value(ir_entity *ent, int pos) {
750         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
751         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
752         return ent->attr.cmpd_attr.values[pos];
753 }  /* get_compound_ent_value */
754
755 compound_graph_path *
756 get_compound_ent_value_path(ir_entity *ent, int pos) {
757         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
758         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths));
759         return ent->attr.cmpd_attr.val_paths[pos];
760 }  /* get_compound_ent_value_path */
761
762 /**
763  * Returns non-zero, if two compound_graph_pathes are equal
764  *
765  * @param path1            the first path
766  * @param visited_indices
767  * @param path2            the second path
768  */
769 static int equal_paths(compound_graph_path *path1, int *visited_indices, compound_graph_path *path2) {
770         int i;
771         int len1 = get_compound_graph_path_length(path1);
772         int len2 = get_compound_graph_path_length(path2);
773
774         if (len2 != len1) return 0;
775
776         for (i = 0; i < len1; i++) {
777                 ir_type *tp;
778                 ir_entity *node1 = get_compound_graph_path_node(path1, i);
779                 ir_entity *node2 = get_compound_graph_path_node(path2, i);
780
781                 if (node1 != node2) return 0;
782
783                 /* FIXME: Strange code. What is it good for? */
784                 tp = get_entity_owner(node1);
785                 if (is_Array_type(tp)) {
786                         long low;
787
788                         /* Compute the index of this node. */
789                         assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented");
790
791                         low = get_array_lower_bound_int(tp, 0);
792                         if (low + visited_indices[i] < get_compound_graph_path_array_index(path2, i)) {
793                                 visited_indices[i]++;
794                                 return 0;
795                         } else
796                                 assert(low + visited_indices[i] == get_compound_graph_path_array_index(path2, i));
797                 }
798         }
799         return 1;
800 }  /* equal_paths */
801
802 /**
803  * Returns the position of a value with the given path.
804  * The path must contain array indices for all array element entities.
805  *
806  * @todo  This implementation is very low and should be replaced when the new tree oriented
807  *        value representation is finally implemented.
808  */
809 static int get_compound_ent_pos_by_path(ir_entity *ent, compound_graph_path *path) {
810         int i, n_paths = get_compound_ent_n_values(ent);
811         int *visited_indices;
812         int path_len = get_compound_graph_path_length(path);
813
814         NEW_ARR_A(int *, visited_indices, path_len);
815         memset(visited_indices, 0, sizeof(*visited_indices) * path_len);
816         for (i = 0; i < n_paths; i ++) {
817                 if (equal_paths(get_compound_ent_value_path(ent, i), visited_indices, path))
818                         return i;
819         }
820
821 #if 0
822         {
823                 int j;
824                 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
825                 printf("Entity %s : ", get_entity_name(ent));
826                 for (j = 0; j < get_compound_graph_path_length(path); ++j) {
827                         ir_entity *node = get_compound_graph_path_node(path, j);
828                         printf("%s", get_entity_name(node));
829                         if (is_Array_type(get_entity_owner(node)))
830                                 printf("[%d]", get_compound_graph_path_array_index(path, j));
831                 }
832                 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
833         }
834 #endif
835
836         assert(0 && "path not found");
837         return -1;
838 }  /* get_compound_ent_pos_by_path */
839
840 /* Returns a constant value given the access path.
841  *  The path must contain array indices for all array element entities. */
842 ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path) {
843         return get_compound_ent_value(ent, get_compound_ent_pos_by_path(ent, path));
844 }  /* get_compound_ent_value_by_path */
845
846
847 void
848 remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent) {
849         int i;
850         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
851         for (i = 0; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths)); ++i) {
852                 compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i];
853                 if (path->list[path->len-1].node == value_ent) {
854                         for (; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths))-1; ++i) {
855                                 ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1];
856                                 ent->attr.cmpd_attr.values[i]    = ent->attr.cmpd_attr.values[i+1];
857                         }
858                         ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, ARR_LEN(ent->attr.cmpd_attr.val_paths) - 1);
859                         ARR_SETLEN(ir_node*,   ent->attr.cmpd_attr.values,    ARR_LEN(ent->attr.cmpd_attr.values)    - 1);
860                         break;
861                 }
862         }
863 }  /* remove_compound_ent_value */
864
865 void
866 add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member) {
867         compound_graph_path *path;
868         ir_type *owner_tp = get_entity_owner(member);
869         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
870         path = new_compound_graph_path(get_entity_type(ent), 1);
871         path->list[0].node = member;
872         if (is_Array_type(owner_tp)) {
873                 int max;
874                 int i, n;
875
876                 assert(get_array_n_dimensions(owner_tp) == 1 && has_array_lower_bound(owner_tp, 0));
877                 max = get_array_lower_bound_int(owner_tp, 0) -1;
878                 for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
879                         int index = get_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0);
880                         if (index > max) {
881                                 max = index;
882                         }
883                 }
884                 path->list[0].index = max + 1;
885         }
886         add_compound_ent_value_w_path(ent, val, path);
887 }  /* add_compound_ent_value */
888
889
890 ir_entity *
891 get_compound_ent_value_member(ir_entity *ent, int pos) {
892         compound_graph_path *path;
893         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
894         path = get_compound_ent_value_path(ent, pos);
895
896         return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
897 }  /* get_compound_ent_value_member */
898
899 void
900 set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos) {
901         compound_graph_path *path;
902         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
903         path = get_compound_ent_value_path(ent, pos);
904         set_compound_graph_path_node(path, 0, member);
905         set_compound_ent_value_w_path(ent, val, path, pos);
906 }  /* set_compound_ent_value */
907
908 void
909 set_array_entity_values(ir_entity *ent, tarval **values, int num_vals) {
910         int i;
911         ir_graph *rem = current_ir_graph;
912         ir_type *arrtp = get_entity_type(ent);
913         ir_node *val;
914         ir_type *elttp = get_array_element_type(arrtp);
915
916         assert(is_Array_type(arrtp));
917         assert(get_array_n_dimensions(arrtp) == 1);
918         /* One bound is sufficient, the number of constant fields makes the
919            size. */
920         assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
921         assert(get_entity_variability(ent) != variability_uninitialized);
922         current_ir_graph = get_const_code_irg();
923
924         for (i = 0; i < num_vals; i++) {
925                 val = new_Const_type(values[i], elttp);
926                 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
927                 set_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0, i);
928         }
929         current_ir_graph = rem;
930 }  /* set_array_entity_values */
931
932 /* Return the overall offset of value at position pos in bytes. */
933 int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) {
934         compound_graph_path *path;
935         int path_len, i;
936         int offset = 0;
937         ir_type *curr_tp;
938
939         assert(get_type_state(get_entity_type(ent)) == layout_fixed);
940
941         path = get_compound_ent_value_path(ent, pos);
942         path_len = get_compound_graph_path_length(path);
943         curr_tp = path->tp;
944
945         for (i = 0; i < path_len; ++i) {
946                 ir_entity *node = get_compound_graph_path_node(path, i);
947                 ir_type *node_tp = get_entity_type(node);
948
949                 if (is_Array_type(curr_tp)) {
950                         int size  = get_type_size_bits(node_tp);
951                         int align = get_type_alignment_bits(node_tp);
952                         int idx;
953
954                         assert(size > 0);
955                         if(size % align > 0) {
956                                 size += align - (size % align);
957                         }
958                         assert(size % 8 == 0);
959                         size /= 8;
960                         idx = get_compound_graph_path_array_index(path, i);
961                         assert(idx >= 0);
962                         offset += size * idx;
963                 } else {
964                         offset += get_entity_offset(node);
965                 }
966                 curr_tp = node_tp;
967         }
968
969         return offset;
970 }  /* get_compound_ent_value_offset_bytes */
971
972 /* Return the offset in bits from the last byte address. */
973 int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) {
974         compound_graph_path *path;
975         int path_len;
976         ir_entity *last_node;
977
978         assert(get_type_state(get_entity_type(ent)) == layout_fixed);
979
980         path = get_compound_ent_value_path(ent, pos);
981         path_len = get_compound_graph_path_length(path);
982         last_node = get_compound_graph_path_node(path, path_len - 1);
983
984         return get_entity_offset_bits_remainder(last_node);
985 }  /* get_compound_ent_value_offset_bit_remainder */
986
987 int
988 (get_entity_offset)(const ir_entity *ent) {
989         return _get_entity_offset(ent);
990 }  /* get_entity_offset */
991
992 void
993 (set_entity_offset)(ir_entity *ent, int offset) {
994         _set_entity_offset(ent, offset);
995 }  /* set_entity_offset */
996
997 unsigned char
998 (get_entity_offset_bits_remainder)(const ir_entity *ent) {
999         return _get_entity_offset_bits_remainder(ent);
1000 }  /* get_entity_offset_bits_remainder */
1001
1002 void
1003 (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset) {
1004         _set_entity_offset_bits_remainder(ent, offset);
1005 }  /* set_entity_offset_bits_remainder */
1006
1007 void
1008 add_entity_overwrites(ir_entity *ent, ir_entity *overwritten) {
1009 #ifndef NDEBUG
1010         ir_type *owner     = get_entity_owner(ent);
1011         ir_type *ovw_ovner = get_entity_owner(overwritten);
1012         assert(is_Class_type(owner));
1013         assert(is_Class_type(ovw_ovner));
1014         assert(! is_class_final(ovw_ovner));
1015 #endif /* NDEBUG */
1016         ARR_APP1(ir_entity *, ent->overwrites, overwritten);
1017         ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
1018 }  /* add_entity_overwrites */
1019
1020 int
1021 get_entity_n_overwrites(ir_entity *ent) {
1022         assert(is_Class_type(get_entity_owner(ent)));
1023         return (ARR_LEN(ent->overwrites));
1024 }  /* get_entity_n_overwrites */
1025
1026 int
1027 get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten) {
1028         int i;
1029         assert(is_Class_type(get_entity_owner(ent)));
1030         for (i = 0; i < get_entity_n_overwrites(ent); i++)
1031                 if (get_entity_overwrites(ent, i) == overwritten)
1032                         return i;
1033         return -1;
1034 }  /* get_entity_overwrites_index */
1035
1036 ir_entity *
1037 get_entity_overwrites(ir_entity *ent, int pos) {
1038         assert(is_Class_type(get_entity_owner(ent)));
1039         assert(pos < get_entity_n_overwrites(ent));
1040         return ent->overwrites[pos];
1041 }  /* get_entity_overwrites */
1042
1043 void
1044 set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten) {
1045         assert(is_Class_type(get_entity_owner(ent)));
1046         assert(pos < get_entity_n_overwrites(ent));
1047         ent->overwrites[pos] = overwritten;
1048 }  /* set_entity_overwrites */
1049
1050 void
1051 remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten) {
1052         int i;
1053         assert(is_Class_type(get_entity_owner(ent)));
1054         for (i = 0; i < (ARR_LEN (ent->overwrites)); i++)
1055                 if (ent->overwrites[i] == overwritten) {
1056                         for(; i < (ARR_LEN (ent->overwrites))-1; i++)
1057                                 ent->overwrites[i] = ent->overwrites[i+1];
1058                         ARR_SETLEN(ir_entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
1059                         break;
1060                 }
1061 }  /* remove_entity_overwrites */
1062
1063 void
1064 add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) {
1065         add_entity_overwrites(overwrites, ent);
1066 }  /* add_entity_overwrittenby */
1067
1068 int
1069 get_entity_n_overwrittenby(ir_entity *ent) {
1070         assert(is_Class_type(get_entity_owner(ent)));
1071         return (ARR_LEN (ent->overwrittenby));
1072 }  /* get_entity_n_overwrittenby */
1073
1074 int
1075 get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites) {
1076         int i;
1077         assert(is_Class_type(get_entity_owner(ent)));
1078         for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
1079                 if (get_entity_overwrittenby(ent, i) == overwrites)
1080                         return i;
1081         return -1;
1082 }  /* get_entity_overwrittenby_index */
1083
1084 ir_entity *
1085 get_entity_overwrittenby(ir_entity *ent, int pos) {
1086         assert(is_Class_type(get_entity_owner(ent)));
1087         assert(pos < get_entity_n_overwrittenby(ent));
1088         return ent->overwrittenby[pos];
1089 }  /* get_entity_overwrittenby */
1090
1091 void
1092 set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites) {
1093         assert(is_Class_type(get_entity_owner(ent)));
1094         assert(pos < get_entity_n_overwrittenby(ent));
1095         ent->overwrittenby[pos] = overwrites;
1096 }  /* set_entity_overwrittenby */
1097
1098 void    remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) {
1099         int i;
1100         assert(is_Class_type(get_entity_owner(ent)));
1101         for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++)
1102                 if (ent->overwrittenby[i] == overwrites) {
1103                         for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
1104                                 ent->overwrittenby[i] = ent->overwrittenby[i+1];
1105                         ARR_SETLEN(ir_entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
1106                         break;
1107                 }
1108 }  /* remove_entity_overwrittenby */
1109
1110 /* A link to store intermediate information */
1111 void *
1112 (get_entity_link)(const ir_entity *ent) {
1113         return _get_entity_link(ent);
1114 }  /* get_entity_link */
1115
1116 void
1117 (set_entity_link)(ir_entity *ent, void *l) {
1118         _set_entity_link(ent, l);
1119 }  /* set_entity_link */
1120
1121 ir_graph *
1122 (get_entity_irg)(const ir_entity *ent) {
1123         return _get_entity_irg(ent);
1124 }  /* get_entity_irg */
1125
1126 void
1127 set_entity_irg(ir_entity *ent, ir_graph *irg) {
1128         assert(is_method_entity(ent));
1129         /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
1130          * Methode selbst nicht mehr aufgerufen werden kann, die Entität
1131          * aber erhalten bleiben soll?  Wandle die Entitaet in description oder
1132          * inherited um! */
1133         /* assert(irg); */
1134         assert((irg  && ent->peculiarity == peculiarity_existent) ||
1135                 (!irg && (ent->peculiarity == peculiarity_existent)
1136                 && (ent -> visibility == visibility_external_allocated)) ||
1137                 (!irg && ent->peculiarity == peculiarity_description) ||
1138                 (!irg && ent->peculiarity == peculiarity_inherited));
1139         ent->attr.mtd_attr.irg = irg;
1140 }  /* set_entity_irg */
1141
1142 unsigned get_entity_vtable_number(const ir_entity *ent) {
1143         assert(is_method_entity((ir_entity *)ent));
1144         return ent->attr.mtd_attr.vtable_number;
1145 }  /* get_entity_vtable_number */
1146
1147 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number) {
1148         assert(is_method_entity(ent));
1149         ent->attr.mtd_attr.vtable_number = vtable_number;
1150 }  /* set_entity_vtable_number */
1151
1152 /* Returns the section of a method. */
1153 ir_img_section get_method_img_section(const ir_entity *ent) {
1154         assert(is_method_entity((ir_entity *)ent));
1155         return ent->attr.mtd_attr.section;
1156 }  /* get_method_img_section */
1157
1158 /* Sets the section of a method. */
1159 void set_method_img_section(ir_entity *ent, ir_img_section section) {
1160         assert(is_method_entity(ent));
1161         ent->attr.mtd_attr.section = section;
1162 }  /* set_method_img_section */
1163
1164 int
1165 (is_entity)(const void *thing) {
1166         return _is_entity(thing);
1167 }  /* is_entity */
1168
1169 int is_atomic_entity(ir_entity *ent) {
1170         ir_type *t      = get_entity_type(ent);
1171         const tp_op *op = get_type_tpop(t);
1172         return (op == type_primitive || op == type_pointer ||
1173                 op == type_enumeration || op == type_method);
1174 }  /* is_atomic_entity */
1175
1176 int is_compound_entity(ir_entity *ent) {
1177         ir_type     *t  = get_entity_type(ent);
1178         const tp_op *op = get_type_tpop(t);
1179         return (op == type_class || op == type_struct ||
1180                 op == type_array || op == type_union);
1181 }  /* is_compound_entity */
1182
1183 int is_method_entity(ir_entity *ent) {
1184         ir_type *t = get_entity_type(ent);
1185         return is_Method_type(t);
1186 }  /* is_method_entity */
1187
1188 /**
1189  * @todo not implemented!!! */
1190 int equal_entity(ir_entity *ent1, ir_entity *ent2) {
1191         (void) ent1;
1192         (void) ent2;
1193         fprintf(stderr, " calling unimplemented equal entity!!! \n");
1194         return 1;
1195 }  /* equal_entity */
1196
1197
1198 unsigned long (get_entity_visited)(ir_entity *ent) {
1199         return _get_entity_visited(ent);
1200 }  /* get_entity_visited */
1201
1202 void (set_entity_visited)(ir_entity *ent, unsigned long num) {
1203         _set_entity_visited(ent, num);
1204 }  /* set_entity_visited */
1205
1206 /* Sets visited field in ir_entity to entity_visited. */
1207 void (mark_entity_visited)(ir_entity *ent) {
1208         _mark_entity_visited(ent);
1209 }  /* mark_entity_visited */
1210
1211 int (entity_visited)(ir_entity *ent) {
1212         return _entity_visited(ent);
1213 }  /* entity_visited */
1214
1215 int (entity_not_visited)(ir_entity *ent) {
1216         return _entity_not_visited(ent);
1217 }  /* entity_not_visited */
1218
1219 /* Returns the mask of the additional entity properties. */
1220 unsigned get_entity_additional_properties(ir_entity *ent) {
1221         ir_graph *irg;
1222
1223         assert(is_method_entity(ent));
1224
1225         /* first check, if the graph has additional properties */
1226         irg = get_entity_irg(ent);
1227
1228         if (irg)
1229                 return get_irg_additional_properties(irg);
1230
1231         if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
1232                 return get_method_additional_properties(get_entity_type(ent));
1233
1234         return ent->attr.mtd_attr.irg_add_properties;
1235 }  /* get_entity_additional_properties */
1236
1237 /* Sets the mask of the additional graph properties. */
1238 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
1239 {
1240         ir_graph *irg;
1241
1242         assert(is_method_entity(ent));
1243
1244         /* first check, if the graph exists */
1245         irg = get_entity_irg(ent);
1246         if (irg)
1247                 set_irg_additional_properties(irg, property_mask);
1248         else {
1249     /* do not allow to set the mtp_property_inherited flag or
1250                 * the automatic inheritance of flags will not work */
1251                 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1252         }
1253 }  /* set_entity_additional_properties */
1254
1255 /* Sets one additional graph property. */
1256 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
1257 {
1258         ir_graph *irg;
1259
1260         assert(is_method_entity(ent));
1261
1262         /* first check, if the graph exists */
1263         irg = get_entity_irg(ent);
1264         if (irg)
1265                 set_irg_additional_property(irg, flag);
1266         else {
1267                 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
1268
1269                 if (mask & mtp_property_inherited)
1270                         mask = get_method_additional_properties(get_entity_type(ent));
1271
1272                         /* do not allow to set the mtp_property_inherited flag or
1273                 * the automatic inheritance of flags will not work */
1274                 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
1275         }
1276 }  /* set_entity_additional_property */
1277
1278 /* Returns the class type that this type info entity represents or NULL
1279    if ent is no type info entity. */
1280 ir_type *(get_entity_repr_class)(const ir_entity *ent) {
1281         return _get_entity_repr_class(ent);
1282 }  /* get_entity_repr_class */
1283
1284 /* Initialize entity module. */
1285 void firm_init_entity(void)
1286 {
1287         symconst_symbol sym;
1288
1289         assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1290         assert(!unknown_entity && "Call firm_init_entity() only once!");
1291
1292         unknown_entity = new_rd_entity(NULL, firm_unknown_type, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type);
1293         set_entity_visibility(unknown_entity, visibility_external_allocated);
1294         set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1295
1296         current_ir_graph      = get_const_code_irg();
1297         sym.entity_p          = unknown_entity;
1298         unknown_entity->value = new_SymConst(sym, symconst_addr_ent);
1299 }  /* firm_init_entity */