comparison gcc/c-parser.c @ 30:c845c9fe357a

add cbc_replace_arguments function.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Dec 2009 12:43:31 +0900
parents cc07adb17855
children 3f5886e153cb
comparison
equal deleted inserted replaced
29:cc07adb17855 30:c845c9fe357a
3731 3731
3732 return tmp; 3732 return tmp;
3733 } 3733 }
3734 #endif 3734 #endif
3735 3735
3736 static tree
3737 cbc_replace_arguments (location_t loc, tree call)
3738 {
3739 tree args;
3740 tree tmp_decl;
3741 int i=0;
3742
3743 args = CALL_EXPR_ARGS (call);
3744 for ( ;args; args = TREE_CHAIN (args), i++)
3745 {
3746 tree arg = TREE_VALUE (args);
3747
3748 if (CONSTANT_CLASS_P (arg) || VAR_OR_FUNCTION_DECL_P (arg) )
3749 continue;
3750
3751 tmp_decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE(arg));
3752 pushdecl (tmp_decl);
3753
3754 add_stmt (build_modify_expr (loc, tmp_decl, NOP_EXPR, arg));
3755 CALL_EXPR_ARG (call, i) = tmp_decl;
3756 }
3757
3758 return call;
3759 }
3760
3736 /* Parse a statement, other than a labeled statement. */ 3761 /* Parse a statement, other than a labeled statement. */
3737 3762
3738 static void 3763 static void
3739 c_parser_statement_after_labels (c_parser *parser) 3764 c_parser_statement_after_labels (c_parser *parser)
3740 { 3765 {
3794 build_external_ref (id,RID_CbC_CODE , loc); 3819 build_external_ref (id,RID_CbC_CODE , loc);
3795 } 3820 }
3796 expr = c_parser_expr_no_commas (parser, NULL); 3821 expr = c_parser_expr_no_commas (parser, NULL);
3797 if (TREE_CODE(expr.value) == CALL_EXPR ) 3822 if (TREE_CODE(expr.value) == CALL_EXPR )
3798 { 3823 {
3824 location_t loc = c_parser_peek_token (parser)->location;
3825 cbc_replace_arguments (loc, expr.value);
3826
3799 TREE_TYPE(expr.value) = void_type_node; 3827 TREE_TYPE(expr.value) = void_type_node;
3800 //tree env = NULL_TREE; 3828 //tree env = NULL_TREE;
3801 CbC_IS_CbC_GOTO (expr.value) = 1; 3829 CbC_IS_CbC_GOTO (expr.value) = 1;
3802 CALL_EXPR_TAILCALL (expr.value) = 1; 3830 CALL_EXPR_TAILCALL (expr.value) = 1;
3803 add_stmt(expr.value); 3831 add_stmt(expr.value);
5183 @encode ( type-name ) 5211 @encode ( type-name )
5184 objc-string-literal 5212 objc-string-literal
5185 */ 5213 */
5186 5214
5187 static void 5215 static void
5188 cbc_finish_labeled_goto (location_t loc, tree label) 5216 cbc_finish_labeled_goto (location_t loc, tree label, tree retval)
5189 { 5217 {
5190 /* add statement below. 5218 /* add statement below.
5191 * 5219 *
5192 * if (0) { 5220 * if (0) {
5193 * _cbc_exit0: 5221 * _cbc_exit0:
5194 * return retval; 5222 * return retval;
5195 * } 5223 * }
5196 */ 5224 */
5197 tree name;
5198 tree tlab; 5225 tree tlab;
5199 tree cond; 5226 tree cond;
5200 tree retval;
5201 5227
5202 tree cstmt = c_begin_compound_stmt (true); 5228 tree cstmt = c_begin_compound_stmt (true);
5203 5229
5204 tlab = define_label (loc, label); 5230 tlab = define_label (loc, label);
5205 gcc_assert (tlab); 5231 gcc_assert (tlab);
5206 decl_attributes (&tlab, NULL_TREE, 0); 5232 decl_attributes (&tlab, NULL_TREE, 0);
5207 add_stmt (build_stmt (LABEL_EXPR, tlab)); 5233 add_stmt (build_stmt (LABEL_EXPR, tlab));
5208 5234
5209 retval = build_external_ref (get_identifier("retval"), false, loc);
5210 tree ret = c_finish_return (retval); 5235 tree ret = c_finish_return (retval);
5211 TREE_USED(ret) = 1; 5236 TREE_USED(ret) = 1;
5212 5237
5213 cond = integer_zero_node; 5238 cond = integer_zero_node;
5214 tree if_body = c_end_compound_stmt (cstmt, true); 5239 tree if_body = c_end_compound_stmt (cstmt, true);
5230 * retval(lhs)のTREE_DECLを引数から取得するように 5255 * retval(lhs)のTREE_DECLを引数から取得するように
5231 * int _retvalパラメータのタイプはretvalに合わせる 5256 * int _retvalパラメータのタイプはretvalに合わせる
5232 */ 5257 */
5233 5258
5234 tree fnbody; 5259 tree fnbody;
5260 tree _retval_decl, _envp_decl;
5235 struct c_declarator *declarator; 5261 struct c_declarator *declarator;
5236 tree ident; 5262 tree ident;
5237 struct c_arg_info *args; 5263 struct c_arg_info *args;
5238 struct c_declspecs *specs; 5264 struct c_declspecs *specs;
5239 struct c_typespec t; 5265 struct c_typespec t;
5240 { 5266 {
5241 tree _retval_decl, _envp_decl;
5242 push_scope (); 5267 push_scope ();
5243 declare_parm_level (); 5268 declare_parm_level ();
5244 //tree retval_type = TREE_TYPE(retval_decl); 5269 //tree retval_type = TREE_TYPE(retval_decl);
5245 5270
5246 _retval_decl = build_decl (PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl)); 5271 _retval_decl = build_decl (PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl));
5247 DECL_SOURCE_LOCATION (_retval_decl) = loc; 5272 DECL_SOURCE_LOCATION (_retval_decl) = loc;
5273 DECL_ARTIFICIAL (_retval_decl) = 1;
5248 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl); 5274 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl);
5249 pushdecl (_retval_decl); 5275 pushdecl (_retval_decl);
5250 finish_decl (_retval_decl, NULL_TREE, NULL_TREE); 5276 finish_decl (_retval_decl, NULL_TREE, NULL_TREE);
5251 5277
5252 _envp_decl = build_decl (PARM_DECL, get_identifier ("_envp"), ptr_type_node); 5278 _envp_decl = build_decl (PARM_DECL, get_identifier ("_envp"), ptr_type_node);
5253 DECL_SOURCE_LOCATION (_envp_decl) = loc; 5279 DECL_SOURCE_LOCATION (_envp_decl) = loc;
5280 DECL_ARTIFICIAL (_envp_decl) = 1;
5254 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; 5281 DECL_ARG_TYPE (_envp_decl) = ptr_type_node;
5255 pushdecl (_envp_decl); 5282 pushdecl (_envp_decl);
5256 finish_decl (_envp_decl, NULL_TREE, NULL_TREE); 5283 finish_decl (_envp_decl, NULL_TREE, NULL_TREE);
5257 5284
5258 args = get_parm_info(false); 5285 args = get_parm_info(false);
5282 5309
5283 5310
5284 /* start compound statement. */ 5311 /* start compound statement. */
5285 tree cstmt = c_begin_compound_stmt (true); 5312 tree cstmt = c_begin_compound_stmt (true);
5286 5313
5287 //tree lhs = build_external_ref (get_identifier("retval"), false, loc); 5314 add_stmt (build_modify_expr (loc, retval_decl, NOP_EXPR, _retval_decl));
5288 tree rhs = build_external_ref (get_identifier("_retval"), false, loc);
5289 add_stmt (build_modify_expr (loc, retval_decl, NOP_EXPR, rhs));
5290 tree stmt = c_finish_goto_label (label); 5315 tree stmt = c_finish_goto_label (label);
5291 5316
5292 /* end compound statement. */ 5317 /* end compound statement. */
5293 fnbody = c_end_compound_stmt (cstmt, true); 5318 fnbody = c_end_compound_stmt (cstmt, true);
5294 TREE_SIDE_EFFECTS (cstmt) = 1; 5319 TREE_SIDE_EFFECTS (cstmt) = 1;
5859 /* declare retval. (int retval;) */ 5884 /* declare retval. (int retval;) */
5860 tree decl_cond = 5885 tree decl_cond =
5861 build_decl (VAR_DECL, get_identifier ("retval"), 5886 build_decl (VAR_DECL, get_identifier ("retval"),
5862 TREE_TYPE (TREE_TYPE (current_function_decl))); 5887 TREE_TYPE (TREE_TYPE (current_function_decl)));
5863 TREE_STATIC (decl_cond) = 1; 5888 TREE_STATIC (decl_cond) = 1;
5889 DECL_ARTIFICIAL (decl_cond) = 1;
5864 pushdecl (decl_cond); 5890 pushdecl (decl_cond);
5865 5891
5866 /* define nested function. */ 5892 /* define nested function. */
5867 decl = 5893 decl =
5868 cbc_finish_nested_function (location, label, decl_cond); 5894 cbc_finish_nested_function (location, label, decl_cond);
5869 //tree nested_func = cbc_make_nested_function (location); 5895 //tree nested_func = cbc_make_nested_function (location);
5870 5896
5871 /* define if-ed goto label and return statement. */ 5897 /* define if-ed goto label and return statement. */
5872 cbc_finish_labeled_goto (location, label); 5898 cbc_finish_labeled_goto (location, label, decl_cond);
5873 5899
5874 /* get pointer to nested function. */ 5900 /* get pointer to nested function. */
5875 value = build_addr (decl , current_function_decl); 5901 value = build_addr (decl , current_function_decl);
5876 SET_EXPR_LOCATION (value, location); 5902 SET_EXPR_LOCATION (value, location);
5877 add_stmt (value); 5903 add_stmt (value);