Commit c663ef04 authored by Michael Beck's avatar Michael Beck
Browse files

to_op_ops created, alloweing new type kinds to be created (not public yet)

this allows to clean the type.c implementation by removing most switches

__func() renamed to _func()

[r6826]
parent 91134fc4
......@@ -30,39 +30,138 @@ tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none;
tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; }
tp_op *
new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size)
new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size,
const tp_op_ops *ops)
{
tp_op *res;
res = xmalloc(sizeof(*res));
res->code = code;
res->name = name;
res->flags = flags;
res->attr_size = attr_size;
res->code = code;
res->name = name;
res->flags = flags;
res->attr_size = attr_size;
if (ops)
memcpy(&res->ops, ops, sizeof(res->ops));
else
memset(&res->ops, 0, sizeof(res->ops));
return res;
}
INLINE void
void
free_tpop(tp_op *tpop) {
free(tpop);
}
static const tp_op_ops
/** tpop operations for class types */
class_ops = {
free_class_attrs,
free_class_entities,
NULL,
set_class_mode,
set_class_size_bits,
get_class_n_members,
get_class_member
},
/** tpop operations for struct types */
struct_ops = {
free_struct_attrs,
free_struct_entities,
NULL,
set_struct_mode,
set_struct_size_bits,
get_struct_n_members,
get_struct_member
},
/** tpop operations for method types */
method_ops = {
free_method_attrs,
free_method_entities,
NULL,
NULL,
NULL,
NULL,
NULL
},
/** tpop operations for union types */
union_ops = {
free_union_attrs,
free_union_entities,
NULL,
NULL,
set_union_size_bits,
get_union_n_members,
get_union_member
},
/** tpop operations for array types */
array_ops = {
free_array_attrs,
free_array_entities,
free_array_automatic_entities,
NULL,
set_array_size_bits,
NULL,
NULL
},
/** tpop operations for enumeration types */
enum_ops = {
free_enumeration_attrs,
free_enumeration_entities,
NULL,
set_enumeration_mode,
NULL,
NULL,
NULL
},
/** tpop operations for pointer types */
pointer_ops = {
free_pointer_attrs,
free_pointer_entities,
NULL,
set_pointer_mode,
NULL,
NULL,
NULL
},
/** tpop operations for pseudo types */
pseudo_ops = {
NULL,
NULL,
NULL,
NULL,
set_default_size_bits,
NULL,
NULL
},
/** tpop operations for primitive types */
null_ops = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
#define C TP_OP_FLAG_COMPOUND
#define ID(s) new_id_from_chars(s, sizeof(s) - 1)
void
init_tpop(void)
{
type_class = new_tpop(tpo_class , ID("class"), C, sizeof (cls_attr));
type_struct = new_tpop(tpo_struct , ID("struct"), C, sizeof (stc_attr));
type_method = new_tpop(tpo_method , ID("method"), 0, sizeof (mtd_attr));
type_union = new_tpop(tpo_union , ID("union"), C, sizeof (uni_attr));
type_array = new_tpop(tpo_array , ID("array"), C, sizeof (arr_attr));
type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof (enm_attr));
type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof (ptr_attr));
type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, /* sizeof (pri_attr) */ 0);
type_id = new_tpop(tpo_id , ID("type_id"), 0, /* sizeof (id_attr) */ 0);
tpop_none = new_tpop(tpo_none , ID("tpop_none"), 0, /* sizeof (non_attr) */ 0);
tpop_unknown = new_tpop(tpo_unknown , ID("tpop_unknown"),0, /* sizeof (ukn_attr) */ 0);
type_class = new_tpop(tpo_class , ID("class"), C, sizeof (cls_attr), &class_ops);
type_struct = new_tpop(tpo_struct , ID("struct"), C, sizeof (stc_attr), &struct_ops);
type_method = new_tpop(tpo_method , ID("method"), 0, sizeof (mtd_attr), &method_ops);
type_union = new_tpop(tpo_union , ID("union"), C, sizeof (uni_attr), &union_ops);
type_array = new_tpop(tpo_array , ID("array"), C, 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, /* sizeof (pri_attr) */ 0, &null_ops);
type_id = new_tpop(tpo_id , ID("type_id"), 0, /* sizeof (id_attr) */ 0, &null_ops);
tpop_none = new_tpop(tpo_none , ID("tpop_none"), 0, /* sizeof (non_attr) */ 0, &pseudo_ops);
tpop_unknown = new_tpop(tpo_unknown , ID("tpop_unknown"),0, /* sizeof (ukn_attr) */ 0, &pseudo_ops);
}
#undef ID
#undef C
......@@ -88,15 +187,15 @@ const char *get_tpop_name(const tp_op *op) {
return get_id_str(op->name);
}
tp_opcode (get_tpop_code)(const tp_op *op){
return __get_tpop_code(op);
tp_opcode (get_tpop_code)(const tp_op *op) {
return _get_tpop_code(op);
}
ident *(get_tpop_ident)(const tp_op *op){
return __get_tpop_ident(op);
ident *(get_tpop_ident)(const tp_op *op) {
return _get_tpop_ident(op);
}
/* returns the attribute size of the operator. */
int (get_tpop_attr_size)(const tp_op *op) {
return __get_tpop_attr_size(op);
return _get_tpop_attr_size(op);
}
......@@ -9,11 +9,13 @@
* Copyright: (c) 2001-2003 Universität Karlsruhe
* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
# ifndef _TPOP_T_H_
# define _TPOP_T_H_
#ifndef _TPOP_T_H_
#define _TPOP_T_H_
#include "firm_types.h"
#include "tpop.h"
#include "irmode.h"
# include <stddef.h>
# include "tpop.h"
/**
* @file tpop_t.h
*
......@@ -23,6 +25,44 @@
* @see tpop.h
*/
/** A function called to free attributes of a type. */
typedef void (*free_attrs_func)(type *tp);
/** A function called to free owned entities of a type. */
typedef void (*free_entities_func)(type *tp);
/** A function called to free all automatic allocated entities of a type. */
typedef void (*free_auto_entities_func)(type *tp);
/** A function called to set the mode of a type. */
typedef void (*set_type_mode_func)(type *tp, ir_mode *m);
/** A function called to set the size of a type in bits */
typedef void (*set_type_size_func)(type *tp, int size);
/** A function called to get the number of compound members */
typedef int (*get_n_members_func)(const type *tp);
/** A function called to get the pos'th compound member */
typedef entity *(*get_member_func)(const type *tp, int pos);
/** A function called to insert an entity into the type */
typedef void (*insert_entity_func)(type *tp, entity *member);
/**
* tp_op operations.
*/
typedef struct _tp_op_ops {
free_attrs_func free_attrs; /**< called to free the attributes of a type */
free_entities_func free_entities; /**< called to free the owned entities of a type */
free_auto_entities_func free_auto_entities; /**< called to free the automatic allocated entities of a type */
set_type_mode_func set_type_mode; /**< called to set a ir_mode of a type */
set_type_size_func set_type_size; /**< called to set the bit size of a type */
get_n_members_func get_n_members; /**< called to return the number of compound members */
get_member_func get_member; /**< called to get the pos'th compound member */
} tp_op_ops;
/** possible flags for a type opcode */
enum tp_op_flags_t {
TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */
......@@ -30,10 +70,11 @@ enum tp_op_flags_t {
/** 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 */
unsigned flags; /**< flags for this opcode */
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 */
unsigned flags; /**< flags for this opcode */
tp_op_ops ops; /**< tp_op operations */
};
/**
......@@ -48,14 +89,16 @@ struct tp_op {
* @param flags additional flags
* @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 *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size);
tp_op *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size,
const tp_op_ops *ops);
/**
* Free a tpop datastructure.
*/
void free_tpop(tp_op* tpop);
void free_tpop(tp_op *tpop);
/**
* Initialize the tpop module.
......@@ -93,22 +136,22 @@ int get_tpop_attr_size (const tp_op *op);
* -----------------*/
static INLINE tp_opcode
__get_tpop_code(const tp_op *op) {
_get_tpop_code(const tp_op *op) {
return op->code;
}
static INLINE ident *
__get_tpop_ident(const tp_op *op){
_get_tpop_ident(const tp_op *op){
return op->name;
}
static INLINE int
__get_tpop_attr_size(const tp_op *op) {
_get_tpop_attr_size(const tp_op *op) {
return op->attr_size;
}
#define get_tpop_code(op) __get_tpop_code(op)
#define get_tpop_ident(op) __get_tpop_ident(op)
#define get_tpop_attr_size(op) __get_tpop_attr_size(op)
#define get_tpop_code(op) _get_tpop_code(op)
#define get_tpop_ident(op) _get_tpop_ident(op)
#define get_tpop_attr_size(op) _get_tpop_attr_size(op)
#endif /* _TPOP_T_H_ */
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