Commit 357cb9f9 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

a

  Added volatile flag to entity, order flag to array.
  Added a set of assertions.
  Added access function set_class_members()  dded info to type nodes

[r298]
parent 9b530119
......@@ -65,8 +65,12 @@ new_entity (type *owner, ident *name, type *type)
res->owner = owner;
res->name = name;
res->type = type;
res->allocation = dynamic_allocated;
if (get_type_tpop(type) == type_method)
res->allocation = static_allocated;
else
res->allocation = automatic_allocated;
res->visibility = local;
res->offset = -1;
if (is_method_type(type)) {
res->variability = constant;
rem = current_ir_graph;
......@@ -76,6 +80,7 @@ new_entity (type *owner, ident *name, type *type)
} else {
res->variability = uninitialized;
}
res->volatility = non_volatile;
res->ld_name = NULL;
res->overwrites = NEW_ARR_F(entity *, 1);
......@@ -234,6 +239,17 @@ set_entity_variability (entity *ent, ent_variability var){
ent->variability = var;
}
inline ent_volatility
get_entity_volatility (entity *ent) {
return ent->volatility;
}
inline void
set_entity_volatility (entity *ent, ent_volatility vol) {
ent->volatility = vol;
}
/* Set has no effect for entities of type method. */
inline ir_node *
get_atomic_ent_value(entity *ent) {
......
......@@ -144,11 +144,12 @@ type *get_entity_type (entity *ent);
void set_entity_type (entity *ent, type *type);
typedef enum {
dynamic_allocated, /* The entity is allocated during runtime, either explicitly
by an Alloc node or implicitly as component of a compound
type. This is the default. */
automatic_allocated,/* The entity is allocated during runtime, implicitly
as component of a compound type. This is the default. */
dynamic_allocated, /* The entity is allocated during runtime, explicitly
by an Alloc node. */
static_allocated /* The entity is allocated statically. We can use a
SymConst as address of the entity. */
SymConst(?) as address of the entity. */
} ent_allocation;
ent_allocation get_entity_allocation (entity *ent);
......@@ -183,6 +184,15 @@ typedef enum {
ent_variability get_entity_variability (entity *ent);
void set_entity_variability (entity *ent, ent_variability var);
/* This enumeration flags the volatility of entities. */
typedef enum {
non_volatile, /* The entity is not volatile */
is_volatile /* The entity is volatile */
} ent_volatility;
ent_volatility get_entity_volatility (entity *ent);
void set_entity_volatility (entity *ent, ent_volatility vol);
/* Set has no effect for entities of type method. */
ir_node * get_atomic_ent_value(entity *ent);
void set_atomic_ent_value(entity *ent, ir_node *val);
......
......@@ -55,6 +55,7 @@ struct entity {
ent_visibility visibility; /* Specifies visibility to external program
fragments */
ent_variability variability; /* Specifies variability of entities content */
ent_volatility volatility; /* Specifies volatility of entities content */
ir_node *value; /* value of atomic entity */
ir_node **values; /* values of compound entities */
entity **val_ents; /* entities corresponding to constant values */
......
......@@ -88,105 +88,149 @@ void free_type_attrs(type *tp) {
/* set/get the link field */
void *get_type_link(type *tp)
{
assert(tp);
assert(tp && tp->kind == k_type);
return(tp -> link);
}
void set_type_link(type *tp, void *l)
{
assert(tp);
assert(tp && tp->kind == k_type);
tp -> link = l;
}
tp_op* get_type_tpop(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->type_op;
}
ident* get_type_tpop_nameid(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->type_op->name;
}
const char* get_type_tpop_name(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return id_to_str(tp->type_op->name);
}
tp_opcode get_type_tpop_code(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->type_op->code;
}
ir_mode* get_type_mode(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->mode;
}
void set_type_mode(type *tp, ir_mode* m) {
assert(tp);
tp->mode = m;
/* For pointer and primitive size depends on the mode. */
if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
assert(tp && tp->kind == k_type);
assert((tp->type_op != type_primitive) || mode_is_data(m) &&
/* Modes of primitives must be data */
(tp->type_op != type_enumeration) || mode_is_int(m));
/* Modes of enumerations must be integers */
if ((tp->type_op == type_primitive) || (tp->type_op == type_enumeration)) {
/* For pointer, primitive and enumeration size depends on the mode. */
tp->size == get_mode_size(m);
tp->mode = m;
}
}
ident* get_type_ident(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->name;
}
void set_type_ident(type *tp, ident* id) {
assert(tp);
assert(tp && tp->kind == k_type);
tp->name = id;
}
const char* get_type_name(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return id_to_str(tp->name);
}
int get_type_size(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->size;
}
void
set_type_size(type *tp, int size) {
assert(tp);
/* For pointer and primitive size depends on the mode. */
if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive))
assert(tp && tp->kind == k_type);
/* For pointer enumeration and primitive size depends on the mode.
Methods don't have a size. */
if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
(tp->type_op != type_enumeration) && (tp->type_op != type_method))
tp->size = size;
}
type_state
get_type_state(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->state;
}
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)) {
/* @@@ assert that the layout really is fixed!!! */
tp->state = state;
assert(tp && tp->kind == k_type);
if ((tp->type_op == type_pointer) && (tp->type_op == type_primitive) &&
(tp->type_op == type_method))
return;
/* Just a correctness check: */
if (state == layout_fixed) {
int i;
switch (get_type_tpop_code(tp)) {
case tpo_class:
{
assert(get_type_size(tp) > -1);
for (i = 0; i < get_class_n_member(tp); i++)
assert(get_entity_offset(get_class_member(tp, i)) > -1);
assert(get_entity_allocation(get_class_member(tp, i)) == automatic_allocated);
} break;
case tpo_struct:
{
assert(get_type_size(tp) > -1);
for (i = 0; i < get_struct_n_member(tp); i++) {
assert(get_entity_offset(get_struct_member(tp, i)) > -1);
assert(get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated);
}
} break;
case tpo_union:
{ /* ?? */
} break;
case tpo_array:
{ /* ?? */
} break;
case tpo_enumeration:
{
assert(get_type_mode != NULL);
for (i = 0; i < get_enumeration_n_enums(tp); i++)
assert(get_enumeration_enum(tp, i) != NULL);
} break;
default: break;
} /* switch (tp) */
}
tp->state = state;
}
unsigned long get_type_visited(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
return tp->visit;
}
void set_type_visited(type *tp, unsigned long num) {
assert(tp);
assert(tp && tp->kind == k_type);
tp->visit = num;
}
/* Sets visited field in type to type_visited. */
void mark_type_visited(type *tp) {
assert(tp);
assert(tp && tp->kind == k_type);
assert(tp->visit < type_visited);
tp->visit = type_visited;
}
......@@ -240,6 +284,16 @@ void set_class_member (type *clss, entity *member, int pos) {
assert(pos >= 0 && pos < get_class_n_member(clss));
clss->attr.ca.members[pos+1] = member;
}
void set_class_members (type *clss, entity **members, int arity) {
int i;
assert(clss && (clss->type_op == type_class));
DEL_ARR_F(clss->attr.ca.members);
clss->attr.ca.members = NEW_ARR_F (entity *, 1);
for (i = 0; i < arity; i++) {
set_entity_owner(members[i], clss);
ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
}
}
void remove_class_member(type *clss, entity *member) {
int i;
assert(clss && (clss->type_op == type_class));
......@@ -348,6 +402,7 @@ inline void free_struct_attrs (type *strct) {
/* manipulate private fields of struct */
void add_struct_member (type *strct, entity *member) {
assert(strct && (strct->type_op == type_struct));
assert(get_type_tpop(get_entity_type(member)) != type_method);
ARR_APP1 (entity *, strct->attr.sa.members, member);
}
int get_struct_n_member (type *strct) {
......@@ -362,6 +417,7 @@ entity *get_struct_member (type *strct, int pos) {
void set_struct_member (type *strct, int pos, entity *member) {
assert(strct && (strct->type_op == type_struct));
assert(pos >= 0 && pos < get_struct_n_member(strct));
/* assert(get_entity_type(member)->type_op != type_method); @@@ lowerfirm !!*/
strct->attr.sa.members[pos+1] = member;
}
void remove_struct_member(type *strct, entity *member) {
......@@ -389,7 +445,9 @@ bool is_struct_type(type *strct) {
N_param is the number of parameters, n_res the number of results. */
type *new_type_method (ident *name, int n_param, int n_res) {
type *res;
res = new_type(type_method, NULL, name);
res = new_type(type_method, mode_p, name);
res->state = layout_fixed;
res->size = get_mode_size(mode_p);
res->attr.ma.n_params = n_param;
res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
res->attr.ma.n_res = n_res;
......@@ -533,10 +591,20 @@ bool is_union_type (type *uni) {
type *new_type_array (ident *name, int n_dimensions,
type *element_type) {
type *res;
int i;
assert((element_type->type_op != type_method));
assert(get_type_tpop(element_type) != type_method);
res = new_type(type_array, NULL, name);
res->attr.aa.n_dimensions = 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.order = (int *) xmalloc (sizeof (int) * n_dimensions);
for (i = 0; i < n_dimensions; i++) {
res->attr.aa.lower_bound[i] = NULL;
res->attr.aa.upper_bound[i] = NULL;
res->attr.aa.order[i] = i;
}
res->attr.aa.element_type = element_type;
new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
return res;
......@@ -587,6 +655,14 @@ ir_node * get_array_upper_bound (type *array, int dimension) {
assert(array && (array->type_op == type_array));
return array->attr.aa.upper_bound[dimension];
}
void set_array_order (type *array, int dimension, int order) {
assert(array && (array->type_op == type_array));
array->attr.aa.order[dimension] = order;
}
int get_array_order (type *array, int dimension) {
assert(array && (array->type_op == type_array));
return array->attr.aa.order[dimension];
}
void set_array_element_type (type *array, type *type) {
assert(array && (array->type_op == type_array));
array->attr.aa.element_type = type;
......@@ -597,7 +673,9 @@ type *get_array_element_type (type *array) {
}
void set_array_element_entity (type *array, entity *ent) {
assert(array && (array->type_op == type_array));
assert((get_entity_type(ent)->type_op != type_method));
array->attr.aa.element_ent = ent;
array->attr.aa.element_type = get_entity_type(ent);
}
entity *get_array_element_entity (type *array) {
assert(array && (array->type_op == type_array));
......@@ -617,12 +695,18 @@ bool is_array_type (type *array) {
/* create a new type enumeration -- set the enumerators independently */
type *new_type_enumeration (ident *name, int n_enums) {
type *res;
int i;
res = new_type(type_enumeration, NULL, name);
res->attr.ea.n_enums = n_enums;
res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
for (i = 0; i < n_enums; i++) {
res->attr.ea.enumer[i] = NULL;
res->attr.ea.enum_nameid = NULL;
}
return res;
}
inline void free_enumeration_attrs(type *enumeration) {
assert(enumeration && (enumeration->type_op == type_enumeration));
free(enumeration->attr.ea.enumer);
......@@ -717,15 +801,22 @@ inline void free_primitive_attrs (type *primitive) {
/* typecheck */
bool is_primitive_type (type *primitive) {
assert(primitive);
assert(primitive && primitive->kind == k_type);
if (primitive->type_op == type_primitive) return 1; else return 0;
}
int is_atomic_type(type *tp) {
/*******************************************************************/
/** common functionality **/
/*******************************************************************/
inline int is_atomic_type(type *tp) {
assert(tp && tp->kind == k_type);
return (is_primitive_type(tp) || is_pointer_type(tp) ||
is_enumeration_type(tp));
}
int is_compound_type(type *tp) {
inline int is_compound_type(type *tp) {
assert(tp && tp->kind == k_type);
return (is_class_type(tp) || is_struct_type(tp) ||
is_array_type(tp) || is_union_type(tp));
}
......@@ -39,6 +39,7 @@
# include "irmode.h"
# include "bool.h"
#ifndef _ENTITY_TYPEDEF_
#define _ENTITY_TYPEDEF_
/* to resolve recursion between entity.h and type.h */
......@@ -105,6 +106,8 @@ typedef struct ir_node ir_node;
*/
typedef struct type type;
# include "type_or_entity.h"
void* get_type_link(type *tp);
void set_type_link(type *tp, void *l);
tp_op* get_type_tpop(type *tp);
......@@ -112,7 +115,9 @@ ident* get_type_tpop_nameid(type *tp);
const char* get_type_tpop_name(type *tp);
tp_opcode get_type_tpop_code(type *tp);
/* Returns NULL for all non atomic types. */
ir_mode* get_type_mode(type *tp);
/* Only has an effect on primitive and enumeration types */
void set_type_mode(type *tp, ir_mode* m);
ident* get_type_ident(type *tp);
......@@ -120,8 +125,8 @@ void set_type_ident(type *tp, ident* id);
const char* get_type_name(type *tp);
int get_type_size(type *tp);
/* For primitives and pointer types the size is always fixed.
This call is legal but has no effect. */
/* For primitives, enumerationsm, pointer and method types the size
is always fixed. This call is legal but has no effect. */
void set_type_size(type *tp, int size);
typedef enum {
......@@ -138,7 +143,7 @@ typedef enum {
} type_state;
type_state get_type_state(type *tp);
/* For primitives and pointer types the layout is always fixed.
/* For primitives, pointer and method types the layout is always fixed.
This call is legal but has no effect. */
void set_type_state(type *tp, type_state state);
......@@ -215,6 +220,11 @@ entity *get_class_member (type *clss, int pos);
/* Overwrites the member at position pos, 0 <= pos < n_member with
the passed entity. */
void set_class_member (type *clss, entity *member, int pos);
/* Replaces complete member list in class type by the list passed. Copies the
list passed. This function is necessary to reduce the number of members.
members is an array of entities, num the size of this array. Sets all
owners of the members passed to clss. */
void set_class_members (type *clss, entity **members, int arity);
/* Finds member in the list of members and overwrites it with NULL
@@@ Doesn't work properly. */
void remove_class_member(type *clss, entity *member);
......@@ -396,8 +406,10 @@ void set_union_delim_nameid (type *uni, int pos, ident *id);
* SOURCE
*/
/* create a new type array --
Set dimension sizes after call to constructor with set_* routines.
Entity for array elements is built automatically. */
Sets n_dimension to dimension and all dimension entries to NULL.
Initializes order to the order of the dimensions.
Entity for array elements is built automatically.
Set dimension sizes after call to constructor with set_* routines. */
type *new_type_array (ident *name, int n_dimensions,
type *element_type);
......@@ -413,6 +425,9 @@ void set_array_upper_bound (type *array, int dimension, ir_node *upper_bound);
ir_node * get_array_lower_bound (type *array, int dimension);
ir_node * get_array_upper_bound (type *array, int dimension);
void set_array_order (type *array, int dimension, int order);
int get_array_order (type *array, int dimension);
void set_array_element_type (type *array, type *type);
type *get_array_element_type (type *array);
......
......@@ -56,6 +56,7 @@ 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. */
type *element_type; /* The type of the array elements. */
entity *element_ent; /* Entity for the array elements, to be used for
element selection with Sel. */
......@@ -74,9 +75,9 @@ typedef struct {
} ptr_attr;
/*
typedef struct { * No private attr yet. *
} pri_attr;
*/
typedef struct { * No private attr yet! *
} pri_attr; */
/*
typedef struct { * No private attr, must be smaller than others! *
......@@ -97,13 +98,13 @@ typedef union {
struct type {
firm_kind kind;
tp_op *type_op;
ir_mode *mode;
ident *name;
type_state state; /* Represents the types state: layout undefined or
fixed. */
int size; /* Size of an entity of this type. This is determined
when fixing the layout of this class. Size must be
given in bytes. */
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 */
tp_attr attr; /* type kind specific fields. This must be the last
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment