3 * File name: ir/tr/tpop.c
4 * Purpose: Opcode of types.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
20 tp_op *type_class; tp_op *get_tpop_class (void) { return type_class; }
21 tp_op *type_struct; tp_op *get_tpop_struct (void) { return type_struct; }
22 tp_op *type_method; tp_op *get_tpop_method (void) { return type_method; }
23 tp_op *type_union; tp_op *get_tpop_union (void) { return type_union; }
24 tp_op *type_array; tp_op *get_tpop_array (void) { return type_array; }
25 tp_op *type_enumeration; tp_op *get_tpop_enumeration(void) { return type_enumeration; }
26 tp_op *type_pointer; tp_op *get_tpop_pointer (void) { return type_pointer; }
27 tp_op *type_primitive; tp_op *get_tpop_primitive (void) { return type_primitive; }
28 tp_op *type_id; tp_op *get_tpop_id (void) { return type_id; }
29 tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none; }
30 tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; }
33 new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size,
38 res = xmalloc(sizeof(*res));
42 res->attr_size = attr_size;
45 memcpy(&res->ops, ops, sizeof(res->ops));
47 memset(&res->ops, 0, sizeof(res->ops));
53 free_tpop(tp_op *tpop) {
57 static const tp_op_ops
58 /** tpop operations for class types */
67 get_class_member_index
69 /** tpop operations for struct types */
78 get_struct_member_index
80 /** tpop operations for method types */
91 /** tpop operations for union types */
100 get_union_member_index
102 /** tpop operations for array types */
106 free_array_automatic_entities,
113 /** tpop operations for enumeration types */
115 free_enumeration_attrs,
116 free_enumeration_entities,
118 set_enumeration_mode,
124 /** tpop operations for pointer types */
127 free_pointer_entities,
135 /** tpop operations for pseudo types */
141 set_default_size_bits,
146 /** tpop operations for primitive types */
158 #define C TP_OP_FLAG_COMPOUND
159 #define ID(s) new_id_from_chars(s, sizeof(s) - 1)
163 type_class = new_tpop(tpo_class , ID("class"), C, sizeof (cls_attr), &class_ops);
164 type_struct = new_tpop(tpo_struct , ID("struct"), C, sizeof (stc_attr), &struct_ops);
165 type_method = new_tpop(tpo_method , ID("method"), 0, sizeof (mtd_attr), &method_ops);
166 type_union = new_tpop(tpo_union , ID("union"), C, sizeof (uni_attr), &union_ops);
167 type_array = new_tpop(tpo_array , ID("array"), C, sizeof (arr_attr), &array_ops);
168 type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof (enm_attr), &enum_ops);
169 type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof (ptr_attr), &pointer_ops);
170 type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, /* sizeof (pri_attr) */ 0, &null_ops);
171 type_id = new_tpop(tpo_id , ID("type_id"), 0, /* sizeof (id_attr) */ 0, &null_ops);
172 tpop_none = new_tpop(tpo_none , ID("None"), 0, /* sizeof (non_attr) */ 0, &pseudo_ops);
173 tpop_unknown = new_tpop(tpo_unknown , ID("Unknown"), 0, /* sizeof (ukn_attr) */ 0, &pseudo_ops);
178 /* Finalize the tpop module.
179 * Frees all type opcodes. */
180 void finish_tpop(void) {
181 free_tpop(type_class ); type_class = NULL;
182 free_tpop(type_struct ); type_struct = NULL;
183 free_tpop(type_method ); type_method = NULL;
184 free_tpop(type_union ); type_union = NULL;
185 free_tpop(type_array ); type_array = NULL;
186 free_tpop(type_enumeration); type_enumeration = NULL;
187 free_tpop(type_pointer ); type_pointer = NULL;
188 free_tpop(type_primitive ); type_primitive = NULL;
189 free_tpop(type_id ); type_id = NULL;
190 free_tpop(tpop_none ); tpop_none = NULL;
191 free_tpop(tpop_unknown ); tpop_unknown = NULL;
194 /* Returns the string for the tp_opcode. */
195 const char *get_tpop_name(const tp_op *op) {
196 return get_id_str(op->name);
199 tp_opcode (get_tpop_code)(const tp_op *op) {
200 return _get_tpop_code(op);
203 ident *(get_tpop_ident)(const tp_op *op) {
204 return _get_tpop_ident(op);
207 /* returns the attribute size of the operator. */
208 int (get_tpop_attr_size)(const tp_op *op) {
209 return _get_tpop_attr_size(op);