diff options
author | redbrain <redbrain@gcc.gnu.org> | 2011-04-13 09:45:27 +0100 |
---|---|---|
committer | redbrain <redbrain@gcc.gnu.org> | 2011-04-13 09:45:27 +0100 |
commit | 97a239092bd1f11cce039a1d1bf70366745954ca (patch) | |
tree | be0d179e8c86d1db117a2ad51758e24a2ccc9b08 | |
parent | d42acece1346dc0826a32f2bcdcc2fac481a0dac (diff) | |
download | gcc-97a239092bd1f11cce039a1d1bf70366745954ca.tar.gz |
middle of fixing alot
-rw-r--r-- | gcc/python/py-decl.c | 18 | ||||
-rw-r--r-- | gcc/python/py-lang.c | 16 | ||||
-rw-r--r-- | gcc/python/py-stmt.c | 476 | ||||
-rw-r--r-- | gcc/python/py-tree.h | 66 | ||||
-rw-r--r-- | gcc/python/py-types.c | 148 | ||||
-rw-r--r-- | gcc/python/py-types.h | 4 | ||||
-rw-r--r-- | gcc/python/py-vec.c | 146 | ||||
-rw-r--r-- | gcc/python/py-vec.h | 42 |
8 files changed, 308 insertions, 608 deletions
diff --git a/gcc/python/py-decl.c b/gcc/python/py-decl.c index 02d360f09ec..49dc15c9a68 100644 --- a/gcc/python/py-decl.c +++ b/gcc/python/py-decl.c @@ -45,7 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "py-types.h" #include "py-runtime.h" -VEC(tree,gc) * gpy_fold_primitive (const gpy_symbol_obj * const sym) +VEC(tree,gc) * gpy_decl_fold_primitive (const gpy_symbol_obj * const sym) { VEC(tree,gc) * retval = VEC_alloc(tree,gc,0); switch( sym->op_a_t ) @@ -71,15 +71,9 @@ VEC(tree,gc) * gpy_fold_primitive (const gpy_symbol_obj * const sym) return retval; } -VEC(tree,gc) * gpy_fold_call (tree decl, location_t l) -{ - VEC(tree,gc) * retval = VEC_alloc(tree,gc,0); - - return retval; -} - -VEC(tree,gc) * gpy_process_assign (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b, - VEC(gpy_ctx_t,gc) * context) +VEC(tree,gc) * gpy_decl_process_assign (gpy_symbol_obj ** op_a, + gpy_symbol_obj ** op_b, + VEC(gpy_ctx_t,gc) * context) { VEC(tree,gc) * retval = NULL; gpy_symbol_obj *opa, *opb; @@ -132,8 +126,8 @@ VEC(tree,gc) * gpy_process_assign (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_ } VEC(tree,gc) * -gpy_process_bin_expression (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b, - gpy_opcode_t operation, VEC(gpy_ctx_t,gc) * context) +gpy_decl_process_bin_expression (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b, + gpy_opcode_t operation, VEC(gpy_ctx_t,gc) * context) { VEC(tree,gc) * retval = NULL; VEC(tree,gc) * t1 = NULL, * t2 = NULL; diff --git a/gcc/python/py-lang.c b/gcc/python/py-lang.c index 75447c69e80..3e1d1ffc35d 100644 --- a/gcc/python/py-lang.c +++ b/gcc/python/py-lang.c @@ -85,9 +85,8 @@ bool gpy_langhook_init (void) build_common_tree_nodes( false ); build_common_tree_nodes_2( 0 ); - void_list_node = build_tree_list( NULL_TREE, void_type_node ); + void_list_node = build_tree_list (NULL_TREE, void_type_node); - gpy_init_context_tables (); gpy_initilize_types (); return true; @@ -109,8 +108,6 @@ gpy_langhook_handle_option (size_t scode, const char *arg, int value, int kind, enum opt_code code = (enum opt_code) scode; int retval = 1; - debug("inside handle option!\n"); - switch( code ) { default: @@ -243,17 +240,6 @@ void gpy_preserve_from_gc (tree t) gpy_gc_root = tree_cons (NULL_TREE, t, gpy_gc_root); } -void __gpy_debug__( const char * file, unsigned int lineno, - const char * fmt, ... ) -{ - va_list args; - fprintf( stderr, "debug: <%s:%i> -> ", - file, lineno ); - va_start( args, fmt ); - vfprintf( stderr, fmt, args ); - va_end( args ); -} - /* The attribute table might be used for the GCC attribute syntax, e.g. * __attribute__((unused)), but this feature isn't yet used in gcalc */ diff --git a/gcc/python/py-stmt.c b/gcc/python/py-stmt.c index 2c476daebaf..a91b88f3885 100644 --- a/gcc/python/py-stmt.c +++ b/gcc/python/py-stmt.c @@ -49,12 +49,9 @@ along with GCC; see the file COPYING3. If not see #include "py-types.h" #include "py-runtime.h" -static gpy_symbol_obj * gpy_process_AST_Align( gpy_symbol_obj ** ); +static gpy_symbol_obj * gpy_process_AST_Align (gpy_symbol_obj **); static VEC( gpy_sym,gc ) * gpy_decls; -VEC(gpy_ctx_t,gc) * gpy_ctx_table; -VEC(tree,gc) * global_decls; -VEC(tree,gc) * gpy_toplev_fncs; void gpy_process_decl (gpy_symbol_obj * sym) { @@ -104,7 +101,7 @@ void gpy_process_decl (gpy_symbol_obj * sym) 2 2 **/ static -gpy_symbol_obj * gpy_process_AST_Align( gpy_symbol_obj ** sym ) +gpy_symbol_obj * gpy_stmt_process_AST_Align (gpy_symbol_obj ** sym) { gpy_symbol_obj *nn = NULL; gpy_symbol_obj *retval = NULL; @@ -189,8 +186,8 @@ gpy_symbol_obj * gpy_process_AST_Align( gpy_symbol_obj ** sym ) return retval; } -VEC(tree,gc) * gpy_process_expression (const gpy_symbol_obj * const sym, - VEC(gpy_ctx_t,gc) * context) +VEC(tree,gc) * gpy_stmt_process_expression (const gpy_symbol_obj * const sym, + VEC(gpy_ctx_t,gc) * context) { VEC(tree,gc) * retval = NULL; if( sym->type == SYMBOL_PRIMARY ) @@ -264,9 +261,88 @@ VEC(tree,gc) * gpy_process_expression (const gpy_symbol_obj * const sym, return retval; } -VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, - const char * base_ident, - VEC(gpy_ctx_t,gc) * context) +VEC(tree,gc) * gpy_stmt_process_print (gpy_symbol_obj *sym, + VEC(gpy_ctx_t,gc) * context) +{ + VEC(tree,gc) * retval = NULL; + gcc_assert( sym->op_a_t == TYPE_SYMBOL ); + gpy_symbol_obj * argument_list = sym->op_a.symbol_table; + + if( argument_list ) + { + int len = 0; + gpy_symbol_obj * t = argument_list; + while( t ) + { + len++; + t=t->next; + } + + int idx, idy = 0; t = argument_list; + tree * args = XNEWVEC( tree,len ); + for( idx=0; idx<len; ++idx ) + { + VEC(tree,gc) * x = gpy_get_tree( t, context ); + gcc_assert( VEC_length(tree,x) == 1 ); + args[ idy ] = VEC_index(tree,x,0); + idy++; + t = t->next; + } + + VEC (tree,gc) * bc = gpy_builtin_get_print_call (len, args); + GPY_VEC_stmts_append (retval,bc); + } + else + error("print call without any arguments!\n"); + + return retval; +} + +VEC(tree,gc) * gpy_stmt_get_tree (gpy_symbol_obj * sym, + VEC(gpy_ctx_t,gc) * context) +{ + VEC(tree,gc) * retval = NULL; + + debug( "processing decl of type <0x%X> object <%p>\n", + sym->type, (void*) sym ); + + if( sym->exp == OP_EXPRESS ) + { + sym = gpy_process_AST_Align( &sym ); + retval = gpy_process_expression( sym, context ); + } + else + { + switch( sym->type ) + { + case STRUCTURE_FUNCTION_DEF: + { + gpy_hash_table_t ctx; + gpy_dd_hash_init_table (&ctx); + VEC_safe_push (gpy_ctx_t, gc, context, &ctx); + + retval = gpy_decl_process_functor (sym, context); + VEC_pop (gpy_ctx_t, context); + } + break; + + case KEY_PRINT: + { + retval = gpy_process_print (sym, context); + } + break; + + default: + fatal_error("unhandled symbol type <0x%x>\n", sym->type ); + break; + } + } + + return retval; +} + +VEC(tree,gc) * gpy_decl_process_functor (const gpy_symbol_obj * const functor, + VEC(gpy_ctx_t,gc) * context) { VEC(tree,gc) * retval_vec = VEC_alloc (tree,gc,0); @@ -277,7 +353,7 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, gpy_symbol_obj * o = functor->op_a.symbol_table; tree fntype = build_function_type(void_type_node, void_list_node); - tree retval = build_decl (functor->loc, FUNCTION_DECL, + tree retval = build_decl (functor->loc, TYPE_METHOD, get_identifier (functor->identifier), fntype); @@ -288,10 +364,6 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, tree restype = TREE_TYPE (retval); int idx = 0; - gpy_context_branch *co = NULL; - gpy_ident it = NULL; - - SET_DECL_ASSEMBLER_NAME( retval, get_identifier(functor->identifier) ); tree check = gpy_ctx_lookup_decl (context, functor->identifier); if (check) @@ -309,21 +381,14 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, restype); DECL_CONTEXT(resdecl) = retval; DECL_RESULT(retval) = resdecl; - DECL_INITIAL(retval) = block; - /* push a new context for local symbols */ - co = (gpy_context_branch *) - xmalloc( sizeof(gpy_context_branch) ); - gpy_init_ctx_branch( &co ); - VEC_safe_push( gpy_ctx_t, gc, context, co ); - while (o) { /* looping over the gpy_symbol_obj block of function statements and getting the respective tree's and creating the GENERIC block */ - VEC(tree,gc) * x = gpy_get_tree( o,context ); + VEC(tree,gc) * x = gpy_get_tree (o,context); int itx = 0; tree xt; for( ; VEC_iterate(tree,x,itx,xt); ++itx ) { @@ -333,15 +398,21 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, o = o->next; } - for (; VEC_iterate (gpy_ident,co->decl_t, idx, it); ++idx) + gpy_hash_table_t * ctx = VEC_index (tree,context,VEC_length (context)-1); + int size = ctx->size, idx = 0; + gpy_hash_entry_t *array= ctx->array; + + for (idx=0; idx<size; ++idx) { - /* get all block var_decls */ - tree x = gpy_ctx_lookup_decl( context, it->ident); - gcc_assert( TREE_CODE( x ) == VAR_DECL ); - debug("got var decl <%p>:<%s> within func <%s>!\n", (void*)x, - it->ident, functor->identifier ); - TREE_CHAIN( x ) = declare_vars; - declare_vars = x; + if (array[idx).data) + { + tree x = (tree) array[idx].data; + gcc_assert (TREE_CODE(x) == VAR_DECL); + debug("got decl <%p>:<%s> within func <%s>!\n", (void*)x, + IDENTIFIER_POINTER (DECL_NAME(x)), functor->identifier); + TREE_CHAIN( x ) = declare_vars; + declare_vars = x; + } } if (declare_vars != NULL_TREE) @@ -359,8 +430,6 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, block = bind; DECL_SAVED_TREE(retval) = block; - VEC_pop (gpy_ctx_t, gpy_ctx_table); - gimplify_function_tree (retval); cgraph_add_new_function (retval, false); @@ -376,280 +445,205 @@ VEC(tree,gc) * gpy_process_functor (const gpy_symbol_obj * const functor, return retval_vec; } -VEC(tree,gc) * gpy_process_print (gpy_symbol_obj *sym, - VEC(gpy_ctx_t,gc) * context) +tree gpy_decl_create_module_initilzer (VEC(tree,gc) * stmts, + VEC(tree,gc) * var_decls) { - VEC(tree,gc) * retval = NULL; - gcc_assert( sym->op_a_t == TYPE_SYMBOL ); - gpy_symbol_obj * argument_list = sym->op_a.symbol_table; - - if( argument_list ) - { - int len = 0; - gpy_symbol_obj * t = argument_list; - while( t ) - { - len++; - t=t->next; - } - - int idx, idy = 0; t = argument_list; - tree * args = XNEWVEC( tree,len ); - for( idx=0; idx<len; ++idx ) - { - VEC(tree,gc) * x = gpy_get_tree( t, context ); - gcc_assert( VEC_length(tree,x) == 1 ); - args[ idy ] = VEC_index(tree,x,0); - idy++; - t = t->next; - } - - VEC (tree,gc) * bc = gpy_builtin_get_print_call (len, args); - GPY_VEC_stmts_append (retval,bc); - } - else - error("print call without any arguments!\n"); - - return retval; -} + tree params = NULL_TREE, retval = NULL_TREE; + chainon( params, tree_cons (NULL_TREE, void_type_node, NULL_TREE) ); -VEC(tree,gc) * gpy_process_class( gpy_symbol_obj * const sym, - VEC(gpy_ctx_t,gc) * context ) -{ - VEC(tree,gc) * retval = NULL; - return retval; -} + tree fntype = build_function_type(void_type_node, void_list_node); + retval = build_decl (BUILTINS_LOCATION, TYPE_METHOD, + get_identifier ("mangled_module_initilizer__"), + fntype); -VEC(tree,gc) * gpy_get_tree (gpy_symbol_obj * sym, - VEC(gpy_ctx_t,gc) * context) -{ - VEC(tree,gc) * retval = NULL; + tree declare_vars = NULL_TREE; + tree bind = NULL_TREE; + tree block = alloc_stmt_list (); + tree resdecl = NULL_TREE; + tree restype = TREE_TYPE (retval); - debug( "processing decl of type <0x%X> object <%p>\n", - sym->type, (void*) sym ); + tree itx = NULL_TREE; + int idx = 0; - if( sym->exp == OP_EXPRESS ) + TREE_PUBLIC(retval) = 1; + TREE_STATIC(retval) = 1; + + resdecl = build_decl (BUILTINS_LOCATION, RESULT_DECL, NULL_TREE, + restype); + DECL_CONTEXT(resdecl) = retval; + DECL_RESULT(retval) = resdecl; + DECL_INITIAL(retval) = block; + + for (; VEC_iterate (tree,stmts,idx,itx); ++idx) { - sym = gpy_process_AST_Align( &sym ); - retval = gpy_process_expression( sym, context ); + gcc_assert (ixt); + append_to_statement_list (itx, &block); } - else + for (idx = 0; VEC_iterate (tree,var_decls,idx,itx); ++idx) { - switch( sym->type ) - { - case STRUCTURE_OBJECT_DEF: - { - VEC(gpy_ctx_t,gc) * class_ctx = VEC_alloc(gpy_ctx_t,gc,0); - retval = gpy_process_class( sym, class_ctx ); - } - break; - - case STRUCTURE_FUNCTION_DEF: - { - VEC(gpy_ctx_t,gc) * func_ctx = VEC_alloc(gpy_ctx_t,gc,0); - retval = gpy_process_functor( sym, NULL, func_ctx ); - } - break; - - case KEY_PRINT: - retval = gpy_process_print( sym, context ); - break; - - default: - fatal_error("unhandled symbol type <0x%x>\n", sym->type ); - break; - } + gcc_assert (TREE_CODE (itx) == VAR_DECL); + TREE_CHAIN (itx) = declare_vars; + declare_vars = itx; } + if (declare_vars != NULL_TREE) + { + tree bl = make_node(BLOCK); + BLOCK_SUPERCONTEXT(bl) = retval; + DECL_INITIAL(retval) = bl; + BLOCK_VARS(bl) = declare_vars; + TREE_USED(bl) = 1; + bind = build3(BIND_EXPR, void_type_node, BLOCK_VARS(bl), + NULL_TREE, bl); + TREE_SIDE_EFFECTS(bind) = 1; + } + BIND_EXPR_BODY(bind) = block; + block = bind; + DECL_SAVED_TREE(retval) = block; + + gimplify_function_tree (retval); + + cgraph_add_new_function (retval, false); + cgraph_finalize_function (retval, true); + return retval; } -tree gpy_main_method_decl (VEC(tree,gc) * block, gpy_context_branch * co) +tree gpy_decl_create_module (VEC(tree,gc) * var_decls, + VEC(tree,gc) * functors, + const char * ident) { - tree retval = NULL_TREE; int idx; - - tree main_fn_type = build_function_type_list( integer_type_node, NULL_TREE ); - tree main_fn_decl = build_decl( BUILTINS_LOCATION, FUNCTION_DECL, - get_identifier("main"), main_fn_type ); - - DECL_CONTEXT(main_fn_decl) = NULL_TREE; - TREE_STATIC(main_fn_decl) = true; - TREE_PUBLIC(main_fn_decl) = true; - DECL_ARGUMENTS(main_fn_decl) = NULL_TREE; - - /* Define the return type (represented by RESULT_DECL) for the main functin */ - tree main_ret = build_decl( BUILTINS_LOCATION, RESULT_DECL, - NULL_TREE, TREE_TYPE(main_fn_type) ); - DECL_CONTEXT(main_ret) = main_fn_decl; - DECL_ARTIFICIAL(main_ret) = true; - DECL_IGNORED_P(main_ret) = true; - - DECL_RESULT(main_fn_decl) = main_ret; + tree retval = NULL_TREE; - tree main_art_block = build_block(NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); - DECL_INITIAL(main_fn_decl) = main_art_block; - - tree declare_vars = NULL_TREE; - tree main_stmts = alloc_stmt_list (); - - tree it = NULL_TREE; - VEC(tree,gc) * vt = gpy_builtin_get_init_call (); - for (idx = 0; VEC_iterate (tree,vt,idx,it); ++idx) - append_to_statement_list (it, &main_stmts); - - for (idx = 0; VEC_iterate(tree,block,idx,it); ++idx) + tree module = make_node (RECORD_TYPE); + int idx = 0; + tree itx = NULL_TREE, field, last_field; + for (; VEC_iterate(tree,var_decls,idx,itx); ++idx) { - gcc_assert (it); - append_to_statement_list( it, &main_stmts ); + gcc_assert (TREE_CODE(itx) == VAR_DECL); + name = DECL_NAME(itx); + field = build_decl (BUILTINS_LOCATION, FIELD_DECL, name, + gpy_object_type_ptr); + DECL_CONTEXT(field) = module; + TYPE_FIELDS(module) = field; + last_field = field; } - int block_decl_len = 0; gpy_ident vit = NULL; - for( idx = 0; VEC_iterate( gpy_ident,co->decl_t, idx, vit ); ++idx ) + for (idx = 0; VEC_iterate(tree,functors,idx,itx); ++idx) { - /* get all block var_decls */ - tree x = gpy_ctx_lookup_decl( gpy_ctx_table, vit->ident); - gcc_assert( TREE_CODE( x ) == VAR_DECL ); - debug("got var decl <%p>:<%s> within func <%s>!\n", (void*)x, - vit->ident, "main" ); - TREE_CHAIN( x ) = declare_vars; - declare_vars = x; - block_decl_len++; + gcc_assert (TREE_CODE(itx) == TYPE_METHOD); + field = itx; + DECL_CONTEXT(field) = module; + TYPE_METHODS(module) = field; + last_field = field } - 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->decl_t, idx, vit ); ++idx ) - { - tree x = gpy_ctx_lookup_decl( gpy_ctx_table, vit->ident); - gcc_assert( TREE_CODE( x ) == VAR_DECL ); - - block_decl_vec[ idy ] = x; - idy++; - } - //block_decl_vec[ idy ] = main_ret; idy++; - VEC(tree,gc) * bc = gpy_builtin_get_finalize_block_call (block_decl_len, - block_decl_vec); - for (idx = 0; VEC_iterate (tree,bc,idx,it); ++idx) - append_to_statement_list (it, &main_stmts); - } - else - { - declare_vars = main_ret; - } - - VEC(tree,gc) * bc = gpy_builtin_get_cleanup_final_call (); - for (idx = 0; VEC_iterate (tree,bc,idx,it); ++idx) - append_to_statement_list (it, &main_stmts); - - tree main_set_ret = build2( MODIFY_EXPR, TREE_TYPE(main_ret), - main_ret, build_int_cst(integer_type_node, 0)); - tree main_ret_expr = build1( RETURN_EXPR, void_type_node, main_set_ret ); - append_to_statement_list( main_ret_expr, &main_stmts ); - - tree bind = NULL_TREE; - if( declare_vars != NULL_TREE ) - { - tree bl = make_node(BLOCK); - BLOCK_SUPERCONTEXT(bl) = main_fn_decl; - DECL_INITIAL(main_fn_decl) = bl; - BLOCK_VARS(bl) = declare_vars; - TREE_USED(bl) = 1; - bind = build3( BIND_EXPR, void_type_node, BLOCK_VARS(bl), - NULL_TREE, bl ); - TREE_SIDE_EFFECTS(bind) = 1; - } - BIND_EXPR_BODY(bind) = main_stmts; - main_stmts = bind; - DECL_SAVED_TREE(main_fn_decl) = main_stmts; + tree id = get_identifier (ident); + tree module_type_decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, + id, module); + DECL_ARTIFICIAL (module_type_decl) = 1; + TYPE_NAME (module_type_decl) = id; + gpy_preserve_from_gc (module_type_decl); + rest_of_decl_compilation (module_type_decl, 1, 0); - gimplify_function_tree( main_fn_decl ); - cgraph_finalize_function( main_fn_decl, false ); - - retval = main_fn_decl; + retval = module_type_decl; return retval; } +tree gpy_decl_create_main_ (tree module, tree module_init) +{ + return NULL; +} + void gpy_write_globals (void) { - gpy_context_branch *co = NULL; + VEC (gpy_ctx_t, gc) * context = VEC_alloc (gpy_ctx_t,gc,0) + gpy_hash_table_t ctx; + gpy_dd_hash_init_table (&ctx); + + VEC_safe_push (gpy_ctx_t, gc, context, &ctx); gpy_symbol_obj * it = NULL; - VEC(tree,gc) * main_stmts_vec = VEC_alloc(tree,gc,0); - /* push a new context for local symbols */ - co = (gpy_context_branch *) - xmalloc( sizeof(gpy_context_branch) ); - gpy_init_ctx_branch( &co ); - VEC_safe_push( gpy_ctx_t, gc, gpy_ctx_table, co ); + VEC(tree,gc) * globals_vec = VEC_alloc (tree,gc,0); + VEC(tree,gc) * main_stmts_vec = VEC_alloc (tree,gc,0); + VEC(tree,gc) * functors = VEC_alloc (tree,gc,0); - int idx; - for( idx= 0; VEC_iterate(gpy_sym,gpy_decls,idx,it); ++idx ) + tree xt = NULL_TREE; + int idx = 0; + for ( ; VEC_iterate (gpy_sym, gpy_decls, idx, it); ++idx) { - VEC(tree,gc) * x = gpy_get_tree (it, gpy_ctx_table); - gcc_assert (x); int itx = 0; tree xt; + VEC(tree,gc) * x = gpy_get_tree (it, context); + gcc_assert (x); + int itx = 0; + for ( ; VEC_iterate(tree,x,itx,xt); ++itx ) { - if( TREE_CODE(xt) == FUNCTION_DECL ) + if( TREE_CODE(xt) == TYPE_METHOD ) { - VEC_safe_push (tree,gc,global_decls,xt); - } - else if( TREE_CODE(xt) == VAR_DECL ) - { - VEC_safe_push (tree,gc,global_decls,xt); + VEC_safe_push (tree,gc,functors,xt); } else { VEC_safe_push (tree,gc,main_stmts_vec,xt); } } + + } + + VEC(tree,gc) * global_var_decls = VEC_alloc (tree,gc,0); + gpy_hash_table_t * ctx = VEC_index (tree,context,VEC_length (context)-1); + int size = ctx->size, idx = 0; + gpy_hash_entry_t *array= ctx->array; + + for (idx=0; idx<size; ++idx) + { + if (array[idx).data) + { + tree x = (tree) array[idx].data; + gcc_assert (TREE_CODE(x) == VAR_DECL); + debug("got decl <%p>:<%s>!\n", (void*)x, + IDENTIFIER_POINTER (DECL_NAME(x))); + VEC_safe_push (tree, gc, global_var_decls, x); + } } - tree itx = NULL_TREE; - /* Add in the main method decl! */ - VEC_safe_push (tree,gc,global_decls,gpy_main_method_decl (main_stmts_vec,co)); + tree mod_init = gpy_decl_create_module_initilzer (main_stmts_vec, NULL); + VEC_safe_push (tree,gc,functors,mod_init); - VEC_pop( gpy_ctx_t, gpy_ctx_table ); + tree module_main = gpy_decl_create_module(global_var_decls, + functors, + "mangled_module_name__"); + VEC_safe_push (tree,gc,globals_vec,module_main); + VEC_safe_push (tree,gc,globals_vec,gpy_decl_create_main_ (module_main, + mod_init)) + int global_vec_len = VEC_length (tree, globals_vec); int idy = 0; - int global_vec_len = VEC_length (tree, global_decls); + tree itx = NULL_TREE; tree * global_vec = XNEWVEC (tree, global_vec_len); - FILE *tu_stream = dump_begin (TDI_tu, NULL); - for ( idx=0; VEC_iterate(tree,global_decls,idx,itx); ++idx ) + + for (idx = 0; VEC_iterate(tree, globals_vec, idx, itx); ++idx) { debug_tree (itx); if (tu_stream) dump_node(itx, 0, tu_stream); - global_vec[ idy ] = itx; + global_vec[idy] = itx; idy++; } if (tu_stream) dump_end(TDI_tu, tu_stream); debug("Finished processing!\n\n"); - debug("global_vec len = <%i>!\n", global_vec_len); wrapup_global_declarations (global_vec, global_vec_len); - - debug ("whoop1!\n"); - check_global_declarations (global_vec, global_vec_len); - - debug ("whoop2!\n"); - emit_debug_global_declarations (global_vec, global_vec_len); - - debug ("whoop3!\n"); - cgraph_finalize_compilation_unit (); - debug ("whoop4!\n"); - debug("finished passing to middle-end!\n\n"); } diff --git a/gcc/python/py-tree.h b/gcc/python/py-tree.h index 030b7319d49..e74916f8167 100644 --- a/gcc/python/py-tree.h +++ b/gcc/python/py-tree.h @@ -17,68 +17,22 @@ along with GCC; see the file COPYING3. If not see #ifndef __PY_TREE_H__ #define __PY_TREE_H__ -extern void gpy_ident_vec_init( gpy_ident_vector_t * const v ) - __attribute__((nonnull)); - -extern void gpy_ident_vec_push( gpy_ident_vector_t * const v, void * s ) - __attribute__((nonnull)); - -extern void * gpy_ident_vec_pop( gpy_ident_vector_t * const v ) - __attribute__((nonnull)); - -extern gpy_hashval_t gpy_dd_hash_string( const char * ); - -extern gpy_hash_entry_t * gpy_dd_hash_lookup_table( gpy_hash_tab_t *, gpy_hashval_t ); - -extern void ** gpy_dd_hash_insert( gpy_hashval_t, void *, gpy_hash_tab_t * ); - -extern void gpy_dd_hash_grow_table( gpy_hash_tab_t * ); - -extern void gpy_dd_hash_init_table( gpy_hash_tab_t ** ); - -extern void gpy_gg_invoke_garbage( void ); - -extern void gpy_garbage_free_obj( gpy_symbol_obj ** ); - -/* expression.c */ -extern VEC(tree,gc) * gpy_process_assign (gpy_symbol_obj ** , gpy_symbol_obj **, - VEC(gpy_ctx_t,gc) *); - -extern VEC(tree,gc) * gpy_process_bin_expression (gpy_symbol_obj ** , gpy_symbol_obj **, - gpy_opcode_t, VEC(gpy_ctx_t,gc) *); +extern VEC(tree,gc) * gpy_decl_process_assign (gpy_symbol_obj ** , gpy_symbol_obj **, + VEC(gpy_ctx_t,gc) *); + +extern VEC(tree,gc) * gpy_decl_process_bin_expression (gpy_symbol_obj ** , gpy_symbol_obj **, + gpy_opcode_t, VEC(gpy_ctx_t,gc) *); extern VEC(tree,gc) * gpy_fold_primitive (const gpy_symbol_obj * const); -extern VEC(tree,gc) * gpy_fold_call (tree, location_t); - -/* ------- */ - -extern VEC(tree,gc) * gpy_process_expression( const gpy_symbol_obj * const, VEC(gpy_ctx_t,gc) * ); - -extern VEC(tree,gc) * gpy_process_class( gpy_symbol_obj * const, VEC(gpy_ctx_t,gc) * ); - -extern VEC(tree,gc) * gpy_process_functor( const gpy_symbol_obj * const, const char *, - VEC(gpy_ctx_t,gc) * ); - -extern VEC(tree,gc) * gpy_get_tree( gpy_symbol_obj *, VEC(gpy_ctx_t,gc) * ); +extern VEC(tree,gc) * gpy_get_tree (gpy_symbol_obj *, VEC(gpy_ctx_t,gc) *); -extern VEC(tree,gc) * gpy_process_print( gpy_symbol_obj *, VEC(gpy_ctx_t,gc) * ); -/* ------- */ +extern void gpy_process_decl (gpy_symbol_obj *); -extern tree gpy_main_method_decl( VEC(tree,gc) * , gpy_context_branch * ); +extern tree gpy_ctx_lookup_decl (VEC(gpy_ctx_t,gc) *, const char *); -extern tree gpy_ctx_lookup_decl( VEC(gpy_ctx_t,gc) *, const char * ); - -extern void gpy_process_decl( gpy_symbol_obj * ); - -extern bool gpy_ctx_push_decl( tree, const char *, gpy_context_branch * ); - -extern void gpy_symbol_init_ctx( gpy_symbol_obj * const ) - __attribute__((nonnull)); - -extern void gpy_init_ctx_branch( gpy_context_branch * const * ) - __attribute__((nonnull)); - +extern bool gpy_ctx_push_decl (tree, const char *, gpy_hash_table_t *); + #define GPY_VEC_stmts_append(x,y) \ do { \ int x_ = 0; tree t_ = NULL_TREE; \ diff --git a/gcc/python/py-types.c b/gcc/python/py-types.c index eccef70d036..47a7ec911ac 100644 --- a/gcc/python/py-types.c +++ b/gcc/python/py-types.c @@ -187,146 +187,6 @@ tree gpy_build_py_object_type (void) return build_pointer_type (gpy_object_struct_Type); } -/* - typedef gpy_object_t * (*gpy_std_callable) - (gpy_object_t **); - - typedef gpy_callable__t { - char * ident; - gpy_std_callable call; - int n; - } gpy_callable_t ; -*/ -static -tree gpy_build_callable_record_type (void) -{ - tree callable_struct_Type = make_node (RECORD_TYPE); - - tree name = get_identifier("ident"); - tree field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, - build_pointer_type(char_type_node)); - DECL_CONTEXT(field) = callable_struct_Type; - TYPE_FIELDS(callable_struct_Type) = field; - tree last_field = field; - - name = get_identifier("call"); - field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, ptr_type_node); - DECL_CONTEXT(field) = callable_struct_Type; - DECL_CHAIN(last_field) = field; - last_field = field; - - name = get_identifier("n"); - field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, - integer_type_node); - DECL_CONTEXT(field) = callable_struct_Type; - DECL_CHAIN(last_field) = field; - last_field = field; - - layout_type(callable_struct_Type); - - name = get_identifier("gpy_callable_t"); - tree gpy_callable_type_decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, name, - callable_struct_Type); - DECL_ARTIFICIAL(gpy_callable_type_decl) = 1; - TYPE_NAME(callable_struct_Type) = name; - gpy_preserve_from_gc(gpy_callable_type_decl); - rest_of_decl_compilation(gpy_callable_type_decl, 1, 0); - - return callable_struct_Type; -} - -static -tree gpy_build_callable_record_type_ptr (void) -{ - tree callable_struct_Type = make_node (RECORD_TYPE); - - tree const_char_type = build_qualified_type(unsigned_char_type_node, - TYPE_QUAL_CONST); - tree ctype = build_pointer_type(const_char_type); - gpy_preserve_from_gc(ctype); - - tree name = get_identifier("ident"); - tree field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, - ctype); - DECL_CONTEXT(field) = callable_struct_Type; - TYPE_FIELDS(callable_struct_Type) = field; - tree last_field = field; - - name = get_identifier("call"); - field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, ptr_type_node); - DECL_CONTEXT(field) = callable_struct_Type; - DECL_CHAIN(last_field) = field; - last_field = field; - - name = get_identifier("n"); - field = build_decl(BUILTINS_LOCATION, FIELD_DECL, name, - integer_type_node); - DECL_CONTEXT(field) = callable_struct_Type; - DECL_CHAIN(last_field) = field; - last_field = field; - - layout_type(callable_struct_Type); - - name = get_identifier("gpy_callable_t"); - tree gpy_callable_type_decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, name, - callable_struct_Type); - DECL_ARTIFICIAL(gpy_callable_type_decl) = 1; - TYPE_NAME(callable_struct_Type) = name; - gpy_preserve_from_gc(gpy_callable_type_decl); - rest_of_decl_compilation(gpy_callable_type_decl, 1, 0); - - return build_pointer_type (callable_struct_Type); -} - -tree gpy_init_callable_record (tree id, int n, tree decl) -{ - tree struct_tree = gpy_callable_type; - - VEC(constructor_elt,gc)* init = VEC_alloc(constructor_elt, gc, 3); - - constructor_elt* elt = VEC_quick_push(constructor_elt, init, NULL); - tree field = TYPE_FIELDS(struct_tree); - gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "ident") == 0); - elt->index = field; - if (id == NULL_TREE) - elt->value = build_string(strlen("__null"), - "__null"); - else - elt->value = build_string(strlen(IDENTIFIER_POINTER(id)), - IDENTIFIER_POINTER(id)); - - if (decl != NULL_TREE) - { - elt = VEC_quick_push(constructor_elt, init, NULL); - field = DECL_CHAIN(field); - gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "call") == 0); - elt->index = field; - elt->value = fold_convert_loc(BUILTINS_LOCATION, TREE_TYPE(field), - build_fold_addr_expr (decl)); - } - else - { - elt = VEC_quick_push(constructor_elt, init, NULL); - field = DECL_CHAIN(field); - gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "call") == 0); - elt->index = field; - elt->value = fold_convert_loc(BUILTINS_LOCATION, TREE_TYPE(field), - build_int_cst (integer_type_node,0)); - } - - elt = VEC_quick_push(constructor_elt, init, NULL); - field = DECL_CHAIN(field); - gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "n") == 0); - elt->index = field; - elt->value = fold_convert_loc(BUILTINS_LOCATION, TREE_TYPE(field), - build_int_cst (integer_type_node,n)); - - tree constructor = build_constructor(struct_tree, init); - TREE_CONSTANT(constructor) = 1; - - return constructor; -} - void gpy_initilize_types (void) { gpy_builtin_types_vec = VEC_alloc(tree,gc,0); @@ -342,14 +202,6 @@ void gpy_initilize_types (void) VEC_safe_push (tree,gc,gpy_builtin_types_vec, build_pointer_type (gpy_object_type_ptr)); gpy_preserve_from_gc (gpy_object_type_ptr_ptr); - - VEC_safe_push (tree,gc,gpy_builtin_types_vec, - gpy_build_callable_record_type ()); - gpy_preserve_from_gc (gpy_callable_type); - - VEC_safe_push (tree,gc,gpy_builtin_types_vec, - gpy_build_callable_record_type_ptr ()); - gpy_preserve_from_gc (gpy_callable_type_ptr); VEC_safe_push (tree,gc,gpy_builtin_types_vec,ctype); gpy_preserve_from_gc (gpy_const_char_ptr); diff --git a/gcc/python/py-types.h b/gcc/python/py-types.h index b5ae330cc12..8d567f3c7af 100644 --- a/gcc/python/py-types.h +++ b/gcc/python/py-types.h @@ -23,10 +23,6 @@ extern VEC(tree,gc) * gpy_builtin_types_vec; #define gpy_object_type_ptr_ptr VEC_index(tree,gpy_builtin_types_vec,1) -#define gpy_callable_type VEC_index(tree,gpy_builtin_types_vec,2) - -#define gpy_callable_type_ptr VEC_index(tree,gpy_builtin_types_vec,3) - #define gpy_const_char_ptr VEC_index(tree,gpy_builtin_types_vec,4) extern tree gpy_init_callable_record (tree, int, tree); diff --git a/gcc/python/py-vec.c b/gcc/python/py-vec.c index 65e44402378..ba58dd09f96 100644 --- a/gcc/python/py-vec.c +++ b/gcc/python/py-vec.c @@ -132,12 +132,12 @@ gpy_hashval_t gpy_dd_hash_string (const char * s) } gpy_hash_entry_t * -gpy_dd_hash_lookup_table( gpy_hash_tab_t * tbl, gpy_hashval_t h ) +gpy_dd_hash_lookup_table (gpy_hash_tab_t * tbl, gpy_hashval_t h) { gpy_hash_entry_t* retval = NULL; if( tbl->array ) { - gpy_hashval_t size= tbl->size, idx= (h % size); + int size= tbl->size, idx= (h % size); gpy_hash_entry_t *array= tbl->array; while( array[idx].data ) @@ -157,8 +157,8 @@ gpy_dd_hash_lookup_table( gpy_hash_tab_t * tbl, gpy_hashval_t h ) return retval; } -void ** gpy_dd_hash_insert( gpy_hashval_t h, void * obj, - gpy_hash_tab_t *tbl ) +void ** gpy_dd_hash_insert (gpy_hashval_t h, void * obj, + gpy_hash_tab_t *tbl) { void **retval = NULL; gpy_hash_entry_t *entry = NULL; @@ -202,134 +202,70 @@ void gpy_dd_hash_grow_table( gpy_hash_tab_t * tbl ) } inline -void gpy_dd_hash_init_table( gpy_hash_tab_t ** tbl ) +void gpy_dd_hash_init_table (gpy_hash_tab_t * tbl) { - if( tbl ) - { - gpy_hash_tab_t *tb= *tbl; - tb->size= 0; tb->length= 0; - tb->array= NULL; - } -} - -void gpy_ident_vec_init( gpy_ident_vector_t * const v ) -{ - v->size = threshold_alloc( 0 ); - v->vector = (void**) xcalloc( v->size, sizeof(void*) ); - v->length = 0; -} - -void gpy_ident_vec_push( gpy_ident_vector_t * const v, void * s ) -{ - if( s ) - { - if( v->length >= v->size ) - { - signed long size = threshold_alloc( v->size ); - v->vector = (void**) xrealloc( v->vector, size*sizeof(void*) ); - v->size = size; - } - v->vector[ v->length ] = s; - v->length++; - } -} - -void * gpy_ident_vec_pop( gpy_ident_vector_t * const v ) -{ - void * retval = v->vector[ v->length-1 ]; - v->length--; - return retval; -} - -inline -void gpy_init_ctx_branch( gpy_context_branch * const * o ) -{ - if( o ) - { - (*o)->decls = (gpy_hash_tab_t *) - xmalloc( sizeof(gpy_hash_tab_t) ); - - gpy_dd_hash_init_table( &((*o)->decls) ); - - (*o)->decl_t = VEC_alloc(gpy_ident,gc,0); - } + gpy_hash_tab_t *tb= tbl; + tb->size= 0; tb->length= 0; + tb->array= NULL; } -void gpy_init_context_tables( void ) +bool gpy_ctx_push_decl (tree decl, const char * s, + gpy_hash_table_t * tbl) { - gpy_context_branch *o = (gpy_context_branch *) - xmalloc( sizeof(gpy_context_branch) ); - - gpy_init_ctx_branch( &o ); - - VEC_safe_push( gpy_ctx_t, gc, gpy_ctx_table, o ); -} - -bool gpy_ctx_push_decl( tree decl, const char * s, - gpy_context_branch * ctx) -{ - bool retval = true; gpy_hash_tab_t *t = NULL; + bool retval = true; gpy_hashval_t h = 0; - void ** slot = NULL; - gpy_ident o = (gpy_ident) xmalloc( sizeof(gpy_ident_t) ); - o->ident = xstrdup( s ); - - debug("ident <%s> at <%p>!\n", s, (void*)o ); + h = gpy_dd_hash_string (s); + void ** slot = gpy_dd_hash_insert (h,decl,tbl); - t = ctx->decls; - debug("trying to push decl <%s>!\n", s ); - - h = gpy_dd_hash_string( o->ident ); - slot = gpy_dd_hash_insert( h, decl, t ); - if( !slot ) + if (!slot) { - debug("successfully pushed DECL <%s>!\n", s); - VEC_safe_push( gpy_ident, gc, ctx->decl_t, o ); - - if (TREE_CODE(decl) == FUNCTION_DECL) - { - VEC_safe_push (tree,gc,gpy_function_decls,decl); - } + debug ("pushed decl <%s> into context!\n", s); } else { - debug("decl <%s> already pushed!\n", s ); - retval = false; + debug ("error pushing decl <%s>!\n", s); } - + return retval; } tree gpy_ctx_lookup_decl (VEC(gpy_ctx_t,gc) * context, const char * s) { - tree retval = NULL; - unsigned int n_ctx = VEC_length( gpy_ctx_t,context ); - int idx = 0; gpy_context_branch * it = NULL; + tree retval = NULL_TREE; - gpy_hashval_t h = gpy_dd_hash_string( s ); - debug( "trying to lookup <%s> : context table length = <%i>!\n", - s, n_ctx ); + gpy_hashval_t = h = gpy_dd_hash_string (s); + gpy_ctx_t it; - for( idx=(n_ctx-1); idx>=0; --idx ) + int i; + int l = VEC_length (gpy_ctx_t,context); + for (i = (l-1); i>=0; --i) { - it = VEC_index( gpy_ctx_t, context, idx ); + it = VEC_index (gpy_ctx_t, context, i); gpy_hash_entry_t * o = NULL; - gpy_hash_tab_t * decl_table = NULL; - - decl_table = it->decls; - - o = gpy_dd_hash_lookup_table( decl_table, h ); - if( o ) + o = gpy_dd_hash_lookup_table (it, h); + if (o) { - if( o->data ) + if (o->data) { - debug("found symbol <%s> in context <%p>!\n", s, (void*)it ); - retval = (tree) (o->data) ; + debug ("found decl <%s>!\n", s); + retval = (tree) o->data; break; } } } + return retval; } + +void __gpy_debug__ (const char * file, unsigned int lineno, + const char * fmt, ...) +{ + va_list args; + fprintf( stderr, "debug: <%s:%i> -> ", + file, lineno ); + va_start( args, fmt ); + vfprintf( stderr, fmt, args ); + va_end( args ); +} diff --git a/gcc/python/py-vec.h b/gcc/python/py-vec.h index e1508e2434b..a3b38cb48bf 100644 --- a/gcc/python/py-vec.h +++ b/gcc/python/py-vec.h @@ -22,41 +22,19 @@ typedef struct gpy_vector_t { signed long size, length; } gpy_ident_vector_t; -enum OPERATOR_T { - LESS_OP, GREATER_OP, EQ_EQ_OP, - GREATER_EQ_OP, LESS_EQ_OP -}; - typedef unsigned long gpy_hashval_t; typedef struct gpy_hash_entry { gpy_hashval_t hash; void * data; } gpy_hash_entry_t ; -typedef struct gpy_hash_table_t { +typedef struct GTY(()) gpy_hash_table_t { unsigned int size, length; gpy_hash_entry_t * array; } gpy_hash_tab_t ; -typedef struct gpy_id_t { - char * ident; -} gpy_ident_t; -typedef gpy_ident_t * gpy_ident; - -typedef int gpy_int; -DEF_VEC_I( gpy_int ); -DEF_VEC_ALLOC_I( gpy_int,gc ); - -DEF_VEC_P( gpy_ident ); -DEF_VEC_ALLOC_P( gpy_ident,gc ); - -typedef struct GTY(()) gpy_context_branch_t { - gpy_hash_tab_t * decls; - VEC(gpy_ident,gc) *decl_t; -} gpy_context_branch ; - typedef gpy_symbol_obj *gpy_sym; -typedef gpy_context_branch *gpy_ctx_t; +typedef gpy_hash_tab_t *gpy_ctx_t; DEF_VEC_P( gpy_sym ); DEF_VEC_ALLOC_P( gpy_sym,gc ); @@ -66,9 +44,19 @@ DEF_VEC_ALLOC_P( gpy_ctx_t,gc ); extern VEC(gpy_ctx_t,gc) * gpy_ctx_table; extern VEC(gpy_sym,gc) * gpy_garbage_decls; -extern VEC(tree,gc) * global_decls; -extern VEC(tree,gc) * gpy_function_decls; -extern void gpy_init_context_tables ( void ); +extern gpy_hashval_t gpy_dd_hash_string( const char * ); + +extern gpy_hash_entry_t * gpy_dd_hash_lookup_table( gpy_hash_tab_t *, gpy_hashval_t ); + +extern void ** gpy_dd_hash_insert( gpy_hashval_t, void *, gpy_hash_tab_t * ); + +extern void gpy_dd_hash_grow_table( gpy_hash_tab_t * ); + +extern void gpy_dd_hash_init_table( gpy_hash_tab_t * ); + +extern void gpy_gg_invoke_garbage( void ); + +extern void gpy_garbage_free_obj( gpy_symbol_obj ** ); #endif /*__PY_VEC_H__*/ |