summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredbrain <redbrain@gcc.gnu.org>2011-07-04 12:24:35 +0100
committerredbrain <redbrain@gcc.gnu.org>2011-07-04 12:24:35 +0100
commitad0e954fcba497d3f644404bb88eb49e2c9dae4f (patch)
treee3312660be065d22f055b93e17ed398b1c03a6c8
parente4417637d94bfa5c846e556510f2b518cedb1886 (diff)
downloadgcc-python.tar.gz
it compiles nowpython
-rw-r--r--gcc/python/py-builtins.c20
-rw-r--r--gcc/python/py-stmt-pass-lower.c160
-rw-r--r--gcc/python/py-stmt-pass-mangr.c2
-rw-r--r--gcc/python/py-stmt-pass-types.c30
4 files changed, 147 insertions, 65 deletions
diff --git a/gcc/python/py-builtins.c b/gcc/python/py-builtins.c
index c4af0d12806..b65e232fe38 100644
--- a/gcc/python/py-builtins.c
+++ b/gcc/python/py-builtins.c
@@ -48,17 +48,17 @@ static tree gpy_build_py_object_type (void);
tree gpy_builtin_get_init_call (void)
{
- tree fntype = build_function_type( void_type_node, void_list_node );
- tree gpy_rr_init = build_decl( UNKNOWN_LOCATION, FUNCTION_DECL,
+ tree fntype = build_function_type (void_type_node, void_list_node);
+ tree gpy_rr_init = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
get_identifier("gpy_rr_init_runtime"),
- fntype );
- tree restype = TREE_TYPE(gpy_rr_init);
- tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
- restype );
- DECL_CONTEXT(resdecl) = gpy_rr_init;
- DECL_RESULT(gpy_rr_init) = resdecl;
- DECL_EXTERNAL( gpy_rr_init ) = 1;
- TREE_PUBLIC( gpy_rr_init ) = 1;
+ fntype);
+ tree restype = TREE_TYPE (gpy_rr_init);
+ tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
+ restype);
+ DECL_CONTEXT (resdecl) = gpy_rr_init;
+ DECL_RESULT (gpy_rr_init) = resdecl;
+ DECL_EXTERNAL (gpy_rr_init) = 1;
+ TREE_PUBLIC (gpy_rr_init) = 1;
return build_call_expr (gpy_rr_init, 0, NULL_TREE);
}
diff --git a/gcc/python/py-stmt-pass-lower.c b/gcc/python/py-stmt-pass-lower.c
index 2146b90a0a8..abbe81b2464 100644
--- a/gcc/python/py-stmt-pass-lower.c
+++ b/gcc/python/py-stmt-pass-lower.c
@@ -50,7 +50,9 @@ along with GCC; see the file COPYING3. If not see
static VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t *, VEC(gpydot,gc) *);
static tree gpy_stmt_pass_lower_get_module_type (const char *, gpy_hash_tab_t *);
static void gpy_stmt_pass_lower_gen_toplevl_context (tree, tree, gpy_hash_tab_t *);
+
static tree gpy_stmt_pass_lower_gen_concat_identifier (const char *, const char *);
+static tree gpy_stmt_pass_lower_gen_main (tree);
static
tree gpy_stmt_pass_lower_gen_concat_identifier (const char * s1,
@@ -83,7 +85,6 @@ tree gpy_stmt_pass_lower_get_module_type (const char * s,
{
tree retval = error_mark_node;
- debug ("looking for module type <%s>!\n", s);
gpy_hashval_t h = gpy_dd_hash_string (s);
gpy_hash_entry_t * e = gpy_dd_hash_lookup_table (modules, h);
if (e)
@@ -103,16 +104,17 @@ void gpy_stmt_pass_lower_gen_toplevl_context (tree module, tree param_decl,
return;
else
{
- debug ("gen toplevel context!\n");
tree field = TYPE_FIELDS (module);
-
do {
gcc_assert (TREE_CODE (field) == FIELD_DECL);
+ debug ("generating refernence to <%s>!\n", IDENTIFIER_POINTER(DECL_NAME (field)));
gpy_hashval_t h = gpy_dd_hash_string (IDENTIFIER_POINTER(DECL_NAME (field)));
- tree ref = build3 (COMPONENT_REF, TREE_TYPE (field), param_decl, field, NULL_TREE);
+ tree ref = build3 (COMPONENT_REF, TREE_TYPE (field), build_fold_indirect_ref(param_decl),
+ field, NULL_TREE);
void ** e = gpy_dd_hash_insert (h, ref, context);
-
+
+ debug_tree (ref);
if (e)
fatal_error ("problem inserting component reference into context!\n");
} while ((field = DECL_CHAIN (field)));
@@ -135,8 +137,8 @@ tree gpy_stmt_decl_lower_scalar (gpy_dot_tree_t * decl, tree * cblock)
case D_T_INTEGER:
{
retval = build_decl (UNKNOWN_LOCATION, VAR_DECL,
- create_tmp_var_name ("P"),
- gpy_object_type_ptr);
+ create_tmp_var_name ("P"),
+ gpy_object_type_ptr);
append_to_statement_list (build2 (MODIFY_EXPR, gpy_object_type_ptr, retval,
gpy_builtin_get_fold_int_call (DOT_lhs_TC (decl)->o.integer)),
cblock);
@@ -287,33 +289,39 @@ tree gpy_stmt_pass_lower_functor (gpy_dot_tree_t * decl,
tree main_init_module = gpy_stmt_pass_lower_get_module_type ("main.main",
modules);
- tree fntype = build_function_type_list (build_pointer_type (main_init_module),
+ tree pdecl_t = build_pointer_type (main_init_module);
+ tree fntype = build_function_type_list (void_type_node, pdecl_t,
/*
handle function parameters
...
*/
NULL_TREE);
- tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
- gpy_stmt_pass_lower_gen_concat_identifier ("main.main",
- DOT_IDENTIFIER_POINTER (DOT_FIELD (decl))),
- fntype);
+ tree concat_ident = gpy_stmt_pass_lower_gen_concat_identifier ("main.main",
+ DOT_IDENTIFIER_POINTER (DOT_FIELD (decl)));
+ tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, concat_ident, fntype);
DECL_EXTERNAL (fndecl) = 0;
TREE_PUBLIC (fndecl) = 1;
TREE_STATIC (fndecl) = 1;
+ tree arglist = NULL_TREE;
+
+ tree result_decl = build_decl (BUILTINS_LOCATION, RESULT_DECL, NULL_TREE,
+ integer_type_node);
+ DECL_RESULT (fndecl) = result_decl;
+
+ SET_DECL_ASSEMBLER_NAME (fndecl, concat_ident);
- SET_DECL_ASSEMBLER_NAME (fndecl,
- gpy_stmt_pass_lower_gen_concat_identifier ("main.main",
- DOT_IDENTIFIER_POINTER (DOT_FIELD (decl))
- )
- );
tree self_parm_decl = build_decl (BUILTINS_LOCATION, PARM_DECL,
get_identifier ("__self__"),
- TYPE_ARG_TYPES (TREE_TYPE (fndecl))
- );
+ pdecl_t);
+
DECL_CONTEXT (self_parm_decl) = fndecl;
DECL_ARG_TYPE (self_parm_decl) = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
TREE_READONLY (self_parm_decl) = 1;
+ arglist = chainon (arglist, self_parm_decl);
+
+ TREE_USED (self_parm_decl) = 1;
+ DECL_ARGUMENTS (fndecl) = arglist;
gpy_stmt_pass_lower_gen_toplevl_context (main_init_module, self_parm_decl,
&toplvl);
@@ -344,6 +352,19 @@ tree gpy_stmt_pass_lower_functor (gpy_dot_tree_t * decl,
}
} while ((idtx = DOT_CHAIN (idtx)));
+ tree bl = make_node(BLOCK);
+ BLOCK_SUPERCONTEXT(bl) = fndecl;
+ DECL_INITIAL(fndecl) = bl;
+ BLOCK_VARS(bl) = NULL_TREE;
+ TREE_USED(bl) = 1;
+ tree 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(fndecl) = block;
+
gimplify_function_tree (fndecl);
cgraph_add_new_function (fndecl, false);
@@ -368,7 +389,7 @@ VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t * modules,
tree main_init_module = gpy_stmt_pass_lower_get_module_type ("main.main", modules);
tree pdecl_t = build_pointer_type (main_init_module);
- tree main_init_fntype = build_function_type_list (pdecl_t, NULL_TREE);
+ tree main_init_fntype = build_function_type_list (void_type_node, pdecl_t, NULL_TREE);
tree main_init_fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
get_identifier ("main.main.init"),
main_init_fntype);
@@ -376,14 +397,16 @@ VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t * modules,
TREE_PUBLIC (main_init_fndecl) = 1;
TREE_STATIC (main_init_fndecl) = 1;
- debug ("1!\n");
+ tree result_decl = build_decl (BUILTINS_LOCATION, RESULT_DECL, NULL_TREE,
+ integer_type_node);
+ DECL_RESULT (main_init_fndecl) = result_decl;
+
tree arglist = NULL_TREE;
SET_DECL_ASSEMBLER_NAME (main_init_fndecl, get_identifier("main.main.init"));
tree self_parm_decl = build_decl (BUILTINS_LOCATION, PARM_DECL,
get_identifier ("__self__"),
pdecl_t);
- debug ("2!\n");
DECL_CONTEXT (self_parm_decl) = main_init_fndecl;
DECL_ARG_TYPE (self_parm_decl) = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (main_init_fndecl)));
TREE_READONLY (self_parm_decl) = 1;
@@ -399,11 +422,6 @@ VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t * modules,
VEC_safe_push (gpy_ctx_t, gc, toplevl_context, &toplvl);
VEC_safe_push (gpy_ctx_t, gc, toplevl_context, &topnxt);
- /*
- DECL_CONTEXT(main_init_resdecl) = main_init_fndecl;
- DECL_RESULT(main_init_fndecl) = resdecl;
- */
-
DECL_INITIAL(main_init_fndecl) = block;
int idx = 0;
@@ -443,6 +461,19 @@ VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t * modules,
}
}
+ tree bl = make_node(BLOCK);
+ BLOCK_SUPERCONTEXT(bl) = main_init_fndecl;
+ DECL_INITIAL(main_init_fndecl) = bl;
+ BLOCK_VARS(bl) = NULL_TREE;
+ TREE_USED(bl) = 1;
+ tree 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(main_init_fndecl) = block;
+
gimplify_function_tree (main_init_fndecl);
cgraph_add_new_function (main_init_fndecl, false);
@@ -453,6 +484,70 @@ VEC(tree,gc) * gpy_stmt_pass_lower_genericify (gpy_hash_tab_t * modules,
return retval;
}
+static
+tree gpy_stmt_pass_lower_gen_main (tree module)
+{
+ 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) = 1;
+ TREE_PUBLIC (main_fn_decl) = 1;
+ 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) = 1;
+ DECL_IGNORED_P(main_ret) = 1;
+ DECL_RESULT(main_fn_decl) = main_ret;
+
+ 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 ();
+
+ append_to_statement_list (gpy_builtin_get_init_call(), &main_stmts);
+ tree mod_decl = build_decl (BUILTINS_LOCATION, VAR_DECL, create_tmp_var_name ("I"),
+ module);
+ declare_vars = mod_decl;
+ tree module_init_fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
+ get_identifier ("main.main.init"),
+ build_function_type_list (void_type_node,
+ build_pointer_type (module), NULL_TREE)
+ );
+ append_to_statement_list (build_call_expr (module_init_fndecl, 1, build_fold_addr_expr(mod_decl)),
+ &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 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;
+ 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;
+
+ gimplify_function_tree (main_fn_decl);
+ cgraph_finalize_function (main_fn_decl, false);
+
+ return main_fn_decl;
+}
+
/* Now we start to iterate over the dot IL to lower it down to */
/* a vector of GENERIC decls */
@@ -472,11 +567,6 @@ VEC(tree,gc) * gpy_stmt_pass_lower (VEC(tree,gc) *modules,
for (; VEC_iterate (tree, modules, idx, itx); ++idx)
{
- /*
- debug_tree (itx);
- gcc_assert (TREE_CODE (itx) == TYPE_DECL);
- */
-
debug ("hashing module name <%s>!\n", IDENTIFIER_POINTER (TYPE_NAME(itx)));
gpy_hashval_t h = gpy_dd_hash_string (IDENTIFIER_POINTER (TYPE_NAME(itx)));
void ** e = gpy_dd_hash_insert (h, itx, &module_ctx);
@@ -485,16 +575,12 @@ VEC(tree,gc) * gpy_stmt_pass_lower (VEC(tree,gc) *modules,
fatal_error ("module <%q+E> is already defined!\n", itx);
}
- debug ("lowering!\n");
retval = gpy_stmt_pass_lower_genericify (&module_ctx, decls);
- debug ("lowered!\n");
- /*
VEC_safe_push (tree, gc, retval,
gpy_stmt_pass_lower_gen_main (gpy_stmt_pass_lower_get_module_type ("main.main",
- module_ctx)
+ &module_ctx)
)
);
- */
// free (context.array);
return retval;
diff --git a/gcc/python/py-stmt-pass-mangr.c b/gcc/python/py-stmt-pass-mangr.c
index aa739a50c9b..546de26ef8e 100644
--- a/gcc/python/py-stmt-pass-mangr.c
+++ b/gcc/python/py-stmt-pass-mangr.c
@@ -265,7 +265,7 @@ void gpy_stmt_write_globals (void)
FILE *tu_stream = dump_begin (TDI_tu, NULL);
for (idx=0; VEC_iterate (tree,globals,idx,itx); ++idx)
{
- // debug_tree (itx);
+ debug_tree (itx);
if (tu_stream)
dump_node (itx, 0, tu_stream);
diff --git a/gcc/python/py-stmt-pass-types.c b/gcc/python/py-stmt-pass-types.c
index f8577a5252d..8a365ccc79d 100644
--- a/gcc/python/py-stmt-pass-types.c
+++ b/gcc/python/py-stmt-pass-types.c
@@ -78,8 +78,6 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
gpy_hash_tab_t context;
gpy_dd_hash_init_table (&context);
- debug ("SIT SON!\n");
-
for (; VEC_iterate (gpydot, decls, idx, itx); ++idx)
{
/*
@@ -93,7 +91,6 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
*/
if (DOT_T_FIELD (itx) == D_D_EXPR)
{
- debug ("expr expr!!\n");
itx = gpy_stmt_process_AST_Align (&itx);
if (DOT_TYPE(itx) == D_MODIFY_EXPR)
@@ -102,8 +99,6 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
&& (DOT_rhs_T(itx) == D_TD_DOT)
);
- debug ("modify expr!!!!!!!!!!!\n");
-
gpy_dot_tree_t * target = DOT_lhs_TT (itx);
// remember to handle target lists here with DOT_CHAIN
do {
@@ -114,7 +109,6 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
}
}
- debug ("context length = <%i>!\n", context.length);
if (context.length > 0)
{
const char * ident = "main.main";
@@ -127,14 +121,15 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
gpy_dot_tree_t * d = (gpy_dot_tree_t *) array[idx].data;
if (d)
{
+ debug ("generating field <%s>!\n", DOT_IDENTIFIER_POINTER (d));
field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
get_identifier (DOT_IDENTIFIER_POINTER (d)),
gpy_object_type_ptr);
- DECL_CONTEXT(field) = retval;
- if (idy>0)
- DECL_CHAIN (last_field) = field;
- else
+ DECL_CONTEXT (field) = retval;
+ if (idy == 0)
TYPE_FIELDS (retval) = field;
+ else
+ DECL_CHAIN (last_field) = field;
last_field = field;
idy++;
}
@@ -142,14 +137,15 @@ tree gpy_stmt_pass_process_toplevel_decls (VEC(gpydot,gc) * decls)
// free (context.array);
- finish_builtin_struct (retval, ident, field, NULL_TREE);
- TYPE_NAME (retval) = get_identifier (ident);
+ layout_type (retval);
+ tree name = get_identifier (ident);
+ tree type_decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, name,
+ retval);
+ DECL_ARTIFICIAL (type_decl) = 1;
+ TYPE_NAME (retval) = name;
- /*
- DECL_ARTIFICIAL (retval) = 1;
- gpy_preserve_from_gc (retval);
- rest_of_decl_compilation (retval, 1, 0);
- */
+ gpy_preserve_from_gc (type_decl);
+ rest_of_decl_compilation(type_decl, 1, 0);
}
else
retval = error_mark_node;