Some access routines for visited flags in entity.h, irnode.h,
[libfirm] / ir / tr / type.c
index f8dfbca..ada05cd 100644 (file)
  *   type_t.h type tpop
  *****
  */
+
+/* $Id$ */
+
 # include <stdlib.h>
 # include <stddef.h>
 # include "type_t.h"
 # include "tpop_t.h"
 # include "typegmod_t.h"
 # include "array.h"
+# include "irprog.h"
+# include "mangle.h"
+# include "tv.h"
+# include "ircons.h"
 
 /*******************************************************************/
 /** TYPE                                                          **/
@@ -100,18 +107,22 @@ ident*      get_type_tpop_nameid(type *tp) {
   assert(tp);
   return tp->type_op->name;
 }
+
 const char* get_type_tpop_name(type *tp) {
   assert(tp);
   return id_to_str(tp->type_op->name);
 }
+
 tp_opcode    get_type_tpop_code(type *tp) {
   assert(tp);
   return tp->type_op->code;
 }
+
 ir_mode*    get_type_mode(type *tp) {
   assert(tp);
   return tp->mode;
 }
+
 void        set_type_mode(type *tp, ir_mode* m) {
   assert(tp);
   tp->mode = m;
@@ -119,18 +130,22 @@ void        set_type_mode(type *tp, ir_mode* m) {
   if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
     tp->size == get_mode_size(m);
 }
-ident*      get_type_nameid(type *tp) {
+
+ident*      get_type_ident(type *tp) {
   assert(tp);
   return tp->name;
 }
-void        set_type_nameid(type *tp, ident* id) {
+
+void        set_type_ident(type *tp, ident* id) {
   assert(tp);
   tp->name = id;
 }
+
 const char* get_type_name(type *tp) {
   assert(tp);
   return id_to_str(tp->name);
 }
+
 int         get_type_size(type *tp) {
   assert(tp);
   return tp->size;
@@ -154,8 +169,10 @@ void
 set_type_state(type *tp, type_state state) {
   assert(tp);
   /* For pointer and primitive always fixed. */
-  if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive))
+  if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive)) {
+    /* @@@ assert that the layout really is fixed!!! */
     tp->state = state;
+  }
 }
 
 unsigned long get_type_visited(type *tp) {
@@ -502,7 +519,7 @@ type *new_type_array         (ident *name, int n_dimensions,
   res->attr.aa.lower_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
   res->attr.aa.upper_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
   res->attr.aa.element_type = element_type;
-  new_entity(res, name, element_type);
+  new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
   return res;
 }
 inline void free_array_attrs (type *array) {
@@ -516,8 +533,21 @@ int   get_array_n_dimensions (type *array) {
   assert(array && (array->type_op == type_array));
   return array->attr.aa.n_dimensions;
 }
-void  set_array_bounds       (type *array, int dimension, ir_node * lower_bound,
-                                                          ir_node * upper_bound) {
+void  set_array_bounds_int (type *array, int dimension, int lower_bound,
+                           int upper_bound) {
+  ir_graph *rem;
+  assert(array && (array->type_op == type_array));
+  rem = current_ir_graph;
+  current_ir_graph = get_const_code_irg();
+  array->attr.aa.lower_bound[dimension] =
+    new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
+  array->attr.aa.upper_bound[dimension] =
+    new_Const(mode_I, tarval_from_long (mode_I, upper_bound));
+  current_ir_graph = rem;
+}
+
+void  set_array_bounds (type *array, int dimension, ir_node * lower_bound,
+                       ir_node * upper_bound) {
   assert(array && (array->type_op == type_array));
   array->attr.aa.lower_bound[dimension] = lower_bound;
   array->attr.aa.upper_bound[dimension] = upper_bound;
@@ -666,3 +696,12 @@ bool  is_primitive_type  (type *primitive) {
   assert(primitive);
   if (primitive->type_op == type_primitive) return 1; else return 0;
 }
+
+int is_atomic_type(type *tp) {
+  return (is_primitive_type(tp) || is_pointer_type(tp) ||
+         is_enumeration_type(tp));
+}
+int is_compound_type(type *tp) {
+  return (is_class_type(tp) || is_struct_type(tp) ||
+         is_array_type(tp) || is_union_type(tp));
+}