2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * File name: ir/tr/tpop.c
23 * Purpose: Opcode of types.
24 * Author: Goetz Lindenmaier
28 * Copyright: (c) 2001-2003 Universität Karlsruhe
38 tp_op *type_class; tp_op *get_tpop_class (void) { return type_class; }
39 tp_op *type_struct; tp_op *get_tpop_struct (void) { return type_struct; }
40 tp_op *type_method; tp_op *get_tpop_method (void) { return type_method; }
41 tp_op *type_union; tp_op *get_tpop_union (void) { return type_union; }
42 tp_op *type_array; tp_op *get_tpop_array (void) { return type_array; }
43 tp_op *type_enumeration; tp_op *get_tpop_enumeration(void) { return type_enumeration; }
44 tp_op *type_pointer; tp_op *get_tpop_pointer (void) { return type_pointer; }
45 tp_op *type_primitive; tp_op *get_tpop_primitive (void) { return type_primitive; }
46 tp_op *type_id; tp_op *get_tpop_id (void) { return type_id; }
47 tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none; }
48 tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; }
51 new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size,
56 res = xmalloc(sizeof(*res));
60 res->attr_size = attr_size;
63 memcpy(&res->ops, ops, sizeof(res->ops));
65 memset(&res->ops, 0, sizeof(res->ops));
71 free_tpop(tp_op *tpop) {
75 static const tp_op_ops
76 /** tpop operations for class types */
85 get_class_member_index
87 /** tpop operations for struct types */
96 get_struct_member_index
98 /** tpop operations for method types */
101 free_method_entities,
109 /** tpop operations for union types */
118 get_union_member_index
120 /** tpop operations for array types */
124 free_array_automatic_entities,
131 /** tpop operations for enumeration types */
133 free_enumeration_attrs,
134 free_enumeration_entities,
136 set_enumeration_mode,
142 /** tpop operations for pointer types */
145 free_pointer_entities,
153 /** tpop operations for pseudo types */
159 set_default_size_bits,
164 /** tpop operations for primitive types */
176 #define C TP_OP_FLAG_COMPOUND
177 #define ID(s) new_id_from_chars(s, sizeof(s) - 1)
181 type_class = new_tpop(tpo_class , ID("class"), C, sizeof (cls_attr), &class_ops);
182 type_struct = new_tpop(tpo_struct , ID("struct"), C, sizeof (stc_attr), &struct_ops);
183 type_method = new_tpop(tpo_method , ID("method"), 0, sizeof (mtd_attr), &method_ops);
184 type_union = new_tpop(tpo_union , ID("union"), C, sizeof (uni_attr), &union_ops);
185 type_array = new_tpop(tpo_array , ID("array"), C, sizeof (arr_attr), &array_ops);
186 type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof (enm_attr), &enum_ops);
187 type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof (ptr_attr), &pointer_ops);
188 type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, /* sizeof (pri_attr) */ 0, &null_ops);
189 type_id = new_tpop(tpo_id , ID("type_id"), 0, /* sizeof (id_attr) */ 0, &null_ops);
190 tpop_none = new_tpop(tpo_none , ID("None"), 0, /* sizeof (non_attr) */ 0, &pseudo_ops);
191 tpop_unknown = new_tpop(tpo_unknown , ID("Unknown"), 0, /* sizeof (ukn_attr) */ 0, &pseudo_ops);
196 /* Finalize the tpop module.
197 * Frees all type opcodes. */
198 void finish_tpop(void) {
199 free_tpop(type_class ); type_class = NULL;
200 free_tpop(type_struct ); type_struct = NULL;
201 free_tpop(type_method ); type_method = NULL;
202 free_tpop(type_union ); type_union = NULL;
203 free_tpop(type_array ); type_array = NULL;
204 free_tpop(type_enumeration); type_enumeration = NULL;
205 free_tpop(type_pointer ); type_pointer = NULL;
206 free_tpop(type_primitive ); type_primitive = NULL;
207 free_tpop(type_id ); type_id = NULL;
208 free_tpop(tpop_none ); tpop_none = NULL;
209 free_tpop(tpop_unknown ); tpop_unknown = NULL;
212 /* Returns the string for the tp_opcode. */
213 const char *get_tpop_name(const tp_op *op) {
214 return get_id_str(op->name);
217 tp_opcode (get_tpop_code)(const tp_op *op) {
218 return _get_tpop_code(op);
221 ident *(get_tpop_ident)(const tp_op *op) {
222 return _get_tpop_ident(op);
225 /* returns the attribute size of the operator. */
226 int (get_tpop_attr_size)(const tp_op *op) {
227 return _get_tpop_attr_size(op);