2 * Copyright (C) 1995-2011 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 * @brief Opcode of types.
23 * @author Goetz Lindenmaier, Michael Beck
33 const tp_op *type_class; const tp_op *get_tpop_class (void) { return type_class; }
34 const tp_op *type_struct; const tp_op *get_tpop_struct (void) { return type_struct; }
35 const tp_op *type_method; const tp_op *get_tpop_method (void) { return type_method; }
36 const tp_op *type_union; const tp_op *get_tpop_union (void) { return type_union; }
37 const tp_op *type_array; const tp_op *get_tpop_array (void) { return type_array; }
38 const tp_op *type_enumeration; const tp_op *get_tpop_enumeration(void) { return type_enumeration; }
39 const tp_op *type_pointer; const tp_op *get_tpop_pointer (void) { return type_pointer; }
40 const tp_op *type_primitive; const tp_op *get_tpop_primitive (void) { return type_primitive; }
41 const tp_op *tpop_code; const tp_op *get_tpop_code_type (void) { return tpop_code; }
42 const tp_op *tpop_none; const tp_op *get_tpop_none (void) { return tpop_none; }
43 const tp_op *tpop_unknown; const tp_op *get_tpop_unknown (void) { return tpop_unknown; }
46 new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size, const tp_op_ops *ops)
48 tp_op *res = XMALLOC(tp_op);
52 res->attr_size = attr_size;
57 memset(&res->ops, 0, sizeof(res->ops));
62 void free_tpop(const tp_op *tpop)
67 static const tp_op_ops
68 /** tpop operations for class types */
77 get_class_member_index
79 /** tpop operations for struct types */
88 get_struct_member_index
90 /** tpop operations for method types */
101 /** tpop operations for union types */
110 get_union_member_index
112 /** tpop operations for array types */
116 free_array_automatic_entities,
123 /** tpop operations for enumeration types */
125 free_enumeration_attrs,
126 free_enumeration_entities,
128 set_enumeration_mode,
134 /** tpop operations for pointer types */
137 free_pointer_entities,
145 /** tpop operations for pseudo types */
156 /** tpop operations for primitive types */
170 #define ID(s) new_id_from_chars(s, sizeof(s) - 1)
171 type_class = new_tpop(tpo_class , ID("class"), TP_OP_FLAG_COMPOUND, sizeof(cls_attr), &class_ops);
172 type_struct = new_tpop(tpo_struct , ID("struct"), TP_OP_FLAG_COMPOUND, sizeof(stc_attr), &struct_ops);
173 type_method = new_tpop(tpo_method , ID("method"), 0, sizeof(mtd_attr), &method_ops);
174 type_union = new_tpop(tpo_union , ID("union"), TP_OP_FLAG_COMPOUND, sizeof(uni_attr), &union_ops);
175 type_array = new_tpop(tpo_array , ID("array"), 0, sizeof(arr_attr), &array_ops);
176 type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof(enm_attr), &enum_ops);
177 type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof(ptr_attr), &pointer_ops);
178 type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, sizeof(pri_attr), &null_ops);
179 tpop_code = new_tpop(tpo_code , ID("code"), 0, 0, &null_ops);
180 tpop_none = new_tpop(tpo_none , ID("None"), 0, 0, &pseudo_ops);
181 tpop_unknown = new_tpop(tpo_unknown , ID("Unknown"), 0, 0, &pseudo_ops);
185 /* Finalize the tpop module.
186 * Frees all type opcodes. */
187 void finish_tpop(void)
189 free_tpop(type_class ); type_class = NULL;
190 free_tpop(type_struct ); type_struct = NULL;
191 free_tpop(type_method ); type_method = NULL;
192 free_tpop(type_union ); type_union = NULL;
193 free_tpop(type_array ); type_array = NULL;
194 free_tpop(type_enumeration); type_enumeration = NULL;
195 free_tpop(type_pointer ); type_pointer = NULL;
196 free_tpop(type_primitive ); type_primitive = NULL;
197 free_tpop(tpop_code ); tpop_code = NULL;
198 free_tpop(tpop_none ); tpop_none = NULL;
199 free_tpop(tpop_unknown ); tpop_unknown = NULL;
202 /* Returns the string for the tp_opcode. */
203 const char *get_tpop_name(const tp_op *op)
205 return get_id_str(op->name);
208 tp_opcode (get_tpop_code)(const tp_op *op)
210 return _get_tpop_code(op);
213 /* returns the attribute size of the operator. */
214 size_t (get_tpop_attr_size)(const tp_op *op)
216 return _get_tpop_attr_size(op);