summaryrefslogtreecommitdiffhomepage
path: root/ir/tr
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-12-07 04:01:54 +0100
committerMatthias Braun <matze@braunis.de>2015-12-07 04:02:00 +0100
commitf119db2422d572ef8da668cd063fb5ac960fb758 (patch)
tree6c2d123311912b34c13c71319d9a6d193375fae2 /ir/tr
parent6f319bb1b3f32c12edafbcce6bb68c6bf83477d4 (diff)
Get rid of last tp_op_op and the callback structure
Diffstat (limited to 'ir/tr')
-rw-r--r--ir/tr/tpop.c44
-rw-r--r--ir/tr/tpop_t.h13
-rw-r--r--ir/tr/type.c25
3 files changed, 32 insertions, 50 deletions
diff --git a/ir/tr/tpop.c b/ir/tr/tpop.c
index b55fc2c..cd303c8 100644
--- a/ir/tr/tpop.c
+++ b/ir/tr/tpop.c
@@ -23,14 +23,12 @@ const tp_op *type_primitive; const tp_op *get_tpop_primitive(void) { return type
const tp_op *tpop_code; const tp_op *get_tpop_code_type(void) { return tpop_code; }
const tp_op *tpop_unknown; const tp_op *get_tpop_unknown (void) { return tpop_unknown; }
-const tp_op *new_tpop(tp_opcode code, ident *name, size_t attr_size,
- const tp_op_ops *ops)
+const tp_op *new_tpop(tp_opcode code, ident *name, size_t attr_size)
{
tp_op *res = XMALLOC(tp_op);
res->code = code;
res->name = name;
res->attr_size = attr_size;
- res->ops = *ops;
return res;
}
@@ -39,39 +37,17 @@ void free_tpop(const tp_op *tpop)
free((void*)tpop);
}
-static const tp_op_ops
- /** tpop operations for class types */
- class_ops = {
- .free_attrs = free_class_attrs,
- },
- /** tpop operations for struct types */
- struct_ops = {
- .free_attrs = free_compound_attrs,
- },
- /** tpop operations for method types */
- method_ops = {
- .free_attrs = free_method_attrs,
- },
- /** tpop operations for union types */
- union_ops = {
- .free_attrs = free_compound_attrs,
- },
- null_ops = {
- .free_attrs = NULL,
- }
-;
-
void init_tpop(void)
{
- type_class = new_tpop(tpo_class, NEW_IDENT("class"), sizeof(cls_attr), &class_ops);
- type_struct = new_tpop(tpo_struct, NEW_IDENT("struct"), sizeof(compound_attr), &struct_ops);
- type_method = new_tpop(tpo_method, NEW_IDENT("method"), sizeof(mtd_attr), &method_ops);
- type_union = new_tpop(tpo_union, NEW_IDENT("union"), sizeof(compound_attr), &union_ops);
- type_array = new_tpop(tpo_array, NEW_IDENT("array"), sizeof(arr_attr), &null_ops);
- type_pointer = new_tpop(tpo_pointer, NEW_IDENT("pointer"), sizeof(ptr_attr), &null_ops);
- type_primitive = new_tpop(tpo_primitive, NEW_IDENT("primitive"), 0, &null_ops);
- tpop_code = new_tpop(tpo_code, NEW_IDENT("code"), 0, &null_ops);
- tpop_unknown = new_tpop(tpo_unknown, NEW_IDENT("Unknown"), 0, &null_ops);
+ type_class = new_tpop(tpo_class, NEW_IDENT("class"), sizeof(cls_attr) );
+ type_struct = new_tpop(tpo_struct, NEW_IDENT("struct"), sizeof(compound_attr));
+ type_method = new_tpop(tpo_method, NEW_IDENT("method"), sizeof(mtd_attr) );
+ type_union = new_tpop(tpo_union, NEW_IDENT("union"), sizeof(compound_attr));
+ type_array = new_tpop(tpo_array, NEW_IDENT("array"), sizeof(arr_attr) );
+ type_pointer = new_tpop(tpo_pointer, NEW_IDENT("pointer"), sizeof(ptr_attr) );
+ type_primitive = new_tpop(tpo_primitive, NEW_IDENT("primitive"), 0 );
+ tpop_code = new_tpop(tpo_code, NEW_IDENT("code"), 0 );
+ tpop_unknown = new_tpop(tpo_unknown, NEW_IDENT("Unknown"), 0 );
}
void finish_tpop(void)
diff --git a/ir/tr/tpop_t.h b/ir/tr/tpop_t.h
index 89b2fb7..146c870 100644
--- a/ir/tr/tpop_t.h
+++ b/ir/tr/tpop_t.h
@@ -19,20 +19,11 @@
#define get_tpop_code(op) _get_tpop_code(op)
#define get_tpop_ident(op) _get_tpop_ident(op)
-/**
- * tp_op operations.
- */
-typedef struct tp_op_ops {
- /** Called to free the attributes of a type. */
- void (*free_attrs)(ir_type *type);
-} tp_op_ops;
-
/** The type opcode. */
struct tp_op {
tp_opcode code; /**< The tpop code. */
ident *name; /**< The name of the type opcode. */
size_t attr_size; /**< The attribute size for a type of this opcode. */
- tp_op_ops ops; /**< tp_op operations. */
};
/**
@@ -46,11 +37,9 @@ struct tp_op {
* @param name an ident for the name of the type opcode.
* @param attr_size the size of the attributes necessary for a type with
* this opcode
- * @param ops the tp_op operations for this type
* @return A new type opcode.
*/
-tp_op const *new_tpop(tp_opcode code, ident *name, size_t attr_size,
- tp_op_ops const *ops);
+tp_op const *new_tpop(tp_opcode code, ident *name, size_t attr_size);
/**
* Free a tpop data structure.
diff --git a/ir/tr/type.c b/ir/tr/type.c
index 9ed8aee..f5390cd 100644
--- a/ir/tr/type.c
+++ b/ir/tr/type.c
@@ -135,11 +135,28 @@ void free_type_entities(ir_type *const type)
free_compound_entities(type);
}
-static void free_type_attrs(ir_type *tp)
+static void free_type_attrs(ir_type *const type)
{
- const tp_op *tpop = get_type_tpop(tp);
- if (tpop->ops.free_attrs)
- tpop->ops.free_attrs(tp);
+ switch (type->type_op->code) {
+ case tpo_class:
+ free_class_attrs(type);
+ return;
+ case tpo_union:
+ case tpo_struct:
+ free_compound_attrs(type);
+ return;
+ case tpo_method:
+ free_method_attrs(type);
+ return;
+ case tpo_code:
+ case tpo_primitive:
+ case tpo_pointer:
+ case tpo_array:
+ case tpo_unknown:
+ case tpo_uninitialized:
+ return;
+ }
+ panic("Invalid type");
}
void free_type(ir_type *tp)