-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-* All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer
-*
-*/
-
-/* $Id$ */
+/*
+ * Project: libFIRM
+ * File name: ir/tr/entity.c
+ * Purpose: Representation of all program known entities.
+ * Author: Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier
+ * Created:
+ * CVS-ID: $Id$
+ * Copyright: (c) 1998-2003 Universität Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ */
#ifdef HAVE_CONFIG_H
# include <config.h>
# include "entity_t.h"
# include "mangle.h"
-# include "typegmod_t.h"
+# include "typegmod.h"
# include "array.h"
/* All this is needed to build the constant node for methods: */
# include "irprog_t.h"
res->owner = owner;
res->name = name;
res->type = type;
+
if (get_type_tpop(type) == type_method)
- res->allocation = static_allocated;
+ res->allocation = allocation_static;
else
- res->allocation = automatic_allocated;
- res->visibility = local;
+ res->allocation = allocation_automatic;
+
+ res->visibility = visibility_local;
res->offset = -1;
if (is_method_type(type)) {
- res->variability = constant;
+ res->variability = variability_constant;
rem = current_ir_graph;
current_ir_graph = get_const_code_irg();
res->value = new_Const(mode_P_mach, new_tarval_from_entity(res, mode_P_mach));
current_ir_graph = rem;
} else {
- res->variability = uninitialized;
- res->value = NULL;
+ res->variability = variability_uninitialized;
+ res->value = NULL;
res->values = NULL;
}
- res->peculiarity = existent;
- res->volatility = non_volatile;
- res->ld_name = NULL;
- res->overwrites = NEW_ARR_F(entity *, 1);
+ res->peculiarity = peculiarity_existent;
+ res->volatility = volatility_non_volatile;
+ res->ld_name = NULL;
+ res->overwrites = NEW_ARR_F(entity *, 1);
res->overwrittenby = NEW_ARR_F(entity *, 1);
res->irg = NULL;
free_entity (entity *ent) {
free_tarval_entity(ent);
free_entity_attrs(ent);
+ ent->kind = k_BAD;
free(ent);
}
{
#define X(a) case a: return #a
switch (all) {
- X(automatic_allocated);
- X(parameter_allocated);
- X(dynamic_allocated);
- X(static_allocated);
+ X(allocation_automatic);
+ X(allocation_parameter);
+ X(allocation_dynamic);
+ X(allocation_static);
default: return "BAD VALUE";
}
#undef X
INLINE void
set_entity_visibility (entity *ent, ent_visibility vis) {
- if (vis != local)
- assert((ent->allocation == static_allocated) ||
- (ent->allocation == automatic_allocated));
+ if (vis != visibility_local)
+ assert((ent->allocation == allocation_static) ||
+ (ent->allocation == allocation_automatic));
/* @@@ Test that the owner type is not local, but how??
&& get_class_visibility(get_entity_owner(ent)) != local));*/
ent->visibility = vis;
{
#define X(a) case a: return #a
switch (vis) {
- X(local);
- X(external_visible);
- X(external_allocated);
+ X(visibility_local);
+ X(visibility_external_visible);
+ X(visibility_external_allocated);
default: return "BAD VALUE";
}
#undef X
}
INLINE void
-set_entity_variability (entity *ent, ent_variability var){
- if (var == part_constant)
+set_entity_variability (entity *ent, ent_variability var)
+{
+ if (var == variability_part_constant)
assert(is_class_type(ent->type) || is_struct_type(ent->type));
+
if ((is_compound_type(ent->type)) &&
- (ent->variability == uninitialized) && (var != uninitialized)) {
+ (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
/* Allocate datastructures for constant values */
ent->values = NEW_ARR_F(ir_node *, 1);
ent->val_paths = NEW_ARR_F(compound_graph_path *, 1);
}
+
if ((is_compound_type(ent->type)) &&
- (var == uninitialized) && (ent->variability != uninitialized)) {
+ (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
/* Free datastructures for constant values */
DEL_ARR_F(ent->values);
DEL_ARR_F(ent->val_paths);
{
#define X(a) case a: return #a
switch (var) {
- X(uninitialized);
- X(initialized);
- X(part_constant);
- X(constant);
+ X(variability_uninitialized);
+ X(variability_initialized);
+ X(variability_part_constant);
+ X(variability_constant);
default: return "BAD VALUE";
}
#undef X
{
#define X(a) case a: return #a
switch (var) {
- X(non_volatile);
- X(is_volatile);
+ X(volatility_non_volatile);
+ X(volatility_is_volatile);
default: return "BAD VALUE";
}
#undef X
{
#define X(a) case a: return #a
switch (var) {
- X(description);
- X(inherited);
- X(existent);
+ X(peculiarity_description);
+ X(peculiarity_inherited);
+ X(peculiarity_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));
- assert((ent->variability != uninitialized));
+get_atomic_ent_value(entity *ent)
+{
+ assert(ent);
+ assert(is_atomic_entity(ent));
+ assert(ent->variability != variability_uninitialized);
return ent->value;
}
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)) && (ent->peculiarity==existent)) return;
+ assert(ent && is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
+ if (is_method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
+ return;
ent->value = val;
}
+/* Returns true if the the node is representable as code on
+ * const_code_irg. */
+int is_irn_const_expression(ir_node *n) {
+ ir_mode *m;
+
+ m = get_irn_mode(n);
+ switch(get_irn_opcode(n)) {
+ case iro_Const:
+ case iro_SymConst:
+ case iro_Unknown:
+ return true; break;
+ case iro_Add:
+ if (is_irn_const_expression(get_Add_left(n)))
+ return is_irn_const_expression(get_Add_right(n));
+ case iro_Conv:
+ case iro_Cast:
+ return is_irn_const_expression(get_irn_n(n, 0));
+ default:
+ return false;
+ break;
+ }
+ return false;
+}
+
ir_node *copy_const_value(ir_node *n) {
ir_node *nn;
case iro_SymConst:
nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
case iro_Add:
- nn = new_Add(copy_const_value(get_Add_left(n)), copy_const_value(get_Add_right(n)), m); break;
+ nn = new_Add(copy_const_value(get_Add_left(n)),
+ copy_const_value(get_Add_right(n)), m); break;
+ case iro_Cast:
+ nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break;
+ case iro_Conv:
+ nn = new_Conv(copy_const_value(get_Conv_op(n)), m); break;
case iro_Unknown:
- nn = new_Unknown(); break;
+ nn = new_Unknown(m); break;
default:
DDMN(n);
assert(0 && "opdope invalid or not implemented");
INLINE void
free_compound_graph_path (compound_graph_path *gr) {
assert(gr && is_compound_graph_path(gr));
+ gr->kind = k_BAD;
free(gr);
}
the compound. */
INLINE void
add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ assert(ent && is_compound_entity(ent) && (ent->variability != variability_uninitialized));
ARR_APP1 (ir_node *, ent->values, val);
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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != 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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != 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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != 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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != 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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != 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-1] == value_ent) {
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);
+ compound_graph_path *path;
+ assert(ent && is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ path = new_compound_graph_path(get_entity_owner(ent), 1);
path->nodes[0] = member;
add_compound_ent_value_w_path(ent, val, path);
}
copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
ir_graph *rem = current_ir_graph;
- assert(get_entity_variability(ent) != uninitialized);
+ assert(get_entity_variability(ent) != variability_uninitialized);
current_ir_graph = get_const_code_irg();
val = copy_const_value(val);
/* Copies the value i of the entity to current_block in current_ir_graph.
ir_node *
copy_compound_ent_value(entity *ent, int pos) {
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ assert(ent && is_compound_entity(ent) && (ent->variability != variability_uninitialized));
return copy_const_value(ent->values[pos+1]);
}*/
INLINE entity *
get_compound_ent_value_member(entity *ent, int pos) {
compound_graph_path *path;
- assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
+ assert(ent && is_compound_entity(ent) && (ent->variability != variability_uninitialized));
path = get_compound_ent_value_path(ent, pos);
- assert(path->len == 1);
return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
}
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));
+ assert(ent && is_compound_entity(ent) && (ent->variability != variability_uninitialized));
path = get_compound_ent_value_path(ent, pos);
set_compound_graph_path_node(path, 0, member);
set_compound_ent_value_w_path(ent, val, path, pos);
/* One bound is sufficient, the nunmber of constant fields makes the
size. */
assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
- assert(get_entity_variability(ent) != uninitialized);
+ assert(get_entity_variability(ent) != variability_uninitialized);
current_ir_graph = get_const_code_irg();
for (i = 0; i < num_vals; i++) {
* aber erhalten bleiben soll. */
/* assert (irg); */
assert (is_method_type(ent->type));
- assert (ent->peculiarity == existent);
+ assert (ent->peculiarity == peculiarity_existent);
ent->irg = irg;
}
INLINE bool entity_visited(entity *ent) {
return get_entity_visited(ent) >= type_visited;
}
+
INLINE bool entity_not_visited(entity *ent) {
return get_entity_visited(ent) < type_visited;
}