Commit 89c75d37 authored by Matthias Braun's avatar Matthias Braun
Browse files

remove support for enumeration types

It is not usefull for optimization in most languages:
- In C/C++ you can't really change the value of enum constants as casting
  from/to integer has to produce the expected results.
- In Java (and other OO languages) enum members are objects so the
  libfirm enumeration type can't be used there anyway
parent a9e1430b
......@@ -66,9 +66,6 @@ typedef struct ir_heights_t ir_heights_t;
/** @ingroup ir_tarval
* Target Machine Value */
typedef struct ir_tarval ir_tarval;
/** @ingroup enumeration_type
* Enumeration constant */
typedef struct ir_enum_const ir_enum_const;
/** @ingroup ir_type
* Type */
typedef struct ir_type ir_type;
......@@ -273,17 +270,15 @@ ENUM_BITSET(mtp_additional_properties)
* Use the proper access routine after testing this flag.
*/
typedef enum symconst_kind {
symconst_type_size, /**< The SymConst is the size of the given type.
symconst_symbol is type *. */
symconst_type_align, /**< The SymConst is the alignment of the given type.
symconst_symbol is type *. */
symconst_addr_ent, /**< The SymConst is a symbolic pointer to be filled in
by the linker. The pointer is represented by an entity.
symconst_symbol is entity *. */
symconst_ofs_ent, /**< The SymConst is the offset of its entity in the entities
owner type. */
symconst_enum_const /**< The SymConst is a enumeration constant of an
enumeration type. */
symconst_type_size, /**< The SymConst is the size of the given type.
symconst_symbol is type *. */
symconst_type_align, /**< The SymConst is the alignment of the given type.
symconst_symbol is type *. */
symconst_addr_ent, /**< The SymConst is a symbolic pointer to be filled in
by the linker. The pointer is represented by an
entity. symconst_symbol is entity *. */
symconst_ofs_ent, /**< The SymConst is the offset of its entity in the
entities owner type. */
} symconst_kind;
/**
......@@ -296,7 +291,6 @@ typedef enum symconst_kind {
typedef union symconst_symbol {
ir_type *type_p; /**< The type of a SymConst. */
ir_entity *entity_p; /**< The entity of a SymConst. */
ir_enum_const *enum_p; /**< The enumeration constant of a SymConst. */
} symconst_symbol;
/** A input/output constraint attribute.
......
......@@ -373,8 +373,6 @@ FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
* explicitly by a firm entity.
* - symconst_ofs_ent The symbolic constant represents the offset of an
* entity in its owner type.
* - symconst_enum_const The symbolic constant is a enumeration constant of
* an enumeration type.
*
* Inputs to the node:
* No inputs except the block it belongs to.
......@@ -446,8 +444,6 @@ FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
* explicitly by a firm entity.
* - symconst_ofs_ent The symbolic constant represents the offset of an
* entity in its owner type.
* - symconst_enum_const The symbolic constant is a enumeration constant of
* an enumeration type.
*
* Inputs to the node:
* No inputs except the block it belongs to.
......@@ -482,8 +478,6 @@ FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
* explicitly by a firm entity.
* - symconst_ofs_ent The symbolic constant represents the offset of an
* entity in its owner type.
* - symconst_enum_const The symbolic constant is a enumeration constant of
* an enumeration type.
*
* Inputs to the node:
* No inputs except the block it belongs to.
......@@ -518,8 +512,6 @@ FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
* explicitly by a firm entity.
* - symconst_ofs_ent The symbolic constant represents the offset of an
* entity in its owner type.
* - symconst_enum_const The symbolic constant is a enumeration constant of
* an enumeration type.
*
* Inputs to the node:
* No inputs except the block it belongs to.
......
......@@ -347,9 +347,6 @@ FIRM_API int is_SymConst_addr_ent(const ir_node *node);
/** Returns non-zero if s symconst kind has an entity attribute */
#define SYMCONST_HAS_ENT(kind) ((kind) == symconst_addr_ent || (kind) == symconst_ofs_ent)
/** Returns non-zero if s symconst kind has an enum_const attribute */
#define SYMCONST_HAS_ENUM(kind) ((kind) == symconst_enum_const)
/** Returns the kind of the SymConst. */
FIRM_API symconst_kind get_SymConst_kind(const ir_node *node);
/** Sets the kind of the SymConst. */
......@@ -369,13 +366,6 @@ FIRM_API ir_entity *get_SymConst_entity(const ir_node *node);
/** Sets the entity attribute of Symconst node @p node. */
FIRM_API void set_SymConst_entity(ir_node *node, ir_entity *ent);
/** Returns the enum attribute of SymConst node @p node.
* Only to access SymConst of kind symconst_enum_const, else assertion
*/
FIRM_API ir_enum_const *get_SymConst_enum(const ir_node *node);
/** Sets the enum attribute of SymConst node @p node. */
FIRM_API void set_SymConst_enum(ir_node *node, ir_enum_const *ec);
/** Returns the symbol attribute of SymConst node @p node. */
FIRM_API union symconst_symbol get_SymConst_symbol(const ir_node *node);
/** Sets the symbol attribute of SymConst node @p node. */
......
......@@ -574,7 +574,7 @@ FIRM_API void remove_entity_overwrittenby(ir_entity *ent,
FIRM_API int is_entity(const void *thing);
/** Returns true if the type of the entity is a primitive, pointer
* enumeration or method type.
* or method type.
*
* @note This is a different classification than from is_primitive_type().
*/
......@@ -741,10 +741,10 @@ ENUM_BITSET(ptr_access_kind)
* @defgroup tp_op Type Opcodes
* This module specifies the kinds of types available in firm.
*
* They are called type opcodes. These include classes, structs, methods, unions,
* arrays, enumerations, pointers and primitive types.
* Special types with own opcodes are the id type, a type representing an unknown
* type and a type used to specify that something has no type.
* They are called type opcodes. These include classes, structs, methods,
* unions, arrays, pointers and primitive types.
* Special types with own opcodes are the id type, a type representing an
* unknown type and a type used to specify that something has no type.
*
* @{
*/
......@@ -760,7 +760,6 @@ typedef enum tp_opcode {
tpo_method, /**< A method type. */
tpo_union, /**< An union type. */
tpo_array, /**< An array type. */
tpo_enumeration, /**< An enumeration type. */
tpo_pointer, /**< A pointer type. */
tpo_primitive, /**< A primitive type. */
tpo_code, /**< a piece of code (a basic block) */
......@@ -1014,14 +1013,15 @@ typedef enum {
layout_undefined, /**< The layout of this type is not defined.
Address computation to access fields is not
possible, fields must be accessed by Sel
nodes. Enumeration constants might be undefined.
nodes.
This is the default value except for
pointer, primitive and method types. */
layout_fixed /**< The layout is fixed, all component/member entities
have an offset assigned. Size of the type is known.
Arrays can be accessed by explicit address
computation. Enumeration constants must be defined.
Default for pointer, primitive and method types. */
have an offset assigned. Size of the type is
known. Arrays can be accessed by explicit address
computation.
Default for pointer, primitive and method types.
*/
} ir_type_state;
/** Returns a human readable string for the enum entry. */
......@@ -1045,7 +1045,7 @@ FIRM_API ir_mode *get_type_mode(const ir_type *tp);
/** Sets the mode of a type.
*
* Only has an effect on primitive, enumeration and pointer types.
* Only has an effect on primitive and pointer types.
*/
FIRM_API void set_type_mode(ir_type *tp, ir_mode* m);
......@@ -1054,8 +1054,8 @@ FIRM_API unsigned get_type_size_bytes(const ir_type *tp);
/** Sets the size of a type in bytes.
*
* For primitive, enumeration, pointer and method types the size
* is always fixed. This call is legal but has no effect.
* For primitive, pointer and method types the size is always fixed.
* This call is legal but has no effect.
*/
FIRM_API void set_type_size_bytes(ir_type *tp, unsigned size);
......@@ -1149,7 +1149,7 @@ FIRM_API long get_type_nr(const ir_type *tp);
* - member: All entities belonging to this class. This are method entities
* which have type_method or fields that can have any of the
* following type kinds: type_class, type_struct, type_union,
* type_array, type_enumeration, type_pointer, type_primitive.
* type_array, type_pointer, type_primitive.
*
* The following two are dynamic lists that can be grown with an "add_" function,
* but not shrinked:
......@@ -1316,8 +1316,8 @@ FIRM_API const tp_op *get_tpop_class(void);
* The following attributes are private to this type kind:
* - member: All entities belonging to this class. This are the fields
* that can have any of the following types: type_class,
* type_struct, type_union, type_array, type_enumeration,
* type_pointer, type_primitive.
* type_struct, type_union, type_array, type_pointer,
* type_primitive.
* This is a dynamic list that can be grown with an "add_" function,
* but not shrinked.
* This is a dynamic list that can be grown with an "add_" function,
......@@ -1736,81 +1736,6 @@ FIRM_API const tp_op *get_tpop_array(void);
/** @} */
/**
* @defgroup enumeration_type Enumeration
*
* Enumeration types need not necessarily be represented explicitly
* by Firm types, as the frontend can lower them to integer constants as
* well. For debugging purposes or similar tasks this information is useful.
* The type state layout_fixed is set, if all enumeration constants have
* their tarvals assigned. Until then
*
* - *const: The target values representing the constants used to
* represent individual enumerations.
* @{
*/
/** Create a new type enumeration -- set the enumerators independently. */
FIRM_API ir_type *new_type_enumeration(ident *name, size_t n_enums);
/** Create a new type enumeration with debug information -- set the enumerators independently. */
FIRM_API ir_type *new_d_type_enumeration(ident *name, size_t n_enums,
type_dbg_info *db);
/** Returns enumeration identifier */
FIRM_API ident *get_enumeration_ident(const ir_type *enumeration);
/** Returns enumeration identifier as c-string */
FIRM_API const char *get_enumeration_name(const ir_type *enumeration);
/** Sets an enumeration constant to a enumeration type at a given position. */
FIRM_API void set_enumeration_const(ir_type *enumeration, size_t pos,
ident *nameid, ir_tarval *con);
/** Returns the number of enumeration values of this enumeration */
FIRM_API size_t get_enumeration_n_enums(const ir_type *enumeration);
/** Returns the enumeration constant at a given position. */
FIRM_API ir_enum_const *get_enumeration_const(const ir_type *enumeration,
size_t pos);
/** Returns the enumeration type owner of an enumeration constant. */
FIRM_API ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
/** Sets the enumeration constant value. */
FIRM_API void set_enumeration_value(ir_enum_const *enum_cnst, ir_tarval *con);
/** Returns the enumeration constant value. */
FIRM_API ir_tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
/** Assign an ident to an enumeration constant. */
FIRM_API void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
/** Returns the assigned ident of an enumeration constant. */
FIRM_API ident *get_enumeration_const_nameid(const ir_enum_const *enum_cnst);
/** Returns the assigned name of an enumeration constant. */
FIRM_API const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
/** Returns true if a type is a enumeration type. */
FIRM_API int is_Enumeration_type(const ir_type *enumeration);
/**
* This type opcode marks that the corresponding type is an enumeration type.
*
* Consequently it contains a list of idents for the enumeration identifiers
* and a list of target values that are the constants used to implement
* the enumerators.
* This struct is dynamically allocated but constant for the lifetime
* of the library.
*/
FIRM_API const tp_op *type_enumeration;
/** Returns type opcode for enumeration type. @see type_enumeration */
FIRM_API const tp_op *get_tpop_enumeration(void);
/** @} */
/**
* @defgroup pointer_type Pointer
*
......@@ -1939,7 +1864,7 @@ FIRM_API const tp_op *get_tpop_unknown(void);
/**
* Checks whether a type is atomic.
* @param tp any type
* @return true if type is primitive, pointer or enumeration
* @return true if type is primitive or pointer
*/
FIRM_API int is_atomic_type(const ir_type *tp);
......
......@@ -663,12 +663,6 @@ static void emit_init_expression(be_gas_decl_env_t *env, ir_node *init)
case symconst_type_align:
be_emit_irprintf("%u", get_type_alignment_bytes(get_SymConst_type(init)));
return;
case symconst_enum_const: {
ir_tarval *tv = get_enumeration_value(get_SymConst_enum(init));
emit_arith_tarval(tv, bytes);
return;
}
}
panic("invalid SymConst kind");
......
......@@ -361,11 +361,6 @@ void print_entityid(FILE *F, const ir_entity *entity)
fprintf(F, "\"e%ld\"", get_entity_nr(entity));
}
static void print_itemid(FILE *F, const ir_type *tp, size_t itemnr)
{
fprintf(F, "\"i%ldT%zu\"", get_type_nr(tp), itemnr);
}
/**
* Prints the edge kind of a given IR node.
*
......@@ -494,24 +489,6 @@ static void print_node_ent_edge(FILE *F, const ir_node *irn, const ir_entity *en
va_end(ap);
}
/**
* Prints the edge from a type tp to an enumeration item item with additional info fmt, ...
* to the file F.
*/
static void print_enum_item_edge(FILE *F, const ir_type *tp, size_t item, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(F, "edge: { sourcename: ");
print_typeid(F, tp);
fprintf(F, " targetname: ");
print_itemid(F, tp, item);
ir_vfprintf(F, fmt, ap);
fprintf(F,"}\n");
va_end(ap);
}
/*-----------------------------------------------------------------*/
/* global and ahead declarations */
/*-----------------------------------------------------------------*/
......@@ -730,9 +707,6 @@ void dump_node_opcode(FILE *F, const ir_node *n)
case symconst_type_align:
ir_fprintf(F, "SymC %+F align", get_SymConst_type(n));
break;
case symconst_enum_const:
fprintf(F, "SymC %s enum", get_enumeration_const_name(get_SymConst_enum(n)));
break;
}
break;
......@@ -1567,8 +1541,6 @@ static void print_typespecific_vcgattr(FILE *F, ir_type *tp)
break;
case tpo_array:
break;
case tpo_enumeration:
break;
case tpo_pointer:
break;
case tpo_primitive:
......@@ -1615,24 +1587,6 @@ static void dump_entity_node(FILE *F, ir_entity *ent)
fprintf(F, "}\n");
}
static void dump_enum_item(FILE *F, ir_type *tp, size_t pos)
{
char buf[1024];
ir_enum_const *ec = get_enumeration_const(tp, pos);
ident *id = get_enumeration_const_nameid(ec);
ir_tarval *tv = get_enumeration_value(ec);
if (tv)
tarval_snprintf(buf, sizeof(buf), tv);
else
strncpy(buf, "<not set>", sizeof(buf));
fprintf(F, "node: {title: ");
print_itemid(F, tp, pos);
fprintf(F, " label: ");
fprintf(F, "\"enum item %s\" " ENUM_ITEM_NODE_ATTR, get_id_str(id));
fprintf(F, "\n info1: \"value: %s\"}\n", buf);
}
/**
* Dumps a new style initializer.
*/
......@@ -1728,13 +1682,6 @@ static void dump_type_info(type_or_ent tore, void *env)
dump_const_expression(F, lower);
}
break;
case tpo_enumeration:
for (i = get_enumeration_n_enums(tp); i > 0;) {
--i;
dump_enum_item(F, tp, i);
print_enum_item_edge(F, tp, i, "label: \"item %zu\"", i);
}
break;
case tpo_pointer:
print_type_type_edge(F, tp, get_pointer_points_to_type(tp), PTR_PTS_TO_EDGE_ATTR);
break;
......
......@@ -293,10 +293,6 @@ void dump_irnode_to_file(FILE *const F, const ir_node *const n)
fprintf(F, " type: ");
dump_type_to_file(F, get_SymConst_type(n));
break;
case symconst_enum_const:
fprintf(F, " kind: enumeration\n");
fprintf(F, " name: %s\n", get_enumeration_const_name(get_SymConst_enum(n)));
break;
}
break;
}
......
......@@ -650,13 +650,6 @@ static void write_type_pointer(write_env_t *env, ir_type *tp)
fputc('\n', env->file);
}
static void write_type_enumeration(write_env_t *env, ir_type *tp)
{
write_type_common(env, tp);
write_ident_null(env, get_enumeration_ident(tp));
fputc('\n', env->file);
}
static void write_type(write_env_t *env, ir_type *tp)
{
if (type_visited(tp))
......@@ -677,7 +670,6 @@ static void write_type(write_env_t *env, ir_type *tp)
return;
case tpo_primitive: write_type_primitive(env, tp); return;
case tpo_enumeration: write_type_enumeration(env, tp); return;
case tpo_method: write_type_method(env, tp); return;
case tpo_pointer: write_type_pointer(env, tp); return;
case tpo_array: write_type_array(env, tp); return;
......@@ -1781,7 +1773,6 @@ static void read_type(read_env_t *env)
case tpo_code:
case tpo_unknown:
case tpo_enumeration:
case tpo_uninitialized:
parse_error(env, "can't import this type kind (%d)", tpop);
return;
......
......@@ -699,20 +699,7 @@ void set_SymConst_entity(ir_node *node, ir_entity *ent)
node->attr.symc.sym.entity_p = ent;
}
ir_enum_const *get_SymConst_enum(const ir_node *node)
{
assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
return node->attr.symc.sym.enum_p;
}
void set_SymConst_enum(ir_node *node, ir_enum_const *ec)
{
assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
node->attr.symc.sym.enum_p = ec;
}
union symconst_symbol
get_SymConst_symbol(const ir_node *node)
union symconst_symbol get_SymConst_symbol(const ir_node *node)
{
assert(is_SymConst(node));
return node->attr.symc.sym;
......
......@@ -504,7 +504,6 @@ static int verify_node_SymConst(const ir_node *n)
switch (get_SymConst_kind(n)) {
case symconst_type_size:
case symconst_type_align:
case symconst_enum_const:
case symconst_ofs_ent:
return check_mode_func(n, mode_is_int, "int");
case symconst_addr_ent: {
......
......@@ -185,13 +185,11 @@ static void lower_sel(ir_node *sel)
*/
static void lower_symconst(ir_node *symc)
{
ir_node *newn;
ir_type *tp;
ir_entity *ent;
ir_tarval *tv;
ir_enum_const *ec;
ir_mode *mode;
ir_graph *irg;
ir_node *newn;
ir_type *tp;
ir_entity *ent;
ir_mode *mode;
ir_graph *irg;
switch (get_SymConst_kind(symc)) {
case symconst_type_size:
......@@ -236,19 +234,6 @@ static void lower_symconst(ir_node *symc)
hook_lower(symc);
exchange(symc, newn);
return;
case symconst_enum_const:
/* rewrite the SymConst node by a Const node */
irg = get_irn_irg(symc);
ec = get_SymConst_enum(symc);
assert(get_type_state(get_enumeration_owner(ec)) == layout_fixed);
tv = get_enumeration_value(ec);
newn = new_r_Const(irg, tv);
assert(newn);
/* run the hooks */
hook_lower(symc);
exchange(symc, newn);
return;
}
panic("invalid SymConst kind");
}
......
......@@ -805,8 +805,8 @@ int is_atomic_entity(const ir_entity *ent)
{
ir_type *t = get_entity_type(ent);
const tp_op *op = get_type_tpop(t);
return (op == type_primitive || op == type_pointer ||
op == type_enumeration || op == type_method);
return op == type_primitive || op == type_pointer
|| op == type_method;
}
int is_compound_entity(const ir_entity *ent)
......
......@@ -18,7 +18,6 @@ const tp_op *type_struct; const tp_op *get_tpop_struct (void) { retur
const tp_op *type_method; const tp_op *get_tpop_method (void) { return type_method; }
const tp_op *type_union; const tp_op *get_tpop_union (void) { return type_union; }
const tp_op *type_array; const tp_op *get_tpop_array (void) { return type_array; }
const tp_op *type_enumeration; const tp_op *get_tpop_enumeration(void) { return type_enumeration; }
const tp_op *type_pointer; const tp_op *get_tpop_pointer (void) { return type_pointer; }
const tp_op *type_primitive; const tp_op *get_tpop_primitive (void) { return type_primitive; }
const tp_op *tpop_code; const tp_op *get_tpop_code_type (void) { return tpop_code; }
......@@ -102,17 +101,6 @@ static const tp_op_ops
NULL,
NULL
},
/** tpop operations for enumeration types */
enum_ops = {
free_enumeration_attrs,
free_enumeration_entities,
NULL,
set_enumeration_mode,
NULL,
NULL,
NULL,
NULL
},
/** tpop operations for pointer types */
pointer_ops = {
free_pointer_attrs,
......@@ -156,7 +144,6 @@ void init_tpop(void)
type_method = new_tpop(tpo_method , ID("method"), 0, sizeof(mtd_attr), &method_ops);
type_union = new_tpop(tpo_union , ID("union"), TP_OP_FLAG_COMPOUND, sizeof(uni_attr), &union_ops);
type_array = new_tpop(tpo_array , ID("array"), 0, sizeof(arr_attr), &array_ops);
type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof(enm_attr), &enum_ops);
type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof(ptr_attr), &pointer_ops);
type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, 0, &null_ops);
tpop_code = new_tpop(tpo_code , ID("code"), 0, 0, &null_ops);
......@@ -171,7 +158,6 @@ void finish_tpop(void)
free_tpop(type_method ); type_method = NULL;
free_tpop(type_union ); type_union = NULL;
free_tpop(type_array ); type_array = NULL;
free_tpop(type_enumeration); type_enumeration = NULL;
free_tpop(type_pointer ); type_pointer = NULL;
free_tpop(type_primitive ); type_primitive = NULL;
free_tpop(tpop_code ); tpop_code = NULL;
......
......@@ -103,7 +103,7 @@ void free_tpop(const tp_op *tpop);
* opcodes and sets the globals that are external visible as specified
* in tpop.h.
* Allocates opcodes for classes, struct, method, union, array,
* enumeration, pointer and primitive and sets the according values.
* pointer and primitive and sets the according values.
*/
void init_tpop(void);
......
......@@ -103,7 +103,6 @@ int check_type(const ir_type *tp)
case tpo_array: return check_array_type(tp);
case tpo_primitive: return check_primitive_type(tp);
case tpo_pointer: return check_pointer_type(tp);
case tpo_enumeration:
case tpo_method:
case tpo_uninitialized:
case tpo_unknown:
......
......@@ -325,15 +325,6 @@ void set_type_state(ir_type *tp, ir_type_state state)
assert(get_entity_offset(get_struct_member(tp, i)) > -1);
}
break;
case tpo_enumeration:
assert(get_type_mode(tp) != NULL);
for (size_t i = 0, n_enums = get_enumeration_n_enums(tp);
i < n_enums; ++i) {
ir_enum_const *ec = get_enumeration_const(tp, i);
ir_tarval *tv = get_enumeration_value(ec);
assert(tv != NULL && tv != tarval_bad);
}
break;
case tpo_union:
case tpo_array:
default:
......@@ -1288,112 +1279,6 @@ void set_array_size(ir_type *tp, unsigned size)
}
ir_type *new_d_type_enumeration(ident *name, size_t n_enums, type_dbg_info *db)
{
ir_type *res = new_type(type_enumeration, NULL, db);
res->name = name;
res->attr.ea.enumer = NEW_ARR_F(ir_enum_const, n_enums);
hook_new_type(res);
return res;
}
ir_type *new_type_enumeration(ident *name, size_t n_enums)
{
return new_d_type_enumeration(name, n_enums, NULL);
}
void free_enumeration_entities(ir_type *enumeration)
{
(void) enumeration;
assert(enumeration->type_op == type_enumeration);
}
void free_enumeration_attrs(ir_type *enumeration)
{
assert(enumeration->type_op == type_enumeration);
DEL_ARR_F(enumeration->attr.ea.enumer);
}
ident *get_enumeration_ident(const ir_type *enumeration)