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