#include "irgraph_t.h"
#include "callgraph.h"
#include "error.h"
-#include "compound_path.h"
-
-/*-----------------------------------------------------------------*/
-/** general **/
-/*-----------------------------------------------------------------*/
-
-ir_entity *unknown_entity = NULL;
-
-ir_entity *get_unknown_entity(void) { return unknown_entity; }
/** The name of the unknown entity. */
#define UNKNOWN_ENTITY_NAME "unknown_entity"
+ir_entity *get_unknown_entity(void)
+{
+ return irp->unknown_entity;
+}
+
/*-----------------------------------------------------------------*/
/* ENTITY */
/*-----------------------------------------------------------------*/
static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
ident *name, ir_type *type, dbg_info *dbgi)
{
- ir_entity *res;
-
- res = XMALLOCZ(ir_entity);
+ ir_entity *res = XMALLOCZ(ir_entity);
res->kind = k_entity;
res->name = name;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->compiler_gen = 0;
- res->visibility = ir_visibility_default;
+ res->visibility = ir_visibility_external;
res->offset = -1;
res->offset_bit_remainder = 0;
res->alignment = 0;
} else if (owner != NULL
&& (is_compound_type(owner) && !(owner->flags & tf_segment))) {
res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type, db);
- res->attr.cmpd_attr.values = NULL;
- res->attr.cmpd_attr.val_paths = NULL;
} else {
res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, db);
}
ident *name = id_unique("label_%u");
ir_type *global_type = get_glob_type();
ir_entity *res
- = intern_new_entity(global_type, IR_ENTITY_LABEL, name, firm_code_type,
+ = intern_new_entity(global_type, IR_ENTITY_LABEL, name, get_code_type(),
dbgi);
res->attr.code_attr.label = label;
hook_new_entity(res);
if (ent->initializer != NULL) {
/* TODO: free initializers */
- } else if (entity_has_compound_ent_values(ent)) {
- /* can't free compound graph path as it might be used
- * multiple times */
- ent->attr.cmpd_attr.val_paths = NULL;
}
- if (ent->entity_kind == IR_ENTITY_COMPOUND_MEMBER) {
- ent->attr.cmpd_attr.values = NULL;
- } else if (ent->entity_kind == IR_ENTITY_METHOD) {
+ if (ent->entity_kind == IR_ENTITY_METHOD) {
if (ent->attr.mtd_attr.param_access) {
DEL_ARR_F(ent->attr.mtd_attr.param_access);
ent->attr.mtd_attr.param_access = NULL;
*newe = *old;
if (old->initializer != NULL) {
/* FIXME: the initializers are NOT copied */
- } else if (entity_has_compound_ent_values(old)) {
- newe->attr.cmpd_attr.values = NULL;
- newe->attr.cmpd_attr.val_paths = NULL;
- if (old->attr.cmpd_attr.values)
- newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
-
- /* FIXME: the compound graph paths are NOT copied */
- if (old->attr.cmpd_attr.val_paths)
- newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
} else if (is_method_entity(old)) {
/* do NOT copy them, reanalyze. This might be the best solution */
newe->attr.mtd_attr.param_access = NULL;
return newe;
}
-/*
- * Copies the entity if the new_owner is different from the
- * owner of the old entity, else returns the old entity.
- */
ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
{
ir_entity *newe;
assert(ent && ent->kind == k_entity);
free_entity_attrs(ent);
+#ifdef DEBUG_libfirm
ent->kind = k_BAD;
+#endif
xfree(ent);
}
-/* Outputs a unique number for this node */
long get_entity_nr(const ir_entity *ent)
{
assert(ent && ent->kind == k_entity);
assert(!is_Method_type(type));
break;
case IR_ENTITY_LABEL:
- assert(type == firm_code_type);
+ assert(type == get_code_type());
break;
case IR_ENTITY_COMPOUND_MEMBER:
break;
_set_entity_volatility(ent, vol);
}
-/* Return the name of the volatility. */
const char *get_volatility_name(ir_volatility var)
{
#define X(a) case a: return #a
_set_entity_alignment(ent, alignment);
}
-/* Return the name of the alignment. */
const char *get_align_name(ir_align a)
{
#define X(a) case a: return #a
return ent->attr.code_attr.label;
}
-static void verify_visibility(const ir_entity *entity)
-{
- if (get_entity_visibility(entity) == ir_visibility_external
- && !is_method_entity(entity)) {
- assert(!entity_has_definition(entity));
- }
-}
-
void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
{
entity->visibility = visibility;
- verify_visibility(entity);
}
ir_visibility get_entity_visibility(const ir_entity *entity)
entity->linkage &= ~linkage;
}
-/* Checks if an entity is compiler generated */
int (is_entity_compiler_generated)(const ir_entity *ent)
{
return _is_entity_compiler_generated(ent);
}
-/* Sets/resets the compiler generated flag */
void (set_entity_compiler_generated)(ir_entity *ent, int flag)
{
_set_entity_compiler_generated(ent, flag);
_set_entity_usage(ent, flags);
}
-/* Set has no effect for existent entities of type method. */
-ir_node *get_atomic_ent_value(ir_entity *entity)
+ir_node *get_atomic_ent_value(const ir_entity *entity)
{
ir_initializer_t *initializer = get_entity_initializer(entity);
panic("compound initializer in atomic entity not allowed (%+F)", entity);
}
- panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
+ panic("invalid initializer kind (%+F)", entity);
}
void set_atomic_ent_value(ir_entity *entity, ir_node *val)
entity->initializer = initializer;
}
-/* Returns true if the the node is representable as code on
- * const_code_irg. */
int is_irn_const_expression(ir_node *n)
{
/* we are in danger iff an exception will arise. TODO: be more precisely,
return 0;
}
-/*
- * Copies a firm subgraph that complies to the restrictions for
- * constant expressions to block.
- */
ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
{
ir_graph *irg = get_irn_irg(block);
nn = new_rd_Conv(dbg, block,
copy_const_value(dbg, get_Conv_op(n), block), m);
break;
+ case iro_Minus:
+ nn = new_rd_Minus(dbg, block,
+ copy_const_value(dbg, get_Minus_op(n), block), m);
+ break;
+ case iro_Not:
+ nn = new_rd_Not(dbg, block,
+ copy_const_value(dbg, get_Not_op(n), block), m);
+ break;
case iro_Unknown:
nn = new_r_Unknown(irg, m); break;
default:
- panic("opcode invalid or not implemented");
+ panic("opcode invalid or not implemented %+F", n);
}
return nn;
}
-/** Return the name of the initializer kind. */
const char *get_initializer_kind_name(ir_initializer_kind_t ini)
{
#define X(a) case a: return #a
ent->attr.mtd_attr.vtable_number = vtable_number;
}
+int is_unknown_entity(const ir_entity *entity)
+{
+ return entity->entity_kind == IR_ENTITY_UNKNOWN;
+}
+
int (is_entity)(const void *thing)
{
return _is_entity(thing);
}
}
-/* Returns the class type that this type info entity represents or NULL
- if ent is no type info entity. */
ir_type *(get_entity_repr_class)(const ir_entity *ent)
{
return _get_entity_repr_class(ent);
int entity_has_definition(const ir_entity *entity)
{
- return entity->initializer != NULL
- || get_entity_irg(entity) != NULL
- || entity_has_compound_ent_values(entity);
+ if (is_method_entity(entity)) {
+ return get_entity_irg(entity) != NULL
+ && (get_entity_linkage(entity) & IR_LINKAGE_NO_CODEGEN) == 0;
+ } else {
+ return entity->initializer != NULL;
+ }
}
-void ir_init_entity(void)
+void ir_init_entity(ir_prog *irp)
{
- assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
- assert(!unknown_entity && "Call firm_init_entity() only once!");
-
- unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
- firm_unknown_type, NULL);
- set_entity_visibility(unknown_entity, ir_visibility_external);
- set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
+ ident *id = new_id_from_str(UNKNOWN_ENTITY_NAME);
+ irp->unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id,
+ irp->unknown_type, NULL);
+ set_entity_visibility(irp->unknown_entity, ir_visibility_external);
+ set_entity_ld_ident(irp->unknown_entity, id);
+ hook_new_entity(irp->unknown_entity);
}
-void ir_finish_entity(void)
+void ir_finish_entity(ir_prog *irp)
{
- if (unknown_entity != NULL) {
- free_entity(unknown_entity);
- unknown_entity = NULL;
- }
+ free_entity(irp->unknown_entity);
}
ir_allocation get_entity_allocation(const ir_entity *entity)