/* All this is needed to build the constant node for methods: */
# include "irprog_t.h"
# include "ircons.h"
+# include "tv_t.h"
/*******************************************************************/
/** general **/
assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
- res = (entity *) malloc (sizeof (entity));
+ res = (entity *) xmalloc (sizeof (entity));
res->kind = k_entity;
assert_legal_owner_of_ent(owner);
res->owner = owner;
res->variability = constant;
rem = current_ir_graph;
current_ir_graph = get_const_code_irg();
- res->value = new_Const(mode_P, tarval_P_from_entity(res));
+ res->value = new_Const(mode_P_mach, new_tarval_from_entity(res, mode_P_mach));
current_ir_graph = rem;
} else {
res->variability = uninitialized;
assert_legal_owner_of_ent(new_owner);
if (old->owner == new_owner) return old;
- new = (entity *) malloc (sizeof (entity));
+ new = (entity *) xmalloc (sizeof (entity));
memcpy (new, old, sizeof (entity));
new->owner = new_owner;
/*
entity *new;
if (old->name == new_name) return old;
- new = (entity *) malloc (sizeof (entity));
+ new = (entity *) xmalloc (sizeof (entity));
memcpy (new, old, sizeof (entity));
new->name = new_name;
new->ld_name = NULL;
void
free_entity (entity *ent) {
- free_tv_entity(ent);
+ free_tarval_entity(ent);
free_entity_attrs(ent);
free(ent);
}
ent->allocation = al;
}
+/* return the name of the visibility */
+const char *get_allocation_name(ent_allocation all)
+{
+#define X(a) case a: return #a
+ switch (all) {
+ X(automatic_allocated);
+ X(parameter_allocated);
+ X(dynamic_allocated);
+ X(static_allocated);
+ default: return "BAD VALUE";
+ }
+#undef X
+}
+
INLINE ent_visibility
get_entity_visibility (entity *ent) {
if (vis != local)
assert((ent->allocation == static_allocated) ||
(ent->allocation == automatic_allocated));
- // @@@ Test that the owner type is not local, but how??
- // && get_class_visibility(get_entity_owner(ent)) != local));
+ /* @@@ Test that the owner type is not local, but how??
+ && get_class_visibility(get_entity_owner(ent)) != local));*/
ent->visibility = vis;
}
+/* return the name of the visibility */
+const char *get_visibility_name(ent_visibility vis)
+{
+#define X(a) case a: return #a
+ switch (vis) {
+ X(local);
+ X(external_visible);
+ X(external_allocated);
+ default: return "BAD VALUE";
+ }
+#undef X
+}
+
INLINE ent_variability
get_entity_variability (entity *ent) {
return ent->variability;
(ent->variability == uninitialized) && (var != uninitialized)) {
/* Allocate datastructures for constant values */
ent->values = NEW_ARR_F(ir_node *, 1);
- ent->val_ents = NEW_ARR_F(entity *, 1);
+ ent->val_paths = NEW_ARR_F(compound_graph_path *, 1);
}
if ((is_compound_type(ent->type)) &&
(var == uninitialized) && (ent->variability != uninitialized)) {
/* Free datastructures for constant values */
DEL_ARR_F(ent->values);
- DEL_ARR_F(ent->val_ents);
+ DEL_ARR_F(ent->val_paths);
}
ent->variability = var;
}
+/* return the name of the variablity */
+const char *get_variability_name(ent_variability var)
+{
+#define X(a) case a: return #a
+ switch (var) {
+ X(uninitialized);
+ X(initialized);
+ X(part_constant);
+ X(constant);
+ default: return "BAD VALUE";
+ }
+#undef X
+}
INLINE ent_volatility
get_entity_volatility (entity *ent) {
ent->volatility = vol;
}
+/* return the name of the volatility */
+const char *get_volatility_name(ent_volatility var)
+{
+#define X(a) case a: return #a
+ switch (var) {
+ X(non_volatile);
+ X(is_volatile);
+ default: return "BAD VALUE";
+ }
+#undef X
+}
+
INLINE peculiarity
get_entity_peculiarity (entity *ent) {
assert (ent);
ent->peculiarity = pec;
}
-/* Set has no effect for entities of type method. */
+/* return the name of the peculiarity */
+const char *get_peculiarity_name(peculiarity var)
+{
+#define X(a) case a: return #a
+ switch (var) {
+ X(description);
+ X(inherited);
+ X(existent);
+ default: return "BAD VALUE";
+ }
+#undef X
+}
+
+/* Set has no effect for existent entities of type method. */
INLINE ir_node *
get_atomic_ent_value(entity *ent) {
assert(ent); assert(is_atomic_entity(ent));
INLINE void
set_atomic_ent_value(entity *ent, ir_node *val) {
assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized));
- if (is_method_type(ent->type)) return;
+ if ((is_method_type(ent->type)) && (ent->peculiarity==existent)) return;
ent->value = val;
}
case iro_Add:
nn = new_Add(copy_const_value(get_Add_left(n)), copy_const_value(get_Add_right(n)), m); break;
default:
- assert(0 && "opdope invalid or not implemented"); break;
+ assert(0 && "opdope invalid or not implemented");
+ nn=NULL;
+ break;
}
return nn;
}
-/* A value of a compound entity is a pair of value and the corresponding member of
+compound_graph_path *
+new_compound_graph_path(type *tp, int length) {
+ compound_graph_path *res;
+ assert(is_type(tp) && is_compound_type(tp));
+ assert(length > 0);
+
+ res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
+ res->kind = k_ir_compound_graph_path;
+ res->tp = tp;
+ res->len = length;
+ memset(res->nodes, 0, sizeof(entity *) * length);
+ return res;
+}
+
+INLINE void
+free_compound_graph_path (compound_graph_path *gr) {
+ assert(gr && is_compound_graph_path(gr));
+ free(gr);
+}
+
+INLINE int
+is_compound_graph_path(void *thing) {
+ return (get_kind(thing) == k_ir_compound_graph_path);
+}
+
+/* checks whether nodes 0..pos are correct (all lie on a path.) */
+/* @@@ not implemented */
+INLINE int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
+ int i;
+ entity *node;
+ type *owner = gr->tp;
+ for (i = 0; i <= pos; i++) {
+ node = get_compound_graph_path_node(gr, i);
+ if (get_entity_owner(node) != owner) return false;
+ owner = get_entity_type(node);
+ }
+ if (pos == get_compound_graph_path_length(gr) -1)
+ if (!is_atomic_type(owner)) return false;
+ return true;
+}
+
+INLINE int
+get_compound_graph_path_length(compound_graph_path *gr) {
+ assert(gr && is_compound_graph_path(gr));
+ return gr->len;
+}
+
+INLINE entity *
+get_compound_graph_path_node(compound_graph_path *gr, int pos) {
+ assert(gr && is_compound_graph_path(gr));
+ assert(pos >= 0 && pos < gr->len);
+ return gr->nodes[pos];
+}
+
+INLINE void
+set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
+ assert(gr && is_compound_graph_path(gr));
+ assert(pos >= 0 && pos < gr->len);
+ assert(is_entity(node));
+ gr->nodes[pos] = node;
+ assert(is_proper_compound_graph_path(gr, pos));
+}
+
+/* A value of a compound entity is a pair of value and the corresponding path to a member of
the compound. */
INLINE void
-add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
+add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
ARR_APP1 (ir_node *, ent->values, val);
- ARR_APP1 (entity *, ent->val_ents, member);
+ ARR_APP1 (compound_graph_path *, ent->val_paths, path);
+}
+
+INLINE void
+set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ ent->values[pos+1] = val;
+ ent->val_paths[pos+1] = path;
+}
+
+INLINE int
+get_compound_ent_n_values(entity *ent) {
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ return (ARR_LEN (ent->values))-1;
+}
+
+INLINE ir_node *
+get_compound_ent_value(entity *ent, int pos) {
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ return ent->values[pos+1];
+}
+
+INLINE compound_graph_path *
+get_compound_ent_value_path(entity *ent, int pos) {
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ return ent->val_paths[pos+1];
+}
+
+void
+remove_compound_ent_value(entity *ent, entity *value_ent) {
+ int i;
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ for (i = 1; i < (ARR_LEN (ent->val_paths)); i++) {
+ compound_graph_path *path = ent->val_paths[i];
+ if (path->nodes[path->len] == value_ent) {
+ for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
+ ent->val_paths[i] = ent->val_paths[i+1];
+ ent->values[i] = ent->values[i+1];
+ }
+ ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1);
+ ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
+ break;
+ }
+ }
+}
+
+INLINE void
+add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
+ assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ compound_graph_path *path = new_compound_graph_path(get_entity_owner(ent), 1);
+ path->nodes[0] = member;
+ add_compound_ent_value_w_path(ent, val, path);
}
/* Copies the firm subgraph referenced by val to const_code_irg and adds
current_ir_graph = rem;
}*/
-INLINE int
-get_compound_ent_n_values(entity *ent) {
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
- return (ARR_LEN (ent->values))-1;
-}
-
-INLINE ir_node *
-get_compound_ent_value(entity *ent, int pos) {
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
- return ent->values[pos+1];
-}
-
/* Copies the value i of the entity to current_block in current_ir_graph.
ir_node *
copy_compound_ent_value(entity *ent, int pos) {
INLINE entity *
get_compound_ent_value_member(entity *ent, int pos) {
+ compound_graph_path *path;
assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
- return ent->val_ents[pos+1];
+ path = get_compound_ent_value_path(ent, pos);
+ assert(path->len == 1);
+
+ return get_compound_graph_path_node(path, 0);
}
INLINE void
set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
+ compound_graph_path *path;
assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
- ent->values[pos+1] = val;
- ent->val_ents[pos+1] = member;
-}
-
-void
-remove_compound_ent_value(entity *ent, entity *value_ent) {
- int i;
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
- for (i = 1; i < (ARR_LEN (ent->val_ents)); i++) {
- if (ent->val_ents[i] == value_ent) {
- for(; i < (ARR_LEN (ent->val_ents))-1; i++) {
- ent->val_ents[i] = ent->val_ents[i+1];
- ent->values[i] = ent->values[i+1];
- }
- ARR_SETLEN(entity*, ent->val_ents, ARR_LEN(ent->val_ents) - 1);
- ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
- break;
- }
- }
+ path = new_compound_graph_path(get_entity_owner(ent), 1);
+ set_compound_graph_path_node(path, 0, member);
+ set_compound_ent_value_w_path(ent, val, path, pos);
}
void
current_ir_graph = get_const_code_irg();
for (i = 0; i < num_vals; i++) {
- val = new_Const(get_tv_mode (values[i]), values[i]);
+ val = new_Const(get_tarval_mode (values[i]), values[i]);
add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
}
current_ir_graph = rem;