Commit 274626e2 authored by Matthias Braun's avatar Matthias Braun
Browse files

make unique types/entities part of irprog

unknown_type, code_type, none_type, unknown_entity reference are hold in
the irprog now. This makes handling more consistent since now all types
and entities are equally part of irprog.
parent a276562e
......@@ -44,17 +44,14 @@
#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 */
/*-----------------------------------------------------------------*/
......@@ -62,9 +59,7 @@ ir_entity *get_unknown_entity(void) { return unknown_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;
......@@ -161,7 +156,7 @@ ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi)
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);
......@@ -285,7 +280,9 @@ void free_entity(ir_entity *ent)
assert(ent && ent->kind == k_entity);
free_entity_attrs(ent);
#ifdef DEBUG_libfirm
ent->kind = k_BAD;
#endif
xfree(ent);
}
......@@ -364,7 +361,7 @@ void set_entity_type(ir_entity *ent, ir_type *type)
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;
......@@ -1079,26 +1076,19 @@ int entity_has_definition(const ir_entity *entity)
|| entity_has_compound_ent_values(entity);
}
void ir_init_entity(void)
void ir_init_entity(ir_prog *irp)
{
ident *id = new_id_from_str(UNKNOWN_ENTITY_NAME);
assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
assert(!unknown_entity && "Call firm_init_entity() only once!");
unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id,
firm_unknown_type, NULL);
set_entity_visibility(unknown_entity, ir_visibility_external);
set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
hook_new_entity(unknown_entity);
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)
......
......@@ -181,9 +181,9 @@ struct ir_entity {
};
/** Initialize the entity module. */
void ir_init_entity(void);
void ir_init_entity(ir_prog *irp);
/** Cleanup entity module */
void ir_finish_entity(void);
void ir_finish_entity(ir_prog *irp);
/**
* Creates an entity corresponding to the start address of a basic block
......@@ -359,7 +359,7 @@ static inline void _set_entity_link(ir_entity *ent, void *l)
static inline ir_graph *_get_entity_irg(const ir_entity *ent)
{
assert(ent && ent->kind == k_entity);
if (!is_Method_type(ent->type) || ent == unknown_entity) {
if (!is_Method_type(ent->type) || is_unknown_entity(ent)) {
return NULL;
}
......
......@@ -59,56 +59,45 @@
#include "entity_t.h"
#include "error.h"
#include "dbginfo.h"
#include "irprog_t.h"
#include "array.h"
ir_type *firm_none_type;
ir_type *get_none_type(void)
{
return firm_none_type;
return irp->none_type;
}
ir_type *firm_code_type;
ir_type *get_code_type(void)
{
return firm_code_type;
return irp->code_type;
}
ir_type *firm_unknown_type;
ir_type *get_unknown_type(void)
{
return firm_unknown_type;
return irp->unknown_type;
}
void ir_init_type(void)
void ir_init_type(ir_prog *irp)
{
/* construct none and unknown type. */
firm_none_type = new_type(tpop_none, mode_BAD, NULL);
set_type_size_bytes(firm_none_type, 0);
set_type_state (firm_none_type, layout_fixed);
irp->none_type = new_type(tpop_none, mode_BAD, NULL);
set_type_size_bytes(irp->none_type, 0);
set_type_state (irp->none_type, layout_fixed);
firm_code_type = new_type(tpop_code, mode_ANY, NULL);
set_type_state(firm_code_type, layout_fixed);
irp->code_type = new_type(tpop_code, mode_ANY, NULL);
set_type_state(irp->code_type, layout_fixed);
firm_unknown_type = new_type(tpop_unknown, mode_ANY, NULL);
set_type_size_bytes(firm_unknown_type, 0);
set_type_state (firm_unknown_type, layout_fixed);
irp->unknown_type = new_type(tpop_unknown, mode_ANY, NULL);
set_type_size_bytes(irp->unknown_type, 0);
set_type_state (irp->unknown_type, layout_fixed);
}
void ir_finish_type(void)
void ir_finish_type(ir_prog *irp)
{
if (firm_none_type != NULL) {
free_type(firm_none_type);
firm_none_type = NULL;
}
if (firm_code_type != NULL) {
free_type(firm_code_type);
firm_code_type = NULL;
}
if (firm_unknown_type != NULL) {
free_type(firm_unknown_type);
firm_unknown_type = NULL;
}
/** nothing todo. (The none, code, unknown types are in the global type list
* and freed there */
(void)irp;
}
ir_visited_t firm_type_visited;
......@@ -160,9 +149,6 @@ void free_type(ir_type *tp)
{
const tp_op *op = get_type_tpop(tp);
if ((get_type_tpop(tp) == tpop_none) || (get_type_tpop(tp) == tpop_unknown)
|| (get_type_tpop(tp) == tpop_code))
return;
/* Remove from list of all types */
remove_irp_type(tp);
/* Free the attributes of the type. */
......@@ -171,7 +157,9 @@ void free_type(ir_type *tp)
if (op->ops.free_auto_entities)
op->ops.free_auto_entities(tp);
/* And now the type itself... */
#ifdef DEBUG_libfirm
tp->kind = k_BAD;
#endif
free(tp);
}
......@@ -1821,11 +1809,10 @@ ir_type *find_pointer_type_to_type(ir_type *tp)
if (is_Pointer_type(found) && get_pointer_points_to_type(found) == tp)
return (found);
}
return firm_unknown_type;
return get_unknown_type();
}
ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info *db)
{
ir_type *res = new_type(type_primitive, mode, db);
......
......@@ -236,10 +236,10 @@ int get_class_dfn(const ir_type *clss);
void add_compound_member(ir_type *compound, ir_entity *entity);
/** Initialize the type module. */
void ir_init_type(void);
void ir_init_type(ir_prog *irp);
/** free internal datastructures of type module */
void ir_finish_type(void);
void ir_finish_type(ir_prog *irp);
/** Clone an existing method type.
*
......
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