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 tree
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 return ( build_call_expr( gpy_rr_init
, 0, NULL_TREE
) );
65 tree
gpy_builtin_get_cleanup_final_call( void )
67 tree fntype
= build_function_type( void_type_node
, void_list_node
);
68 tree gpy_rr_cleanup
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
69 get_identifier("gpy_rr_cleanup_final"),
71 tree restype
= TREE_TYPE( gpy_rr_cleanup
);
72 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
74 DECL_CONTEXT(resdecl
) = gpy_rr_cleanup
;
75 DECL_RESULT(gpy_rr_cleanup
) = resdecl
;
76 DECL_EXTERNAL( gpy_rr_cleanup
) = 1;
77 TREE_PUBLIC( gpy_rr_cleanup
) = 1;
79 return ( build_call_expr( gpy_rr_cleanup
, 0, NULL_TREE
) );
82 tree
gpy_builtin_get_push_context_call( void )
84 tree fntype
= build_function_type( void_type_node
, void_list_node
);
85 tree gpy_rr_push
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
86 get_identifier("gpy_rr_push_context"),
88 tree restype
= TREE_TYPE( gpy_rr_push
);
89 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
91 DECL_CONTEXT(resdecl
) = gpy_rr_push
;
92 DECL_RESULT(gpy_rr_push
) = resdecl
;
93 DECL_EXTERNAL( gpy_rr_push
) = 1;
94 TREE_PUBLIC( gpy_rr_push
) = 1;
96 return ( build_call_expr( gpy_rr_push
, 0, NULL_TREE
) );
99 tree
gpy_builtin_get_pop_context_call( void )
101 tree fntype
= build_function_type( void_type_node
, void_list_node
);
102 tree gpy_rr_pop
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
103 get_identifier("gpy_rr_pop_context"),
105 tree restype
= TREE_TYPE( gpy_rr_pop
);
106 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
108 DECL_CONTEXT(resdecl
) = gpy_rr_pop
;
109 DECL_RESULT(gpy_rr_pop
) = resdecl
;
110 DECL_EXTERNAL( gpy_rr_pop
) = 1;
111 TREE_PUBLIC( gpy_rr_pop
) = 1;
113 return ( build_call_expr( gpy_rr_pop
, 0, NULL_TREE
) );
116 tree
gpy_builtin_get_fold_int_call( int val
)
118 tree params
= NULL_TREE
;
120 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
121 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
123 tree fntype
= build_function_type( ptr_type_node
, params
);
124 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
125 get_identifier("gpy_rr_fold_integer"),
127 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
128 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
130 DECL_CONTEXT(resdecl
) = gpy_eval_expr_decl
;
131 DECL_RESULT(gpy_eval_expr_decl
) = resdecl
;
132 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
133 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
135 return ( build_call_expr( gpy_eval_expr_decl
, 1,
136 build_int_cst( integer_type_node
,
142 tree
gpy_builtin_get_eval_expression_call( tree t1
, tree t2
, gpy_opcode_t op
)
144 tree params
= NULL_TREE
;
146 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
147 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
148 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
149 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
151 tree fntype
= build_function_type( ptr_type_node
, params
);
152 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
153 get_identifier("gpy_rr_eval_expression"),
155 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
156 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
158 DECL_CONTEXT( resdecl
) = gpy_eval_expr_decl
;
159 DECL_RESULT( gpy_eval_expr_decl
) = resdecl
;
160 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
161 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
163 return ( build_call_expr( gpy_eval_expr_decl
, 3, t1
, t2
,
164 build_int_cst( integer_type_node
, op
))
168 tree
gpy_builtin_get_incr_ref_call( tree x
)
170 tree params
= NULL_TREE
;
172 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
173 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
175 tree fntype
= build_function_type( ptr_type_node
, params
);
176 tree gpy_incr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
177 get_identifier("gpy_rr_incr_ref_count"),
179 tree restype
= TREE_TYPE( gpy_incr_ref_decl
);
180 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
182 DECL_CONTEXT( resdecl
) = gpy_incr_ref_decl
;
183 DECL_RESULT( gpy_incr_ref_decl
) = resdecl
;
184 DECL_EXTERNAL( gpy_incr_ref_decl
) = 1;
185 TREE_PUBLIC( gpy_incr_ref_decl
) = 1;
187 return ( build_call_expr( gpy_incr_ref_decl
, 1, x
) );
190 tree
gpy_builtin_get_decr_ref_call( tree x
)
192 tree params
= NULL_TREE
;
194 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
195 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
197 tree fntype
= build_function_type( ptr_type_node
, params
);
198 tree gpy_decr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
199 get_identifier("gpy_rr_decr_ref_count"),
201 tree restype
= TREE_TYPE( gpy_decr_ref_decl
);
202 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
204 DECL_CONTEXT( resdecl
) = gpy_decr_ref_decl
;
205 DECL_RESULT( gpy_decr_ref_decl
) = resdecl
;
206 DECL_EXTERNAL( gpy_decr_ref_decl
) = 1;
207 TREE_PUBLIC( gpy_decr_ref_decl
) = 1;
209 return ( build_call_expr( gpy_decr_ref_decl
, 1, x
) );
212 tree
gpy_builtin_get_print_call( int n
, tree
* args
)
214 tree params
= NULL_TREE
;
216 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
217 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
218 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
219 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
221 tree fntype
= build_function_type( ptr_type_node
, params
);
222 tree gpy_eval_print_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
223 get_identifier("gpy_rr_eval_print"),
225 tree restype
= TREE_TYPE(gpy_eval_print_decl
);
226 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
228 DECL_CONTEXT( resdecl
) = gpy_eval_print_decl
;
229 DECL_RESULT( gpy_eval_print_decl
) = resdecl
;
230 DECL_EXTERNAL( gpy_eval_print_decl
) = 1;
231 TREE_PUBLIC( gpy_eval_print_decl
) = 1;
233 tree
* vec
= XNEWVEC( tree
, n
+2 );
235 printf("n = <%i>!!\n\n", n
);
237 vec
[0] = build_int_cst( integer_type_node
, 1 );
238 vec
[1] = build_int_cst( integer_type_node
, n
);
240 int idx
= 2, idy
= 0;
241 for( ; idy
<n
; ++idy
)
243 vec
[idx
] = args
[idy
];
247 return ( build_call_expr_loc_array( UNKNOWN_LOCATION
, gpy_eval_print_decl
,
252 tree
gpy_builtin_get_finalize_block_call( int n
, tree
* args
)
254 tree params
= NULL_TREE
;
256 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
257 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
258 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
260 tree fntype
= build_function_type( ptr_type_node
, params
);
261 tree gpy_finalize_block_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
262 get_identifier("gpy_rr_finalize_block_decls"),
265 tree restype
= TREE_TYPE( gpy_finalize_block_decl
);
266 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
269 DECL_CONTEXT( resdecl
) = gpy_finalize_block_decl
;
270 DECL_RESULT( gpy_finalize_block_decl
) = resdecl
;
271 DECL_EXTERNAL( gpy_finalize_block_decl
) = 1;
272 TREE_PUBLIC( gpy_finalize_block_decl
) = 1;
274 tree
* vec
= XNEWVEC (tree
, n
+1);
276 vec
[0] = build_int_cst (integer_type_node
, n
);
278 int idx
= 1, idy
= 0;
279 for( ; idy
<n
; ++idy
)
281 vec
[idx
] = args
[idy
];
285 return ( build_call_expr_loc_array( UNKNOWN_LOCATION
, gpy_finalize_block_decl
,
289 tree
gpy_builtin_get_set_decl_call (tree decl
)
291 tree params
= NULL_TREE
;
293 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
294 chainon (params
, tree_cons (NULL_TREE
, gpy_object_type_ptr
, NULL_TREE
));
295 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
297 tree fntype
= build_function_type (void_type_node
, params
);
298 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
299 get_identifier("gpy_rr_set_decl_val"),
302 tree restype
= TREE_TYPE (gpy_rr_decl
);
303 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
306 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
307 DECL_RESULT (gpy_rr_decl
) = resdecl
;
308 DECL_EXTERNAL (gpy_rr_decl
) = 1;
309 TREE_PUBLIC (gpy_rr_decl
) = 1;
311 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
312 debug ("c_ident = <%s>!\n", c_ident
);
314 tree str
= build_string (strlen (c_ident
), c_ident
);
315 TREE_TYPE (str
) = gpy_const_char_ptr
;
316 tree ident
= build_fold_addr_expr (str
);
318 return build_call_expr (gpy_rr_decl
, 2, ident
, decl
);
321 tree
gpy_builtin_get_register_decl_call (tree decl
)
323 tree params
= NULL_TREE
;
324 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
326 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
327 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
329 tree fntype
= build_function_type (void_type_node
, params
);
330 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
331 get_identifier("gpy_rr_register_decl"),
334 tree restype
= TREE_TYPE (gpy_rr_decl
);
335 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
338 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
339 DECL_RESULT (gpy_rr_decl
) = resdecl
;
340 DECL_EXTERNAL (gpy_rr_decl
) = 1;
341 TREE_PUBLIC (gpy_rr_decl
) = 1;
343 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
344 debug ("c_ident = <%s>!\n", c_ident
);
346 tree str
= build_string (strlen (c_ident
), c_ident
);
347 TREE_TYPE (str
) = gpy_const_char_ptr
;
348 tree ident
= build_fold_addr_expr (str
);
351 return build_call_expr (gpy_rr_decl
, 1, ident
);
354 tree
gpy_builtin_get_register_callable_call (tree decl
, int n
)
356 tree params
= NULL_TREE
;
357 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
359 chainon (params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
));
360 chainon (params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
));
361 chainon (params
, tree_cons (NULL_TREE
, gpy_const_char_ptr
, NULL_TREE
));
362 chainon (params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
));
364 tree fntype
= build_function_type (void_type_node
, params
);
365 tree gpy_rr_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
366 get_identifier("gpy_rr_register_callable"),
369 tree restype
= TREE_TYPE (gpy_rr_decl
);
370 tree resdecl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
373 DECL_CONTEXT (resdecl
) = gpy_rr_decl
;
374 DECL_RESULT (gpy_rr_decl
) = resdecl
;
375 DECL_EXTERNAL (gpy_rr_decl
) = 1;
376 TREE_PUBLIC (gpy_rr_decl
) = 1;
378 const char * c_ident
= IDENTIFIER_POINTER(DECL_NAME(decl
));
379 debug ("c_ident = <%s>!\n", c_ident
);
381 tree str
= build_string (strlen (c_ident
), c_ident
);
382 TREE_TYPE (str
) = gpy_const_char_ptr
;
383 tree ident
= build_fold_addr_expr (str
);
384 TREE_TYPE (ident
) = gpy_const_char_ptr
;
386 return build_call_expr (gpy_rr_decl
, 3,
387 build_fold_addr_expr (decl
),
388 build_int_cst (integer_type_node
, n
),
393 tree
gpy_builtin_get_fold_call_call (const char * ident
, int n
,
396 tree retval
= NULL_TREE
;
401 tree
gpy_builtin_get_eval_accessor_call (tree t1
, tree t2
)
403 fatal_error("Accessor's not implemented yet!\n");