summaryrefslogtreecommitdiff
path: root/gcc/python
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/python')
-rw-r--r--gcc/python/expression.c14
-rw-r--r--gcc/python/py_builtins.c38
-rw-r--r--gcc/python/pypy.c30
-rw-r--r--gcc/python/runtime.h2
4 files changed, 78 insertions, 6 deletions
diff --git a/gcc/python/expression.c b/gcc/python/expression.c
index 37d5b62e627..5944ce99c4b 100644
--- a/gcc/python/expression.c
+++ b/gcc/python/expression.c
@@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see
#include "gpy.h"
#include "symbols.h"
#include "opcodes.def"
-#include "y.py.h"
+#include "runtime.h"
tree gpy_process_assign( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
tree * block)
@@ -75,7 +75,17 @@ tree gpy_process_assign( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
}
rhs_tree = gpy_process_expression( opb, block );
- retval = build2( MODIFY_EXPR, ptr_type_node, decl, rhs_tree );
+
+ tree address = build_decl( opa->loc, VAR_DECL,
+ create_tmp_var_name("A"),
+ build_pointer_type( void_type_node ) );
+
+ append_to_statement_list( build2( MODIFY_EXPR, ptr_type_node, address, rhs_tree ),
+ block );
+
+ append_to_statement_list( gpy_builtin_get_incr_ref_call( address ), block );
+
+ retval = build2( MODIFY_EXPR, ptr_type_node, decl, address );
}
else
fatal_error("Invalid accessor for assignment <0x%x>!\n", opa->type );
diff --git a/gcc/python/py_builtins.c b/gcc/python/py_builtins.c
index 2a880246130..6b1dbe648a4 100644
--- a/gcc/python/py_builtins.c
+++ b/gcc/python/py_builtins.c
@@ -248,6 +248,44 @@ tree gpy_builtin_get_print_call( int n, tree * args )
);
}
+tree gpy_builtin_get_finalize_block_call( int n, tree * args )
+{
+ tree params = NULL_TREE;
+
+ chainon( params, tree_cons (NULL_TREE, integer_type_node, NULL_TREE) );
+ chainon( params, tree_cons (NULL_TREE, va_list_type_node, NULL_TREE) );
+ chainon( params, tree_cons (NULL_TREE, void_type_node, NULL_TREE) );
+
+ tree fntype = build_function_type( ptr_type_node, params );
+ tree gpy_finalize_block_decl = build_decl( UNKNOWN_LOCATION, FUNCTION_DECL,
+ get_identifier("gpy_rr_finalize_block_decls"),
+ fntype );
+
+ tree restype = TREE_TYPE( gpy_finalize_block_decl );
+ tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
+ restype );
+
+ DECL_CONTEXT( resdecl ) = gpy_finalize_block_decl;
+ DECL_RESULT( gpy_finalize_block_decl ) = resdecl;
+ DECL_EXTERNAL( gpy_finalize_block_decl ) = 1;
+ TREE_PUBLIC( gpy_finalize_block_decl ) = 1;
+
+ tree * vec = XNEWVEC( tree, n+1 );
+
+ vec[0] = build_int_cst( integer_type_node, n );
+
+ int idx = 1, idy = 0;
+ for( ; idy<n; ++idy )
+ {
+ vec[idx] = args[idy];
+ idx++;
+ }
+
+ return ( build_call_expr_loc_array( UNKNOWN_LOCATION, gpy_finalize_block_decl,
+ n+1, vec )
+ );
+}
+
tree gpy_builtin_get_eval_accessor_call( tree t1, tree t2 )
{
fatal_error("Accessor's not implemented yet!\n");
diff --git a/gcc/python/pypy.c b/gcc/python/pypy.c
index d9ec23a7deb..cfa4052a646 100644
--- a/gcc/python/pypy.c
+++ b/gcc/python/pypy.c
@@ -504,7 +504,7 @@ tree gpy_process_print( gpy_symbol_obj *sym )
t = t->next;
}
- return ( gpy_builtin_get_print_call( len, args) );
+ return ( gpy_builtin_get_print_call( len, args ) );
}
else
error("print call without any arguments!\n");
@@ -523,6 +523,7 @@ tree gpy_get_tree( gpy_symbol_obj * sym, tree * block )
{
sym = gpy_process_AST_Align( &sym );
/*sym = gpy_process_AST_Split_Asigns( &sym );*/
+
retval_decl = gpy_process_expression( sym, block );
}
else
@@ -600,7 +601,7 @@ void gpy_write_globals( void )
for( idx= 0; VEC_iterate(gpy_sym,gpy_decls,idx,it); ++idx )
{
- tree x = gpy_get_tree( it , NULL );
+ tree x = gpy_get_tree( it , &main_stmts );
gpy_preserve_from_gc( x );
gcc_assert( x );
@@ -615,8 +616,7 @@ void gpy_write_globals( void )
}
}
- append_to_statement_list( gpy_builtin_get_cleanup_final_call( ), &main_stmts );
-
+ int block_decl_len = 0;
gpy_ident vit = NULL;
for( idx = 0; VEC_iterate( gpy_ident,co->var_decl_t, idx, vit ); ++idx )
{
@@ -627,8 +627,30 @@ void gpy_write_globals( void )
vit->ident, "main" );
TREE_CHAIN( x ) = declare_vars;
declare_vars = x;
+ block_decl_len++;
}
+ if( block_decl_len > 0 )
+ {
+ tree * block_decl_vec = XNEWVEC( tree, block_decl_len );
+ int idy = 0;
+
+ for( idx = 0; VEC_iterate( gpy_ident,co->var_decl_t, idx, vit ); ++idx )
+ {
+ tree x = gpy_ctx_lookup_decl( vit->ident, VAR );
+ gcc_assert( TREE_CODE( x ) == VAR_DECL );
+
+ block_decl_vec[ idy ] = x;
+ idy++;
+ }
+
+ append_to_statement_list( gpy_builtin_get_finalize_block_call( block_decl_len,
+ block_decl_vec ),
+ &main_stmts );
+ }
+
+ append_to_statement_list( gpy_builtin_get_cleanup_final_call( ), &main_stmts );
+
tree main_set_ret = build2( MODIFY_EXPR, TREE_TYPE(main_ret),
main_ret, build_int_cst(integer_type_node, 0));
TREE_USED(main_set_ret) = true;
diff --git a/gcc/python/runtime.h b/gcc/python/runtime.h
index f0e02935320..b1bbbbba420 100644
--- a/gcc/python/runtime.h
+++ b/gcc/python/runtime.h
@@ -35,6 +35,8 @@ extern tree gpy_builtin_get_decr_ref_call( tree );
extern tree gpy_builtin_get_print_call( int , tree * );
+extern tree gpy_builtin_get_finalize_block_call( int , tree * );
+
extern tree gpy_builtin_get_eval_expression_call( tree , tree , gpy_opcode_t );
#endif /* __RUNTIME_H__ */