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