From b343eaa5efd70d82cca06f0d59c8eb1249be890f Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 23 Jun 2016 06:07:54 -0400 Subject: [PATCH 27/28] FIXME: WIP on __RTL from cc1 --- gcc/read-rtl-function.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c index 90689ff..3f8ee08 100644 --- a/gcc/read-rtl-function.c +++ b/gcc/read-rtl-function.c @@ -544,27 +544,34 @@ function_reader::create_function () else rtl_register_cfg_hooks (); - /* Create cfun. */ - tree fn_name = get_identifier ("test_1"); - tree int_type = integer_type_node; - tree return_type = int_type; - tree arg_types[3] = {int_type, int_type, int_type}; - tree fn_type = build_function_type_array (return_type, 3, arg_types); - tree fndecl = build_decl_stat (UNKNOWN_LOCATION, FUNCTION_DECL, fn_name, - fn_type); - tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, - return_type); - DECL_ARTIFICIAL (resdecl) = 1; - DECL_IGNORED_P (resdecl) = 1; - DECL_RESULT (fndecl) = resdecl; - allocate_struct_function (fndecl, false); - /* This sets cfun. */ + /* When run from "rtl1", cfun is NULL. + When run from "cc1", cfun is the function tagged with "__RTL". */ + if (!cfun) + { + tree fn_name = get_identifier ("test_1"); + tree int_type = integer_type_node; + tree return_type = int_type; + tree arg_types[3] = {int_type, int_type, int_type}; + tree fn_type = build_function_type_array (return_type, 3, arg_types); + tree fndecl = build_decl_stat (UNKNOWN_LOCATION, FUNCTION_DECL, fn_name, + fn_type); + tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, + return_type); + DECL_ARTIFICIAL (resdecl) = 1; + DECL_IGNORED_P (resdecl) = 1; + DECL_RESULT (fndecl) = resdecl; + allocate_struct_function (fndecl, false); + /* This sets cfun. */ + current_function_decl = fndecl; + } + gcc_assert (cfun); + gcc_assert (current_function_decl); + tree fndecl = current_function_decl; /* Normally, various state gets set up by expand_function_start, e.g. crtl->return_rtx, based on DECL_RESULT (fndecl). We call it here to ensure the state is set up, with emit_insns as false, so no new instructions are emitted. */ - current_function_decl = fndecl; expand_function_start (fndecl, false); create_cfg_and_basic_blocks (); -- 1.8.5.3