1 /*
2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
3 *
4 * This file is part of libFirm.
5 *
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.
10 *
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.
14 *
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
17 * PURPOSE.
18 */
19
20 /**
21 * @file
22 * @brief Opcode of types -- private header.
23 * @author Goetz Lindenmaier, Michael Beck
24 */
25 #ifndef FIRM_TR_TPOP_T_H
26 #define FIRM_TR_TPOP_T_H
27
28 #include <stdlib.h>
29
30 #include "firm_types.h"
31 #include "typerep.h"
32 #include "irmode.h"
33
34 /** A function called to free attributes of a type. */
35 typedef void (*free_attrs_func)(ir_type *tp);
36
37 /** A function called to free owned entities of a type. */
38 typedef void (*free_entities_func)(ir_type *tp);
39
40 /** A function called to free all automatic allocated entities of a type. */
41 typedef void (*free_auto_entities_func)(ir_type *tp);
42
43 /** A function called to set the mode of a type. */
44 typedef void (*set_type_mode_func)(ir_type *tp, ir_mode *m);
45
46 /** A function called to set the size of a type in bytes. */
47 typedef void (*set_type_size_func)(ir_type *tp, unsigned size);
48
49 /** A function called to get the number of compound members */
50 typedef size_t (*get_n_members_func)(const ir_type *tp);
51
52 /** A function called to get the pos'th compound member */
53 typedef ir_entity *(*get_member_func)(const ir_type *tp, size_t pos);
54
55 typedef size_t (*get_member_index_func)(const ir_type *tp, ir_entity *member);
56
57 /** A function called to insert an entity into the type */
58 typedef void (*insert_entity_func)(ir_type *tp, ir_entity *member);
59
60 /**
61 * tp_op operations.
62 */
63 typedef struct tp_op_ops {
64 free_attrs_func free_attrs; /**< Called to free the attributes of a type. */
65 free_entities_func free_entities; /**< Called to free the owned entities of a type. */
66 free_auto_entities_func free_auto_entities; /**< Called to free the automatic allocated entities of a type. */
67 set_type_mode_func set_type_mode; /**< Called to set a ir_mode of a type. */
68 set_type_size_func set_type_size; /**< Called to set the byte size of a type. */
69 get_n_members_func get_n_members; /**< Called to return the number of compound members. */
70 get_member_func get_member; /**< Called to get the pos'th compound member. */
71 get_member_index_func get_member_index; /**< Called to get the index of a compound member. */
72 } tp_op_ops;
73
74 /** possible flags for a type opcode */
75 enum tp_op_flags_t {
76 TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */
77 };
78
79 /** The type opcode. */
80 struct tp_op {
81 tp_opcode code; /**< The tpop code. */
82 ident *name; /**< The name of the type opcode. */
83 size_t attr_size; /**< The attribute size for a type of this opcode. */
84 unsigned flags; /**< Flags for this opcode. */
85 tp_op_ops ops; /**< tp_op operations. */
86 };
87
88 /**
89 * Returns a new type opcode.
90 *
91 * Allocates a new tp_op struct and initializes its fields with
92 * the passed values. This function is only to be used during
93 * initialization of the library.
94 *
95 * @param code the enum for this type opcode.
96 * @param name an ident for the name of the type opcode.
97 * @param flags additional flags
98 * @param attr_size the size of the attributes necessary for a type with
99 * this opcode
100 * @param ops the tp_op operations for this type
101 * @return A new type opcode.
102 */
103 const tp_op *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size, const tp_op_ops *ops);
104
105 /**
106 * Free a tpop data structure.
107 */
108 void free_tpop(const tp_op *tpop);
109
110 /**
111 * Initialize the tpop module.
112 *
113 * Must be called during the initialization of the library. Allocates
114 * opcodes and sets the globals that are external visible as specified
115 * in tpop.h.
116 * Allocates opcodes for classes, struct, method, union, array,
117 * enumeration, pointer and primitive and sets the according values.
118 */
119 void init_tpop(void);
120
121 /**
122 * Finalize the tpop module.
123 *
124 * Frees all type opcodes.
125 */
126 void finish_tpop(void);
127
128 /**
129 * Returns the size of the attribute to this kind
130 * of type.
131 *
132 * Internal feature.
133 *
134 * @param op The type opcode to get the size for.
135 * @return The size of the attribute of types with this opcode.
136 */
137 size_t get_tpop_attr_size(const tp_op *op);
138
139
140 /* ---------------- *
141 * inline functions *
142 * -----------------*/
143
_get_tpop_code(const tp_op * op)144 static inline tp_opcode _get_tpop_code(const tp_op *op)
145 {
146 return op->code;
147 }
148
_get_tpop_ident(const tp_op * op)149 static inline ident *_get_tpop_ident(const tp_op *op)
150 {
151 return op->name;
152 }
153
_get_tpop_attr_size(const tp_op * op)154 static inline size_t _get_tpop_attr_size(const tp_op *op)
155 {
156 return op->attr_size;
157 }
158
159 #define get_tpop_code(op) _get_tpop_code(op)
160 #define get_tpop_ident(op) _get_tpop_ident(op)
161 #define get_tpop_attr_size(op) _get_tpop_attr_size(op)
162
163 #endif /* FIRM_TR_TPOP_T_H */
164