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