fixed many errors and cleaned up includes
[official-gcc.git] / gcc / python / py-runtime.c
blobbb4807f06a1646914ed2d83e8b21cd9314b7a0fe
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
6 version.
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
11 for more details.
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/>. */
17 #include "config.h"
18 #include "system.h"
19 #include "ansidecl.h"
20 #include "coretypes.h"
21 #include "opts.h"
22 #include "tree.h"
23 #include "gimple.h"
24 #include "toplev.h"
25 #include "debug.h"
26 #include "options.h"
27 #include "flags.h"
28 #include "convert.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
32 #include "target.h"
34 #include <gmp.h>
35 #include <mpfr.h>
37 #include "vec.h"
38 #include "hashtab.h"
40 #include "gpython.h"
41 #include "py-dot-codes.def"
42 #include "py-dot.h"
43 #include "py-vec.h"
44 #include "py-tree.h"
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"),
52 fntype );
53 tree restype = TREE_TYPE(gpy_rr_init);
54 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
55 restype );
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"),
69 fntype );
70 tree restype = TREE_TYPE( gpy_rr_cleanup );
71 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
72 restype );
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"),
86 fntype );
87 tree restype = TREE_TYPE( gpy_rr_push );
88 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
89 restype );
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"),
103 fntype );
104 tree restype = TREE_TYPE( gpy_rr_pop );
105 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
106 restype );
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"),
125 fntype );
126 tree restype = TREE_TYPE(gpy_eval_expr_decl);
127 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
128 restype );
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,
136 val )
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"),
153 fntype );
154 tree restype = TREE_TYPE(gpy_eval_expr_decl);
155 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
156 restype );
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"),
177 fntype );
178 tree restype = TREE_TYPE( gpy_incr_ref_decl );
179 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
180 restype );
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"),
199 fntype );
200 tree restype = TREE_TYPE( gpy_decr_ref_decl );
201 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
202 restype );
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"),
223 fntype );
224 tree restype = TREE_TYPE(gpy_eval_print_decl);
225 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
226 restype );
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];
243 idx++;
246 return ( build_call_expr_loc_array( UNKNOWN_LOCATION, gpy_eval_print_decl,
247 n+2, vec )
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"),
262 fntype );
264 tree restype = TREE_TYPE( gpy_finalize_block_decl );
265 tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
266 restype );
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];
281 idx++;
284 return ( build_call_expr_loc_array( UNKNOWN_LOCATION, gpy_finalize_block_decl,
285 n+1, vec ) );
288 tree gpy_builtin_get_eval_accessor_call( tree t1, tree t2 )
290 fatal_error("Accessor's not implemented yet!\n");