13abc278811fb23ba922a58752e2a60a5080aa12
[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         assert(get_irn_mode(val) == get_type_mode(ent->type));
608         ent->value = val;
609 }  /* set_atomic_ent_value */
610
611 /* Returns true if the the node is representable as code on
612  *  const_code_irg. */
613 int is_irn_const_expression(ir_node *n) {
614         ir_mode *m;
615
616         /* we are in danger iff an exception will arise. TODO: be more precisely,
617          * for instance Div. will NOT rise if divisor != 0
618          */
619         if (is_binop(n) && !is_fragile_op(n))
620                 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
621
622         m = get_irn_mode(n);
623         switch (get_irn_opcode(n)) {
624         case iro_Const:
625         case iro_SymConst:
626         case iro_Unknown:
627                 return 1;
628         case iro_Conv:
629         case iro_Cast:
630                 return is_irn_const_expression(get_irn_n(n, 0));
631         default:
632                 break;
633         }
634         return 0;
635 }  /* is_irn_const_expression */
636
637 /*
638  * Copies a firm subgraph that complies to the restrictions for
639  * constant expressions to current_block in current_ir_graph.
640  */
641 ir_node *copy_const_value(dbg_info *dbg, ir_node *n) {
642         ir_node *nn;
643         ir_mode *m;
644
645         /* @@@ GL I think  we should implement this using the routines from irgopt for
646                dead node elimination/inlineing. */
647
648         m = get_irn_mode(n);
649         switch (get_irn_opcode(n)) {
650         case iro_Const:
651                 nn = new_d_Const_type(dbg, m, get_Const_tarval(n), get_Const_type(n));
652                 break;
653         case iro_SymConst:
654                 nn = new_d_SymConst_type(dbg, get_SymConst_symbol(n), get_SymConst_kind(n),
655                         get_SymConst_value_type(n));
656                 break;
657         case iro_Add:
658                 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
659                         copy_const_value(dbg, get_Add_right(n)), m); break;
660         case iro_Sub:
661                 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
662                         copy_const_value(dbg, get_Sub_right(n)), m); break;
663         case iro_Mul:
664                 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
665                         copy_const_value(dbg, get_Mul_right(n)), m); break;
666         case iro_And:
667                 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
668                         copy_const_value(dbg, get_And_right(n)), m); break;
669         case iro_Or:
670                 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
671                         copy_const_value(dbg, get_Or_right(n)), m); break;
672         case iro_Eor:
673                 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
674                         copy_const_value(dbg, get_Eor_right(n)), m); break;
675         case iro_Cast:
676                 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
677         case iro_Conv:
678                 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
679         case iro_Unknown:
680                 nn = new_d_Unknown(m); break;
681         default:
682                 assert(0 && "opcode invalid or not implemented");
683                 nn = NULL;
684                 break;
685         }
686         return nn;
687 }  /* copy_const_value */
688
689 /* Creates a new compound graph path. */
690 compound_graph_path *
691 new_compound_graph_path(ir_type *tp, int length) {
692         compound_graph_path *res;
693
694         assert(is_compound_type(tp));
695         assert(length > 0);
696
697         res = xmalloc(sizeof(*res) + (length-1) * sizeof(res->list[0]));
698         memset(res, 0, sizeof(*res) + (length-1) * sizeof(res->list[0]));
699         res->kind         = k_ir_compound_graph_path;
700         res->tp           = tp;
701         res->len          = length;
702
703         return res;
704 }  /* new_compound_graph_path */
705
706 /* Frees an graph path object */
707 void free_compound_graph_path (compound_graph_path *gr) {
708         assert(gr && is_compound_graph_path(gr));
709         gr->kind = k_BAD;
710         free(gr);
711 }  /* free_compound_graph_path */
712
713 /* Returns non-zero if an object is a compound graph path */
714 int is_compound_graph_path(const void *thing) {
715         return (get_kind(thing) == k_ir_compound_graph_path);
716 }  /* is_compound_graph_path */
717
718 /* Checks whether the path up to pos is correct. If the path contains a NULL,
719  *  assumes the path is not complete and returns 'true'. */
720 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
721         int i;
722         ir_entity *node;
723         ir_type *owner = gr->tp;
724
725         for (i = 0; i <= pos; i++) {
726                 node = get_compound_graph_path_node(gr, i);
727                 if (node == NULL)
728                         /* Path not yet complete. */
729                         return 1;
730                 if (get_entity_owner(node) != owner)
731                         return 0;
732                 owner = get_entity_type(node);
733         }
734         if (pos == get_compound_graph_path_length(gr))
735                 if (!is_atomic_type(owner))
736                         return 0;
737                 return 1;
738 }  /* is_proper_compound_graph_path */
739
740 /* Returns the length of a graph path */
741 int get_compound_graph_path_length(const compound_graph_path *gr) {
742         assert(gr && is_compound_graph_path(gr));
743         return gr->len;
744 }  /* get_compound_graph_path_length */
745
746 ir_entity *
747 get_compound_graph_path_node(const compound_graph_path *gr, int pos) {
748         assert(gr && is_compound_graph_path(gr));
749         assert(pos >= 0 && pos < gr->len);
750         return gr->list[pos].node;
751 }  /* get_compound_graph_path_node */
752
753 void
754 set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node) {
755         assert(gr && is_compound_graph_path(gr));
756         assert(pos >= 0 && pos < gr->len);
757         assert(is_entity(node));
758         gr->list[pos].node = node;
759         assert(is_proper_compound_graph_path(gr, pos));
760 }  /* set_compound_graph_path_node */
761
762 int
763 get_compound_graph_path_array_index(const compound_graph_path *gr, int pos) {
764         assert(gr && is_compound_graph_path(gr));
765         assert(pos >= 0 && pos < gr->len);
766         return gr->list[pos].index;
767 }  /* get_compound_graph_path_array_index */
768
769 void
770 set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index) {
771         assert(gr && is_compound_graph_path(gr));
772         assert(pos >= 0 && pos < gr->len);
773         gr->list[pos].index = index;
774 }  /* set_compound_graph_path_array_index */
775
776 /* A value of a compound entity is a pair of value and the corresponding path to a member of
777    the compound. */
778 void
779 add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path) {
780         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
781         assert(is_compound_graph_path(path));
782         ARR_APP1(ir_node *, ent->attr.cmpd_attr.values, val);
783         ARR_APP1(compound_graph_path *, ent->attr.cmpd_attr.val_paths, path);
784 }  /* add_compound_ent_value_w_path */
785
786 void
787 set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos) {
788         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
789         assert(is_compound_graph_path(path));
790         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
791         ent->attr.cmpd_attr.values[pos]    = val;
792         ent->attr.cmpd_attr.val_paths[pos] = path;
793 }  /* set_compound_ent_value_w_path */
794
795 int
796 get_compound_ent_n_values(ir_entity *ent) {
797         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
798         return ARR_LEN(ent->attr.cmpd_attr.values);
799 }  /* get_compound_ent_n_values */
800
801 ir_node *
802 get_compound_ent_value(ir_entity *ent, int pos) {
803         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
804         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
805         return ent->attr.cmpd_attr.values[pos];
806 }  /* get_compound_ent_value */
807
808 compound_graph_path *
809 get_compound_ent_value_path(ir_entity *ent, int pos) {
810         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
811         assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths));
812         return ent->attr.cmpd_attr.val_paths[pos];
813 }  /* get_compound_ent_value_path */
814
815 /**
816  * Returns non-zero, if two compound_graph_pathes are equal
817  *
818  * @param path1            the first path
819  * @param visited_indices
820  * @param path2            the second path
821  */
822 static int equal_paths(compound_graph_path *path1, int *visited_indices, compound_graph_path *path2) {
823         int i;
824         int len1 = get_compound_graph_path_length(path1);
825         int len2 = get_compound_graph_path_length(path2);
826
827         if (len2 != len1) return 0;
828
829         for (i = 0; i < len1; i++) {
830                 ir_type *tp;
831                 ir_entity *node1 = get_compound_graph_path_node(path1, i);
832                 ir_entity *node2 = get_compound_graph_path_node(path2, i);
833
834                 if (node1 != node2) return 0;
835
836                 /* FIXME: Strange code. What is it good for? */
837                 tp = get_entity_owner(node1);
838                 if (is_Array_type(tp)) {
839                         long low;
840
841                         /* Compute the index of this node. */
842                         assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented");
843
844                         low = get_array_lower_bound_int(tp, 0);
845                         if (low + visited_indices[i] < get_compound_graph_path_array_index(path2, i)) {
846                                 visited_indices[i]++;
847                                 return 0;
848                         } else
849                                 assert(low + visited_indices[i] == get_compound_graph_path_array_index(path2, i));
850                 }
851         }
852         return 1;
853 }  /* equal_paths */
854
855 /**
856  * Returns the position of a value with the given path.
857  * The path must contain array indices for all array element entities.
858  *
859  * @todo  This implementation is very slow (O(number of initializers^2) and should
860  *        be replaced when the new tree oriented
861  *        value representation is finally implemented.
862  */
863 static int get_compound_ent_pos_by_path(ir_entity *ent, compound_graph_path *path) {
864         int i, n_paths = get_compound_ent_n_values(ent);
865         int *visited_indices;
866         int path_len = get_compound_graph_path_length(path);
867
868         NEW_ARR_A(int *, visited_indices, path_len);
869         memset(visited_indices, 0, sizeof(*visited_indices) * path_len);
870         for (i = 0; i < n_paths; i ++) {
871                 if (equal_paths(get_compound_ent_value_path(ent, i), visited_indices, path))
872                         return i;
873         }
874
875 #if 0
876         {
877                 int j;
878                 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
879                 printf("Entity %s : ", get_entity_name(ent));
880                 for (j = 0; j < get_compound_graph_path_length(path); ++j) {
881                         ir_entity *node = get_compound_graph_path_node(path, j);
882                         printf("%s", get_entity_name(node));
883                         if (is_Array_type(get_entity_owner(node)))
884                                 printf("[%d]", get_compound_graph_path_array_index(path, j));
885                 }
886                 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
887         }
888 #endif
889
890         assert(0 && "path not found");
891         return -1;
892 }  /* get_compound_ent_pos_by_path */
893
894 /* Returns a constant value given the access path.
895  *  The path must contain array indices for all array element entities. */
896 ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path) {
897         return get_compound_ent_value(ent, get_compound_ent_pos_by_path(ent, path));
898 }  /* get_compound_ent_value_by_path */
899
900
901 void
902 remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent) {
903         int i, n;
904         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
905
906         n = ARR_LEN(ent->attr.cmpd_attr.val_paths);
907         for (i = 0; i < n; ++i) {
908                 compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i];
909                 if (path->list[path->len-1].node == value_ent) {
910                         for (; i < n - 1; ++i) {
911                                 ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1];
912                                 ent->attr.cmpd_attr.values[i]    = ent->attr.cmpd_attr.values[i+1];
913                         }
914                         ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, n - 1);
915                         ARR_SETLEN(ir_node*,   ent->attr.cmpd_attr.values,    n - 1);
916                         break;
917                 }
918         }
919 }  /* remove_compound_ent_value */
920
921 void
922 add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member) {
923         compound_graph_path *path;
924         ir_type *owner_tp = get_entity_owner(member);
925         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
926         path = new_compound_graph_path(get_entity_type(ent), 1);
927         path->list[0].node = member;
928         if (is_Array_type(owner_tp)) {
929                 int max;
930                 int i, n;
931
932                 assert(get_array_n_dimensions(owner_tp) == 1 && has_array_lower_bound(owner_tp, 0));
933                 max = get_array_lower_bound_int(owner_tp, 0) -1;
934                 for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
935                         int index = get_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0);
936                         if (index > max) {
937                                 max = index;
938                         }
939                 }
940                 path->list[0].index = max + 1;
941         }
942         add_compound_ent_value_w_path(ent, val, path);
943 }  /* add_compound_ent_value */
944
945
946 ir_entity *
947 get_compound_ent_value_member(ir_entity *ent, int pos) {
948         compound_graph_path *path;
949         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
950         path = get_compound_ent_value_path(ent, pos);
951
952         return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
953 }  /* get_compound_ent_value_member */
954
955 void
956 set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos) {
957         compound_graph_path *path;
958         assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
959         path = get_compound_ent_value_path(ent, pos);
960         set_compound_graph_path_node(path, 0, member);
961         set_compound_ent_value_w_path(ent, val, path, pos);
962 }  /* set_compound_ent_value */
963
964 void
965 set_array_entity_values(ir_entity *ent, tarval **values, int num_vals) {
966         int i;
967         ir_graph *rem = current_ir_graph;
968         ir_type *arrtp = get_entity_type(ent);
969         ir_node *val;
970         ir_type *elttp = get_array_element_type(arrtp);
971
972         assert(is_Array_type(arrtp));
973         assert(get_array_n_dimensions(arrtp) == 1);
974         /* One bound is sufficient, the number of constant fields makes the
975            size. */
976         assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
977         assert(get_entity_variability(ent) != variability_uninitialized);
978         current_ir_graph = get_const_code_irg();
979
980         for (i = 0; i < num_vals; i++) {
981                 val = new_Const_type(values[i], elttp);
982                 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
983                 set_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0, i);
984         }
985         current_ir_graph = rem;
986 }  /* set_array_entity_values */
987
988 /* Return the overall offset of value at position pos in bytes. */
989 int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) {
990         compound_graph_path *path;
991         int path_len, i;
992         int offset = 0;
993         ir_type *curr_tp;
994
995         assert(get_type_state(get_entity_type(ent)) == layout_fixed);
996
997         path = get_compound_ent_value_path(ent, pos);
998         path_len = get_compound_graph_path_length(path);
999         curr_tp = path->tp;
1000
1001         for (i = 0; i < path_len; ++i) {
1002                 ir_entity *node = get_compound_graph_path_node(path, i);
1003                 ir_type *node_tp = get_entity_type(node);
1004
1005                 if (is_Array_type(curr_tp)) {
1006                         int size  = get_type_size_bits(node_tp);
1007                         int align = get_type_alignment_bits(node_tp);
1008                         int idx;
1009
1010                         assert(size > 0);
1011                         if(size % align > 0) {
1012                                 size += align - (size % align);
1013                         }
1014                         assert(size % 8 == 0);
1015                         size /= 8;
1016                         idx = get_compound_graph_path_array_index(path, i);
1017                         assert(idx >= 0);
1018                         offset += size * idx;
1019                 } else {
1020                         offset += get_entity_offset(node);
1021                 }
1022                 curr_tp = node_tp;
1023         }
1024
1025         return offset;
1026 }  /* get_compound_ent_value_offset_bytes */
1027
1028 /* Return the offset in bits from the last byte address. */
1029 int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) {
1030         compound_graph_path *path;
1031         int path_len;
1032         ir_entity *last_node;
1033
1034         assert(get_type_state(get_entity_type(ent)) == layout_fixed);
1035
1036         path = get_compound_ent_value_path(ent, pos);
1037         path_len = get_compound_graph_path_length(path);
1038         last_node = get_compound_graph_path_node(path, path_len - 1);
1039
1040         return get_entity_offset_bits_remainder(last_node);
1041 }  /* get_compound_ent_value_offset_bit_remainder */
1042
1043 int
1044 (get_entity_offset)(const ir_entity *ent) {
1045         return _get_entity_offset(ent);
1046 }  /* get_entity_offset */
1047
1048 void
1049 (set_entity_offset)(ir_entity *ent, int offset) {
1050         _set_entity_offset(ent, offset);
1051 }  /* set_entity_offset */
1052
1053 unsigned char
1054 (get_entity_offset_bits_remainder)(const ir_entity *ent) {
1055         return _get_entity_offset_bits_remainder(ent);
1056 }  /* get_entity_offset_bits_remainder */
1057
1058 void
1059 (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset) {
1060         _set_entity_offset_bits_remainder(ent, offset);
1061 }  /* set_entity_offset_bits_remainder */
1062
1063 void
1064 add_entity_overwrites(ir_entity *ent, ir_entity *overwritten) {
1065 #ifndef NDEBUG
1066         ir_type *owner     = get_entity_owner(ent);
1067         ir_type *ovw_ovner = get_entity_owner(overwritten);
1068         assert(is_Class_type(owner));
1069         assert(is_Class_type(ovw_ovner));
1070         assert(! is_class_final(ovw_ovner));
1071 #endif /* NDEBUG */
1072         ARR_APP1(ir_entity *, ent->overwrites, overwritten);
1073         ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
1074 }  /* add_entity_overwrites */
1075
1076 int
1077 get_entity_n_overwrites(ir_entity *ent) {
1078         assert(is_Class_type(get_entity_owner(ent)));
1079         return (ARR_LEN(ent->overwrites));
1080 }  /* get_entity_n_overwrites */
1081
1082 int
1083 get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten) {
1084         int i, n;
1085         assert(is_Class_type(get_entity_owner(ent)));
1086         n = get_entity_n_overwrites(ent);
1087         for (i = 0; i < n; ++i) {
1088                 if (get_entity_overwrites(ent, i) == overwritten)
1089                         return i;
1090         }
1091         return -1;
1092 }  /* get_entity_overwrites_index */
1093
1094 ir_entity *
1095 get_entity_overwrites(ir_entity *ent, int pos) {
1096         assert(is_Class_type(get_entity_owner(ent)));
1097         assert(pos < get_entity_n_overwrites(ent));
1098         return ent->overwrites[pos];
1099 }  /* get_entity_overwrites */
1100
1101 void
1102 set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten) {
1103         assert(is_Class_type(get_entity_owner(ent)));
1104         assert(pos < get_entity_n_overwrites(ent));
1105         ent->overwrites[pos] = overwritten;
1106 }  /* set_entity_overwrites */
1107
1108 void
1109 remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten) {
1110         int i, n;
1111         assert(is_Class_type(get_entity_owner(ent)));
1112         n = ARR_LEN(ent->overwrites);
1113         for (i = 0; i < n; ++i) {
1114                 if (ent->overwrites[i] == overwritten) {
1115                         for (; i < n - 1; i++)
1116                                 ent->overwrites[i] = ent->overwrites[i+1];
1117                         ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
1118                         break;
1119                 }
1120         }
1121 }  /* remove_entity_overwrites */
1122
1123 void
1124 add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) {
1125         add_entity_overwrites(overwrites, ent);
1126 }  /* add_entity_overwrittenby */
1127
1128 int
1129 get_entity_n_overwrittenby(ir_entity *ent) {
1130         assert(is_Class_type(get_entity_owner(ent)));
1131         return ARR_LEN(ent->overwrittenby);
1132 }  /* get_entity_n_overwrittenby */
1133
1134 int
1135 get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites) {
1136         int i, n;
1137         assert(is_Class_type(get_entity_owner(ent)));
1138         n = get_entity_n_overwrittenby(ent);
1139         for (i = 0; i < n; ++i) {
1140                 if (get_entity_overwrittenby(ent, i) == overwrites)
1141                         return i;
1142         }
1143         return -1;
1144 }  /* get_entity_overwrittenby_index */
1145
1146 ir_entity *
1147 get_entity_overwrittenby(ir_entity *ent, int pos) {
1148         assert(is_Class_type(get_entity_owner(ent)));
1149         assert(pos < get_entity_n_overwrittenby(ent));
1150         return ent->overwrittenby[pos];
1151 }  /* get_entity_overwrittenby */
1152
1153 void
1154 set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites) {
1155         assert(is_Class_type(get_entity_owner(ent)));
1156         assert(pos < get_entity_n_overwrittenby(ent));
1157         ent->overwrittenby[pos] = overwrites;
1158 }  /* set_entity_overwrittenby */
1159
1160 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites) {
1161         int i, n;
1162         assert(is_Class_type(get_entity_owner(ent)));
1163
1164         n = ARR_LEN(ent->overwrittenby);
1165         for (i = 0; i < n; ++i) {
1166                 if (ent->overwrittenby[i] == overwrites) {
1167                         for(; i < n - 1; ++i)
1168                                 ent->overwrittenby[i] = ent->overwrittenby[i+1];
1169                         ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
1170                         break;
1171                 }
1172         }
1173 }  /* remove_entity_overwrittenby */
1174
1175 /* A link to store intermediate information */
1176 void *
1177 (get_entity_link)(const ir_entity *ent) {
1178         return _get_entity_link(ent);
1179 }  /* get_entity_link */
1180
1181 void
1182 (set_entity_link)(ir_entity *ent, void *l) {
1183         _set_entity_link(ent, l);
1184 }  /* set_entity_link */
1185
1186 ir_graph *
1187 (get_entity_irg)(const ir_entity *ent) {
1188         return _get_entity_irg(ent);
1189 }  /* get_entity_irg */
1190
1191 void
1192 set_entity_irg(ir_entity *ent, ir_graph *irg) {
1193         assert(is_method_entity(ent));
1194         /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
1195          * Methode selbst nicht mehr aufgerufen werden kann, die Entität
1196          * aber erhalten bleiben soll?  Wandle die Entitaet in description oder
1197          * inherited um! */
1198         /* assert(irg); */
1199         assert((irg  && ent->peculiarity == peculiarity_existent) ||
1200                 (!irg && (ent->peculiarity == peculiarity_existent)
1201                 && (ent -> visibility == visibility_external_allocated)) ||
1202                 (!irg && ent->peculiarity == peculiarity_description) ||
1203                 (!irg && ent->peculiarity == peculiarity_inherited));
1204         ent->attr.mtd_attr.irg = irg;
1205 }  /* set_entity_irg */
1206
1207 unsigned get_entity_vtable_number(const ir_entity *ent) {
1208         assert(is_method_entity((ir_entity *)ent));
1209         return ent->attr.mtd_attr.vtable_number;
1210 }  /* get_entity_vtable_number */
1211
1212 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number) {
1213         assert(is_method_entity(ent));
1214         ent->attr.mtd_attr.vtable_number = vtable_number;
1215 }  /* set_entity_vtable_number */
1216
1217 /* Returns the section of a method. */
1218 ir_img_section get_method_img_section(const ir_entity *ent) {
1219         assert(is_method_entity((ir_entity *)ent));
1220         return ent->attr.mtd_attr.section;
1221 }  /* get_method_img_section */
1222
1223 /* Sets the section of a method. */
1224 void set_method_img_section(ir_entity *ent, ir_img_section section) {
1225         assert(is_method_entity(ent));
1226         ent->attr.mtd_attr.section = section;
1227 }  /* set_method_img_section */
1228
1229 int
1230 (is_entity)(const void *thing) {
1231         return _is_entity(thing);
1232 }  /* is_entity */
1233
1234 int is_atomic_entity(ir_entity *ent) {
1235         ir_type *t      = get_entity_type(ent);
1236         const tp_op *op = get_type_tpop(t);
1237         return (op == type_primitive || op == type_pointer ||
1238                 op == type_enumeration || op == type_method);
1239 }  /* is_atomic_entity */
1240
1241 int is_compound_entity(ir_entity *ent) {
1242         ir_type     *t  = get_entity_type(ent);
1243         const tp_op *op = get_type_tpop(t);
1244         return (op == type_class || op == type_struct ||
1245                 op == type_array || op == type_union);
1246 }  /* is_compound_entity */
1247
1248 int is_method_entity(ir_entity *ent) {
1249         ir_type *t = get_entity_type(ent);
1250         return is_Method_type(t);
1251 }  /* is_method_entity */
1252
1253 /**
1254  * @todo not implemented!!! */
1255 int equal_entity(ir_entity *ent1, ir_entity *ent2) {
1256         (void) ent1;
1257         (void) ent2;
1258         fprintf(stderr, " calling unimplemented equal entity!!! \n");
1259         return 1;
1260 }  /* equal_entity */
1261
1262
1263 unsigned long (get_entity_visited)(ir_entity *ent) {
1264         return _get_entity_visited(ent);
1265 }  /* get_entity_visited */
1266
1267 void (set_entity_visited)(ir_entity *ent, unsigned long num) {
1268         _set_entity_visited(ent, num);
1269 }  /* set_entity_visited */
1270
1271 /* Sets visited field in ir_entity to entity_visited. */
1272 void (mark_entity_visited)(ir_entity *ent) {
1273         _mark_entity_visited(ent);
1274 }  /* mark_entity_visited */
1275
1276 int (entity_visited)(ir_entity *ent) {
1277         return _entity_visited(ent);
1278 }  /* entity_visited */
1279
1280 int (entity_not_visited)(ir_entity *ent) {
1281         return _entity_not_visited(ent);
1282 }  /* entity_not_visited */
1283
1284 /* Returns the mask of the additional entity properties. */
1285 unsigned get_entity_additional_properties(ir_entity *ent) {
1286         ir_graph *irg;
1287
1288         assert(is_method_entity(ent));
1289
1290         /* first check, if the graph has additional properties */
1291         irg = get_entity_irg(ent);
1292
1293         if (irg)
1294                 return get_irg_additional_properties(irg);
1295
1296         if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
1297                 return get_method_additional_properties(get_entity_type(ent));
1298
1299         return ent->attr.mtd_attr.irg_add_properties;
1300 }  /* get_entity_additional_properties */
1301
1302 /* Sets the mask of the additional graph properties. */
1303 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
1304 {
1305         ir_graph *irg;
1306
1307         assert(is_method_entity(ent));
1308
1309         /* first check, if the graph exists */
1310         irg = get_entity_irg(ent);
1311         if (irg)
1312                 set_irg_additional_properties(irg, property_mask);
1313         else {
1314     /* do not allow to set the mtp_property_inherited flag or
1315                 * the automatic inheritance of flags will not work */
1316                 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1317         }
1318 }  /* set_entity_additional_properties */
1319
1320 /* Sets one additional graph property. */
1321 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
1322 {
1323         ir_graph *irg;
1324
1325         assert(is_method_entity(ent));
1326
1327         /* first check, if the graph exists */
1328         irg = get_entity_irg(ent);
1329         if (irg)
1330                 set_irg_additional_property(irg, flag);
1331         else {
1332                 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
1333
1334                 if (mask & mtp_property_inherited)
1335                         mask = get_method_additional_properties(get_entity_type(ent));
1336
1337                         /* do not allow to set the mtp_property_inherited flag or
1338                 * the automatic inheritance of flags will not work */
1339                 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
1340         }
1341 }  /* set_entity_additional_property */
1342
1343 /* Returns the class type that this type info entity represents or NULL
1344    if ent is no type info entity. */
1345 ir_type *(get_entity_repr_class)(const ir_entity *ent) {
1346         return _get_entity_repr_class(ent);
1347 }  /* get_entity_repr_class */
1348
1349 dbg_info *(get_entity_dbg_info)(const ir_entity *ent) {
1350         return _get_entity_dbg_info(ent);
1351 }  /* get_entity_dbg_info */
1352
1353 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db) {
1354         _set_entity_dbg_info(ent, db);
1355 }  /* set_entity_dbg_info */
1356
1357 /* Initialize entity module. */
1358 void firm_init_entity(void)
1359 {
1360         symconst_symbol sym;
1361
1362         assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1363         assert(!unknown_entity && "Call firm_init_entity() only once!");
1364
1365         unknown_entity = new_rd_entity(NULL, firm_unknown_type, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type);
1366         set_entity_visibility(unknown_entity, visibility_external_allocated);
1367         set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1368
1369         current_ir_graph      = get_const_code_irg();
1370         sym.entity_p          = unknown_entity;
1371         unknown_entity->value = new_SymConst(sym, symconst_addr_ent);
1372 }  /* firm_init_entity */