1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 You should have received a copy of the GNU General Public License
14 along with GCC; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
20 #include "coretypes.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
41 #include "py-dot-codes.def"
46 #include "py-runtime.h"
48 VEC(tree
,gc
) * gpy_builtin_get_init_call (void)
50 tree fntype
= build_function_type( void_type_node
, void_list_node
);
51 tree gpy_rr_init
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
52 get_identifier("gpy_rr_init_runtime"),
54 tree restype
= TREE_TYPE(gpy_rr_init
);
55 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
57 DECL_CONTEXT(resdecl
) = gpy_rr_init
;
58 DECL_RESULT(gpy_rr_init
) = resdecl
;
59 DECL_EXTERNAL( gpy_rr_init
) = 1;
60 TREE_PUBLIC( gpy_rr_init
) = 1;
62 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
63 VEC_safe_push (tree
,gc
,retval
,
64 build_call_expr( gpy_rr_init
, 0, NULL_TREE
));
69 VEC(tree
,gc
) * gpy_builtin_get_cleanup_final_call( void )
71 tree fntype
= build_function_type( void_type_node
, void_list_node
);
72 tree gpy_rr_cleanup
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
73 get_identifier("gpy_rr_cleanup_final"),
75 tree restype
= TREE_TYPE( gpy_rr_cleanup
);
76 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
78 DECL_CONTEXT(resdecl
) = gpy_rr_cleanup
;
79 DECL_RESULT(gpy_rr_cleanup
) = resdecl
;
80 DECL_EXTERNAL( gpy_rr_cleanup
) = 1;
81 TREE_PUBLIC( gpy_rr_cleanup
) = 1;
83 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
84 VEC_safe_push (tree
,gc
,retval
,
85 build_call_expr( gpy_rr_cleanup
, 0, NULL_TREE
));
90 VEC(tree
,gc
) * gpy_builtin_get_push_context_call( void )
92 tree fntype
= build_function_type( void_type_node
, void_list_node
);
93 tree gpy_rr_push
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
94 get_identifier("gpy_rr_push_context"),
96 tree restype
= TREE_TYPE( gpy_rr_push
);
97 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
99 DECL_CONTEXT(resdecl
) = gpy_rr_push
;
100 DECL_RESULT(gpy_rr_push
) = resdecl
;
101 DECL_EXTERNAL( gpy_rr_push
) = 1;
102 TREE_PUBLIC( gpy_rr_push
) = 1;
104 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
105 VEC_safe_push (tree
,gc
,retval
,
106 build_call_expr( gpy_rr_push
, 0, NULL_TREE
)
112 VEC(tree
,gc
) * gpy_builtin_get_pop_context_call( void )
114 tree fntype
= build_function_type( void_type_node
, void_list_node
);
115 tree gpy_rr_pop
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
116 get_identifier("gpy_rr_pop_context"),
118 tree restype
= TREE_TYPE( gpy_rr_pop
);
119 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
121 DECL_CONTEXT(resdecl
) = gpy_rr_pop
;
122 DECL_RESULT(gpy_rr_pop
) = resdecl
;
123 DECL_EXTERNAL( gpy_rr_pop
) = 1;
124 TREE_PUBLIC( gpy_rr_pop
) = 1;
126 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
127 VEC_safe_push (tree
,gc
,retval
,
128 build_call_expr( gpy_rr_pop
, 0, NULL_TREE
));
133 VEC(tree
,gc
) * gpy_builtin_get_fold_int_call( int val
)
135 tree params
= NULL_TREE
;
137 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
138 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
140 tree fntype
= build_function_type( ptr_type_node
, params
);
141 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
142 get_identifier("gpy_rr_fold_integer"),
144 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
145 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
147 DECL_CONTEXT(resdecl
) = gpy_eval_expr_decl
;
148 DECL_RESULT(gpy_eval_expr_decl
) = resdecl
;
149 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
150 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
152 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
153 VEC_safe_push (tree
,gc
,retval
,
154 build_call_expr (gpy_eval_expr_decl
, 1,
155 build_int_cst (integer_type_node
,
163 VEC(tree
,gc
) * gpy_builtin_get_eval_expression_call( tree t1
, tree t2
, gpy_opcode_t op
)
165 tree params
= NULL_TREE
;
167 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
168 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
169 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
170 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
172 tree fntype
= build_function_type( ptr_type_node
, params
);
173 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
174 get_identifier("gpy_rr_eval_expression"),
176 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
177 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
179 DECL_CONTEXT( resdecl
) = gpy_eval_expr_decl
;
180 DECL_RESULT( gpy_eval_expr_decl
) = resdecl
;
181 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
182 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
184 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
185 VEC_safe_push (tree
,gc
,retval
,
186 build_call_expr( gpy_eval_expr_decl
, 3, t1
, t2
,
187 build_int_cst( integer_type_node
, op
))
193 VEC(tree
,gc
) * gpy_builtin_get_incr_ref_call( tree x
)
195 tree params
= NULL_TREE
;
197 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
198 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
200 tree fntype
= build_function_type( ptr_type_node
, params
);
201 tree gpy_incr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
202 get_identifier("gpy_rr_incr_ref_count"),
204 tree restype
= TREE_TYPE( gpy_incr_ref_decl
);
205 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
207 DECL_CONTEXT( resdecl
) = gpy_incr_ref_decl
;
208 DECL_RESULT( gpy_incr_ref_decl
) = resdecl
;
209 DECL_EXTERNAL( gpy_incr_ref_decl
) = 1;
210 TREE_PUBLIC( gpy_incr_ref_decl
) = 1;
212 VEC(tree
,gc
) * retval
= VEC_alloc (tree
, gc
, 0);
213 VEC_safe_push (tree
,gc
,retval
,
214 build_call_expr( gpy_incr_ref_decl
, 1, x
)
220 VEC(tree
,gc
) * gpy_builtin_get_decr_ref_call( tree x
)
222 tree params
= NULL_TREE
;
224 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
225 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
227 tree fntype
= build_function_type( ptr_type_node
, params
);
228 tree gpy_decr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
229 get_identifier("gpy_rr_decr_ref_count"),
231 tree restype
= TREE_TYPE( gpy_decr_ref_decl
);
232 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
234 DECL_CONTEXT( resdecl
) = gpy_decr_ref_decl
;
235 DECL_RESULT( gpy_decr_ref_decl
) = resdecl
;
236 DECL_EXTERNAL( gpy_decr_ref_decl
) = 1;
237 TREE_PUBLIC( gpy_decr_ref_decl
) = 1;
239 VEC(tree
,gc
) * retval
= VEC_alloc (tree
, gc
, 0);
240 VEC_safe_push(tree
,gc
,retval
,
241 build_call_expr( gpy_decr_ref_decl
, 1, x
)
247 VEC(tree
,gc
) * gpy_builtin_get_print_call( int n
, tree
* args
)
249 tree params
= NULL_TREE
;
251 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
252 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
253 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
254 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
256 tree fntype
= build_function_type( ptr_type_node
, params
);
257 tree gpy_eval_print_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
258 get_identifier("gpy_rr_eval_print"),
260 tree restype
= TREE_TYPE(gpy_eval_print_decl
);
261 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
263 DECL_CONTEXT( resdecl
) = gpy_eval_print_decl
;
264 DECL_RESULT( gpy_eval_print_decl
) = resdecl
;
265 DECL_EXTERNAL( gpy_eval_print_decl
) = 1;
266 TREE_PUBLIC( gpy_eval_print_decl
) = 1;
268 tree
* vec
= XNEWVEC( tree
, n
+2 );
270 printf("n = <%i>!!\n\n", n
);
272 vec
[0] = build_int_cst( integer_type_node
, 1 );
273 vec
[1] = build_int_cst( integer_type_node
, n
);
275 int idx
= 2, idy
= 0;
276 for( ; idy
<n
; ++idy
)
278 vec
[idx
] = args
[idy
];
281 VEC(tree
,gc
) * retval
= VEC_alloc (tree
, gc
, 0);
282 VEC_safe_push (tree
,gc
,retval
,
283 build_call_expr_loc_array (UNKNOWN_LOCATION
,
290 VEC(tree
,gc
) * gpy_builtin_get_finalize_block_call (int n
, tree
* args
)
292 tree params
= NULL_TREE
;
294 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
295 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
296 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
298 tree fntype
= build_function_type( ptr_type_node
, params
);
299 tree gpy_finalize_block_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
300 get_identifier("gpy_rr_finalize_block_decls"),
303 tree restype
= TREE_TYPE( gpy_finalize_block_decl
);
304 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
307 DECL_CONTEXT( resdecl
) = gpy_finalize_block_decl
;
308 DECL_RESULT( gpy_finalize_block_decl
) = resdecl
;
309 DECL_EXTERNAL( gpy_finalize_block_decl
) = 1;
310 TREE_PUBLIC( gpy_finalize_block_decl
) = 1;
312 tree
* vec
= XNEWVEC (tree
, n
+1);
314 vec
[0] = build_int_cst (integer_type_node
, n
);
316 int idx
= 1, idy
= 0;
317 for( ; idy
<n
; ++idy
)
319 vec
[idx
] = args
[idy
];
323 VEC(tree
,gc
) * retval
= VEC_alloc (tree
, gc
, 0);
324 VEC_safe_push (tree
, gc
, retval
,
325 build_call_expr_loc_array (UNKNOWN_LOCATION
,
326 gpy_finalize_block_decl
,
333 VEC(tree
,gc
) * gpy_builtin_get_set_decl_call (tree decl
)
335 tree params
= NULL_TREE
;
337 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
338 chainon (params
, tree_cons (NULL_TREE
, gpy_object_type_ptr
, NULL_TREE
));
339 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
341 tree fntype
= build_function_type (void_type_node
, params
);
342 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
343 get_identifier("gpy_rr_set_decl_val"),
346 tree restype
= TREE_TYPE (gpy_rr_decl
);
347 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
350 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
351 DECL_RESULT (gpy_rr_decl
) = resdecl
;
352 DECL_EXTERNAL (gpy_rr_decl
) = 1;
353 TREE_PUBLIC (gpy_rr_decl
) = 1;
355 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
356 debug ("c_ident = <%s>!\n", c_ident
);
358 tree str
= build_string (strlen (c_ident
), c_ident
);
359 TREE_TYPE (str
) = gpy_const_char_ptr
;
360 tree ident
= build_fold_addr_expr (str
);
362 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
363 VEC_safe_push (tree
,gc
,retval
,
364 build_call_expr (gpy_rr_decl
, 2, ident
, decl
)
370 VEC(tree
,gc
) * gpy_builtin_get_register_decl_call (tree decl
)
372 tree params
= NULL_TREE
;
373 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
375 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
376 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
378 tree fntype
= build_function_type (void_type_node
, params
);
379 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
380 get_identifier("gpy_rr_register_decl"),
383 tree restype
= TREE_TYPE (gpy_rr_decl
);
384 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
387 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
388 DECL_RESULT (gpy_rr_decl
) = resdecl
;
389 DECL_EXTERNAL (gpy_rr_decl
) = 1;
390 TREE_PUBLIC (gpy_rr_decl
) = 1;
392 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
393 debug ("c_ident = <%s>!\n", c_ident
);
395 tree str
= build_string (strlen (c_ident
), c_ident
);
396 TREE_TYPE (str
) = gpy_const_char_ptr
;
397 tree ident
= build_fold_addr_expr (str
);
399 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
400 VEC_safe_push (tree
,gc
,retval
,
401 build_call_expr (gpy_rr_decl
, 1, ident
)
407 VEC(tree
,gc
) * gpy_builtin_get_register_callable_call (tree decl
, int n
)
409 tree params
= NULL_TREE
;
410 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
412 chainon (params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
));
413 chainon (params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
));
414 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
415 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
417 tree fntype
= build_function_type (void_type_node
, params
);
418 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
419 get_identifier("gpy_rr_register_callable"),
422 tree restype
= TREE_TYPE (gpy_rr_decl
);
423 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
426 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
427 DECL_RESULT (gpy_rr_decl
) = resdecl
;
428 DECL_EXTERNAL (gpy_rr_decl
) = 1;
429 TREE_PUBLIC (gpy_rr_decl
) = 1;
431 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
432 debug ("c_ident = <%s>!\n", c_ident
);
434 tree str
= build_string (strlen (c_ident
), c_ident
);
435 TREE_TYPE (str
) = gpy_const_char_ptr
;
436 tree ident
= build_fold_addr_expr (str
);
438 tree address
= build_decl (BUILTINS_LOCATION
, VAR_DECL
, create_tmp_var_name("C"),
441 VEC(tree
,gc
) * retval
= VEC_alloc (tree
,gc
,0);
443 VEC_safe_push (tree
, gc
, retval
,
444 build2 (MODIFY_EXPR
, gpy_const_char_ptr
,
446 VEC_safe_push (tree
, gc
, retval
,
447 build_call_expr (gpy_rr_decl
, 3,
448 build_fold_addr_expr (decl
),
449 build_int_cst (integer_type_node
, n
),
455 VEC(tree
,gc
) * gpy_builtin_get_fold_call_call (const char * ident
, int n
,
461 VEC(tree
,gc
) * gpy_builtin_get_eval_accessor_call (tree t1
, tree t2
)
463 fatal_error("Accessor's not implemented yet!\n");