/* ENTITY */
/*-----------------------------------------------------------------*/
-static ir_entity *intern_new_entity(ir_type *owner, ident *name, ir_type *type,
- dbg_info *dbgi)
+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->type = type;
res->owner = owner;
+ res->entity_kind = kind;
res->volatility = volatility_non_volatile;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
dbg_info *db)
{
- ir_entity *res = intern_new_entity(owner, name, type, db);
+ ir_entity *res;
if (is_Method_type(type)) {
ir_graph *irg = get_const_code_irg();
symconst_symbol sym;
ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
+ res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, db);
sym.entity_p = res;
set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
res->linkage = IR_LINKAGE_CONSTANT;
res->attr.mtd_attr.param_access = NULL;
res->attr.mtd_attr.param_weight = NULL;
res->attr.mtd_attr.irg = NULL;
- } else if (is_compound_type(type)) {
+ } 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 if (is_code_type(type)) {
- res->attr.code_attr.label = (ir_label_t) -1;
+ } else {
+ res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, db);
}
hook_new_entity(res);
ir_entity *new_d_parameter_entity(ir_type *owner, size_t pos, ir_type *type,
dbg_info *dbgi)
{
- ident *name = make_parameter_entity_name(pos);
- ir_entity *res = intern_new_entity(owner, name, type, dbgi);
- res->is_parameter = true;
+ ident *name = make_parameter_entity_name(pos);
+ ir_entity *res
+ = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type, dbgi);
res->attr.parameter.number = pos;
hook_new_entity(res);
return res;
return new_d_parameter_entity(owner, pos, type, NULL);
}
+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,
+ dbgi);
+ res->attr.code_attr.label = label;
+ hook_new_entity(res);
+ return res;
+}
+
+ir_entity *new_label_entity(ir_label_t label)
+{
+ return new_d_label_entity(label, NULL);
+}
+
/**
* Free entity attributes.
*
* multiple times */
ent->attr.cmpd_attr.val_paths = NULL;
}
- if (is_compound_entity(ent)) {
+ if (ent->entity_kind == IR_ENTITY_COMPOUND_MEMBER) {
ent->attr.cmpd_attr.values = NULL;
- } else if (is_method_entity(ent)) {
+ } else 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;
return _get_entity_type(ent);
}
-void (set_entity_type)(ir_entity *ent, ir_type *type)
+void set_entity_type(ir_entity *ent, ir_type *type)
{
- _set_entity_type(ent, type);
+ switch (ent->entity_kind) {
+ case IR_ENTITY_METHOD:
+ assert(is_Method_type(type));
+ break;
+ case IR_ENTITY_NORMAL:
+ assert(!is_Method_type(type));
+ break;
+ case IR_ENTITY_LABEL:
+ assert(type == firm_code_type);
+ break;
+ case IR_ENTITY_COMPOUND_MEMBER:
+ break;
+ }
+ ent->type = type;
}
ir_volatility (get_entity_volatility)(const ir_entity *ent)
void set_entity_label(ir_entity *ent, ir_label_t label)
{
+ assert(ent->entity_kind == IR_ENTITY_LABEL);
ent->attr.code_attr.label = label;
}
ir_label_t get_entity_label(const ir_entity *ent)
{
+ assert(ent->entity_kind == IR_ENTITY_LABEL);
return ent->attr.code_attr.label;
}
lowering...) */
} parameter_ent_attr;
+typedef enum ir_entity_kind {
+ IR_ENTITY_NORMAL,
+ IR_ENTITY_METHOD,
+ IR_ENTITY_COMPOUND_MEMBER,
+ IR_ENTITY_PARAMETER,
+ IR_ENTITY_LABEL,
+} ir_entity_kind;
/**
* An abstract data type to represent program entities.
ir_type *type; /**< The type of this entity */
ir_type *owner; /**< The compound type (e.g. class type) this
entity belongs to. */
+ unsigned entity_kind:3; /**< entity kind */
unsigned linkage:10; /**< Specifies linkage type */
unsigned volatility:1; /**< Specifies volatility of entities content.*/
unsigned aligned:1; /**< Specifies alignment of entities content. */
/**< If the entity is a bit field, this is the
offset of the start of the bit field
within the byte specified by offset. */
- unsigned is_parameter:1; /**< 1 if this represents a function parameter */
int offset; /**< Offset in bytes for this entity. Fixed
when layout of owner is determined. */
unsigned alignment; /**< entity alignment in bytes */
/** Cleanup entity module */
void ir_finish_entity(void);
+/**
+ * Creates an entity corresponding to the start address of a basic block
+ * (the basic block is marked with a label id).
+ */
+ir_entity *new_label_entity(ir_label_t label);
+
+/**
+ * Like new_label_entity() but with debug information.
+ */
+ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi);
+
/* ----------------------- inline functions ------------------------ */
static inline int _is_entity(const void *thing)
{
return ent->type;
}
-static inline void _set_entity_type(ir_entity *ent, ir_type *type)
-{
- assert(ent && ent->kind == k_entity);
- ent->type = type;
-}
-
static inline ir_linkage _get_entity_linkage(const ir_entity *ent)
{
assert(ent && ent->kind == k_entity);
static inline int _is_parameter_entity(const ir_entity *entity)
{
- return entity->is_parameter;
+ return entity->entity_kind == IR_ENTITY_PARAMETER;
}
static inline size_t _get_entity_parameter_number(const ir_entity *entity)
{
- assert(entity->is_parameter);
+ assert(entity->entity_kind == IR_ENTITY_PARAMETER);
return entity->attr.parameter.number;
}
#define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
#define get_entity_ld_name(ent) _get_entity_ld_name(ent)
#define get_entity_type(ent) _get_entity_type(ent)
-#define set_entity_type(ent, type) _set_entity_type(ent, type)
#define get_entity_linkage(ent) _get_entity_linkage(ent)
#define get_entity_volatility(ent) _get_entity_volatility(ent)
#define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)