Added new type opcode "id".
authorGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Wed, 11 Jul 2001 12:17:48 +0000 (12:17 +0000)
committerGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Wed, 11 Jul 2001 12:17:48 +0000 (12:17 +0000)
Implemented exchange_type similarly to exchange for Ir_nodes.
Added to all type access routines skip_tid so that only real tyeps
are retruned.
the new opcode should never be visible externaly.C

[r223]

Changes
ir/ir/irnode.c
ir/ir/irprog.c
ir/tr/Makefile.in
ir/tr/entity.c
ir/tr/entity.h
ir/tr/tpop.c
ir/tr/tpop.h
ir/tr/type.c
ir/tr/type_t.h

diff --git a/Changes b/Changes
index c1a1eb8..7f4bcd4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+  9.7.2001 Goetz
+  Added some new access routines to types.
+  List of overwritten fields for entities.
+  Removed a bug in irnode.
+
   4.7.2001 Goetz
   Added a routine to set the mangled entity name.
   Added two routines to copy entites.
   4.7.2001 Goetz
   Added a routine to set the mangled entity name.
   Added two routines to copy entites.
index 76646ca..0601822 100644 (file)
@@ -13,6 +13,7 @@
 #include "irgraph_t.h"
 #include "ident_t.h"
 #include "irmode_t.h"
 #include "irgraph_t.h"
 #include "ident_t.h"
 #include "irmode_t.h"
+#include "typegmod_t.h"
 #include "array.h"
 
 #ifdef DEBUG_libfirm
 #include "array.h"
 
 #ifdef DEBUG_libfirm
@@ -324,7 +325,7 @@ inline type *
 get_irn_free_attr     (ir_node *node)
 {
   assert (node->op == op_Free);
 get_irn_free_attr     (ir_node *node)
 {
   assert (node->op == op_Free);
-  return node->attr.f;
+  return node->attr.f = skip_tid(node->attr.f);
 }
 
 inline symconst_attr
 }
 
 inline symconst_attr
@@ -338,7 +339,7 @@ inline type *
 get_irn_call_attr (ir_node *node)
 {
   assert (node->op == op_Call);
 get_irn_call_attr (ir_node *node)
 {
   assert (node->op == op_Call);
-  return node->attr.call;
+  return node->attr.call = skip_tid(node->attr.call);
 }
 
 inline sel_attr
 }
 
 inline sel_attr
@@ -603,7 +604,7 @@ get_SymConst_type (ir_node *node) {
   assert (   (node->op == op_SymConst)
           && (   get_SymConst_kind(node) == type_tag
               || get_SymConst_kind(node) == size));
   assert (   (node->op == op_SymConst)
           && (   get_SymConst_kind(node) == type_tag
               || get_SymConst_kind(node) == size));
-  return node->attr.i.tori.typ;
+  return node->attr.i.tori.typ = skip_tid(node->attr.i.tori.typ);
 }
 
 inline void
 }
 
 inline void
@@ -785,7 +786,7 @@ set_Call_param (ir_node *node, int pos, ir_node *param) {
 inline type *
 get_Call_type (ir_node *node) {
   assert (node->op == op_Call);
 inline type *
 get_Call_type (ir_node *node) {
   assert (node->op == op_Call);
-  return node->attr.call;
+  return node->attr.call = skip_tid(node->attr.call);
 }
 
 inline void
 }
 
 inline void
@@ -1590,7 +1591,7 @@ set_Alloc_size (ir_node *node, ir_node *size) {
 inline type  *
 get_Alloc_type (ir_node *node) {
   assert (node->op == op_Alloc);
 inline type  *
 get_Alloc_type (ir_node *node) {
   assert (node->op == op_Alloc);
-  return node->attr.a.type;
+  return node->attr.a.type = skip_tid(node->attr.a.type);
 }
 
 inline void
 }
 
 inline void
@@ -1651,7 +1652,7 @@ set_Free_size (ir_node *node, ir_node *size) {
 inline type  *
 get_Free_type (ir_node *node) {
   assert (node->op == op_Free);
 inline type  *
 get_Free_type (ir_node *node) {
   assert (node->op == op_Free);
-  return node->attr.f;
+  return node->attr.f = skip_tid(node->attr.f);
 }
 
 inline void
 }
 
 inline void
index 128298d..1858224 100644 (file)
@@ -13,6 +13,7 @@
 # include "irprog_t.h"
 # include "array.h"
 # include "obst.h"
 # include "irprog_t.h"
 # include "array.h"
 # include "obst.h"
+# include "typegmod.h"
 
 #define GLOBAL_TYPE_NAME "GlobalType"
 
 
 #define GLOBAL_TYPE_NAME "GlobalType"
 
@@ -62,7 +63,7 @@ void set_irp_main_irg(ir_graph *main_irg) {
 
 type *get_glob_type(void) {
   assert(irp);
 
 type *get_glob_type(void) {
   assert(irp);
-  return irp->glob_type;
+  return irp->glob_type = skip_tid(irp->glob_type);
 }
 
 /* Adds irg to the list of ir graphs in irp. */
 }
 
 /* Adds irg to the list of ir graphs in irp. */
@@ -107,8 +108,8 @@ int get_irp_n_types (void) {
 type *get_irp_type(int pos) {
   assert (irp && irp->types);
   /* Strangely the first element of the array is NULL.  Why??  */
 type *get_irp_type(int pos) {
   assert (irp && irp->types);
   /* Strangely the first element of the array is NULL.  Why??  */
-  return irp->types[pos+1];
-
+  /* Don't set the skip_id result so that no double entries are generated. */
+  return skip_id(irp->types[pos+1]);
 }
 
 void  set_irp_type(int pos, type *typ) {
 }
 
 void  set_irp_type(int pos, type *typ) {
@@ -116,7 +117,6 @@ void  set_irp_type(int pos, type *typ) {
   assert (pos < (ARR_LEN((irp)->types) - 1));
   /* Strangely the first element of the array is NULL.  Why??  */
   irp->types[pos+1] = typ;
   assert (pos < (ARR_LEN((irp)->types) - 1));
   /* Strangely the first element of the array is NULL.  Why??  */
   irp->types[pos+1] = typ;
-
 }
 
 #ifdef DEBUG_libfirm
 }
 
 #ifdef DEBUG_libfirm
index dc29119..1ae5879 100644 (file)
@@ -10,12 +10,13 @@ srcdir = @srcdir@
 topdir = ../..
 subdir := ir/tr
 
 topdir = ../..
 subdir := ir/tr
 
-INSTALL_HEADERS = entity.h mangle.h tpop.h type.h typewalk.h type_or_entity.h
+INSTALL_HEADERS = entity.h mangle.h tpop.h type.h typewalk.h type_or_entity.h typegmod.h
 
 SOURCES = $(INSTALL_HEADERS)
 
 SOURCES += Makefile.in \
 
 SOURCES = $(INSTALL_HEADERS)
 
 SOURCES += Makefile.in \
-               entity.c entity_t.h mangle.c tpop.c tpop_t.h type.c type_t.h typewalk.c
+               entity.c entity_t.h mangle.c tpop.c tpop_t.h type.c type_t.h    \
+               typewalk.c typegmod.c typegmod_t.h
 
 
 include $(topdir)/MakeRules
 
 
 include $(topdir)/MakeRules
index 516f366..ec5c6d5 100644 (file)
@@ -118,7 +118,7 @@ void   set_entity_ld_ident (entity *, ident *ld_ident);
 
 inline type *
 get_entity_owner (entity *ent) {
 
 inline type *
 get_entity_owner (entity *ent) {
-  return ent->owner;
+  return ent->owner = skip_tid(ent->owner);
 }
 
 inline void
 }
 
 inline void
@@ -144,7 +144,8 @@ get_entity_ld_ident (entity *ent)
   return ent->ld_name;
 }
 
   return ent->ld_name;
 }
 
-void   set_entity_ld_ident (entity *ent, ident *ld_ident) {
+inline void
+set_entity_ld_ident (entity *ent, ident *ld_ident) {
   ent->ld_name = ld_ident;
 }
 
   ent->ld_name = ld_ident;
 }
 
@@ -155,7 +156,7 @@ void   set_entity_ld_name  (entity *, char *ld_name);
 
 inline type *
 get_entity_type (entity *ent) {
 
 inline type *
 get_entity_type (entity *ent) {
-  return ent->type;
+  return ent->type = skip_tid(ent->type);
 }
 
 inline void
 }
 
 inline void
index 43b3558..45176fb 100644 (file)
@@ -118,6 +118,7 @@ void      set_entity_ld_name  (entity *ent, char *ld_name);
 */
 
 type     *get_entity_owner (entity *ent);
 */
 
 type     *get_entity_owner (entity *ent);
+/* Sets the owner field in entity to owner. */
 void      set_entity_owner (entity *ent, type *owner);
 inline void  assert_legal_owner_of_ent(type *owner);
 
 void      set_entity_owner (entity *ent, type *owner);
 inline void  assert_legal_owner_of_ent(type *owner);
 
index fd7f78b..217c2b3 100644 (file)
@@ -44,6 +44,7 @@ init_tpop(void)
   type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration",11), sizeof (enm_attr));
   type_pointer     = new_tpop (tpo_pointer    , id_from_str("pointer"    , 7), sizeof (ptr_attr));
   type_primitive   = new_tpop (tpo_primitive  , id_from_str("primitive"  , 9), /* sizeof (pri_attr) */ 0);
   type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration",11), sizeof (enm_attr));
   type_pointer     = new_tpop (tpo_pointer    , id_from_str("pointer"    , 7), sizeof (ptr_attr));
   type_primitive   = new_tpop (tpo_primitive  , id_from_str("primitive"  , 9), /* sizeof (pri_attr) */ 0);
+  type_id          = new_tpop (tpo_id         , id_from_str("type_id"    , 7), /* sizeof (id_attr)  */ 0);
 }
 
 /* Returns the string for the tp_opcode. */
 }
 
 /* Returns the string for the tp_opcode. */
index 376c2a5..13267d8 100644 (file)
@@ -35,7 +35,8 @@ typedef enum {
   tpo_array,
   tpo_enumeration,
   tpo_pointer,
   tpo_array,
   tpo_enumeration,
   tpo_pointer,
-  tpo_primitive
+  tpo_primitive,
+  tpo_id
 } tp_opcode;
 /******/
 
 } tp_opcode;
 /******/
 
@@ -224,4 +225,28 @@ extern tp_op *type_pointer;
 extern tp_op *type_primitive;
 /******/
 
 extern tp_op *type_primitive;
 /******/
 
+/****d* tpop/type_id
+ *
+ * NAME
+ *   type_id
+ * PURPOSE
+ *   This type opcode is an auxiliary opcode dedicated to support transformations
+ *   of the type structure.  If a type is changed to another type with another
+ *   opcode the new type will be allocated with new memory.  All nodes refereing
+ *   to the old type need to be changed to refer the new one.  This is simplified
+ *   by turning the old type into an id type that merely forwards to the new type
+ *   that now replaces the old one.
+ *   type_ids should never be visible out of the type module.  All access routines
+ *   should automatically check for type_id and eventually follow the forward in
+ *   type_id.  Two types are exchanged by a call to exchange_types.
+ *   If a type_id is visible externally report this as bug.  If it is assured that
+ *   this never happens this extern variable can be moved to type_t.h.
+ * NOTES
+ *   This struct is dynamically allocated but constant for the lifetime
+ *   of the library.
+ * SOURCE
+ */
+extern tp_op *type_id;
+/******/
+
 # endif /*_TYPEOP_H_ */
 # endif /*_TYPEOP_H_ */
index f1b6b28..98b8c48 100644 (file)
@@ -32,6 +32,7 @@
 # include <stddef.h>
 # include "type_t.h"
 # include "tpop_t.h"
 # include <stddef.h>
 # include "type_t.h"
 # include "tpop_t.h"
+# include "typegmod_t.h"
 # include "array.h"
 
 /*******************************************************************/
 # include "array.h"
 
 /*******************************************************************/
@@ -43,8 +44,11 @@ unsigned long type_visited;
 inline type *
 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
   type *res;
 inline type *
 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
   type *res;
+  int node_size ;
 
 
-  int node_size = offsetof (type, attr) +  type_op->attr_size;
+  assert(type_op != type_id);
+
+  node_size = offsetof (type, attr) +  type_op->attr_size;
   res = (type *) xmalloc (node_size);
   add_irp_type(res);   /* Remember the new type global. */
 
   res = (type *) xmalloc (node_size);
   add_irp_type(res);   /* Remember the new type global. */
 
@@ -206,7 +210,7 @@ int     get_class_n_subtype (type *clss) {
 }
 type   *get_class_subtype   (type *clss, int pos) {
   assert(clss && (clss->type_op == type_class));
 }
 type   *get_class_subtype   (type *clss, int pos) {
   assert(clss && (clss->type_op == type_class));
-  return clss->attr.ca.subtypes[pos+1];
+  return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
 }
 void    set_class_subtype   (type *clss, type *subtype, int pos) {
   assert(clss && (clss->type_op == type_class));
 }
 void    set_class_subtype   (type *clss, type *subtype, int pos) {
   assert(clss && (clss->type_op == type_class));
@@ -235,7 +239,7 @@ int     get_class_n_supertype (type *clss) {
 }
 type   *get_class_supertype   (type *clss, int pos) {
   assert(clss && (clss->type_op == type_class));
 }
 type   *get_class_supertype   (type *clss, int pos) {
   assert(clss && (clss->type_op == type_class));
-  return clss->attr.ca.supertypes[pos+1];
+  return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
 }
 void    set_class_supertype   (type *clss, type *supertype, int pos) {
   assert(clss && (clss->type_op == type_class));
 }
 void    set_class_supertype   (type *clss, type *supertype, int pos) {
   assert(clss && (clss->type_op == type_class));
@@ -326,7 +330,7 @@ int   get_method_n_params  (type *method) {
 }
 type *get_method_param_type(type *method, int pos) {
   assert(method && (method->type_op == type_method));
 }
 type *get_method_param_type(type *method, int pos) {
   assert(method && (method->type_op == type_method));
-  return method->attr.ma.param_type[pos];
+  return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
 }
 void  set_method_param_type(type *method, int pos, type* type) {
   assert(method && (method->type_op == type_method));
 }
 void  set_method_param_type(type *method, int pos, type* type) {
   assert(method && (method->type_op == type_method));
@@ -339,7 +343,7 @@ int   get_method_n_res   (type *method) {
 }
 type *get_method_res_type(type *method, int pos) {
   assert(method && (method->type_op == type_method));
 }
 type *get_method_res_type(type *method, int pos) {
   assert(method && (method->type_op == type_method));
-  return method->attr.ma.res_type[pos];
+  return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
 }
 void  set_method_res_type(type *method, int pos, type* type) {
   assert(method && (method->type_op == type_method));
 }
 void  set_method_res_type(type *method, int pos, type* type) {
   assert(method && (method->type_op == type_method));
@@ -374,7 +378,7 @@ int    get_union_n_types      (type *uni) {
 }
 type  *get_union_unioned_type (type *uni, int pos) {
   assert(uni && (uni->type_op == type_union));
 }
 type  *get_union_unioned_type (type *uni, int pos) {
   assert(uni && (uni->type_op == type_union));
-  return uni->attr.ua.unioned_type[pos];
+  return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
 }
 void   set_union_unioned_type (type *uni, int pos, type *type) {
   assert(uni && (uni->type_op == type_union));
 }
 void   set_union_unioned_type (type *uni, int pos, type *type) {
   assert(uni && (uni->type_op == type_union));
@@ -478,7 +482,7 @@ void  set_array_element_type (type *array, type *type) {
 }
 type *get_array_element_type (type *array) {
   assert(array && (array->type_op == type_array));
 }
 type *get_array_element_type (type *array) {
   assert(array && (array->type_op == type_array));
-  return array->attr.aa.element_type;
+  return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
 }
 void  set_array_element_entity (type *array, entity *ent) {
   assert(array && (array->type_op == type_array));
 }
 void  set_array_element_entity (type *array, entity *ent) {
   assert(array && (array->type_op == type_array));
@@ -561,7 +565,7 @@ void  set_pointer_points_to_type (type *pointer, type *type) {
 }
 type *get_pointer_points_to_type (type *pointer) {
   assert(pointer && (pointer->type_op == type_pointer));
 }
 type *get_pointer_points_to_type (type *pointer) {
   assert(pointer && (pointer->type_op == type_pointer));
-  return pointer->attr.pa.points_to;
+  return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
 }
 
 /* typecheck */
 }
 
 /* typecheck */
index 151509a..2d0737f 100644 (file)
@@ -76,6 +76,12 @@ typedef struct {        * No private attr yet. *
 } pri_attr;
 */
 
 } pri_attr;
 */
 
+/*
+typedef struct {        * No private attr, must be smaller than others! *
+} id_attr;
+*/
+
+
 typedef union {
   cls_attr ca;
   stc_attr sa;
 typedef union {
   cls_attr ca;
   stc_attr sa;
@@ -108,7 +114,7 @@ struct type {
  * SYNOPSIS
  *  type *new_type(tp_op *type_op, ir_mode *mode, ident* name);
  * INPUTS
  * SYNOPSIS
  *  type *new_type(tp_op *type_op, ir_mode *mode, ident* name);
  * INPUTS
- *   type_op - the kind of this type
+ *   type_op - the kind of this type.  May not be type_id.
  *   mode    - the mode to be used for this type, may be NULL
  *   name    - an ident for the name of this type.
  * RESULT
  *   mode    - the mode to be used for this type, may be NULL
  *   name    - an ident for the name of this type.
  * RESULT