*** empty log message ***
[libfirm] / ir / tr / type.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer &
5 **          Goetz Lindenmaier
6 **
7 ** type.h: datastructures to hold type information.
8 */
9
10 # ifndef _TYPE_H_
11 # define _TYPE_H_
12
13 # include "common.h"
14 # include "ident.h"
15 # include "irmode.h"
16
17 /* for recursive type definiton */
18 typedef union type type;
19
20 /* visited flag to traverse the type information */
21 extern unsigned long type_visited;
22
23 /*******************************************************************/
24 /** TYPE_CLASS                                                    **/
25 /*******************************************************************/
26
27 typedef struct {
28   firm_kind kind;
29   ident *name;
30   /** needs list with it's entities -- does it really??
31       Entities can be added during their creation.
32   int n_members;
33   entity **member; **/
34   unsigned long visit;     /* visited counter for walks of the type information */
35 } type_class;
36
37
38 /* create a new type_class */
39 type_class *new_type_class (ident *name);
40
41 /* manipulate fields of type_class */
42 char  *get_class_name  (type_class *clss);
43 ident *get_class_ident (type_class *clss);
44 /*
45 void   set_class_name  (type_class *clss, char *name);
46 void   set_class_ident (type_class *clss, ident* ident);
47 */
48
49 /*******************************************************************/
50 /** TYPE_STRCT                                                   **/
51 /*******************************************************************/
52
53 typedef struct {
54   firm_kind kind;
55   ident *name;
56   /** needs list with it's entities -- does it really??
57       Entities can be added during their creation.
58   int n_members;
59   entity **member; **/
60   unsigned long visit;     /* visited counter for walks of the type information */
61 } type_strct;
62
63
64 /* create a new type_strct */
65 type_strct *new_type_strct (ident *name);
66
67 /* manipulate fields of type_strct */
68 char  *get_strct_name  (type_strct *strct);
69 ident *get_strct_ident (type_strct *strct);
70 /*
71 void   set_strct_name  (type_strct *strct, char *name);
72 void   set_strct_ident (type_strct *strct, ident* ident);
73 */
74
75
76 /*******************************************************************/
77 /** TYPE_METHOD                                                   **/
78 /*******************************************************************/
79
80 typedef struct {
81   firm_kind kind;
82   ident *name;         /* do I need the name,
83                           or is the name in entity sufficient?
84                           No, there is no name for the type.  Types have
85                           only names if typedef's give them one.  */
86   int arity;           /* number of parameters, better n_params */
87   type **param_type;   /* code generation needs this information.
88                           Should it be generated by the frontend,
89                           or does this impose unnecessary work for
90                           optimizations that change the parameters of
91                           methods? */
92   int n_res;           /* number of results */
93   type **res_type;
94   /** needs pointer to it's ir_graph ??
95   ir_graph *graph; **/
96   unsigned long visit;     /* visited counter for walks of the type information */
97 } type_method;
98
99 /* create a new type_method */
100 type_method *new_type_method (ident *name, int arity, int n_res);
101
102 /* manipulate fields of type_method */
103
104 char  *get_method_name  (type_method *method);
105 ident *get_method_ident (type_method *method);
106 /* GL 9.2.2000: who commened these in?
107    I think it's not safe to have these methods.
108    Please add changes to Changes file.
109 void   set_method_name  (type_method *method, char *name);
110 void   set_method_ident (type_method *method, ident* ident); */
111
112 inline int   get_method_arity (type_method *method);
113 inline void  set_method_arity (type_method *method, int arity);
114 inline type *get_method_param_type(type_method *method, int pos);
115 inline void  set_method_param_type(type_method *method, int pos, type* type);
116
117 inline int   get_method_n_res (type_method *method);
118 inline void  set_method_n_res (type_method *method, int n_res);
119 inline type *get_method_res_type(type_method *method, int pos);
120 inline void  set_method_res_type(type_method *method, int pos, type* type);
121
122 /*
123 ir_graph *get_method_graph(type_method *method);
124 void *get_method_graph(type_method *method, ir_graph* graph);
125 */
126
127 /*******************************************************************/
128 /** TYPE_UNION                                                    **/
129 /*******************************************************************/
130
131 typedef struct {
132   firm_kind kind;
133   ident *name;             /* do I need a name? */
134   int n_types;
135   /* type **unioned_type;    ... or something like that? */
136   unsigned long visit;     /* visited counter for walks of the type information */
137 } type_union;
138
139 /* create a new type_union -- set unioned types by hand. */
140 type_union *new_type_union (ident *name, int n_types);
141
142 /* manipulate fields of type_union */
143 char  *get_union_name  (type_union *uni);
144 ident *get_union_ident (type_union *uni);
145 /*
146 void   set_union_name  (type_union *union, char *name);
147 void   set_union_ident (type_union *union, ident* ident);
148 */
149 /*
150 int    get_union_n_types (type_union *union);
151 void   set_union_n_types (type_union *union, int n);
152 type  *get_union_unioned_type (type_union *union, int pos);
153 void   set_union_unioned_type (type_union *union, int pos, type *type);
154 */
155
156 /*******************************************************************/
157 /** TYPE_ARRAY                                                    **/
158 /*******************************************************************/
159
160 /* multidimensional, polyhedric arrays */
161 typedef struct {
162   firm_kind kind;
163   ident *name;
164   int n_dimensions;   /* Extend Sel to select from multidimensional arrays.  This  */
165   int *lower_bound;   /* will allow to generate explicit array index computations  */
166   int *upper_bound;   /* by replacing a single FIRM node.  As long as this is not
167                          done create arrays with arrays as elements.  */
168                       /* Should I use tarval? */
169   type *element_type;
170   unsigned long visit;     /* visited counter for walks of the type information */
171 } type_array;
172
173 /* create a new type array -- set dimension sizes independently */
174 type_array *new_type_array (ident *name, int n_dimensions);
175
176 /* manipulate fields of type_array */
177 char  *get_array_name  (type_array *array);
178 ident *get_array_ident (type_array *array);
179 /*
180 void   set_array_name  (type_array *array, char *name);
181 void   set_array_ident (type_array *array, ident* ident);
182 */
183 void  set_array_n_dimensions  (type_array *array, int n);
184 int   get_array_n_dimensions  (type_array *array);
185
186 void  set_array_bounds      (type_array *array, int dimension, int lower_bound,
187                                                               int upper_bound);
188 void  set_array_lower_bound (type_array *array, int dimension, int lower_bound);
189 void  set_array_upper_bound (type_array *array, int dimension, int upper_bound);
190 int   get_array_lower_bound (type_array *array, int dimension);
191 int   get_array_upper_bound (type_array *array, int dimension);
192
193 void  set_array_element_type (type_array *array, type *type);
194 type *get_array_element_type (type_array *array);
195
196 /*******************************************************************/
197 /** TYPE_ENUMERATION                                              **/
198 /*******************************************************************/
199 /** Enums are needed to keep debugging information.  They can as well
200     be lowered to integers. **/
201
202 typedef struct {
203   firm_kind kind;
204   ident *name;
205   /* int n_enums;
206   ir_node **enum    * Contains all constant nodes that represent a member
207                      of the enum -- enumerators. */
208   /* is ir_node the propper array member? */
209   unsigned long visit;     /* visited counter for walks of the type information */
210 } type_enumeration;
211
212 /* create a new type enumeration -- set the enumerators independently */
213 type_enumeration *new_type_enumeration (ident *name /* , int n_enums */);
214
215 /* manipulate fields of type_enumeration */
216 char  *get_enumeration_name  (type_enumeration *enumeration);
217 ident *get_enumeration_ident (type_enumeration *enumeration);
218 /*
219 void   set_enumeration_name  (type_enumeration *enumeration, char *name);
220 void   set_enumeration_ident (type_enumeration *enumeration, ident* ident);
221 */
222 /*
223 void     set_enumeration_n_enums (type_enumeration *enumeration, int n);
224 int     *get_enumeration_n_enums (type_enumeration *enumeration);
225 void     set_enumeration_enum    (type_enumeration *enumeration, int pos,
226                                  ir_node const);
227 ir_node *get_enumeration_enum    (type_enumeration *enumeration, int pos);
228 */
229
230 /*******************************************************************/
231 /** TYPE_POINTER                                                  **/
232 /*******************************************************************/
233
234 typedef struct {
235   firm_kind kind;
236   ident *name;
237   /* ir_mode *mode;      * The mode to be used for this type.
238                             Not here as there might be several pointer types?
239                             A method get_pointer_mode should read a unique,
240                             global variable. */
241   type *points_to;
242   unsigned long visit;     /* visited counter for walks of the type information */
243 } type_pointer;
244
245 /* create a new type pointer */
246 type_pointer *new_type_pointer (ident *name, type *points_to);
247
248 /* manipulate fields of type_pointer */
249 char  *get_pointer_name  (type_pointer *pointer);
250 ident *get_pointer_ident (type_pointer *pointer);
251 /*
252 void   set_pointer_name  (type_pointer *pointer, char *name);
253 void   set_pointer_ident (type_pointer *pointer, ident* ident);
254 */
255 void  set_pointer_points_to_type (type_pointer *pointer, type *type);
256 type *get_pointer_points_to_type (type_pointer *pointer);
257
258 /*******************************************************************/
259 /** TYPE_PRIMITIVE                                                **/
260 /*******************************************************************/
261
262 /* primitive, language-defined types */
263 /* What is the type of an entity if it is atomic?  Are alle basic data
264    types classses in Sather? Else this is needed. */
265 typedef struct {
266   firm_kind kind;
267   ident *name;
268   ir_mode *mode;       /* The mode to be used for this type */
269   unsigned long visit;     /* visited counter for walks of the type information */
270 } type_primitive;
271
272 /* create a new type primitive */
273 type_primitive *new_type_primitive (ident *name, ir_mode *mode);
274
275 /* manipulate fields of type_primitive */
276 char  *get_primitive_name  (type_primitive *primitive);
277 ident *get_primitive_ident (type_primitive *primitive);
278 /*
279 void   set_primitive_name  (type_primitive *primitive, char *name);
280 void   set_primitive_ident (type_primitive *primitive, ident* ident);
281 */
282 ir_mode *get_primitive_mode (type_primitive *primitive);
283 void     set_primitive_mode (type_primitive *primitive, ir_mode *mode);
284
285
286
287
288 /*******************************************************************/
289 /**  To manage all different types the same                       **/
290 /*******************************************************************/
291
292 union type {
293   firm_kind kind;
294   type_class clss;
295   type_strct strct;
296   type_method method;
297   type_array array;
298   type_union uni;  /* union is keyword */
299   type_enumeration enumeration;
300   type_pointer pointer;
301   type_primitive primitive;
302 };
303
304 int is_type(void *thing);
305
306
307
308
309 # endif /* _TYPE_H_ */