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