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"
45 #include "py-runtime.h"
47 tree
gpy_builtin_get_init_call( void )
49 tree fntype
= build_function_type( void_type_node
, void_list_node
);
50 tree gpy_rr_init
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
51 get_identifier("gpy_rr_init_runtime"),
53 tree restype
= TREE_TYPE(gpy_rr_init
);
54 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
56 DECL_CONTEXT(resdecl
) = gpy_rr_init
;
57 DECL_RESULT(gpy_rr_init
) = resdecl
;
58 DECL_EXTERNAL( gpy_rr_init
) = 1;
59 TREE_PUBLIC( gpy_rr_init
) = 1;
61 return ( build_call_expr( gpy_rr_init
, 0, NULL_TREE
) );
64 tree
gpy_builtin_get_cleanup_final_call( void )
66 tree fntype
= build_function_type( void_type_node
, void_list_node
);
67 tree gpy_rr_cleanup
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
68 get_identifier("gpy_rr_cleanup_final"),
70 tree restype
= TREE_TYPE( gpy_rr_cleanup
);
71 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
73 DECL_CONTEXT(resdecl
) = gpy_rr_cleanup
;
74 DECL_RESULT(gpy_rr_cleanup
) = resdecl
;
75 DECL_EXTERNAL( gpy_rr_cleanup
) = 1;
76 TREE_PUBLIC( gpy_rr_cleanup
) = 1;
78 return ( build_call_expr( gpy_rr_cleanup
, 0, NULL_TREE
) );
81 tree
gpy_builtin_get_push_context_call( void )
83 tree fntype
= build_function_type( void_type_node
, void_list_node
);
84 tree gpy_rr_push
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
85 get_identifier("gpy_rr_push_context"),
87 tree restype
= TREE_TYPE( gpy_rr_push
);
88 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
90 DECL_CONTEXT(resdecl
) = gpy_rr_push
;
91 DECL_RESULT(gpy_rr_push
) = resdecl
;
92 DECL_EXTERNAL( gpy_rr_push
) = 1;
93 TREE_PUBLIC( gpy_rr_push
) = 1;
95 return ( build_call_expr( gpy_rr_push
, 0, NULL_TREE
) );
98 tree
gpy_builtin_get_pop_context_call( void )
100 tree fntype
= build_function_type( void_type_node
, void_list_node
);
101 tree gpy_rr_pop
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
102 get_identifier("gpy_rr_pop_context"),
104 tree restype
= TREE_TYPE( gpy_rr_pop
);
105 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
107 DECL_CONTEXT(resdecl
) = gpy_rr_pop
;
108 DECL_RESULT(gpy_rr_pop
) = resdecl
;
109 DECL_EXTERNAL( gpy_rr_pop
) = 1;
110 TREE_PUBLIC( gpy_rr_pop
) = 1;
112 return ( build_call_expr( gpy_rr_pop
, 0, NULL_TREE
) );
115 tree
gpy_builtin_get_fold_int_call( int val
)
117 tree params
= NULL_TREE
;
119 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
120 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
122 tree fntype
= build_function_type( ptr_type_node
, params
);
123 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
124 get_identifier("gpy_rr_fold_integer"),
126 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
127 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
129 DECL_CONTEXT(resdecl
) = gpy_eval_expr_decl
;
130 DECL_RESULT(gpy_eval_expr_decl
) = resdecl
;
131 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
132 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
134 return ( build_call_expr( gpy_eval_expr_decl
, 1,
135 build_int_cst( integer_type_node
,
141 tree
gpy_builtin_get_eval_expression_call( tree t1
, tree t2
, gpy_opcode_t op
)
143 tree params
= NULL_TREE
;
145 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
146 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
147 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
148 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
150 tree fntype
= build_function_type( ptr_type_node
, params
);
151 tree gpy_eval_expr_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
152 get_identifier("gpy_rr_eval_expression"),
154 tree restype
= TREE_TYPE(gpy_eval_expr_decl
);
155 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
157 DECL_CONTEXT( resdecl
) = gpy_eval_expr_decl
;
158 DECL_RESULT( gpy_eval_expr_decl
) = resdecl
;
159 DECL_EXTERNAL( gpy_eval_expr_decl
) = 1;
160 TREE_PUBLIC( gpy_eval_expr_decl
) = 1;
162 return ( build_call_expr( gpy_eval_expr_decl
, 3, t1
, t2
,
163 build_int_cst( integer_type_node
, op
))
167 tree
gpy_builtin_get_incr_ref_call( tree x
)
169 tree params
= NULL_TREE
;
171 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
172 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
174 tree fntype
= build_function_type( ptr_type_node
, params
);
175 tree gpy_incr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
176 get_identifier("gpy_rr_incr_ref_count"),
178 tree restype
= TREE_TYPE( gpy_incr_ref_decl
);
179 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
181 DECL_CONTEXT( resdecl
) = gpy_incr_ref_decl
;
182 DECL_RESULT( gpy_incr_ref_decl
) = resdecl
;
183 DECL_EXTERNAL( gpy_incr_ref_decl
) = 1;
184 TREE_PUBLIC( gpy_incr_ref_decl
) = 1;
186 return ( build_call_expr( gpy_incr_ref_decl
, 1, x
) );
189 tree
gpy_builtin_get_decr_ref_call( tree x
)
191 tree params
= NULL_TREE
;
193 chainon( params
, tree_cons (NULL_TREE
, ptr_type_node
, NULL_TREE
) );
194 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
196 tree fntype
= build_function_type( ptr_type_node
, params
);
197 tree gpy_decr_ref_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
198 get_identifier("gpy_rr_decr_ref_count"),
200 tree restype
= TREE_TYPE( gpy_decr_ref_decl
);
201 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
203 DECL_CONTEXT( resdecl
) = gpy_decr_ref_decl
;
204 DECL_RESULT( gpy_decr_ref_decl
) = resdecl
;
205 DECL_EXTERNAL( gpy_decr_ref_decl
) = 1;
206 TREE_PUBLIC( gpy_decr_ref_decl
) = 1;
208 return ( build_call_expr( gpy_decr_ref_decl
, 1, x
) );
211 tree
gpy_builtin_get_print_call( int n
, tree
* args
)
213 tree params
= NULL_TREE
;
215 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
216 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
217 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
218 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
220 tree fntype
= build_function_type( ptr_type_node
, params
);
221 tree gpy_eval_print_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
222 get_identifier("gpy_rr_eval_print"),
224 tree restype
= TREE_TYPE(gpy_eval_print_decl
);
225 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
227 DECL_CONTEXT( resdecl
) = gpy_eval_print_decl
;
228 DECL_RESULT( gpy_eval_print_decl
) = resdecl
;
229 DECL_EXTERNAL( gpy_eval_print_decl
) = 1;
230 TREE_PUBLIC( gpy_eval_print_decl
) = 1;
232 tree
* vec
= XNEWVEC( tree
, n
+2 );
234 printf("n = <%i>!!\n\n", n
);
236 vec
[0] = build_int_cst( integer_type_node
, 1 );
237 vec
[1] = build_int_cst( integer_type_node
, n
);
239 int idx
= 2, idy
= 0;
240 for( ; idy
<n
; ++idy
)
242 vec
[idx
] = args
[idy
];
246 return ( build_call_expr_loc_array( UNKNOWN_LOCATION
, gpy_eval_print_decl
,
251 tree
gpy_builtin_get_finalize_block_call( int n
, tree
* args
)
253 tree params
= NULL_TREE
;
255 chainon( params
, tree_cons (NULL_TREE
, integer_type_node
, NULL_TREE
) );
256 chainon( params
, tree_cons (NULL_TREE
, va_list_type_node
, NULL_TREE
) );
257 chainon( params
, tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
) );
259 tree fntype
= build_function_type( ptr_type_node
, params
);
260 tree gpy_finalize_block_decl
= build_decl( UNKNOWN_LOCATION
, FUNCTION_DECL
,
261 get_identifier("gpy_rr_finalize_block_decls"),
264 tree restype
= TREE_TYPE( gpy_finalize_block_decl
);
265 tree resdecl
= build_decl( UNKNOWN_LOCATION
, RESULT_DECL
, NULL_TREE
,
268 DECL_CONTEXT( resdecl
) = gpy_finalize_block_decl
;
269 DECL_RESULT( gpy_finalize_block_decl
) = resdecl
;
270 DECL_EXTERNAL( gpy_finalize_block_decl
) = 1;
271 TREE_PUBLIC( gpy_finalize_block_decl
) = 1;
273 tree
* vec
= XNEWVEC( tree
, n
+1 );
275 vec
[0] = build_int_cst( integer_type_node
, n
);
277 int idx
= 1, idy
= 0;
278 for( ; idy
<n
; ++idy
)
280 vec
[idx
] = args
[idy
];
284 return ( build_call_expr_loc_array( UNKNOWN_LOCATION
, gpy_finalize_block_decl
,
288 tree
gpy_builtin_get_eval_accessor_call( tree t1
, tree t2
)
290 fatal_error("Accessor's not implemented yet!\n");