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