2 /* This file is part of GCC.
4 GCC is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
9 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
19 This file was generated via autogen @see py-runtime.{def/tpl}
20 - To regenerate with new definitions $ autogen py-runtime.def
27 #include "coretypes.h"
31 #include "tree-iterator.h"
32 #include "tree-pass.h"
39 #include "diagnostic-core.h"
40 #include "langhooks.h"
41 #include "langhooks-def.h"
49 #include <py-il-dot.h>
50 #include <py-il-tree.h>
51 #include <py-runtime.h>
54 VEC(tree
,gc
) * gpy_builtin_types_vec
;
55 static tree
gpy_build_py_object_type (void);
56 static tree
gpy_build_py_vector_type (void);
59 tree
GPY_RR_extend_globl_stack (tree size
)
61 tree fntype
= build_function_type_list (void_type_node
,
64 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
65 get_identifier ("gpy_rr_extend_runtime_stack"),
67 tree restype
= TREE_TYPE (fndecl
);
68 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
70 DECL_CONTEXT (resdecl
) = fndecl
;
71 DECL_RESULT (fndecl
) = resdecl
;
72 DECL_EXTERNAL (fndecl
) = 1;
73 TREE_PUBLIC (fndecl
) = 1;
75 return build_call_expr (fndecl
, 1, size
);
78 tree
GPY_RR_fold_attrib (tree ident
, tree addr
, tree offset
)
80 tree fntype
= build_function_type_list (gpy_attrib_type_ptr
,
82 gpy_unsigned_char_ptr
,
85 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
86 get_identifier ("gpy_rr_fold_attribute"),
88 tree restype
= TREE_TYPE (fndecl
);
89 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
91 DECL_CONTEXT (resdecl
) = fndecl
;
92 DECL_RESULT (fndecl
) = resdecl
;
93 DECL_EXTERNAL (fndecl
) = 1;
94 TREE_PUBLIC (fndecl
) = 1;
96 return build_call_expr (fndecl
, 3, ident
, addr
, offset
);
99 tree
GPY_RR_fold_attrib_list (VEC(tree
,gc
) * attribs
)
101 tree fntype
= build_function_type_list (gpy_attrib_type_ptr_ptr
,
105 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
106 get_identifier ("gpy_rr_fold_attrib_list"),
108 tree restype
= TREE_TYPE (fndecl
);
109 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
111 DECL_CONTEXT (resdecl
) = fndecl
;
112 DECL_RESULT (fndecl
) = resdecl
;
113 DECL_EXTERNAL (fndecl
) = 1;
114 TREE_PUBLIC (fndecl
) = 1;
116 return build_call_expr_loc_vec (BUILTINS_LOCATION
, fndecl
, attribs
);
119 tree
GPY_RR_fold_class_decl (tree attrib_list
, tree size
, tree identifier
)
121 tree fntype
= build_function_type_list (gpy_object_type_ptr
,
122 gpy_attrib_type_ptr_ptr
,
126 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
127 get_identifier ("gpy_rr_fold_class_decl"),
129 tree restype
= TREE_TYPE (fndecl
);
130 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
132 DECL_CONTEXT (resdecl
) = fndecl
;
133 DECL_RESULT (fndecl
) = resdecl
;
134 DECL_EXTERNAL (fndecl
) = 1;
135 TREE_PUBLIC (fndecl
) = 1;
137 return build_call_expr (fndecl
, 3, attrib_list
, size
, identifier
);
140 tree
GPY_RR_fold_integer (tree integer
)
142 tree fntype
= build_function_type_list (gpy_object_type_ptr
,
145 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
146 get_identifier ("gpy_rr_fold_integer"),
148 tree restype
= TREE_TYPE (fndecl
);
149 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
151 DECL_CONTEXT (resdecl
) = fndecl
;
152 DECL_RESULT (fndecl
) = resdecl
;
153 DECL_EXTERNAL (fndecl
) = 1;
154 TREE_PUBLIC (fndecl
) = 1;
156 return build_call_expr (fndecl
, 1, integer
);
159 tree
GPY_RR_get_object_state (tree obj
)
161 tree fntype
= build_function_type_list (ptr_type_node
,
164 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
165 get_identifier ("gpy_rr_get_object_state"),
167 tree restype
= TREE_TYPE (fndecl
);
168 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
170 DECL_CONTEXT (resdecl
) = fndecl
;
171 DECL_RESULT (fndecl
) = resdecl
;
172 DECL_EXTERNAL (fndecl
) = 1;
173 TREE_PUBLIC (fndecl
) = 1;
175 return build_call_expr (fndecl
, 1, obj
);
178 tree
GPY_RR_incr_ref_count (tree obj
)
180 tree fntype
= build_function_type_list (void_type_node
,
183 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
184 get_identifier ("gpy_rr_incr_ref_count"),
186 tree restype
= TREE_TYPE (fndecl
);
187 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
189 DECL_CONTEXT (resdecl
) = fndecl
;
190 DECL_RESULT (fndecl
) = resdecl
;
191 DECL_EXTERNAL (fndecl
) = 1;
192 TREE_PUBLIC (fndecl
) = 1;
194 return build_call_expr (fndecl
, 1, obj
);
197 tree
GPY_RR_decr_ref_count (tree obj
)
199 tree fntype
= build_function_type_list (void_type_node
,
202 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
203 get_identifier ("gpy_rr_decr_ref_count"),
205 tree restype
= TREE_TYPE (fndecl
);
206 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
208 DECL_CONTEXT (resdecl
) = fndecl
;
209 DECL_RESULT (fndecl
) = resdecl
;
210 DECL_EXTERNAL (fndecl
) = 1;
211 TREE_PUBLIC (fndecl
) = 1;
213 return build_call_expr (fndecl
, 1, obj
);
216 tree
GPY_RR_eval_print (VEC(tree
,gc
) * arguments
)
218 tree fntype
= build_function_type_list (void_type_node
,
223 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
224 get_identifier ("gpy_rr_eval_print"),
226 tree restype
= TREE_TYPE (fndecl
);
227 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
229 DECL_CONTEXT (resdecl
) = fndecl
;
230 DECL_RESULT (fndecl
) = resdecl
;
231 DECL_EXTERNAL (fndecl
) = 1;
232 TREE_PUBLIC (fndecl
) = 1;
234 return build_call_expr_loc_vec (BUILTINS_LOCATION
, fndecl
, arguments
);
237 tree
GPY_RR_eval_expression (tree x
, tree y
, tree op
)
239 tree fntype
= build_function_type_list (gpy_object_type_ptr
,
243 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
244 get_identifier ("gpy_rr_eval_expression"),
246 tree restype
= TREE_TYPE (fndecl
);
247 tree resdecl
= build_decl (BUILTINS_LOCATION
, RESULT_DECL
, NULL_TREE
,
249 DECL_CONTEXT (resdecl
) = fndecl
;
250 DECL_RESULT (fndecl
) = resdecl
;
251 DECL_EXTERNAL (fndecl
) = 1;
252 TREE_PUBLIC (fndecl
) = 1;
254 return build_call_expr (fndecl
, 3, x
, y
, op
);
259 tree
gpy_build_py_vector_type (void)
261 tree vec_struct_type
= make_node (RECORD_TYPE
);
263 tree field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
, get_identifier ("vector"),
264 build_pointer_type (ptr_type_node
));
265 DECL_CONTEXT (field
) = vec_struct_type
;
266 TYPE_FIELDS (vec_struct_type
) = field
;
267 tree last_field
= field
;
269 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
, get_identifier ("size"),
271 DECL_CONTEXT (field
) = vec_struct_type
;
272 DECL_CHAIN (last_field
) = field
;
275 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
, get_identifier ("length"),
277 DECL_CONTEXT (field
) = vec_struct_type
;
278 DECL_CHAIN (last_field
) = field
;
280 layout_type (vec_struct_type
);
281 tree ident
= get_identifier ("gpy_vector_t");
282 tree type_decl
= build_decl (BUILTINS_LOCATION
, TYPE_DECL
, ident
,
284 DECL_ARTIFICIAL (type_decl
) = 1;
285 TYPE_NAME (vec_struct_type
) = ident
;
287 gpy_preserve_from_gc (type_decl
);
288 rest_of_decl_compilation (type_decl
, 1, 0);
290 return vec_struct_type
;
294 tree
gpy_build_py_attrib_type (void)
296 tree attrib_struct_type
= make_node (RECORD_TYPE
);
298 tree field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
299 get_identifier ("identifier"),
301 DECL_CONTEXT (field
) = attrib_struct_type
;
302 TYPE_FIELDS (attrib_struct_type
) = field
;
304 tree last_field
= field
;
306 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
307 get_identifier ("offset"),
309 DECL_CONTEXT (field
) = attrib_struct_type
;
310 DECL_CHAIN (last_field
) = field
;
313 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
314 get_identifier ("addr"),
315 gpy_object_type_ptr
);
316 DECL_CONTEXT (field
) = attrib_struct_type
;
317 DECL_CHAIN (last_field
) = field
;
319 layout_type (attrib_struct_type
);
320 tree ident
= get_identifier ("gpy_object_attrib_t");
321 tree type_decl
= build_decl (BUILTINS_LOCATION
, TYPE_DECL
, ident
,
323 DECL_ARTIFICIAL (type_decl
) = 1;
324 TYPE_NAME (attrib_struct_type
) = ident
;
326 gpy_preserve_from_gc (type_decl
);
327 rest_of_decl_compilation (type_decl
, 1, 0);
329 return attrib_struct_type
;
333 tree
gpy_build_py_object_type (void)
335 tree object_state_struct_Type
= make_node (RECORD_TYPE
);
337 tree name
= get_identifier("identifier");
338 tree field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
,
339 build_pointer_type(char_type_node
));
340 DECL_CONTEXT(field
) = object_state_struct_Type
;
341 TYPE_FIELDS(object_state_struct_Type
) = field
;
342 tree last_field
= field
;
344 name
= get_identifier("ref_count");
345 field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
, integer_type_node
);
346 DECL_CONTEXT(field
) = object_state_struct_Type
;
347 DECL_CHAIN(last_field
) = field
;
350 name
= get_identifier("state");
351 field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
,
353 DECL_CONTEXT(field
) = object_state_struct_Type
;
354 DECL_CHAIN(last_field
) = field
;
357 name
= get_identifier("definition");
358 field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
,
360 DECL_CONTEXT(field
) = object_state_struct_Type
;
361 DECL_CHAIN(last_field
) = field
;
364 layout_type(object_state_struct_Type
);
366 // Give the struct a name for better debugging info.
367 name
= get_identifier ("gpy_object_state_t");
368 tree object_state_type_decl
= build_decl (BUILTINS_LOCATION
, TYPE_DECL
, name
,
369 object_state_struct_Type
);
370 DECL_ARTIFICIAL(object_state_type_decl
) = 1;
371 TYPE_NAME(object_state_struct_Type
) = object_state_type_decl
;
372 gpy_preserve_from_gc(object_state_type_decl
);
373 rest_of_decl_compilation(object_state_type_decl
, 1, 0);
375 debug_tree (object_state_type_decl
);
376 tree object_state_ptr_type
= build_pointer_type (object_state_struct_Type
);
377 gpy_preserve_from_gc (object_state_ptr_type
);
379 tree union_type__
= make_node (UNION_TYPE
);
381 name
= get_identifier ("object_state");
382 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
, name
,
383 object_state_ptr_type
);
384 DECL_CONTEXT(field
) = union_type__
;
385 DECL_CHAIN(last_field
) = field
;
388 name
= get_identifier ("literal");
389 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
, name
,
391 DECL_CONTEXT(field
) = union_type__
;
392 DECL_CHAIN(last_field
) = field
;
395 layout_type (union_type__
);
397 name
= get_identifier("o");
398 tree union_type_decl
= build_decl(BUILTINS_LOCATION
, TYPE_DECL
, name
,
400 DECL_ARTIFICIAL(union_type_decl
) = 1;
401 TYPE_NAME(union_type__
) = union_type_decl
;
402 gpy_preserve_from_gc(union_type_decl
);
403 rest_of_decl_compilation(union_type_decl
, 1, 0);
405 tree gpy_object_struct_Type
= make_node (RECORD_TYPE
);
407 name
= get_identifier("type");
408 field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
, integer_type_node
);
409 DECL_CONTEXT(field
) = gpy_object_struct_Type
;
410 DECL_CHAIN(last_field
) = field
;
413 field
= build_decl(BUILTINS_LOCATION
, FIELD_DECL
, name
,
415 DECL_CONTEXT(field
) = gpy_object_struct_Type
;
416 DECL_CHAIN(last_field
) = field
;
419 layout_type (object_state_struct_Type
);
421 name
= get_identifier ("gpy_object_t");
422 tree gpy_object_type_decl
= build_decl(BUILTINS_LOCATION
, TYPE_DECL
, name
,
423 gpy_object_struct_Type
);
424 DECL_ARTIFICIAL(gpy_object_type_decl
) = 1;
425 TYPE_NAME(gpy_object_struct_Type
) = name
;
426 gpy_preserve_from_gc(gpy_object_type_decl
);
427 rest_of_decl_compilation(gpy_object_type_decl
, 1, 0);
429 return build_pointer_type (gpy_object_struct_Type
);
432 void gpy_initilize_types (void)
434 gpy_builtin_types_vec
= VEC_alloc (tree
,gc
,0);
436 tree const_char_type
= build_qualified_type (unsigned_char_type_node
,
438 tree ctype
= build_pointer_type (const_char_type
);
440 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
441 gpy_build_py_object_type ());
442 gpy_preserve_from_gc (gpy_object_type_ptr
);
444 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
445 build_pointer_type (gpy_object_type_ptr
));
446 gpy_preserve_from_gc (gpy_object_type_ptr_ptr
);
448 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
, ctype
);
449 gpy_preserve_from_gc (gpy_const_char_ptr
);
451 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
452 gpy_build_py_vector_type ());
453 gpy_preserve_from_gc (gpy_vector_type
);
455 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
456 build_pointer_type (gpy_vector_type
));
457 gpy_preserve_from_gc (gpy_vector_type_ptr
);
459 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
460 build_pointer_type (gpy_vector_type_ptr
));
461 gpy_preserve_from_gc (gpy_vector_type_ptr_ptr
);
463 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
464 gpy_build_py_attrib_type ());
465 gpy_preserve_from_gc (gpy_attrib_type
);
467 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
469 gpy_preserve_from_gc (gpy_attrib_type_ptr
);
471 VEC_safe_push (tree
, gc
, gpy_builtin_types_vec
,
472 build_pointer_type (gpy_attrib_type_ptr
));
473 gpy_preserve_from_gc (gpy_attrib_type_ptr_ptr
);