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