From 02a879a0c7b7fc0873d5637e633d188856048abc Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 27 Apr 2007 14:29:34 +0000 Subject: [PATCH] Changed header changed indentation [r13527] --- ir/tr/tpop_t.h | 9 - ir/tr/tr_inheritance.c | 807 ++++++++++++++++++------------------ ir/tr/tr_inheritance.h | 47 +-- ir/tr/trvrfy.c | 515 ++++++++++++----------- ir/tr/trvrfy.h | 54 +-- ir/tr/type.c | 21 +- ir/tr/type.h | 23 +- ir/tr/type_identify.c | 99 ++--- ir/tr/type_identify.h | 31 +- ir/tr/type_identify_t.h | 40 -- ir/tr/type_t.h | 391 +++++++++--------- ir/tr/typegmod.c | 68 ++- ir/tr/typegmod.h | 20 +- ir/tr/typewalk.c | 888 ++++++++++++++++++++-------------------- ir/tr/typewalk.h | 26 +- 15 files changed, 1434 insertions(+), 1605 deletions(-) delete mode 100644 ir/tr/type_identify_t.h diff --git a/ir/tr/tpop_t.h b/ir/tr/tpop_t.h index 57498ca0f..086b04f60 100644 --- a/ir/tr/tpop_t.h +++ b/ir/tr/tpop_t.h @@ -32,15 +32,6 @@ #include "tpop.h" #include "irmode.h" -/** - * @file tpop_t.h - * - * This file contains the datatypes hidden in tpop.h. - * - * @author Goetz Lindenmaier - * @see tpop.h - */ - /** A function called to free attributes of a type. */ typedef void (*free_attrs_func)(ir_type *tp); diff --git a/ir/tr/tr_inheritance.c b/ir/tr/tr_inheritance.c index e7674223b..b8aabd7fe 100644 --- a/ir/tr/tr_inheritance.c +++ b/ir/tr/tr_inheritance.c @@ -18,23 +18,11 @@ */ /** - * - * @file tr_inheritance.c - * - * Project: libFIRM
- * File name: ir/tr/tr_inheritance.c
- * Purpose: Utility routines for inheritance representation
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * Copyright: (c) 2001-2005 Universität Karlsruhe
- * CVS-ID: $Id$ - * - * - * - * @see type.h entity.h + * @file tr_inheritance.c + * @brief Utility routines for inheritance representation + * @author Goetz Lindenmaier + * @version $Id$ */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -49,7 +37,6 @@ #include "mangle.h" #include "irgwalk.h" #include "irflag.h" -//#include ".h" /* ----------------------------------------------------------------------- */ @@ -57,53 +44,53 @@ /* ----------------------------------------------------------------------- */ ident *default_mangle_inherited_name(ir_entity *super, ir_type *clss) { - return mangle_u(new_id_from_str("inh"), mangle_u(get_type_ident(clss), get_entity_ident(super))); + return mangle_u(new_id_from_str("inh"), mangle_u(get_type_ident(clss), get_entity_ident(super))); } /** Replicates all entities in all super classes that are not overwritten - by an entity of this class. */ + by an entity of this class. */ static void copy_entities_from_superclass(ir_type *clss, void *env) { - int i, j, k, l; - int overwritten; - ir_type *super, *inhenttype; - ir_entity *inhent, *thisent; - mangle_inherited_name_func *mfunc = *(mangle_inherited_name_func **)env; - - for(i = 0; i < get_class_n_supertypes(clss); i++) { - super = get_class_supertype(clss, i); - assert(is_Class_type(super) && "not a class"); - for(j = 0; j < get_class_n_members(super); j++) { - inhent = get_class_member(super, j); - inhenttype = get_entity_type(inhent); - /* check whether inhent is already overwritten */ - overwritten = 0; - for (k = 0; (k < get_class_n_members(clss)) && (overwritten == 0); k++) { - thisent = get_class_member(clss, k); - for(l = 0; l < get_entity_n_overwrites(thisent); l++) { - if(inhent == get_entity_overwrites(thisent, l)) { - /* overwritten - do not copy */ - overwritten = 1; - break; - } - } - } - /* Inherit entity */ - if (!overwritten) { - thisent = copy_entity_own(inhent, clss); - add_entity_overwrites(thisent, inhent); - if (get_entity_peculiarity(inhent) == peculiarity_existent) - set_entity_peculiarity(thisent, peculiarity_inherited); - set_entity_ld_ident(thisent, mfunc(inhent, clss)); - if (get_entity_variability(inhent) == variability_constant) { - assert(is_atomic_entity(inhent) && /* @@@ */ - "Inheritance of constant, compound entities not implemented"); - set_entity_variability(thisent, variability_constant); - set_atomic_ent_value(thisent, get_atomic_ent_value(inhent)); - } - } - } - } + int i, j, k, l; + int overwritten; + ir_type *super, *inhenttype; + ir_entity *inhent, *thisent; + mangle_inherited_name_func *mfunc = *(mangle_inherited_name_func **)env; + + for(i = 0; i < get_class_n_supertypes(clss); i++) { + super = get_class_supertype(clss, i); + assert(is_Class_type(super) && "not a class"); + for(j = 0; j < get_class_n_members(super); j++) { + inhent = get_class_member(super, j); + inhenttype = get_entity_type(inhent); + /* check whether inhent is already overwritten */ + overwritten = 0; + for (k = 0; (k < get_class_n_members(clss)) && (overwritten == 0); k++) { + thisent = get_class_member(clss, k); + for(l = 0; l < get_entity_n_overwrites(thisent); l++) { + if(inhent == get_entity_overwrites(thisent, l)) { + /* overwritten - do not copy */ + overwritten = 1; + break; + } + } + } + /* Inherit entity */ + if (!overwritten) { + thisent = copy_entity_own(inhent, clss); + add_entity_overwrites(thisent, inhent); + if (get_entity_peculiarity(inhent) == peculiarity_existent) + set_entity_peculiarity(thisent, peculiarity_inherited); + set_entity_ld_ident(thisent, mfunc(inhent, clss)); + if (get_entity_variability(inhent) == variability_constant) { + assert(is_atomic_entity(inhent) && /* @@@ */ + "Inheritance of constant, compound entities not implemented"); + set_entity_variability(thisent, variability_constant); + set_atomic_ent_value(thisent, get_atomic_ent_value(inhent)); + } + } + } + } } /* Resolve implicit inheritance. @@ -111,9 +98,9 @@ static void copy_entities_from_superclass(ir_type *clss, void *env) * Resolves the implicit inheritance supplied by firm. */ void resolve_inheritance(mangle_inherited_name_func *mfunc) { - if (!mfunc) - mfunc = default_mangle_inherited_name; - class_walk_super2sub(copy_entities_from_superclass, NULL, (void *)&mfunc); + if (!mfunc) + mfunc = default_mangle_inherited_name; + class_walk_super2sub(copy_entities_from_superclass, NULL, (void *)&mfunc); } @@ -131,19 +118,19 @@ void resolve_inheritance(mangle_inherited_name_func *mfunc) { /* ----------------------------------------------------------------------- */ void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s) { - irp->inh_trans_closure_state = s; + irp->inh_trans_closure_state = s; } void invalidate_irp_inh_transitive_closure_state(void) { - if (irp->inh_trans_closure_state == inh_transitive_closure_valid) - irp->inh_trans_closure_state = inh_transitive_closure_invalid; + if (irp->inh_trans_closure_state == inh_transitive_closure_valid) + irp->inh_trans_closure_state = inh_transitive_closure_invalid; } inh_transitive_closure_state get_irp_inh_transitive_closure_state(void) { - return irp->inh_trans_closure_state; + return irp->inh_trans_closure_state; } static void assert_valid_state(void) { - assert(irp->inh_trans_closure_state == inh_transitive_closure_valid || - irp->inh_trans_closure_state == inh_transitive_closure_invalid); + assert(irp->inh_trans_closure_state == inh_transitive_closure_valid || + irp->inh_trans_closure_state == inh_transitive_closure_invalid); } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ @@ -155,75 +142,75 @@ static void assert_valid_state(void) { /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ typedef enum { - d_up = 0, - d_down = 1, + d_up = 0, + d_down = 1, } dir; typedef struct { - firm_kind *kind; /* An entity or type. */ - pset *directions[2]; + firm_kind *kind; /* An entity or type. */ + pset *directions[2]; } tr_inh_trans_tp; /* We use this set for all types and entities. */ static set *tr_inh_trans_set = NULL; static int tr_inh_trans_cmp(const void *e1, const void *e2, size_t size) { - tr_inh_trans_tp *ef1 = (tr_inh_trans_tp *)e1; - tr_inh_trans_tp *ef2 = (tr_inh_trans_tp *)e2; - return (ef1->kind != ef2->kind); + tr_inh_trans_tp *ef1 = (tr_inh_trans_tp *)e1; + tr_inh_trans_tp *ef2 = (tr_inh_trans_tp *)e2; + return (ef1->kind != ef2->kind); } static INLINE unsigned int tr_inh_trans_hash(void *e) { - tr_inh_trans_tp *v = e; - return HASH_PTR(v->kind); + tr_inh_trans_tp *v = e; + return HASH_PTR(v->kind); } /* This always completes successfully. */ static tr_inh_trans_tp* get_firm_kind_entry(firm_kind *k) { - tr_inh_trans_tp a, *found; - a.kind = k; + tr_inh_trans_tp a, *found; + a.kind = k; - if (!tr_inh_trans_set) tr_inh_trans_set = new_set(tr_inh_trans_cmp, 128); + if (!tr_inh_trans_set) tr_inh_trans_set = new_set(tr_inh_trans_cmp, 128); - found = set_find(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a)); - if (!found) { - a.directions[d_up] = pset_new_ptr(16); - a.directions[d_down] = pset_new_ptr(16); - found = set_insert(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a)); - } - return found; + found = set_find(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a)); + if (!found) { + a.directions[d_up] = pset_new_ptr(16); + a.directions[d_down] = pset_new_ptr(16); + found = set_insert(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a)); + } + return found; } static pset *get_entity_map(ir_entity *ent, dir d) { - tr_inh_trans_tp *found; + tr_inh_trans_tp *found; - assert(is_entity(ent)); - found = get_firm_kind_entry((firm_kind *)ent); - return found->directions[d]; + assert(is_entity(ent)); + found = get_firm_kind_entry((firm_kind *)ent); + return found->directions[d]; } /* static void add_entity_map(ir_entity *ent, dir d, ir_entity *new) { - tr_inh_trans_tp *found; + tr_inh_trans_tp *found; - assert(is_entity(ent) && is_entity(new)); - tr_inh_trans_tp *found = get_firm_kind_entry((firm_kind *)ent); - pset_insert_ptr(found->directions[d], new); + assert(is_entity(ent) && is_entity(new)); + tr_inh_trans_tp *found = get_firm_kind_entry((firm_kind *)ent); + pset_insert_ptr(found->directions[d], new); } */ static pset *get_type_map(ir_type *tp, dir d) { - tr_inh_trans_tp *found; + tr_inh_trans_tp *found; - assert(is_type(tp)); - found = get_firm_kind_entry((firm_kind *)tp); - return found->directions[d]; + assert(is_type(tp)); + found = get_firm_kind_entry((firm_kind *)tp); + return found->directions[d]; } /* static void add_type_map(ir_type *tp, dir d, type *new) { - tr_inh_trans_tp *found; + tr_inh_trans_tp *found; - assert(is_type(tp) && is_type(new)); - found = get_firm_kind_entry((firm_kind *)tp); - pset_insert_ptr(found->directions[d], new); + assert(is_type(tp) && is_type(new)); + found = get_firm_kind_entry((firm_kind *)tp); + pset_insert_ptr(found->directions[d], new); } */ @@ -245,111 +232,111 @@ static void add_type_map(ir_type *tp, dir d, type *new) { * * Well, we still miss some candidates ... */ static void compute_down_closure(ir_type *tp) { - pset *myset, *subset; - int i, n_subtypes, n_members, n_supertypes; - unsigned long master_visited = get_master_type_visited(); - - assert(is_Class_type(tp)); - - set_type_visited(tp, master_visited-1); - - /* Recursive descend. */ - n_subtypes = get_class_n_subtypes(tp); - for (i = 0; i < n_subtypes; ++i) { - ir_type *stp = get_class_subtype(tp, i); - if (get_type_visited(stp) < master_visited-1) { - compute_down_closure(stp); - } - } - - /* types */ - myset = get_type_map(tp, d_down); - for (i = 0; i < n_subtypes; ++i) { - ir_type *stp = get_class_subtype(tp, i); - subset = get_type_map(stp, d_down); - pset_insert_ptr(myset, stp); - pset_insert_pset_ptr(myset, subset); - } - - /* entities */ - n_members = get_class_n_members(tp); - for (i = 0; i < n_members; ++i) { - ir_entity *mem = get_class_member(tp, i); - int j, n_overwrittenby = get_entity_n_overwrittenby(mem); - - myset = get_entity_map(mem, d_down); - for (j = 0; j < n_overwrittenby; ++j) { - ir_entity *ov = get_entity_overwrittenby(mem, j); - subset = get_entity_map(ov, d_down); - pset_insert_ptr(myset, ov); - pset_insert_pset_ptr(myset, subset); - } - } - - mark_type_visited(tp); - - /* Walk up. */ - n_supertypes = get_class_n_supertypes(tp); - for (i = 0; i < n_supertypes; ++i) { - ir_type *stp = get_class_supertype(tp, i); - if (get_type_visited(stp) < master_visited-1) { - compute_down_closure(stp); - } - } + pset *myset, *subset; + int i, n_subtypes, n_members, n_supertypes; + unsigned long master_visited = get_master_type_visited(); + + assert(is_Class_type(tp)); + + set_type_visited(tp, master_visited-1); + + /* Recursive descend. */ + n_subtypes = get_class_n_subtypes(tp); + for (i = 0; i < n_subtypes; ++i) { + ir_type *stp = get_class_subtype(tp, i); + if (get_type_visited(stp) < master_visited-1) { + compute_down_closure(stp); + } + } + + /* types */ + myset = get_type_map(tp, d_down); + for (i = 0; i < n_subtypes; ++i) { + ir_type *stp = get_class_subtype(tp, i); + subset = get_type_map(stp, d_down); + pset_insert_ptr(myset, stp); + pset_insert_pset_ptr(myset, subset); + } + + /* entities */ + n_members = get_class_n_members(tp); + for (i = 0; i < n_members; ++i) { + ir_entity *mem = get_class_member(tp, i); + int j, n_overwrittenby = get_entity_n_overwrittenby(mem); + + myset = get_entity_map(mem, d_down); + for (j = 0; j < n_overwrittenby; ++j) { + ir_entity *ov = get_entity_overwrittenby(mem, j); + subset = get_entity_map(ov, d_down); + pset_insert_ptr(myset, ov); + pset_insert_pset_ptr(myset, subset); + } + } + + mark_type_visited(tp); + + /* Walk up. */ + n_supertypes = get_class_n_supertypes(tp); + for (i = 0; i < n_supertypes; ++i) { + ir_type *stp = get_class_supertype(tp, i); + if (get_type_visited(stp) < master_visited-1) { + compute_down_closure(stp); + } + } } static void compute_up_closure(ir_type *tp) { - pset *myset, *subset; - int i, n_subtypes, n_members, n_supertypes; - unsigned long master_visited = get_master_type_visited(); - - assert(is_Class_type(tp)); - - set_type_visited(tp, master_visited-1); - - /* Recursive descend. */ - n_supertypes = get_class_n_supertypes(tp); - for (i = 0; i < n_supertypes; ++i) { - ir_type *stp = get_class_supertype(tp, i); - if (get_type_visited(stp) < get_master_type_visited()-1) { - compute_up_closure(stp); - } - } - - /* types */ - myset = get_type_map(tp, d_up); - for (i = 0; i < n_supertypes; ++i) { - ir_type *stp = get_class_supertype(tp, i); - subset = get_type_map(stp, d_up); - pset_insert_ptr(myset, stp); - pset_insert_pset_ptr(myset, subset); - } - - /* entities */ - n_members = get_class_n_members(tp); - for (i = 0; i < n_members; ++i) { - ir_entity *mem = get_class_member(tp, i); - int j, n_overwrites = get_entity_n_overwrites(mem); - - myset = get_entity_map(mem, d_up); - for (j = 0; j < n_overwrites; ++j) { - ir_entity *ov = get_entity_overwrites(mem, j); - subset = get_entity_map(ov, d_up); - pset_insert_pset_ptr(myset, subset); - pset_insert_ptr(myset, ov); - } - } - - mark_type_visited(tp); - - /* Walk down. */ - n_subtypes = get_class_n_subtypes(tp); - for (i = 0; i < n_subtypes; ++i) { - ir_type *stp = get_class_subtype(tp, i); - if (get_type_visited(stp) < master_visited-1) { - compute_up_closure(stp); - } - } + pset *myset, *subset; + int i, n_subtypes, n_members, n_supertypes; + unsigned long master_visited = get_master_type_visited(); + + assert(is_Class_type(tp)); + + set_type_visited(tp, master_visited-1); + + /* Recursive descend. */ + n_supertypes = get_class_n_supertypes(tp); + for (i = 0; i < n_supertypes; ++i) { + ir_type *stp = get_class_supertype(tp, i); + if (get_type_visited(stp) < get_master_type_visited()-1) { + compute_up_closure(stp); + } + } + + /* types */ + myset = get_type_map(tp, d_up); + for (i = 0; i < n_supertypes; ++i) { + ir_type *stp = get_class_supertype(tp, i); + subset = get_type_map(stp, d_up); + pset_insert_ptr(myset, stp); + pset_insert_pset_ptr(myset, subset); + } + + /* entities */ + n_members = get_class_n_members(tp); + for (i = 0; i < n_members; ++i) { + ir_entity *mem = get_class_member(tp, i); + int j, n_overwrites = get_entity_n_overwrites(mem); + + myset = get_entity_map(mem, d_up); + for (j = 0; j < n_overwrites; ++j) { + ir_entity *ov = get_entity_overwrites(mem, j); + subset = get_entity_map(ov, d_up); + pset_insert_pset_ptr(myset, subset); + pset_insert_ptr(myset, ov); + } + } + + mark_type_visited(tp); + + /* Walk down. */ + n_subtypes = get_class_n_subtypes(tp); + for (i = 0; i < n_subtypes; ++i) { + ir_type *stp = get_class_subtype(tp, i); + if (get_type_visited(stp) < master_visited-1) { + compute_up_closure(stp); + } + } } /** Compute the transitive closure of the subclass/superclass and @@ -358,113 +345,113 @@ static void compute_up_closure(ir_type *tp) { * This function walks over the ir (O(#types+#entities)) to compute the * transitive closure. */ void compute_inh_transitive_closure(void) { - int i, n_types = get_irp_n_types(); - free_inh_transitive_closure(); - - /* The 'down' relation */ - inc_master_type_visited(); /* Inc twice: one if on stack, second if values computed. */ - inc_master_type_visited(); - for (i = 0; i < n_types; ++i) { - ir_type *tp = get_irp_type(i); - if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */ - int j, n_subtypes = get_class_n_subtypes(tp); - int has_unmarked_subtype = 0; - - assert(get_type_visited(tp) < get_master_type_visited()-1); - for (j = 0; j < n_subtypes; ++j) { - ir_type *stp = get_class_subtype(tp, j); - if (type_not_visited(stp)) { - has_unmarked_subtype = 1; - break; - } - } - - /* This is a good starting point. */ - if (!has_unmarked_subtype) - compute_down_closure(tp); - } - } - - /* The 'up' relation */ - inc_master_type_visited(); - inc_master_type_visited(); - for (i = 0; i < n_types; ++i) { - ir_type *tp = get_irp_type(i); - if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */ - int j, n_supertypes = get_class_n_supertypes(tp); - int has_unmarked_supertype = 0; - - assert(get_type_visited(tp) < get_master_type_visited()-1); - for (j = 0; j < n_supertypes; ++j) { - ir_type *stp = get_class_supertype(tp, j); - if (type_not_visited(stp)) { - has_unmarked_supertype = 1; - break; - } - } - - /* This is a good starting point. */ - if (!has_unmarked_supertype) - compute_up_closure(tp); - } - } - - irp->inh_trans_closure_state = inh_transitive_closure_valid; + int i, n_types = get_irp_n_types(); + free_inh_transitive_closure(); + + /* The 'down' relation */ + inc_master_type_visited(); /* Inc twice: one if on stack, second if values computed. */ + inc_master_type_visited(); + for (i = 0; i < n_types; ++i) { + ir_type *tp = get_irp_type(i); + if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */ + int j, n_subtypes = get_class_n_subtypes(tp); + int has_unmarked_subtype = 0; + + assert(get_type_visited(tp) < get_master_type_visited()-1); + for (j = 0; j < n_subtypes; ++j) { + ir_type *stp = get_class_subtype(tp, j); + if (type_not_visited(stp)) { + has_unmarked_subtype = 1; + break; + } + } + + /* This is a good starting point. */ + if (!has_unmarked_subtype) + compute_down_closure(tp); + } + } + + /* The 'up' relation */ + inc_master_type_visited(); + inc_master_type_visited(); + for (i = 0; i < n_types; ++i) { + ir_type *tp = get_irp_type(i); + if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */ + int j, n_supertypes = get_class_n_supertypes(tp); + int has_unmarked_supertype = 0; + + assert(get_type_visited(tp) < get_master_type_visited()-1); + for (j = 0; j < n_supertypes; ++j) { + ir_type *stp = get_class_supertype(tp, j); + if (type_not_visited(stp)) { + has_unmarked_supertype = 1; + break; + } + } + + /* This is a good starting point. */ + if (!has_unmarked_supertype) + compute_up_closure(tp); + } + } + + irp->inh_trans_closure_state = inh_transitive_closure_valid; } /** Free memory occupied by the transitive closure information. */ void free_inh_transitive_closure(void) { - if (tr_inh_trans_set) { - tr_inh_trans_tp *elt; - for (elt = set_first(tr_inh_trans_set); elt; elt = set_next(tr_inh_trans_set)) { - del_pset(elt->directions[d_up]); - del_pset(elt->directions[d_down]); - } - del_set(tr_inh_trans_set); - tr_inh_trans_set = NULL; - } - irp->inh_trans_closure_state = inh_transitive_closure_none; + if (tr_inh_trans_set) { + tr_inh_trans_tp *elt; + for (elt = set_first(tr_inh_trans_set); elt; elt = set_next(tr_inh_trans_set)) { + del_pset(elt->directions[d_up]); + del_pset(elt->directions[d_down]); + } + del_set(tr_inh_trans_set); + tr_inh_trans_set = NULL; + } + irp->inh_trans_closure_state = inh_transitive_closure_none; } /* - subtype ------------------------------------------------------------- */ ir_type *get_class_trans_subtype_first(ir_type *tp) { - assert_valid_state(); - return pset_first(get_type_map(tp, d_down)); + assert_valid_state(); + return pset_first(get_type_map(tp, d_down)); } ir_type *get_class_trans_subtype_next (ir_type *tp) { - assert_valid_state(); - return pset_next(get_type_map(tp, d_down)); + assert_valid_state(); + return pset_next(get_type_map(tp, d_down)); } int is_class_trans_subtype (ir_type *tp, ir_type *subtp) { - assert_valid_state(); - return (pset_find_ptr(get_type_map(tp, d_down), subtp) != NULL); + assert_valid_state(); + return (pset_find_ptr(get_type_map(tp, d_down), subtp) != NULL); } /* - supertype ----------------------------------------------------------- */ ir_type *get_class_trans_supertype_first(ir_type *tp) { - assert_valid_state(); - return pset_first(get_type_map(tp, d_up)); + assert_valid_state(); + return pset_first(get_type_map(tp, d_up)); } ir_type *get_class_trans_supertype_next (ir_type *tp) { - assert_valid_state(); - return pset_next(get_type_map(tp, d_up)); + assert_valid_state(); + return pset_next(get_type_map(tp, d_up)); } /* - overwrittenby ------------------------------------------------------- */ ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent) { - assert_valid_state(); - return pset_first(get_entity_map(ent, d_down)); + assert_valid_state(); + return pset_first(get_entity_map(ent, d_down)); } ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent) { - assert_valid_state(); - return pset_next(get_entity_map(ent, d_down)); + assert_valid_state(); + return pset_next(get_entity_map(ent, d_down)); } /* - overwrites ---------------------------------------------------------- */ @@ -472,13 +459,13 @@ ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent) { /** Iterate over all transitive overwritten entities. */ ir_entity *get_entity_trans_overwrites_first(ir_entity *ent) { - assert_valid_state(); - return pset_first(get_entity_map(ent, d_up)); + assert_valid_state(); + return pset_first(get_entity_map(ent, d_up)); } ir_entity *get_entity_trans_overwrites_next (ir_entity *ent) { - assert_valid_state(); - return pset_next(get_entity_map(ent, d_up)); + assert_valid_state(); + return pset_next(get_entity_map(ent, d_up)); } @@ -491,30 +478,30 @@ ir_entity *get_entity_trans_overwrites_next (ir_entity *ent) { /** Returns true if low is subclass of high. */ static int check_is_SubClass_of(ir_type *low, ir_type *high) { - int i, n_subtypes; + int i, n_subtypes; - /* depth first search from high downwards. */ - n_subtypes = get_class_n_subtypes(high); - for (i = 0; i < n_subtypes; i++) { - ir_type *stp = get_class_subtype(high, i); - if (low == stp) return 1; - if (is_SubClass_of(low, stp)) - return 1; - } - return 0; + /* depth first search from high downwards. */ + n_subtypes = get_class_n_subtypes(high); + for (i = 0; i < n_subtypes; i++) { + ir_type *stp = get_class_subtype(high, i); + if (low == stp) return 1; + if (is_SubClass_of(low, stp)) + return 1; + } + return 0; } /* Returns true if low is subclass of high. */ int is_SubClass_of(ir_type *low, ir_type *high) { - assert(is_Class_type(low) && is_Class_type(high)); + assert(is_Class_type(low) && is_Class_type(high)); - if (low == high) return 1; + if (low == high) return 1; - if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) { - pset *m = get_type_map(high, d_down); - return pset_find_ptr(m, low) ? 1 : 0; - } - return check_is_SubClass_of(low, high); + if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) { + pset *m = get_type_map(high, d_down); + return pset_find_ptr(m, low) ? 1 : 0; + } + return check_is_SubClass_of(low, high); } @@ -525,34 +512,34 @@ int is_SubClass_of(ir_type *low, ir_type *high) { * and subclasses, returns true, else false. Can also be called with * two class types. */ int is_SubClass_ptr_of(ir_type *low, ir_type *high) { - while (is_Pointer_type(low) && is_Pointer_type(high)) { - low = get_pointer_points_to_type(low); - high = get_pointer_points_to_type(high); - } + while (is_Pointer_type(low) && is_Pointer_type(high)) { + low = get_pointer_points_to_type(low); + high = get_pointer_points_to_type(high); + } - if (is_Class_type(low) && is_Class_type(high)) - return is_SubClass_of(low, high); - return 0; + if (is_Class_type(low) && is_Class_type(high)) + return is_SubClass_of(low, high); + return 0; } int is_overwritten_by(ir_entity *high, ir_entity *low) { - int i, n_overwrittenby; - assert(is_entity(low) && is_entity(high)); + int i, n_overwrittenby; + assert(is_entity(low) && is_entity(high)); - if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) { - pset *m = get_entity_map(high, d_down); - return pset_find_ptr(m, low) ? 1 : 0; - } + if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) { + pset *m = get_entity_map(high, d_down); + return pset_find_ptr(m, low) ? 1 : 0; + } - /* depth first search from high downwards. */ - n_overwrittenby = get_entity_n_overwrittenby(high); - for (i = 0; i < n_overwrittenby; i++) { - ir_entity *ov = get_entity_overwrittenby(high, i); - if (low == ov) return 1; - if (is_overwritten_by(low, ov)) - return 1; - } - return 0; + /* depth first search from high downwards. */ + n_overwrittenby = get_entity_n_overwrittenby(high); + for (i = 0; i < n_overwrittenby; i++) { + ir_entity *ov = get_entity_overwrittenby(high, i); + if (low == ov) return 1; + if (is_overwritten_by(low, ov)) + return 1; + } + return 0; } /** Resolve polymorphy in the inheritance relation. @@ -564,17 +551,17 @@ int is_overwritten_by(ir_entity *high, ir_entity *low) { * Need two routines because I want to assert the result. */ static ir_entity *do_resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent) { - int i, n_overwrittenby; + int i, n_overwrittenby; - if (get_entity_owner(static_ent) == dynamic_class) return static_ent; + if (get_entity_owner(static_ent) == dynamic_class) return static_ent; - n_overwrittenby = get_entity_n_overwrittenby(static_ent); - for (i = 0; i < n_overwrittenby; ++i) { - ir_entity *ent = get_entity_overwrittenby(static_ent, i); - ent = do_resolve_ent_polymorphy(dynamic_class, ent); - if (ent) return ent; - } - return NULL; + n_overwrittenby = get_entity_n_overwrittenby(static_ent); + for (i = 0; i < n_overwrittenby; ++i) { + ir_entity *ent = get_entity_overwrittenby(static_ent, i); + ent = do_resolve_ent_polymorphy(dynamic_class, ent); + if (ent) return ent; + } + return NULL; } /* Resolve polymorphy in the inheritance relation. @@ -583,13 +570,13 @@ static ir_entity *do_resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *s * dynamic type are given. * Search downwards in overwritten tree. */ ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent) { - ir_entity *res; - assert(static_ent && is_entity(static_ent)); + ir_entity *res; + assert(static_ent && is_entity(static_ent)); - res = do_resolve_ent_polymorphy(dynamic_class, static_ent); - assert(res); + res = do_resolve_ent_polymorphy(dynamic_class, static_ent); + assert(res); - return res; + return res; } @@ -601,106 +588,106 @@ ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent) /* - State handling. ----------------------------------------- */ void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s) { - if (get_irp_class_cast_state() > s) set_irp_class_cast_state(s); - irg->class_cast_state = s; + if (get_irp_class_cast_state() > s) set_irp_class_cast_state(s); + irg->class_cast_state = s; } ir_class_cast_state get_irg_class_cast_state(ir_graph *irg) { - return irg->class_cast_state; + return irg->class_cast_state; } void set_irp_class_cast_state(ir_class_cast_state s) { - int i; - for (i = 0; i < get_irp_n_irgs(); ++i) - assert(get_irg_class_cast_state(get_irp_irg(i)) >= s); - irp->class_cast_state = s; + int i; + for (i = 0; i < get_irp_n_irgs(); ++i) + assert(get_irg_class_cast_state(get_irp_irg(i)) >= s); + irp->class_cast_state = s; } ir_class_cast_state get_irp_class_cast_state(void) { - return irp->class_cast_state; + return irp->class_cast_state; } char *get_class_cast_state_string(ir_class_cast_state s) { #define X(a) case a: return #a - switch(s) { - X(ir_class_casts_any); - X(ir_class_casts_transitive); - X(ir_class_casts_normalized); - X(ir_class_casts_state_max); - default: return "invalid class cast state"; - } + switch(s) { + X(ir_class_casts_any); + X(ir_class_casts_transitive); + X(ir_class_casts_normalized); + X(ir_class_casts_state_max); + default: return "invalid class cast state"; + } #undef X } /* - State verification. ------------------------------------- */ typedef struct ccs_env { - ir_class_cast_state expected_state; - ir_class_cast_state worst_situation; + ir_class_cast_state expected_state; + ir_class_cast_state worst_situation; } ccs_env; void verify_irn_class_cast_state(ir_node *n, void *env) { - ccs_env *ccs = (ccs_env *)env; - ir_class_cast_state this_state = ir_class_casts_any; - ir_type *fromtype, *totype; - int ref_depth = 0; - - if (get_irn_op(n) != op_Cast) return; - - fromtype = get_irn_typeinfo_type(get_Cast_op(n)); - totype = get_Cast_type(n); - - while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { - totype = get_pointer_points_to_type(totype); - fromtype = get_pointer_points_to_type(fromtype); - ref_depth++; - } - - if (!is_Class_type(totype)) return; - - if (is_SubClass_of(totype, fromtype) || - is_SubClass_of(fromtype, totype) ) { - this_state = ir_class_casts_transitive; - if ((get_class_supertype_index(totype, fromtype) != -1) || - (get_class_supertype_index(fromtype, totype) != -1) || - fromtype == totype) { - /* Das ist doch alt? Aus dem cvs aufgetaucht ... - if ((get_class_supertype_index(totype, fromtype) == -1) && - (get_class_supertype_index(fromtype, totype) == -1) ) { */ - this_state = ir_class_casts_normalized; - } - } - - if (!(this_state >= ccs->expected_state)) { - printf(" Node is "); DDMN(n); - printf(" totype "); DDMT(totype); - printf(" fromtype "); DDMT(fromtype); - printf(" this_state: %s, exp. state: %s\n", - get_class_cast_state_string(this_state), - get_class_cast_state_string(ccs->expected_state)); - assert(this_state >= ccs->expected_state && - "invalid state class cast state setting in graph"); - } - - if (this_state < ccs->worst_situation) - ccs->worst_situation = this_state; + ccs_env *ccs = (ccs_env *)env; + ir_class_cast_state this_state = ir_class_casts_any; + ir_type *fromtype, *totype; + int ref_depth = 0; + + if (get_irn_op(n) != op_Cast) return; + + fromtype = get_irn_typeinfo_type(get_Cast_op(n)); + totype = get_Cast_type(n); + + while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { + totype = get_pointer_points_to_type(totype); + fromtype = get_pointer_points_to_type(fromtype); + ref_depth++; + } + + if (!is_Class_type(totype)) return; + + if (is_SubClass_of(totype, fromtype) || + is_SubClass_of(fromtype, totype) ) { + this_state = ir_class_casts_transitive; + if ((get_class_supertype_index(totype, fromtype) != -1) || + (get_class_supertype_index(fromtype, totype) != -1) || + fromtype == totype) { + /* Das ist doch alt? Aus dem cvs aufgetaucht ... + if ((get_class_supertype_index(totype, fromtype) == -1) && + (get_class_supertype_index(fromtype, totype) == -1) ) { */ + this_state = ir_class_casts_normalized; + } + } + + if (!(this_state >= ccs->expected_state)) { + printf(" Node is "); DDMN(n); + printf(" totype "); DDMT(totype); + printf(" fromtype "); DDMT(fromtype); + printf(" this_state: %s, exp. state: %s\n", + get_class_cast_state_string(this_state), + get_class_cast_state_string(ccs->expected_state)); + assert(this_state >= ccs->expected_state && + "invalid state class cast state setting in graph"); + } + + if (this_state < ccs->worst_situation) + ccs->worst_situation = this_state; } /** Verify that the graph meets requirements of state set. */ void verify_irg_class_cast_state(ir_graph *irg) { - ccs_env env; + ccs_env env; - env.expected_state = get_irg_class_cast_state(irg); - env.worst_situation = ir_class_casts_normalized; + env.expected_state = get_irg_class_cast_state(irg); + env.worst_situation = ir_class_casts_normalized; - irg_walk_graph(irg, NULL, verify_irn_class_cast_state, &env); + irg_walk_graph(irg, NULL, verify_irn_class_cast_state, &env); - if ((env.worst_situation > env.expected_state) && get_firm_verbosity()) { - printf("Note: class cast state is set lower than reqired in graph\n "); - DDMG(irg); - printf(" state is %s, reqired is %s\n", - get_class_cast_state_string(env.expected_state), - get_class_cast_state_string(env.worst_situation)); - } + if ((env.worst_situation > env.expected_state) && get_firm_verbosity()) { + printf("Note: class cast state is set lower than reqired in graph\n "); + DDMG(irg); + printf(" state is %s, reqired is %s\n", + get_class_cast_state_string(env.expected_state), + get_class_cast_state_string(env.worst_situation)); + } } diff --git a/ir/tr/tr_inheritance.h b/ir/tr/tr_inheritance.h index a63dcfc40..73b3d18a1 100644 --- a/ir/tr/tr_inheritance.h +++ b/ir/tr/tr_inheritance.h @@ -19,15 +19,10 @@ /** * @file tr_inheritance.h - * - * Project: libFIRM
- * File name: ir/tr/tp_inheritance.h
- * Purpose: Utility routines for inheritance representation
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * Copyright: (c) 2001-2005 Universität Karlsruhe
- * CVS-ID: $Id$ + * @brief Utility routines for inheritance representation + * @author Goetz Lindenmaier + * @version $Id$ + * @summary * * This file supplies a set of utility routines for the inheritance * representation. @@ -40,10 +35,10 @@ * - Compute the transitive closure of the subclass/superclass and * overwrites/overwrittenby relation. * - * @see type.h entity.h + * @see type.h entity.h */ -#ifndef _FIRM_TR_INHERITANCE_H_ -#define _FIRM_TR_INHERITANCE_H_ +#ifndef FIRM_TR_INHERITANCE_H +#define FIRM_TR_INHERITANCE_H #include "firm_types.h" #include "type.h" @@ -155,10 +150,10 @@ void resolve_inheritance(mangle_inherited_name_func *mfunc); * @todo: we could manage the state for each relation separately. Invalidating * the entity relations does not mean invalidating the class relation. */ typedef enum { - inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */ - inh_transitive_closure_valid, /**< Closure computed and valid. */ - inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */ - inh_transitive_closure_max /**< Invalid value. */ + inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */ + inh_transitive_closure_valid, /**< Closure computed and valid. */ + inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */ + inh_transitive_closure_max /**< Invalid value. */ } inh_transitive_closure_state; void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s); @@ -167,10 +162,10 @@ inh_transitive_closure_state get_irp_inh_transitive_closure_state(void); /** Compute transitive closure of the subclass/superclass and -* overwrites/overwrittenby relation. -* -* This function walks over the ir (O(#types+#entities)) to compute the -* transitive closure. */ + * overwrites/overwrittenby relation. + * + * This function walks over the ir (O(#types+#entities)) to compute the + * transitive closure. */ void compute_inh_transitive_closure(void); /** Free memory occupied by the transitive closure information. */ @@ -233,11 +228,11 @@ ir_entity *get_entity_trans_overwrites_next (ir_entity *ent); * * We rely on the ordering of the enum. */ typedef enum { - ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with - the class hierarchy. @@@ So far this does not happen in Firm. */ - ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */ - ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */ - ir_class_casts_state_max + ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with + the class hierarchy. @@@ So far this does not happen in Firm. */ + ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */ + ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */ + ir_class_casts_state_max } ir_class_cast_state; char *get_class_cast_state_string(ir_class_cast_state s); @@ -252,4 +247,4 @@ ir_class_cast_state get_irp_class_cast_state(void); * and firm verbosity is set. */ void verify_irg_class_cast_state(ir_graph *irg); -#endif /* _FIRM_TR_INHERITANCE_H_ */ +#endif /* FIRM_TR_INHERITANCE_H */ diff --git a/ir/tr/trvrfy.c b/ir/tr/trvrfy.c index ee4087f69..7a83dc110 100644 --- a/ir/tr/trvrfy.c +++ b/ir/tr/trvrfy.c @@ -17,15 +17,12 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/trvrfy.c - * Purpose: Check types and entities for correctness. - * Author: Michael Beck, Goetz Lindenmaier - * Modified by: - * Created: 29.1.2003 - * CVS-ID: $Id$ - * Copyright: (c) 2003 Universität Karlsruhe +/** + * @file tr_inheritance.c + * @brief Check types and entities for correctness. + * @date 29.1.2003 + * @author Michael Beck, Goetz Lindenmaier + * @version $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -33,7 +30,7 @@ #include "trvrfy.h" #include "irgraph_t.h" /* for checking whether constant code is allocated - on proper obstack */ + on proper obstack */ #include "irflag_t.h" #include "irprintf.h" #include "irgwalk.h" @@ -86,133 +83,130 @@ do { \ * Show diagnostic if an entity overwrites another one not * in direct superclasses. */ -static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw) -{ - ir_type *owner = get_entity_owner(ent); - ir_type *ov_own = get_entity_owner(ovw); - int i; - - fprintf(stderr, "Type verification error:\n"); - ir_fprintf(stderr, "Entity %+F::%+e owerwrites ", owner, ent); - ir_fprintf(stderr, "Entity %+F::%+e\n", ov_own, ovw); - - ir_fprintf(stderr, "Supertypes of %+F:\n", owner); - for (i = 0; i < get_class_n_supertypes(owner); ++i) { - ir_type *super = get_class_supertype(owner, i); - ir_fprintf(stderr, " %+F:\n", super); - } +static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw) { + ir_type *owner = get_entity_owner(ent); + ir_type *ov_own = get_entity_owner(ovw); + int i; + + fprintf(stderr, "Type verification error:\n"); + ir_fprintf(stderr, "Entity %+F::%+e owerwrites ", owner, ent); + ir_fprintf(stderr, "Entity %+F::%+e\n", ov_own, ovw); + + ir_fprintf(stderr, "Supertypes of %+F:\n", owner); + for (i = 0; i < get_class_n_supertypes(owner); ++i) { + ir_type *super = get_class_supertype(owner, i); + ir_fprintf(stderr, " %+F:\n", super); + } } /** * Show diagnostic if an entity overwrites a wrong number of things. */ -static void show_ent_overwrite_cnt(ir_entity *ent) -{ - ir_type *owner = get_entity_owner(ent); - int i, j, k, found, show_stp = 0; - - fprintf(stderr, "Type verification error:\n"); - ir_fprintf(stderr, "Entity %t::%e owerwrites\n", owner, ent); - for (i = 0; i < get_entity_n_overwrites(ent); ++i) { - ir_entity *ovw = get_entity_overwrites(ent, i); - ir_type *ov_own = get_entity_owner(ovw); - - ir_fprintf(stderr, " %t::%e\n", ov_own, ovw); - for (k = 0; k < i; ++k) - if (ovw == get_entity_overwrites(ent, k)) { - ir_fprintf(stderr, " ->%t::%e entered more than once\n", ov_own, ovw); - break; - } - - found = 0; - for (j = get_class_n_supertypes(owner) - 1; j >= 0; --j) { - if (ov_own == get_class_supertype(owner, j)) { - show_stp = found = 1; - break; - } - } - if (! found) - ir_fprintf(stderr, " ->%t not in super types of %t\n", ov_own, owner); - } - - if (show_stp) { - ir_fprintf(stderr, "Supertypes of %t:\n", owner); - for (i = 0; i < get_class_n_supertypes(owner); ++i) { - ir_type *super = get_class_supertype(owner, i); - ir_fprintf(stderr, " %t:\n", super); - } - } +static void show_ent_overwrite_cnt(ir_entity *ent) { + ir_type *owner = get_entity_owner(ent); + int i, j, k, found, show_stp = 0; + + fprintf(stderr, "Type verification error:\n"); + ir_fprintf(stderr, "Entity %t::%e owerwrites\n", owner, ent); + for (i = 0; i < get_entity_n_overwrites(ent); ++i) { + ir_entity *ovw = get_entity_overwrites(ent, i); + ir_type *ov_own = get_entity_owner(ovw); + + ir_fprintf(stderr, " %t::%e\n", ov_own, ovw); + for (k = 0; k < i; ++k) + if (ovw == get_entity_overwrites(ent, k)) { + ir_fprintf(stderr, " ->%t::%e entered more than once\n", ov_own, ovw); + break; + } + + found = 0; + for (j = get_class_n_supertypes(owner) - 1; j >= 0; --j) { + if (ov_own == get_class_supertype(owner, j)) { + show_stp = found = 1; + break; + } + } + if (! found) + ir_fprintf(stderr, " ->%t not in super types of %t\n", ov_own, owner); + } + + if (show_stp) { + ir_fprintf(stderr, "Supertypes of %t:\n", owner); + for (i = 0; i < get_class_n_supertypes(owner); ++i) { + ir_type *super = get_class_supertype(owner, i); + ir_fprintf(stderr, " %t:\n", super); + } + } } /** * Check a class */ static int check_class(ir_type *tp) { - int i, j, k; - int found; - - /*printf("\n"); DDMT(tp);*/ - - for (i = get_class_n_members(tp) - 1; i >= 0; --i) { - ir_entity *mem = get_class_member(tp, i); - - ASSERT_AND_RET_DBG( - tp == get_entity_owner(mem), - "class member with wrong owner", - error_ent_wrong_owner, - ir_fprintf(stderr, "Type verification error:\n%+F %+e(owner %+F)\n",tp, mem, get_entity_owner(mem)) - ); - ASSERT_AND_RET_DBG( - mem, - "NULL members not allowed", - error_null_mem, - ir_fprintf(stderr, "Type verification error:\n%+F member %d is NULL\n", tp, i) - ); - - ASSERT_AND_RET_DBG( - get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp), - "wrong number of entity overwrites", - error_wrong_ent_overwrites, - show_ent_overwrite_cnt(mem) - ); - - for (j = get_entity_n_overwrites(mem) - 1; j >= 0; --j) { - ir_entity *ovw = get_entity_overwrites(mem, j); - /*printf(" overwrites: "); DDME(ovw);*/ - /* Check whether ovw is member of one of tp's supertypes. If so, - the representation is correct. */ - found = 0; - for (k = get_class_n_supertypes(tp) - 1; k >= 0; --k) { - if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) { - found = 1; - break; - } - } - ASSERT_AND_RET_DBG( - found, - "overwrites an entity not contained in direct supertype", - error_ent_not_cont, - show_ent_not_supertp(mem, ovw) - ); - } - } - return 0; + int i, j, k; + int found; + + for (i = get_class_n_members(tp) - 1; i >= 0; --i) { + ir_entity *mem = get_class_member(tp, i); + + ASSERT_AND_RET_DBG( + tp == get_entity_owner(mem), + "class member with wrong owner", + error_ent_wrong_owner, + ir_fprintf(stderr, "Type verification error:\n%+F %+e(owner %+F)\n",tp, mem, get_entity_owner(mem)) + ); + ASSERT_AND_RET_DBG( + mem, + "NULL members not allowed", + error_null_mem, + ir_fprintf(stderr, "Type verification error:\n%+F member %d is NULL\n", tp, i) + ); + + ASSERT_AND_RET_DBG( + get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp), + "wrong number of entity overwrites", + error_wrong_ent_overwrites, + show_ent_overwrite_cnt(mem) + ); + + for (j = get_entity_n_overwrites(mem) - 1; j >= 0; --j) { + ir_entity *ovw = get_entity_overwrites(mem, j); + /*printf(" overwrites: "); DDME(ovw);*/ + /* Check whether ovw is member of one of tp's supertypes. If so, + the representation is correct. */ + found = 0; + for (k = get_class_n_supertypes(tp) - 1; k >= 0; --k) { + if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) { + found = 1; + break; + } + } + ASSERT_AND_RET_DBG( + found, + "overwrites an entity not contained in direct supertype", + error_ent_not_cont, + show_ent_not_supertp(mem, ovw) + ); + } + } + return 0; } /** * Check an array. */ static int check_array(ir_type *tp) { - int i, n_dim = get_array_n_dimensions(tp); - for (i = 0; i < n_dim; ++i) { - ASSERT_AND_RET_DBG( - has_array_lower_bound(tp, i) || has_array_upper_bound(tp, i), - "array bound missing", - 1, - ir_fprintf(stderr, "%+F in dimension %d\n", tp, i) - ); - } - return 0; + int i, n_dim = get_array_n_dimensions(tp); + + for (i = 0; i < n_dim; ++i) { + ASSERT_AND_RET_DBG( + has_array_lower_bound(tp, i) || has_array_upper_bound(tp, i), + "array bound missing", + 1, + ir_fprintf(stderr, "%+F in dimension %d\n", tp, i) + ); + } + return 0; } @@ -220,13 +214,13 @@ static int check_array(ir_type *tp) { * Check a primitive. */ static int check_primitive(ir_type *tp) { - ASSERT_AND_RET_DBG( - is_mode(get_type_mode(tp)), - "Primitive type without mode", - 1, - ir_fprintf(stderr, "%+F\n", tp) - ); - return 0; + ASSERT_AND_RET_DBG( + is_mode(get_type_mode(tp)), + "Primitive type without mode", + 1, + ir_fprintf(stderr, "%+F\n", tp) + ); + return 0; } @@ -237,48 +231,48 @@ static int check_primitive(ir_type *tp) { * 0 if no error encountered */ int check_type(ir_type *tp) { - switch (get_type_tpop_code(tp)) { - case tpo_class: - return check_class(tp); - case tpo_array: - return check_array(tp); - case tpo_primitive: - return check_primitive(tp); - default: break; - } - return 0; + switch (get_type_tpop_code(tp)) { + case tpo_class: + return check_class(tp); + case tpo_array: + return check_array(tp); + case tpo_primitive: + return check_primitive(tp); + default: break; + } + return 0; } /** * checks the visited flag */ static int check_visited_flag(ir_graph *irg, ir_node *n) { - ASSERT_AND_RET_DBG( - get_irn_visited(n) <= get_irg_visited(irg), - "Visited flag of node is larger than that of corresponding irg.", - 0, - ir_fprintf(stderr, "%+F in %+F\n", n, irg) - ); - return 1; + ASSERT_AND_RET_DBG( + get_irn_visited(n) <= get_irg_visited(irg), + "Visited flag of node is larger than that of corresponding irg.", + 0, + ir_fprintf(stderr, "%+F in %+F\n", n, irg) + ); + return 1; } /** * helper environment struct for constant_on_wrong_obstack() */ struct myenv { - int res; - ir_graph *irg; + int res; + ir_graph *irg; }; /** * called by the walker */ static void on_irg_storage(ir_node *n, void *env) { - struct myenv *myenv = env; + struct myenv *myenv = env; - /* We also test whether the setting of the visited flag is legal. */ - myenv->res = node_is_in_irgs_storage(myenv->irg, n) && - check_visited_flag(myenv->irg, n); + /* We also test whether the setting of the visited flag is legal. */ + myenv->res = node_is_in_irgs_storage(myenv->irg, n) && + check_visited_flag(myenv->irg, n); } /** @@ -286,13 +280,13 @@ static void on_irg_storage(ir_node *n, void *env) { * constant IR graph. */ static int constant_on_wrong_irg(ir_node *n) { - struct myenv env; + struct myenv env; - env.res = 1; /* on right obstack */ - env.irg = get_const_code_irg(); + env.res = 1; /* on right obstack */ + env.irg = get_const_code_irg(); - irg_walk(n, on_irg_storage, NULL, (void *)&env); - return ! env.res; + irg_walk(n, on_irg_storage, NULL, (void *)&env); + return ! env.res; } /** @@ -302,39 +296,38 @@ static int constant_on_wrong_irg(ir_node *n) { * the current_ir_graph's obstack. */ static int constants_on_wrong_irg(ir_entity *ent) { - if (get_entity_variability(ent) == variability_uninitialized) return 0; - - if (is_compound_entity(ent)) { - int i; - for (i = 0; i < get_compound_ent_n_values(ent); i++) { - if (constant_on_wrong_irg(get_compound_ent_value(ent, i))) - return 1; - } - } else { - /* Might not be set if entity belongs to a description or is external allocated. */ - if (get_atomic_ent_value(ent)) - return constant_on_wrong_irg(get_atomic_ent_value(ent)); - else if (get_entity_visibility(ent) != visibility_external_allocated) { - ASSERT_AND_RET_DBG( - is_Class_type(get_entity_owner(ent)) && - get_class_peculiarity(get_entity_owner(ent)) == peculiarity_description, - "Value in constant atomic entity not set.", - 0, - ir_fprintf(stderr, "%+e, owner %+F\n", ent, get_entity_owner(ent)) - ); - } - } - return 0; + if (get_entity_variability(ent) == variability_uninitialized) return 0; + + if (is_compound_entity(ent)) { + int i; + for (i = 0; i < get_compound_ent_n_values(ent); i++) { + if (constant_on_wrong_irg(get_compound_ent_value(ent, i))) + return 1; + } + } else { + /* Might not be set if entity belongs to a description or is external allocated. */ + if (get_atomic_ent_value(ent)) + return constant_on_wrong_irg(get_atomic_ent_value(ent)); + else if (get_entity_visibility(ent) != visibility_external_allocated) { + ASSERT_AND_RET_DBG( + is_Class_type(get_entity_owner(ent)) && + get_class_peculiarity(get_entity_owner(ent)) == peculiarity_description, + "Value in constant atomic entity not set.", + 0, + ir_fprintf(stderr, "%+e, owner %+F\n", ent, get_entity_owner(ent)) + ); + } + } + return 0; } /** * Shows a wrong entity allocation */ -static void show_ent_alloc_error(ir_entity *ent) -{ - ir_fprintf(stderr, "%+e owner %t has allocation %s\n", - ent, get_entity_type(ent), - get_allocation_name(get_entity_allocation(ent))); +static void show_ent_alloc_error(ir_entity *ent) { + ir_fprintf(stderr, "%+e owner %t has allocation %s\n", + ent, get_entity_type(ent), + get_allocation_name(get_entity_allocation(ent))); } /* @@ -346,94 +339,96 @@ static void show_ent_alloc_error(ir_entity *ent) * != 0 a trvrfy_error_codes code */ int check_entity(ir_entity *ent) { - int rem_vpi; - ir_type *tp = get_entity_type(ent); - ir_type *owner = get_entity_owner(ent); - - current_ir_graph = get_const_code_irg(); - ASSERT_AND_RET_DBG( - constants_on_wrong_irg(ent) == 0, - "Contants placed on wrong IRG", - error_const_on_wrong_irg, - ir_fprintf(stderr, "%+e not on %+F\n", ent, current_ir_graph)); - - rem_vpi = get_visit_pseudo_irgs(); - set_visit_pseudo_irgs(1); - if ((get_entity_peculiarity(ent) == peculiarity_existent) && - (get_entity_visibility(ent) != visibility_external_allocated) && - (is_Method_type(get_entity_type(ent))) && - (!get_entity_irg(ent) || !(is_ir_graph(get_entity_irg(ent))))) { - ASSERT_AND_RET_DBG( - 0, - "Method ents with pec_exist must have an irg", - error_existent_entity_without_irg, - ir_fprintf(stderr, "%+e\n", ent) - ); - } - set_visit_pseudo_irgs(rem_vpi); - - /* Originally, this test assumed, that only method entities have - pecularity_inherited. As I changed this, I have to test for method type before - doing the test. */ - if (get_entity_peculiarity(ent) == peculiarity_inherited) { - if (is_Method_type(get_entity_type(ent))) { - ir_entity *impl = get_SymConst_entity(get_atomic_ent_value(ent)); - ASSERT_AND_RET_DBG( - get_entity_peculiarity(impl) == peculiarity_existent, - "inherited method entities must have constant pointing to existent entity.", - error_inherited_ent_without_const, - ir_fprintf(stderr, "%+e points to %+e\n", ent, impl) - ); - } - } - - /* Entities in global type are not dynamic or automatic allocated. */ - if (owner == get_glob_type()) { - ASSERT_AND_RET_DBG( - get_entity_allocation(ent) != allocation_dynamic && - get_entity_allocation(ent) != allocation_automatic, - "Entities in global type are not allowed to by dynamic or automatic allocated", - error_glob_ent_allocation, - show_ent_alloc_error(ent) - ); - } - - if (get_entity_variability(ent) != variability_uninitialized) { - if (is_atomic_type(tp)) { - ir_node *val = get_atomic_ent_value(ent); - if (val) - ASSERT_AND_RET_DBG( - get_irn_mode(val) == get_type_mode(tp), - "Mode of constant in entity must match type.", - error_ent_const_mode, - ir_fprintf(stderr, "%+e const %+F, type %+F(%+F)\n", - ent, val, tp, get_type_mode(tp)) - ); - } - } - return no_error; + int rem_vpi; + ir_type *tp = get_entity_type(ent); + ir_type *owner = get_entity_owner(ent); + + current_ir_graph = get_const_code_irg(); + ASSERT_AND_RET_DBG( + constants_on_wrong_irg(ent) == 0, + "Contants placed on wrong IRG", + error_const_on_wrong_irg, + ir_fprintf(stderr, "%+e not on %+F\n", ent, current_ir_graph) + ); + + rem_vpi = get_visit_pseudo_irgs(); + set_visit_pseudo_irgs(1); + if ((get_entity_peculiarity(ent) == peculiarity_existent) && + (get_entity_visibility(ent) != visibility_external_allocated) && + (is_Method_type(get_entity_type(ent))) && + (!get_entity_irg(ent) || !(is_ir_graph(get_entity_irg(ent))))) { + ASSERT_AND_RET_DBG( + 0, + "Method ents with pec_exist must have an irg", + error_existent_entity_without_irg, + ir_fprintf(stderr, "%+e\n", ent) + ); + } + set_visit_pseudo_irgs(rem_vpi); + + /* Originally, this test assumed, that only method entities have + pecularity_inherited. As I changed this, I have to test for method type before + doing the test. */ + if (get_entity_peculiarity(ent) == peculiarity_inherited) { + if (is_Method_type(get_entity_type(ent))) { + ir_entity *impl = get_SymConst_entity(get_atomic_ent_value(ent)); + ASSERT_AND_RET_DBG( + get_entity_peculiarity(impl) == peculiarity_existent, + "inherited method entities must have constant pointing to existent entity.", + error_inherited_ent_without_const, + ir_fprintf(stderr, "%+e points to %+e\n", ent, impl) + ); + } + } + + /* Entities in global type are not dynamic or automatic allocated. */ + if (owner == get_glob_type()) { + ASSERT_AND_RET_DBG( + get_entity_allocation(ent) != allocation_dynamic && + get_entity_allocation(ent) != allocation_automatic, + "Entities in global type are not allowed to by dynamic or automatic allocated", + error_glob_ent_allocation, + show_ent_alloc_error(ent) + ); + } + + if (get_entity_variability(ent) != variability_uninitialized) { + if (is_atomic_type(tp)) { + ir_node *val = get_atomic_ent_value(ent); + if (val) { + ASSERT_AND_RET_DBG( + get_irn_mode(val) == get_type_mode(tp), + "Mode of constant in entity must match type.", + error_ent_const_mode, + ir_fprintf(stderr, "%+e const %+F, type %+F(%+F)\n", + ent, val, tp, get_type_mode(tp)) + ); + } + } + } + return no_error; } /* * check types and entities */ static void check_tore(type_or_ent *tore, void *env) { - int *res = env; - assert(tore); - if (is_type(tore)) { - *res = check_type((ir_type *)tore); - } else { - assert(is_entity(tore)); - *res = check_entity((ir_entity *)tore); - } + int *res = env; + assert(tore); + if (is_type(tore)) { + *res = check_type((ir_type *)tore); + } else { + assert(is_entity(tore)); + *res = check_entity((ir_entity *)tore); + } } /* * Verify types and entities. */ int tr_vrfy(void) { - int res; + int res; - type_walk(check_tore, NULL, &res); - return res; + type_walk(check_tore, NULL, &res); + return res; } diff --git a/ir/tr/trvrfy.h b/ir/tr/trvrfy.h index 336258bd7..4b38de1ad 100644 --- a/ir/tr/trvrfy.h +++ b/ir/tr/trvrfy.h @@ -17,48 +17,32 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/trvrfy.h - * Purpose: Check types and entities for correctness. - * Author: Michael Beck, Goetz Lindenmaier - * Modified by: - * Created: 29.1.2003 - * CVS-ID: $Id$ - * Copyright: (c) 2003 Universität Karlsruhe +/** + * @file trvrfy.h + * @brief Check types and entities for correctness. + * @date 29.1.2003 + * @author Michael Beck, Goetz Lindenmaier + * @version $Id$ */ -#ifndef TRVRFY_H -#define TRVRFY_H +#ifndef FIRM_TR_TRVRFY_H +#define FIRM_TR_TRVRFY_H #include "firm_types.h" -/** - * @file trvrfy.h - * - * Methods to verify the type representations. - * - * @author Michael Beck, Goetz Lindenmaier - * - * Methods to verify the type representations. - * Copyright 2003 University of Karlsruhe. - * Created 29.1.2003. - * - */ - /** * possible trvrfy() error codes */ enum trvrfy_error_codes { - no_error = 0, /**< no error */ - error_ent_not_cont, /**< overwritten entity not in superclass */ - error_null_mem, /**< compound contains NULL member */ - error_const_on_wrong_irg, /**< constant placed on wrong IRG */ - error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */ - error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */ - error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */ - error_glob_ent_allocation, /**< wrong allocation of a global entity */ - error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */ - error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */ + no_error = 0, /**< no error */ + error_ent_not_cont, /**< overwritten entity not in superclass */ + error_null_mem, /**< compound contains NULL member */ + error_const_on_wrong_irg, /**< constant placed on wrong IRG */ + error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */ + error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */ + error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */ + error_glob_ent_allocation, /**< wrong allocation of a global entity */ + error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */ + error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */ }; /** @@ -102,4 +86,4 @@ int tr_vrfy(void); #define TR_VRFY() tr_vrfy() #endif -#endif /* TRVRFY_H */ +#endif /* FIRM_TR_TRVRFY_H */ diff --git a/ir/tr/type.c b/ir/tr/type.c index d63ec5866..5aac7dfb6 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -17,27 +17,16 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/type.c - * Purpose: Representation of types. - * Author: Goetz Lindenmaier - * Modified by: Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2006 Universität Karlsruhe - */ - /** - * - * @file type.c + * @file type.c + * @brief Representation of types. + * @author Goetz Lindenmaier, Michael Beck + * @version $Id$ + * @summary * * Implementation of the datastructure to hold * type information. * - * (C) 2001-2006 by Universitaet Karlsruhe - * Goetz Lindenmaier, Michael Beck - * * This module supplies a datastructure to represent all types * known in the compiled program. This includes types specified * in the program as well as types defined by the language. In the diff --git a/ir/tr/type.h b/ir/tr/type.h index 750e08313..1ca784b84 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -17,19 +17,12 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/type.h - * Purpose: Representation of types. - * Author: Goetz Lindenmaier - * Modified by: Michael Beck - * Created: - * Copyright: (c) 2001-2006 Universität Karlsruhe - * CVS-ID: $Id$ - */ - /** - * @file type.h + * @file type.h + * @brief Representation of types. + * @author Goetz Lindenmaier, Michael Beck + * @version $Id$ + * @summary * * Datastructure to hold type information. * @@ -50,8 +43,8 @@ * * @see tpop.h */ -#ifndef _FIRM_TR_TYPE_H_ -#define _FIRM_TR_TYPE_H_ +#ifndef FIRM_TR_TYPE_H +#define FIRM_TR_TYPE_H #include "firm_types.h" #include "tpop.h" @@ -1372,4 +1365,4 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at */ long get_type_nr(const ir_type *tp); -#endif /* _FIRM_TR_TYPE_H_ */ +#endif /* FIRM_TR_TYPE_H */ diff --git a/ir/tr/type_identify.c b/ir/tr/type_identify.c index 5a74aa060..a0a80fbf9 100644 --- a/ir/tr/type_identify.c +++ b/ir/tr/type_identify.c @@ -17,30 +17,17 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/type_identify.c - * Purpose: Representation of types. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2003 Universität Karlsruhe - */ - /** - * @file type_identify.c - * - * (C) 2004 by Universitaet Karlsruhe - * Goetz Lindenmaier - * + * @file type_identify.c + * @brief Representation of types. + * @author Goetz Lindenmaier + * @version $Id$ */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "type_identify_t.h" +#include "type_identify.h" #include #include @@ -64,80 +51,76 @@ static hash_types_func_t *hash_types_func; static compare_types_func_t *compare_types_func; int compare_names (const void *tp1, const void *tp2) { - ir_type *t1 = (ir_type *) tp1; - ir_type *t2 = (ir_type *) tp2; + ir_type *t1 = (ir_type *) tp1; + ir_type *t2 = (ir_type *) tp2; - return (t1 != t2 && - (t1->type_op != t2->type_op || - t1->name != t2->name ) ); + return (t1 != t2 && + (t1->type_op != t2->type_op || + t1->name != t2->name ) ); } /* stuff for comparing two types. */ -int compare_strict (const void *tp1, const void *tp2) { - ir_type *t1 = (ir_type *) tp1; - ir_type *t2 = (ir_type *) tp2; - return t1 != t2; +int compare_strict(const void *tp1, const void *tp2) { + const ir_type *t1 = tp1; + const ir_type *t2 = tp2; + return t1 != t2; } /* stuff to compute a hash value for a type. */ -int firm_hash_name (ir_type *tp) { - unsigned h = (unsigned)PTR_TO_INT(tp->type_op); - h = 9*h + (unsigned)PTR_TO_INT(tp->name); - return h; +int firm_hash_name(ir_type *tp) { + unsigned h = (unsigned)PTR_TO_INT(tp->type_op); + h = 9*h + (unsigned)PTR_TO_INT(tp->name); + return h; } /* The function that hashes a type. */ ir_type *mature_type(ir_type *tp) { - ir_type *o; - - assert(type_table); - - o = pset_insert (type_table, tp, hash_types_func(tp) ); + ir_type *o; - if (!o || o == tp) return tp; + assert(type_table); - exchange_types(tp, o); + o = pset_insert (type_table, tp, hash_types_func(tp) ); + if (!o || o == tp) return tp; + exchange_types(tp, o); - return o; + return o; } /* The function that hashes a type. */ ir_type *mature_type_free(ir_type *tp) { - ir_type *o; + ir_type *o; - assert(type_table); + assert(type_table); - o = pset_insert (type_table, tp, hash_types_func(tp) ); + o = pset_insert (type_table, tp, hash_types_func(tp) ); + if (!o || o == tp) return tp; - if (!o || o == tp) return tp; + free_type_entities(tp); + free_type(tp); - free_type_entities(tp); - free_type(tp); - - return o; + return o; } /* The function that hashes a type. */ ir_type *mature_type_free_entities(ir_type *tp) { - ir_type *o; - - assert(type_table); + ir_type *o; - o = pset_insert (type_table, tp, hash_types_func(tp) ); + assert(type_table); - if (!o || o == tp) return tp; + o = pset_insert (type_table, tp, hash_types_func(tp) ); + if (!o || o == tp) return tp; - free_type_entities(tp); - exchange_types(tp, o); + free_type_entities(tp); + exchange_types(tp, o); - return o; + return o; } /* initialize this module */ void init_type_identify(type_identify_if_t *ti_if) { - compare_types_func = ti_if && ti_if->cmp ? ti_if->cmp : compare_strict; - hash_types_func = ti_if && ti_if->hash ? ti_if->hash : firm_hash_name; + compare_types_func = ti_if && ti_if->cmp ? ti_if->cmp : compare_strict; + hash_types_func = ti_if && ti_if->hash ? ti_if->hash : firm_hash_name; - type_table = new_pset (compare_types_func, 8); + type_table = new_pset (compare_types_func, 8); } diff --git a/ir/tr/type_identify.h b/ir/tr/type_identify.h index 47e2e9524..0b4612a64 100644 --- a/ir/tr/type_identify.h +++ b/ir/tr/type_identify.h @@ -18,22 +18,13 @@ */ /** - * @file type.h - * - * Project: libFIRM
- * File name: ir/tr/type.h
- * Purpose: Representation of types.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * Copyright: (c) 2001-2003 Universität Karlsruhe
- * CVS-ID: $Id$ - * - * + * @file type_identify.h + * @brief Representation of types. + * @author Goetz Lindenmaier + * @version $Id$ */ - -# ifndef _TYPE_IDENTIFY_H_ -# define _TYPE_IDENTIFY_H_ +#ifndef FIRM_TR_TYPE_IDENTIFY_H +#define FIRM_TR_TYPE_IDENTIFY_H #include "firm_types.h" @@ -130,10 +121,10 @@ ir_type * mature_type_free_entities(ir_type *tp); * The interface type for the type identify module; */ typedef struct _type_identify_if_t { - compare_types_func_t *cmp; /**< The function that should be used to compare two types. - If NULL, compare_strict() will be used. */ - hash_types_func_t *hash; /**< The function that should be used to calculate a hash - value of a type. If NULL, hash_name() will be used. */ + compare_types_func_t *cmp; /**< The function that should be used to compare two types. + If NULL, compare_strict() will be used. */ + hash_types_func_t *hash; /**< The function that should be used to calculate a hash + value of a type. If NULL, hash_name() will be used. */ } type_identify_if_t; /** @@ -146,4 +137,4 @@ typedef struct _type_identify_if_t { */ void init_type_identify(type_identify_if_t *ti_if); -# endif /* _TYPE_IDENTIFY_H_ */ +#endif /* FIRM_TR_TYPE_IDENTIFY_H */ diff --git a/ir/tr/type_identify_t.h b/ir/tr/type_identify_t.h deleted file mode 100644 index 0bfa23bc4..000000000 --- a/ir/tr/type_identify_t.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file type.h - * - * Project: libFIRM
- * File name: ir/tr/type.h
- * Purpose: Representation of types.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * Copyright: (c) 2001-2003 Universität Karlsruhe
- * CVS-ID: $Id$ - * - * - */ - -# ifndef _TYPE_IDENTIFY_T_H_ -# define _TYPE_IDENTIFY_T_H_ - -#include "type_identify.h" - -# endif /* _TYPE_IDENTIFY_T_H_ */ diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index dc260914d..82909d4fb 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -17,19 +17,14 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/type_t.h - * Purpose: Representation of types -- private header. - * Author: Goetz Lindenmaier - * Modified by: Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2003 Universität Karlsruhe +/** + * @file type.c + * @brief Representation of types -- private header. + * @author Goetz Lindenmaier, Michael Beck + * @version $Id$ */ - -#ifndef _FIRM_TR_TYPE_T_H_ -#define _FIRM_TR_TYPE_T_H_ +#ifndef FIRM_TR_TYPE_T_H +#define FIRM_TR_TYPE_T_H #include "firm_config.h" #include "type.h" @@ -48,82 +43,82 @@ /** Class flags. */ enum class_flags { - cf_none = 0, /**< No flags. */ - cf_final_class = 1, /**< Set if a class is an final class */ - cf_interface_class = 2, /**< Set if a class is an "interface" */ - cf_absctract_class = 4, /**< Set if a class is "abstract" */ + cf_none = 0, /**< No flags. */ + cf_final_class = 1, /**< Set if a class is an final class */ + cf_interface_class = 2, /**< Set if a class is an "interface" */ + cf_absctract_class = 4, /**< Set if a class is "abstract" */ }; /** Class type attributes. */ typedef struct { - ir_entity **members; /**< Array containing the fields and methods of this class. */ - ir_type **subtypes; /**< Array containing the direct subtypes. */ - ir_type **supertypes; /**< Array containing the direct supertypes */ - ir_peculiarity peculiarity; /**< The peculiarity of this class. */ - ir_entity *type_info; /**< An ir_entity representing this class, used for type info. */ - int dfn; /**< A number that can be used for 'instanceof' operator. */ - unsigned vtable_size; /**< The size of the vtable for this class. */ - unsigned clss_flags; /**< Additional class flags. */ + ir_entity **members; /**< Array containing the fields and methods of this class. */ + ir_type **subtypes; /**< Array containing the direct subtypes. */ + ir_type **supertypes; /**< Array containing the direct supertypes */ + ir_peculiarity peculiarity; /**< The peculiarity of this class. */ + ir_entity *type_info; /**< An ir_entity representing this class, used for type info. */ + int dfn; /**< A number that can be used for 'instanceof' operator. */ + unsigned vtable_size; /**< The size of the vtable for this class. */ + unsigned clss_flags; /**< Additional class flags. */ } cls_attr; /** Struct type attributes. */ typedef struct { - ir_entity **members; /**< Fields of this struct. No method entities allowed. */ + ir_entity **members; /**< Fields of this struct. No method entities allowed. */ } stc_attr; /** A (type, ir_entity) pair. */ typedef struct { - ir_type *tp; /**< A type. */ - ir_entity *ent; /**< An ir_entity. */ - ident *param_name; /**< For debugging purposes: the name of the parameter */ + ir_type *tp; /**< A type. */ + ir_entity *ent; /**< An ir_entity. */ + ident *param_name; /**< For debugging purposes: the name of the parameter */ } tp_ent_pair; /** Method type attributes. */ typedef struct { - int n_params; /**< Number of parameters. */ - tp_ent_pair *params; /**< Array of parameter type/value entities pairs. */ - ir_type *value_params; /**< A type whose entities represent copied value arguments. */ - int n_res; /**< Number of results. */ - tp_ent_pair *res_type; /**< Array of result type/value ir_entity pairs. */ - ir_type *value_ress; /**< A type whose entities represent copied value results. */ - variadicity variadicity; /**< The variadicity of the method. */ - int first_variadic_param; /**< The index of the first variadic parameter or -1 if non-variadic .*/ - unsigned additional_properties; /**< Set of additional method properties. */ - unsigned irg_calling_conv; /**< A set of calling convention flags. */ + int n_params; /**< Number of parameters. */ + tp_ent_pair *params; /**< Array of parameter type/value entities pairs. */ + ir_type *value_params; /**< A type whose entities represent copied value arguments. */ + int n_res; /**< Number of results. */ + tp_ent_pair *res_type; /**< Array of result type/value ir_entity pairs. */ + ir_type *value_ress; /**< A type whose entities represent copied value results. */ + variadicity variadicity; /**< The variadicity of the method. */ + int first_variadic_param; /**< The index of the first variadic parameter or -1 if non-variadic .*/ + unsigned additional_properties; /**< Set of additional method properties. */ + unsigned irg_calling_conv; /**< A set of calling convention flags. */ } mtd_attr; /** Union type attributes. */ typedef struct { - ir_entity **members; /**< Fields of this union. No method entities allowed. */ + ir_entity **members; /**< Fields of this union. No method entities allowed. */ } uni_attr; /** Array type attributes. */ typedef struct { - int n_dimensions; /**< Number of array dimensions. */ - ir_node **lower_bound; /**< Lower bounds of dimensions. Usually all 0. */ - ir_node **upper_bound; /**< Upper bounds or dimensions. */ - int *order; /**< Ordering of dimensions. */ - ir_type *element_type; /**< The type of the array elements. */ - ir_entity *element_ent; /**< entity for the array elements, to be used for - element selection with a Sel node. */ + int n_dimensions; /**< Number of array dimensions. */ + ir_node **lower_bound; /**< Lower bounds of dimensions. Usually all 0. */ + ir_node **upper_bound; /**< Upper bounds or dimensions. */ + int *order; /**< Ordering of dimensions. */ + ir_type *element_type; /**< The type of the array elements. */ + ir_entity *element_ent; /**< entity for the array elements, to be used for + element selection with a Sel node. */ } arr_attr; /** An enumerator constant. */ struct ir_enum_const { - tarval *value; /**< The constants that represents this enumerator identifier. */ - ident *nameid; /**< The name of the enumerator identifier. */ - ir_type *owner; /**< owner type of this enumerator constant. */ + tarval *value; /**< The constants that represents this enumerator identifier. */ + ident *nameid; /**< The name of the enumerator identifier. */ + ir_type *owner; /**< owner type of this enumerator constant. */ }; /** Enum type attributes. */ typedef struct { - ir_enum_const *enumer; /**< Contains all enumerator constants that represent a member - of the enum -- enumerators. */ + ir_enum_const *enumer; /**< Contains all enumerator constants that represent a member + of the enum -- enumerators. */ } enm_attr; /** Pointer type attributes. */ typedef struct { - ir_type *points_to; /**< The type of the ir_entity the pointer points to. */ + ir_type *points_to; /**< The type of the ir_entity the pointer points to. */ } ptr_attr; /* @@ -138,54 +133,54 @@ typedef struct { * No private attr, must be smaller than others! * /** General type attributes. */ typedef union { - cls_attr ca; /**< Attributes of a class type */ - stc_attr sa; /**< Attributes of a struct type */ - mtd_attr ma; /**< Attributes of a method type */ - uni_attr ua; /**< Attributes of an union type */ - arr_attr aa; /**< Attributes of an array type */ - enm_attr ea; /**< Attributes of an enumeration type */ - ptr_attr pa; /**< Attributes of a pointer type */ + cls_attr ca; /**< Attributes of a class type */ + stc_attr sa; /**< Attributes of a struct type */ + mtd_attr ma; /**< Attributes of a method type */ + uni_attr ua; /**< Attributes of an union type */ + arr_attr aa; /**< Attributes of an array type */ + enm_attr ea; /**< Attributes of an enumeration type */ + ptr_attr pa; /**< Attributes of a pointer type */ } tp_attr; /** Additional type flags. */ enum type_flags { - tf_none = 0, /**< No flags. */ - tf_frame_type = 1, /**< Set if this is a frame type. */ - tf_value_param_type = 2, /**< Set if this is a value param type. */ - tf_lowered_type = 4, /**< Set if this is a lowered type. */ - tf_layout_fixed = 8, /**< Set if the layout of a type is fixed */ - tf_global_type = 16, /**< Set only for the global type */ - tf_tls_type = 32, /**< Set only for the tls type */ + tf_none = 0, /**< No flags. */ + tf_frame_type = 1, /**< Set if this is a frame type. */ + tf_value_param_type = 2, /**< Set if this is a value param type. */ + tf_lowered_type = 4, /**< Set if this is a lowered type. */ + tf_layout_fixed = 8, /**< Set if the layout of a type is fixed */ + tf_global_type = 16, /**< Set only for the global type */ + tf_tls_type = 32, /**< Set only for the tls type */ }; /** The structure of a type. */ struct ir_type { - firm_kind kind; /**< the firm kind, must be k_type */ - const tp_op *type_op; /**< the type operation of the type */ - ident *name; /**< The name of the type */ - ir_visibility visibility;/**< Visibility of entities of this type. */ - unsigned flags; /**< Type flags, a bitmask of enum type_flags. */ - int size; /**< Size of an ir_entity of this type. This is determined - when fixing the layout of this class. Size must be - given in bits. */ - int align; /**< Alignment of an ir_entity of this type. This should be - set according to the source language needs. If not set it's - calculated automatically by get_type_alignment(). - Alignment must be given in bits. */ - ir_mode *mode; /**< The mode for atomic types */ - unsigned long visit; /**< visited counter for walks of the type information */ - void *link; /**< holds temporary data - like in irnode_t.h */ - struct dbg_info *dbi; /**< A pointer to information for debug support. */ - ir_type *assoc_type; /**< The associated lowered/unlowered type */ - - /* ------------- fields for analyses ---------------*/ + firm_kind kind; /**< the firm kind, must be k_type */ + const tp_op *type_op; /**< the type operation of the type */ + ident *name; /**< The name of the type */ + ir_visibility visibility;/**< Visibility of entities of this type. */ + unsigned flags; /**< Type flags, a bitmask of enum type_flags. */ + int size; /**< Size of an ir_entity of this type. This is determined + when fixing the layout of this class. Size must be + given in bits. */ + int align; /**< Alignment of an ir_entity of this type. This should be + set according to the source language needs. If not set it's + calculated automatically by get_type_alignment(). + Alignment must be given in bits. */ + ir_mode *mode; /**< The mode for atomic types */ + unsigned long visit; /**< visited counter for walks of the type information */ + void *link; /**< holds temporary data - like in irnode_t.h */ + struct dbg_info *dbi; /**< A pointer to information for debug support. */ + ir_type *assoc_type; /**< The associated lowered/unlowered type */ + + /* ------------- fields for analyses ---------------*/ #ifdef DEBUG_libfirm - long nr; /**< An unique node number for each node to make output - readable. */ + long nr; /**< An unique node number for each node to make output + readable. */ #endif - tp_attr attr; /**< Type kind specific fields. This must be the last - entry in this struct! Varying size! */ + tp_attr attr; /**< Type kind specific fields. This must be the last + entry in this struct! Varying size! */ }; /** @@ -254,284 +249,284 @@ static INLINE void _inc_master_type_visited(void) { ++firm_type_vis static INLINE void * _get_type_link(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return(tp -> link); + assert(tp && tp->kind == k_type); + return(tp -> link); } static INLINE void _set_type_link(ir_type *tp, void *l) { - assert(tp && tp->kind == k_type); - tp -> link = l; + assert(tp && tp->kind == k_type); + tp -> link = l; } static INLINE const tp_op* _get_type_tpop(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->type_op; + assert(tp && tp->kind == k_type); + return tp->type_op; } static INLINE ident* _get_type_tpop_nameid(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return get_tpop_ident(tp->type_op); + assert(tp && tp->kind == k_type); + return get_tpop_ident(tp->type_op); } static INLINE tp_opcode _get_type_tpop_code(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return get_tpop_code(tp->type_op); + assert(tp && tp->kind == k_type); + return get_tpop_code(tp->type_op); } static INLINE ir_mode * _get_type_mode(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->mode; + assert(tp && tp->kind == k_type); + return tp->mode; } static INLINE ident * _get_type_ident(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->name; + assert(tp && tp->kind == k_type); + return tp->name; } static INLINE void _set_type_ident(ir_type *tp, ident* id) { - assert(tp && tp->kind == k_type); - tp->name = id; + assert(tp && tp->kind == k_type); + tp->name = id; } static INLINE int _get_type_size_bits(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->size; + assert(tp && tp->kind == k_type); + return tp->size; } static INLINE int _get_type_size_bytes(const ir_type *tp) { - int size = _get_type_size_bits(tp); - if (size < 0) - return -1; - if ((size & 7) != 0) { - assert(0 && "cannot take byte size of this type"); - return -1; - } - return size >> 3; + int size = _get_type_size_bits(tp); + if (size < 0) + return -1; + if ((size & 7) != 0) { + assert(0 && "cannot take byte size of this type"); + return -1; + } + return size >> 3; } static INLINE type_state _get_type_state(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->flags & tf_layout_fixed ? layout_fixed : layout_undefined; + assert(tp && tp->kind == k_type); + return tp->flags & tf_layout_fixed ? layout_fixed : layout_undefined; } static INLINE unsigned long _get_type_visited(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->visit; + assert(tp && tp->kind == k_type); + return tp->visit; } static INLINE void _set_type_visited(ir_type *tp, unsigned long num) { - assert(tp && tp->kind == k_type); - tp->visit = num; + assert(tp && tp->kind == k_type); + tp->visit = num; } static INLINE void _mark_type_visited(ir_type *tp) { - assert(tp && tp->kind == k_type); - assert(tp->visit < firm_type_visited); - tp->visit = firm_type_visited; + assert(tp && tp->kind == k_type); + assert(tp->visit < firm_type_visited); + tp->visit = firm_type_visited; } static INLINE int _type_visited(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->visit >= firm_type_visited; + assert(tp && tp->kind == k_type); + return tp->visit >= firm_type_visited; } static INLINE int _type_not_visited(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return tp->visit < firm_type_visited; + assert(tp && tp->kind == k_type); + return tp->visit < firm_type_visited; } static INLINE int _is_type(const void *thing) { - return (get_kind(thing) == k_type); + return (get_kind(thing) == k_type); } static INLINE int _is_class_type(const ir_type *clss) { - assert(clss); - return (clss->type_op == type_class); + assert(clss); + return (clss->type_op == type_class); } static INLINE int _get_class_n_members (const ir_type *clss) { - assert(clss && (clss->type_op == type_class)); - return (ARR_LEN (clss->attr.ca.members)); + assert(clss && (clss->type_op == type_class)); + return (ARR_LEN (clss->attr.ca.members)); } static INLINE ir_entity * _get_class_member (const ir_type *clss, int pos) { - assert(clss && (clss->type_op == type_class)); - assert(pos >= 0 && pos < _get_class_n_members(clss)); - return clss->attr.ca.members[pos]; + assert(clss && (clss->type_op == type_class)); + assert(pos >= 0 && pos < _get_class_n_members(clss)); + return clss->attr.ca.members[pos]; } static INLINE unsigned _get_class_vtable_size(const ir_type *clss) { - assert(clss && (clss->type_op == type_class)); - return clss->attr.ca.vtable_size; + assert(clss && (clss->type_op == type_class)); + return clss->attr.ca.vtable_size; } static INLINE void _set_class_vtable_size(ir_type *clss, unsigned vtable_size) { - assert(clss && (clss->type_op == type_class)); - clss->attr.ca.vtable_size = vtable_size; + assert(clss && (clss->type_op == type_class)); + clss->attr.ca.vtable_size = vtable_size; } static INLINE int _is_class_final(const ir_type *clss) { - assert(clss && (clss->type_op == type_class)); - return clss->attr.ca.clss_flags & cf_final_class; + assert(clss && (clss->type_op == type_class)); + return clss->attr.ca.clss_flags & cf_final_class; } static INLINE void _set_class_final(ir_type *clss, int final) { - assert(clss && (clss->type_op == type_class)); - if (final) - clss->attr.ca.clss_flags |= cf_final_class; - else - clss->attr.ca.clss_flags &= ~cf_final_class; + assert(clss && (clss->type_op == type_class)); + if (final) + clss->attr.ca.clss_flags |= cf_final_class; + else + clss->attr.ca.clss_flags &= ~cf_final_class; } static INLINE int _is_class_interface(const ir_type *clss) { - assert(clss && (clss->type_op == type_class)); - return clss->attr.ca.clss_flags & cf_interface_class; + assert(clss && (clss->type_op == type_class)); + return clss->attr.ca.clss_flags & cf_interface_class; } static INLINE void _set_class_interface(ir_type *clss, int final) { - assert(clss && (clss->type_op == type_class)); - if (final) - clss->attr.ca.clss_flags |= cf_interface_class; - else - clss->attr.ca.clss_flags &= ~cf_interface_class; + assert(clss && (clss->type_op == type_class)); + if (final) + clss->attr.ca.clss_flags |= cf_interface_class; + else + clss->attr.ca.clss_flags &= ~cf_interface_class; } static INLINE int _is_class_abstract(const ir_type *clss) { - assert(clss && (clss->type_op == type_class)); - return clss->attr.ca.clss_flags & cf_absctract_class; -} + assert(clss && (clss->type_op == type_class)); + return clss->attr.ca.clss_flags & cf_absctract_class; + } static INLINE void _set_class_abstract(ir_type *clss, int final) { - assert(clss && (clss->type_op == type_class)); - if (final) - clss->attr.ca.clss_flags |= cf_absctract_class; - else - clss->attr.ca.clss_flags &= ~cf_absctract_class; + assert(clss && (clss->type_op == type_class)); + if (final) + clss->attr.ca.clss_flags |= cf_absctract_class; + else + clss->attr.ca.clss_flags &= ~cf_absctract_class; } static INLINE int _is_struct_type(const ir_type *strct) { - assert(strct); - return (strct->type_op == type_struct); + assert(strct); + return (strct->type_op == type_struct); } static INLINE int _is_method_type(const ir_type *method) { - assert(method); - return (method->type_op == type_method); + assert(method); + return (method->type_op == type_method); } static INLINE int _is_union_type(const ir_type *uni) { - assert(uni); - return (uni->type_op == type_union); + assert(uni); + return (uni->type_op == type_union); } static INLINE int _is_array_type(const ir_type *array) { - assert(array); - return (array->type_op == type_array); + assert(array); + return (array->type_op == type_array); } static INLINE int _is_enumeration_type(const ir_type *enumeration) { - assert(enumeration); - return (enumeration->type_op == type_enumeration); + assert(enumeration); + return (enumeration->type_op == type_enumeration); } static INLINE int _is_pointer_type(const ir_type *pointer) { - assert(pointer); - return (pointer->type_op == type_pointer); + assert(pointer); + return (pointer->type_op == type_pointer); } /** Returns true if a type is a primitive type. */ static INLINE int _is_primitive_type(const ir_type *primitive) { - assert(primitive && primitive->kind == k_type); - return (primitive->type_op == type_primitive); + assert(primitive && primitive->kind == k_type); + return (primitive->type_op == type_primitive); } static INLINE int _is_atomic_type(const ir_type *tp) { - assert(tp && tp->kind == k_type); - return (_is_primitive_type(tp) || _is_pointer_type(tp) || - _is_enumeration_type(tp)); + assert(tp && tp->kind == k_type); + return (_is_primitive_type(tp) || _is_pointer_type(tp) || + _is_enumeration_type(tp)); } static INLINE int _get_method_n_params(const ir_type *method) { - assert(method && (method->type_op == type_method)); - return method->attr.ma.n_params; + assert(method && (method->type_op == type_method)); + return method->attr.ma.n_params; } static INLINE int _get_method_n_ress(const ir_type *method) { - assert(method && (method->type_op == type_method)); - return method->attr.ma.n_res; + assert(method && (method->type_op == type_method)); + return method->attr.ma.n_res; } static INLINE unsigned _get_method_additional_properties(const ir_type *method) { - assert(method && (method->type_op == type_method)); - return method->attr.ma.additional_properties; + assert(method && (method->type_op == type_method)); + return method->attr.ma.additional_properties; } static INLINE void _set_method_additional_properties(ir_type *method, unsigned mask) { - assert(method && (method->type_op == type_method)); + assert(method && (method->type_op == type_method)); - /* do not allow to set the mtp_property_inherited flag or - * the automatic inheritance of flags will not work */ - method->attr.ma.additional_properties = mask & ~mtp_property_inherited; + /* do not allow to set the mtp_property_inherited flag or + * the automatic inheritance of flags will not work */ + method->attr.ma.additional_properties = mask & ~mtp_property_inherited; } static INLINE void _set_method_additional_property(ir_type *method, mtp_additional_property flag) { - assert(method && (method->type_op == type_method)); + assert(method && (method->type_op == type_method)); - /* do not allow to set the mtp_property_inherited flag or - * the automatic inheritance of flags will not work */ - method->attr.ma.additional_properties |= flag & ~mtp_property_inherited; + /* do not allow to set the mtp_property_inherited flag or + * the automatic inheritance of flags will not work */ + method->attr.ma.additional_properties |= flag & ~mtp_property_inherited; } static INLINE unsigned _get_method_calling_convention(const ir_type *method) { - assert(method && (method->type_op == type_method)); - return method->attr.ma.irg_calling_conv; + assert(method && (method->type_op == type_method)); + return method->attr.ma.irg_calling_conv; } static INLINE void _set_method_calling_convention(ir_type *method, unsigned cc_mask) { - assert(method && (method->type_op == type_method)); - method->attr.ma.irg_calling_conv = cc_mask; + assert(method && (method->type_op == type_method)); + method->attr.ma.irg_calling_conv = cc_mask; } #define set_master_type_visited(val) _set_master_type_visited(val) @@ -581,4 +576,4 @@ _set_method_calling_convention(ir_type *method, unsigned cc_mask) { #define get_method_calling_convention(method) _get_method_calling_convention(method) #define set_method_calling_convention(method, cc_mask) _set_method_calling_convention(method, cc_mask) -#endif /* _FIRM_TR_TYPE_T_H_ */ +#endif /* FIRM_TR_TYPE_T_H */ diff --git a/ir/tr/typegmod.c b/ir/tr/typegmod.c index e07c7814c..647ba7877 100644 --- a/ir/tr/typegmod.c +++ b/ir/tr/typegmod.c @@ -17,15 +17,11 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/typegmod.c - * Purpose: Functionality to modify the type graph. - * Author: Goetz Lindenmaier - * Modified by: Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2006 Universität Karlsruhe +/** + * @file typegmod.c + * @brief Functionality to modify the type graph. + * @author Goetz Lindenmaier, Michael Beck + * @version $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -37,36 +33,36 @@ #include "irmode.h" void exchange_types(ir_type *old_type, ir_type *new_type) { - unsigned flags = old_type->flags & (tf_frame_type | tf_value_param_type | tf_global_type | tf_tls_type); - /* Deallocate datastructures not directly contained in the - old type. We must do this now as it is the latest point - where we know the original kind of type. - */ - free_type_attrs(old_type); + unsigned flags = old_type->flags & (tf_frame_type | tf_value_param_type | tf_global_type | tf_tls_type); + /* Deallocate datastructures not directly contained in the + old type. We must do this now as it is the latest point + where we know the original kind of type. + */ + free_type_attrs(old_type); - /* @@@@ - Things to deal with: - * After exchange_types the type has two entries in the list of - all types in irp. So far this is fine for the walker. - Maybe it's better to remove the id entry and shrink the list. - Does this conflict with the walker? Might a type be left out - during the walk? - * Deallocation: if the Id is removed from the list it will eventually - disappear in a memory leak. When is impossible to determine so we - need to hold it in a separate list for deallocation. - */ + /* @@@@ + Things to deal with: + * After exchange_types the type has two entries in the list of + all types in irp. So far this is fine for the walker. + Maybe it's better to remove the id entry and shrink the list. + Does this conflict with the walker? Might a type be left out + during the walk? + * Deallocation: if the Id is removed from the list it will eventually + disappear in a memory leak. When is impossible to determine so we + need to hold it in a separate list for deallocation. + */ - /* Exchange the types */ - old_type->type_op = type_id; - old_type->mode = (ir_mode *) new_type; - /* ensure that the frame, value param, global and tls flags - are set right if these types are exchanged */ - new_type->flags |= flags; + /* Exchange the types */ + old_type->type_op = type_id; + old_type->mode = (ir_mode *) new_type; + /* ensure that the frame, value param, global and tls flags + are set right if these types are exchanged */ + new_type->flags |= flags; } ir_type *skip_tid(ir_type *tp) { - /* @@@ implement the self cycle killing trick of skip_id(ir_node *) */ - while (tp->type_op == type_id) - tp = (ir_type *) tp->mode; - return tp; + /* @@@ implement the self cycle killing trick of skip_id(ir_node *) */ + while (tp->type_op == type_id) + tp = (ir_type *) tp->mode; + return tp; } diff --git a/ir/tr/typegmod.h b/ir/tr/typegmod.h index 168804329..991149187 100644 --- a/ir/tr/typegmod.h +++ b/ir/tr/typegmod.h @@ -17,18 +17,14 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/typegmod.h - * Purpose: Functionality to modify the type graph. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2003 Universität Karlsruhe +/** + * @file typegmod.h + * @brief Functionality to modify the type graph. + * @author Goetz Lindenmaier, Michael Beck + * @version $Id$ */ -#ifndef _TYPEGMOD_H_ -#define _TYPEGMOD_H_ +#ifndef FIRM_TR_TYPEGMOD_H +#define FIRM_TR_TYPEGMOD_H #include "firm_types.h" @@ -64,4 +60,4 @@ void exchange_types(ir_type *old_type, ir_type *new_type); */ ir_type *skip_tid(ir_type *tp); -#endif /*_TYPEGMOD_H_ */ +#endif /*FIRM_TR_TYPEGMOD_H */ diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c index 896a0c905..9a4464440 100644 --- a/ir/tr/typewalk.c +++ b/ir/tr/typewalk.c @@ -17,26 +17,18 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/typewalk.c - * Purpose: Traverse the type information. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1999-2003 Universität Karlsruhe - */ - /** - * @file typewalk.c + * @file typewalk.c + * @brief Functionality to modify the type graph. + * @author Goetz Lindenmaier + * @version $Id$ + * @summary * * Traverse the type information. The walker walks the whole ir graph * to find the distinct type trees in the type graph forest. * - execute the pre function before recursion * - execute the post function after recursion */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -62,147 +54,146 @@ * The walker environment */ typedef struct type_walk_env { - type_walk_func *pre; /**< Pre-walker function */ - type_walk_func *post; /**< Post-walker function */ - void *env; /**< environment for walker functions */ + type_walk_func *pre; /**< Pre-walker function */ + type_walk_func *post; /**< Post-walker function */ + void *env; /**< environment for walker functions */ } type_walk_env; /* a walker for irn's */ static void irn_type_walker( - ir_node *node, type_walk_func *pre, type_walk_func *post, void *env); + ir_node *node, type_walk_func *pre, type_walk_func *post, void *env); /** * Main walker: walks over all used types/entities of a * type entity. */ static void do_type_walk(type_or_ent *tore, - type_walk_func *pre, - type_walk_func *post, - void *env) + type_walk_func *pre, + type_walk_func *post, + void *env) { - int i, n_types, n_mem; - ir_entity *ent = NULL; - ir_type *tp = NULL; - ir_node *n; - - /* marked? */ - switch (get_kind(tore)) { - case k_entity: - ent = (ir_entity *)tore; - if (entity_visited(ent)) return; - break; - case k_type: - tp = skip_tid((ir_type *)tore); - if (type_visited(tp)) return; - break; - default: - break; - } - - /* execute pre method */ - if (pre) - pre(tore, env); - - /* iterate */ - switch (get_kind(tore)) { - case k_entity: - mark_entity_visited(ent); - do_type_walk((type_or_ent *)get_entity_owner(ent), pre, post, env); - do_type_walk((type_or_ent *)get_entity_type(ent), pre, post, env); - - if (get_entity_variability(ent) != variability_uninitialized) { - /* walk over the value types */ - if (is_atomic_entity(ent)) { - n = get_atomic_ent_value(ent); - irn_type_walker(n, pre, post, env); - } - else { - n_mem = get_compound_ent_n_values(ent); - for (i = 0; i < n_mem; ++i) { - n = get_compound_ent_value(ent, i); - irn_type_walker(n, pre, post, env); - } - } - } - break; - case k_type: - mark_type_visited(tp); - switch (get_type_tpop_code(tp)) { - - case tpo_class: - n_types = get_class_n_supertypes(tp); - for (i = 0; i < n_types; ++i) - do_type_walk((type_or_ent *)get_class_supertype(tp, i), pre, post, env); - - n_mem = get_class_n_members(tp); - for (i = 0; i < n_mem; ++i) - do_type_walk((type_or_ent *)get_class_member(tp, i), pre, post, env); - - n_types = get_class_n_subtypes(tp); - for (i = 0; i < n_types; ++i) - do_type_walk((type_or_ent *)get_class_subtype(tp, i), pre, post, env); - break; - - case tpo_struct: - n_mem = get_struct_n_members(tp); - for (i = 0; i < n_mem; ++i) - do_type_walk((type_or_ent *)get_struct_member(tp, i), pre, post, env); - break; - - case tpo_method: - n_mem = get_method_n_params(tp); - for (i = 0; i < n_mem; ++i) - do_type_walk((type_or_ent *)get_method_param_type(tp, i), pre, post, env); - - n_mem = get_method_n_ress(tp); - for (i = 0; i < n_mem; ++i) - do_type_walk((type_or_ent *)get_method_res_type(tp, i), pre, post, env); - break; - - case tpo_union: - n_mem = get_union_n_members(tp); - for (i = 0; i < n_mem; ++i) - do_type_walk((type_or_ent *)get_union_member(tp, i), pre, post, env); - break; - - case tpo_array: - do_type_walk((type_or_ent *)get_array_element_type(tp), - pre, post, env); - do_type_walk((type_or_ent *)get_array_element_entity(tp), - pre, post, env); - break; - - case tpo_enumeration: - /* a leave */ - break; - - case tpo_pointer: - do_type_walk((type_or_ent *)get_pointer_points_to_type(tp), - pre, post, env); - break; - - case tpo_primitive: - case tpo_id: - case tpo_none: - case tpo_unknown: - /* a leave. */ - break; - default: - assert(0 && "Faulty type"); - break; - } - break; /* end case k_type */ - - default: - printf(" *** Faulty type or entity! \n"); - break; - } - - /* execute post method */ - if (post) - post(tore, env); - - return; + int i, n_types, n_mem; + ir_entity *ent = NULL; + ir_type *tp = NULL; + ir_node *n; + + /* marked? */ + switch (get_kind(tore)) { + case k_entity: + ent = (ir_entity *)tore; + if (entity_visited(ent)) return; + break; + case k_type: + tp = skip_tid((ir_type *)tore); + if (type_visited(tp)) return; + break; + default: + break; + } + + /* execute pre method */ + if (pre) + pre(tore, env); + + /* iterate */ + switch (get_kind(tore)) { + case k_entity: + mark_entity_visited(ent); + do_type_walk((type_or_ent *)get_entity_owner(ent), pre, post, env); + do_type_walk((type_or_ent *)get_entity_type(ent), pre, post, env); + + if (get_entity_variability(ent) != variability_uninitialized) { + /* walk over the value types */ + if (is_atomic_entity(ent)) { + n = get_atomic_ent_value(ent); + irn_type_walker(n, pre, post, env); + } else { + n_mem = get_compound_ent_n_values(ent); + for (i = 0; i < n_mem; ++i) { + n = get_compound_ent_value(ent, i); + irn_type_walker(n, pre, post, env); + } + } + } + break; + case k_type: + mark_type_visited(tp); + switch (get_type_tpop_code(tp)) { + + case tpo_class: + n_types = get_class_n_supertypes(tp); + for (i = 0; i < n_types; ++i) + do_type_walk((type_or_ent *)get_class_supertype(tp, i), pre, post, env); + + n_mem = get_class_n_members(tp); + for (i = 0; i < n_mem; ++i) + do_type_walk((type_or_ent *)get_class_member(tp, i), pre, post, env); + + n_types = get_class_n_subtypes(tp); + for (i = 0; i < n_types; ++i) + do_type_walk((type_or_ent *)get_class_subtype(tp, i), pre, post, env); + break; + + case tpo_struct: + n_mem = get_struct_n_members(tp); + for (i = 0; i < n_mem; ++i) + do_type_walk((type_or_ent *)get_struct_member(tp, i), pre, post, env); + break; + + case tpo_method: + n_mem = get_method_n_params(tp); + for (i = 0; i < n_mem; ++i) + do_type_walk((type_or_ent *)get_method_param_type(tp, i), pre, post, env); + + n_mem = get_method_n_ress(tp); + for (i = 0; i < n_mem; ++i) + do_type_walk((type_or_ent *)get_method_res_type(tp, i), pre, post, env); + break; + + case tpo_union: + n_mem = get_union_n_members(tp); + for (i = 0; i < n_mem; ++i) + do_type_walk((type_or_ent *)get_union_member(tp, i), pre, post, env); + break; + + case tpo_array: + do_type_walk((type_or_ent *)get_array_element_type(tp), + pre, post, env); + do_type_walk((type_or_ent *)get_array_element_entity(tp), + pre, post, env); + break; + + case tpo_enumeration: + /* a leave */ + break; + + case tpo_pointer: + do_type_walk((type_or_ent *)get_pointer_points_to_type(tp), + pre, post, env); + break; + + case tpo_primitive: + case tpo_id: + case tpo_none: + case tpo_unknown: + /* a leave. */ + break; + default: + assert(0 && "Faulty type"); + break; + } + break; /* end case k_type */ + + default: + printf(" *** Faulty type or entity! \n"); + break; + } + + /* execute post method */ + if (post) + post(tore, env); + + return; } /** Check whether node contains types or entities as an attribute. @@ -210,264 +201,259 @@ static void do_type_walk(type_or_ent *tore, static void irn_type_walker( ir_node *node, type_walk_func *pre, type_walk_func *post, void *env) { - ir_entity *ent; - ir_type *tp; + ir_entity *ent; + ir_type *tp; - assert(node); + assert(node); - ent = get_irn_entity_attr(node); - if (ent) - do_type_walk((type_or_ent *)ent, pre, post, env); - tp = get_irn_type_attr(node); - if (tp) - do_type_walk((type_or_ent *)tp, pre, post, env); + ent = get_irn_entity_attr(node); + if (ent) + do_type_walk((type_or_ent *)ent, pre, post, env); + tp = get_irn_type_attr(node); + if (tp) + do_type_walk((type_or_ent *)tp, pre, post, env); } /** Check whether node contains types or entities as an attribute. If so start a walk over that information. */ static void start_type_walk(ir_node *node, void *ctx) { - type_walk_env *env = ctx; - type_walk_func *pre; - type_walk_func *post; - void *envi; + type_walk_env *env = ctx; + type_walk_func *pre; + type_walk_func *post; + void *envi; - pre = env->pre; - post = env->post; - envi = env->env; + pre = env->pre; + post = env->post; + envi = env->env; - irn_type_walker(node, pre, post, envi); + irn_type_walker(node, pre, post, envi); } /* walker: walks over all types */ void type_walk(type_walk_func *pre, type_walk_func *post, void *env) { - int i, n_types = get_irp_n_types(); + int i, n_types = get_irp_n_types(); - inc_master_type_visited(); - for (i = 0; i < n_types; ++i) { - do_type_walk((type_or_ent *)get_irp_type(i), pre, post, env); - } - do_type_walk((type_or_ent *)get_glob_type(), pre, post, env); + inc_master_type_visited(); + for (i = 0; i < n_types; ++i) { + do_type_walk((type_or_ent *)get_irp_type(i), pre, post, env); + } + do_type_walk((type_or_ent *)get_glob_type(), pre, post, env); } -void type_walk_irg (ir_graph *irg, - void (*pre)(type_or_ent*, void*), - void (*post)(type_or_ent*, void*), - void *env) +void type_walk_irg(ir_graph *irg, + type_walk_func *pre, + type_walk_func *post, + void *env) { - ir_graph *rem = current_ir_graph; - /* this is needed to pass the parameters to the walker that actually - walks the type information */ - type_walk_env type_env; - - type_env.pre = pre; - type_env.post = post; - type_env.env = env; - - current_ir_graph = irg; - - /* We walk over the irg to find all irnodes that contain an attribute - with type information. If we find one we call a type walker to - touch the reachable type information. - The same type can be referenced by several irnodes. To avoid - repeated visits of the same type node we must decrease the - type visited flag for each walk. This is done in start_type_walk(). - Here we initially increase the flag. We only call do_type_walk that does - not increase the flag. - */ - inc_master_type_visited(); - irg_walk(get_irg_end(irg), start_type_walk, NULL, &type_env); - - do_type_walk((type_or_ent *)get_irg_entity(irg), pre, post, env); - - do_type_walk((type_or_ent *)get_irg_frame_type(irg), pre, post, env); - - current_ir_graph = rem; - return; + ir_graph *rem = current_ir_graph; + /* this is needed to pass the parameters to the walker that actually + walks the type information */ + type_walk_env type_env; + + type_env.pre = pre; + type_env.post = post; + type_env.env = env; + + current_ir_graph = irg; + + /* We walk over the irg to find all irnodes that contain an attribute + with type information. If we find one we call a type walker to + touch the reachable type information. + The same type can be referenced by several irnodes. To avoid + repeated visits of the same type node we must decrease the + type visited flag for each walk. This is done in start_type_walk(). + Here we initially increase the flag. We only call do_type_walk that does + not increase the flag. + */ + inc_master_type_visited(); + irg_walk(get_irg_end(irg), start_type_walk, NULL, &type_env); + + do_type_walk((type_or_ent *)get_irg_entity(irg), pre, post, env); + + do_type_walk((type_or_ent *)get_irg_frame_type(irg), pre, post, env); + + current_ir_graph = rem; + return; } static void type_walk_s2s_2(type_or_ent *tore, - void (*pre)(type_or_ent*, void*), - void (*post)(type_or_ent*, void*), - void *env) + type_walk_func *pre, + type_walk_func *post, + void *env) { - int i, n; - - /* marked? */ - switch (get_kind(tore)) { - case k_entity: - if (entity_visited((ir_entity *)tore)) return; - break; - case k_type: - if (type_id == get_type_tpop((ir_type*)tore)) { - type_walk_s2s_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env); - return; - } - if (type_visited((ir_type *)tore)) return; - break; - default: - break; - } - - /* iterate */ - switch (get_kind(tore)) { - case k_type: - { - ir_type *tp = (ir_type *)tore; - mark_type_visited(tp); - switch (get_type_tpop_code(tp)) { - case tpo_class: - { - n = get_class_n_supertypes(tp); - for (i = 0; i < n; ++i) { - type_walk_s2s_2((type_or_ent *)get_class_supertype(tp, i), pre, - post, env); - } - /* execute pre method */ - if (pre) - pre(tore, env); - tp = skip_tid((ir_type*)tore); - - n = get_class_n_subtypes(tp); - for (i = 0; i < n; ++i) { - type_walk_s2s_2((type_or_ent *)get_class_subtype(tp, i), pre, - post, env); - } - - /* execute post method */ - if (post) - post(tore, env); - } - break; - case tpo_struct: - case tpo_method: - case tpo_union: - case tpo_array: - case tpo_enumeration: - case tpo_pointer: - case tpo_primitive: - case tpo_id: - /* dont care */ - break; - default: - printf(" *** Faulty type! \n"); - break; - } - } break; /* end case k_type */ - case k_entity: - /* dont care */ - break; - default: - printf(" *** Faulty type or entity! \n"); - break; - } - return; + int i, n; + + /* marked? */ + switch (get_kind(tore)) { + case k_entity: + if (entity_visited((ir_entity *)tore)) return; + break; + case k_type: + if (type_id == get_type_tpop((ir_type*)tore)) { + type_walk_s2s_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env); + return; + } + if (type_visited((ir_type *)tore)) return; + break; + default: + break; + } + + /* iterate */ + switch (get_kind(tore)) { + case k_type: + { + ir_type *tp = (ir_type *)tore; + mark_type_visited(tp); + switch (get_type_tpop_code(tp)) { + case tpo_class: + { + n = get_class_n_supertypes(tp); + for (i = 0; i < n; ++i) { + type_walk_s2s_2((type_or_ent *)get_class_supertype(tp, i), pre, post, env); + } + /* execute pre method */ + if (pre) + pre(tore, env); + tp = skip_tid((ir_type*)tore); + + n = get_class_n_subtypes(tp); + for (i = 0; i < n; ++i) { + type_walk_s2s_2((type_or_ent *)get_class_subtype(tp, i), pre, post, env); + } + + /* execute post method */ + if (post) + post(tore, env); + } + break; + case tpo_struct: + case tpo_method: + case tpo_union: + case tpo_array: + case tpo_enumeration: + case tpo_pointer: + case tpo_primitive: + case tpo_id: + /* dont care */ + break; + default: + printf(" *** Faulty type! \n"); + break; + } + } break; /* end case k_type */ + case k_entity: + /* dont care */ + break; + default: + printf(" *** Faulty type or entity! \n"); + break; + } + return; } -void type_walk_super2sub( - void (*pre)(type_or_ent*, void*), - void (*post)(type_or_ent*, void*), - void *env) +void type_walk_super2sub(type_walk_func *pre, + type_walk_func *post, + void *env) { - int i, n_types = get_irp_n_types(); - ir_type *tp; - - inc_master_type_visited(); - type_walk_s2s_2((type_or_ent *)get_glob_type(), pre, post, env); - for (i = 0; i < n_types; ++i) { - tp = get_irp_type(i); - type_walk_s2s_2((type_or_ent *)tp, pre, post, env); - } + int i, n_types = get_irp_n_types(); + ir_type *tp; + + inc_master_type_visited(); + type_walk_s2s_2((type_or_ent *)get_glob_type(), pre, post, env); + for (i = 0; i < n_types; ++i) { + tp = get_irp_type(i); + type_walk_s2s_2((type_or_ent *)tp, pre, post, env); + } } /*****************************************************************************/ static void type_walk_super_2(type_or_ent *tore, - void (*pre)(type_or_ent*, void*), - void (*post)(type_or_ent*, void*), - void *env) -{ - int i, n; - - /* marked? */ - switch (get_kind(tore)) { - case k_entity: - if (entity_visited((ir_entity *)tore)) return; - break; - case k_type: - if (type_id == get_type_tpop((ir_type*)tore)) { - type_walk_super_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env); - return; - } - if (type_visited((ir_type *)tore)) return; - break; - default: - break; - } - - /* iterate */ - switch (get_kind(tore)) { - case k_type: - { - ir_type *tp = (ir_type *)tore; - mark_type_visited(tp); - switch (get_type_tpop_code(tp)) { - case tpo_class: - { - /* execute pre method */ - if (pre) - pre(tore, env); - tp = skip_tid((ir_type*)tore); - - n = get_class_n_supertypes(tp); - for (i = 0; i < n; ++i) { - type_walk_super_2((type_or_ent *)get_class_supertype(tp, i), pre, - post, env); - } - - /* execute post method */ - if (post) - post(tore, env); - } - break; - case tpo_struct: - case tpo_method: - case tpo_union: - case tpo_array: - case tpo_enumeration: - case tpo_pointer: - case tpo_primitive: - case tpo_id: - /* dont care */ - break; - default: - printf(" *** Faulty type! \n"); - break; - } - } break; /* end case k_type */ - case k_entity: - /* dont care */ - break; - default: - printf(" *** Faulty type or entity! \n"); - break; - } - return; + type_walk_func *pre, + type_walk_func *post, + void *env) { + int i, n; + + /* marked? */ + switch (get_kind(tore)) { + case k_entity: + if (entity_visited((ir_entity *)tore)) return; + break; + case k_type: + if (type_id == get_type_tpop((ir_type*)tore)) { + type_walk_super_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env); + return; + } + if (type_visited((ir_type *)tore)) return; + break; + default: + break; + } + + /* iterate */ + switch (get_kind(tore)) { + case k_type: + { + ir_type *tp = (ir_type *)tore; + mark_type_visited(tp); + switch (get_type_tpop_code(tp)) { + case tpo_class: + { + /* execute pre method */ + if (pre) + pre(tore, env); + tp = skip_tid((ir_type*)tore); + + n = get_class_n_supertypes(tp); + for (i = 0; i < n; ++i) { + type_walk_super_2((type_or_ent *)get_class_supertype(tp, i), pre, + post, env); + } + + /* execute post method */ + if (post) + post(tore, env); + } + break; + case tpo_struct: + case tpo_method: + case tpo_union: + case tpo_array: + case tpo_enumeration: + case tpo_pointer: + case tpo_primitive: + case tpo_id: + /* dont care */ + break; + default: + printf(" *** Faulty type! \n"); + break; + } + } break; /* end case k_type */ + case k_entity: + /* dont care */ + break; + default: + printf(" *** Faulty type or entity! \n"); + break; + } + return; } -void type_walk_super( - void (*pre)(type_or_ent*, void*), - void (*post)(type_or_ent*, void*), - void *env) { - int i, n_types = get_irp_n_types(); - ir_type *tp; - - inc_master_type_visited(); - type_walk_super_2((type_or_ent *)get_glob_type(), pre, post, env); - for (i = 0; i < n_types; ++i) { - tp = get_irp_type(i); - type_walk_super_2((type_or_ent *)tp, pre, post, env); - } +void type_walk_super(type_walk_func *pre, + type_walk_func *post, + void *env) { + int i, n_types = get_irp_n_types(); + ir_type *tp; + + inc_master_type_visited(); + type_walk_super_2((type_or_ent *)get_glob_type(), pre, post, env); + for (i = 0; i < n_types; ++i) { + tp = get_irp_type(i); + type_walk_super_2((type_or_ent *)tp, pre, post, env); + } } /*****************************************************************************/ @@ -475,96 +461,94 @@ void type_walk_super( static void class_walk_s2s_2(ir_type *tp, - void (*pre)(ir_type*, void*), - void (*post)(ir_type*, void*), - void *env) + class_walk_func *pre, + class_walk_func *post, + void *env) { - int i, n; - - /* marked? */ - if (type_visited(tp)) return; - - assert(is_Class_type(tp)); - /* Assure all supertypes are visited before */ - n = get_class_n_supertypes(tp); - for (i = 0; i < n; ++i) { - if (type_not_visited(get_class_supertype(tp, i))) - return; - } - - mark_type_visited(tp); - - /* execute pre method */ - if (pre) - pre(tp, env); - - tp = skip_tid(tp); - n = get_class_n_subtypes(tp); - for (i = 0; i < n; ++i) { - class_walk_s2s_2(get_class_subtype(tp, i), pre, post, env); - } - /* execute post method */ - if (post) - post(tp, env); - - return; + int i, n; + + /* marked? */ + if (type_visited(tp)) return; + + assert(is_Class_type(tp)); + /* Assure all supertypes are visited before */ + n = get_class_n_supertypes(tp); + for (i = 0; i < n; ++i) { + if (type_not_visited(get_class_supertype(tp, i))) + return; + } + + mark_type_visited(tp); + + /* execute pre method */ + if (pre) + pre(tp, env); + + tp = skip_tid(tp); + n = get_class_n_subtypes(tp); + for (i = 0; i < n; ++i) { + class_walk_s2s_2(get_class_subtype(tp, i), pre, post, env); + } + /* execute post method */ + if (post) + post(tp, env); + + return; } -void class_walk_super2sub( - void (*pre)(ir_type*, void*), - void (*post)(ir_type*, void*), - void *env) +void class_walk_super2sub(class_walk_func *pre, + class_walk_func *post, + void *env) { - int i, n_types = get_irp_n_types(); - ir_type *tp; - - inc_master_type_visited(); - for (i = 0; i < n_types; i++) { - tp = get_irp_type(i); - if (is_Class_type(tp) && - (get_class_n_supertypes(tp) == 0) && - type_not_visited(tp)) { - assert(! is_frame_type(tp)); - assert(tp != get_glob_type()); - class_walk_s2s_2(tp, pre, post, env); - } - } + int i, n_types = get_irp_n_types(); + ir_type *tp; + + inc_master_type_visited(); + for (i = 0; i < n_types; i++) { + tp = get_irp_type(i); + if (is_Class_type(tp) && + (get_class_n_supertypes(tp) == 0) && + type_not_visited(tp)) { + assert(! is_frame_type(tp)); + assert(tp != get_glob_type()); + class_walk_s2s_2(tp, pre, post, env); + } + } } /* Walks over all entities in the type */ -void walk_types_entities( - ir_type *tp, - void (*doit)(ir_entity*, void*), - void *env) +void walk_types_entities(ir_type *tp, + entity_walk_func *doit, + void *env) { - int i, n; - - switch (get_type_tpop_code(tp)) { - case tpo_class: - n = get_class_n_members(tp); - for (i = 0; i < n; ++i) - doit(get_class_member(tp, i), env); - break; - case tpo_struct: - n = get_struct_n_members(tp); - for (i = 0; i < n; ++i) - doit(get_struct_member(tp, i), env); - break; - case tpo_union: - n = get_union_n_members(tp); - for (i = 0; i < n; ++i) - doit(get_union_member(tp, i), env); - break; - case tpo_array: - doit(get_array_element_entity(tp), env); - break; - case tpo_method: - case tpo_enumeration: - case tpo_pointer: - case tpo_primitive: - case tpo_id: - default: - break; - } + int i, n; + + switch (get_type_tpop_code(tp)) { + case tpo_class: + n = get_class_n_members(tp); + for (i = 0; i < n; ++i) + doit(get_class_member(tp, i), env); + break; + case tpo_struct: + n = get_struct_n_members(tp); + for (i = 0; i < n; ++i) + doit(get_struct_member(tp, i), env); + break; + case tpo_union: + n = get_union_n_members(tp); + for (i = 0; i < n; ++i) + doit(get_union_member(tp, i), env); + break; + case tpo_array: + doit(get_array_element_entity(tp), env); + break; + case tpo_method: + case tpo_enumeration: + case tpo_pointer: + case tpo_primitive: + case tpo_id: + default: + break; + } } diff --git a/ir/tr/typewalk.h b/ir/tr/typewalk.h index 7278d438b..5c50a7ef2 100644 --- a/ir/tr/typewalk.h +++ b/ir/tr/typewalk.h @@ -17,32 +17,22 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tr/typewalk.h - * Purpose: Traverse the type information. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1999-2003 Universität Karlsruhe - */ - /** - * @file typewalk.h + * @file typewalk.h + * @brief Functionality to modify the type graph. + * @author Goetz Lindenmaier + * @version $Id$ + * @summary * * Traverse the type information. * - * @author Goetz Lindenmaier - * * The walker walks the whole ir graph * to find the distinct type trees in the type graph forest. * - execute the pre() function before recursion * - execute the post() function after recursion */ - -#ifndef _TYPEWALK_H_ -#define _TYPEWALK_H_ +#ifndef FIRM_TR_TYPEWALK_H +#define FIRM_TR_TYPEWALK_H #include "type.h" #include "type_or_entity.h" @@ -141,4 +131,4 @@ void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env); -#endif /* _TYPEWALK_H_ */ +#endif /* FIRM_TR_TYPEWALK_H */ -- 2.20.1