# HG changeset patch # User kent # Date 1252648344 -32400 # Node ID ab98828ce7a706f2bae97e21412ba47512c969b9 # Parent 8f2e43f937f3627723373fc798e4e2e93af10e1f refactor cbc_finish_labeled_goto, cbc_finish_nested_function. diff -r 8f2e43f937f3 -r ab98828ce7a7 gcc/c-parser.c --- a/gcc/c-parser.c Wed Sep 09 18:47:06 2009 +0900 +++ b/gcc/c-parser.c Fri Sep 11 14:52:24 2009 +0900 @@ -59,8 +59,8 @@ #include "cgraph.h" #ifndef noCbC #include "cbc-tree.h" -static tree cbc_make_nested_function (location_t); -static void cbc_make_labeled_goto (location_t loc); +static tree cbc_finish_nested_function (location_t, tree); +static void cbc_finish_labeled_goto (location_t, tree); #endif @@ -5713,25 +5713,59 @@ } #else //by KENT. { - c_parser_consume_token (parser); - - tree stmt = c_begin_stmt_expr (); - cbc_return_f = c_parser_peek_token (parser)->value; - location_t location = c_parser_peek_token (parser)->location; - - //add_stmt (cbc_make_nested_function (location)); - tree nested_func = cbc_make_nested_function (location); - add_stmt (build_stmt (DECL_EXPR, nested_func)); - - cbc_make_labeled_goto (location); - - tree value = build_addr (nested_func , current_function_decl); - SET_EXPR_LOCATION (value, location); - add_stmt (value); - - TREE_SIDE_EFFECTS (stmt) = 1; - expr.value = c_finish_stmt_expr (stmt); - expr.original_code = ERROR_MARK; + /* + ({ + __label__ _cbc_exit0; + void __return_func(int retval_, void *_envp){ + retval = retval_; + goto exit0; + } + if (0) { + _cbc_exit0: + return retval; + } + __return_func; + }); + */ + tree value, stmt, label, tlab, decl; + c_parser_consume_token (parser); + + stmt = c_begin_stmt_expr (); + cbc_return_f = c_parser_peek_token (parser)->value; + location_t location = c_parser_peek_token (parser)->location; + + /* create label. (__label__ _cbc_exit0;) */ + label = get_identifier ("_cbc_exit0"); + tlab = declare_label (label); + C_DECLARED_LABEL_FLAG (tlab) = 1; + add_stmt (build_stmt (DECL_EXPR, tlab)); + + /* declare retval. (int retval;) */ + tree decl_cond = + build_decl (VAR_DECL, get_identifier ("retval"), + intHI_type_node); + TREE_STATIC (decl_cond) = 1; + pushdecl (decl_cond); + + /* define nested function. */ + decl = + cbc_finish_nested_function (location, label); + //tree nested_func = cbc_make_nested_function (location); + + /* define if-ed goto label and return statement. */ + cbc_finish_labeled_goto (location, label); + + /* get pointer to nested function. */ + value = build_addr (decl , current_function_decl); + SET_EXPR_LOCATION (value, location); + add_stmt (value); + //value = build_external_ref (get_identifier("_cbc_internal_return"), false, location); + //value = build_unary_op (location, ADDR_EXPR, value, 0); + //add_stmt (value); + + TREE_SIDE_EFFECTS (stmt) = 1; + expr.value = c_finish_stmt_expr (stmt); + expr.original_code = ERROR_MARK; } #endif //0 @@ -5769,22 +5803,26 @@ } static void -cbc_make_labeled_goto (location_t loc) -{ +cbc_finish_labeled_goto (location_t loc, tree label) +{ + /* add statement below. + * + * if (0) { + * _cbc_exit0: + * return retval; + * } + */ tree name; tree tlab; tree cond; tree retval; - //tree fwlabel = create_artificial_label (); tree cstmt = c_begin_compound_stmt (true); - name = get_identifier("_cbc_exit0"); - - tlab = define_label (loc, name); + + tlab = define_label (loc, label); gcc_assert (tlab); decl_attributes (&tlab, NULL_TREE, 0); add_stmt (build_stmt (LABEL_EXPR, tlab)); - //TREE_USED(decl) = 1; retval = build_external_ref (get_identifier("retval"), false, loc); tree ret = c_finish_return (retval); @@ -5797,11 +5835,11 @@ } static tree -cbc_make_nested_function (location_t loc) -{ - - /* - * void __return_func(int _retval, void *fp){ +cbc_finish_nested_function (location_t loc, tree label) +{ + + /* add statement below. + * void __return_func(int _retval, void *_envp){ * retval = _retval; * goto exit0; * } @@ -5882,7 +5920,7 @@ tree lhs = build_external_ref (get_identifier("retval"), false, loc); tree rhs = build_external_ref (get_identifier("_retval"), false, loc); add_stmt (build_modify_expr (loc, lhs, NOP_EXPR, rhs)); - tree stmt = c_finish_goto_label (get_identifier ("_cbc_exit0")); + tree stmt = c_finish_goto_label (label); /* end compound statement. */ fnbody = c_end_compound_stmt (cstmt, true); @@ -5894,8 +5932,7 @@ finish_function (); c_pop_function_context (); - //add_stmt (build_stmt (DECL_EXPR, decl)); - //return build_stmt (DECL_EXPR, decl); + add_stmt (build_stmt (DECL_EXPR, decl)); return decl; }