Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-parser.c @ 7:7ff9aed93de8
partially written goto with env...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 20 Aug 2009 19:09:17 +0900 |
parents | 983001f85155 |
children | ddf292032e7d |
comparison
equal
deleted
inserted
replaced
6:983001f85155 | 7:7ff9aed93de8 |
---|---|
3674 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | 3674 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
3675 c_parser_label (parser); | 3675 c_parser_label (parser); |
3676 c_parser_statement_after_labels (parser); | 3676 c_parser_statement_after_labels (parser); |
3677 } | 3677 } |
3678 | 3678 |
3679 #if 0 | |
3680 static tree | |
3681 c_parser_cbc_make_env(c_parser *parser) | |
3682 { | |
3683 struct c_expr env; | |
3684 tree field, fields=NULL_TREE; | |
3685 tree env_struct, env_struct_type; | |
3686 tree ebp, argsp; | |
3687 tree tmp; | |
3688 | |
3689 c_parser_consume_token (parser); | |
3690 env = c_parser_expr_no_commas (parser, NULL); | |
3691 env = default_function_array_conversion (env); | |
3692 | |
3693 /* build type_node of environment structure */ | |
3694 env_struct_type = start_struct (RECORD_TYPE, NULL_TREE); | |
3695 field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node); | |
3696 fields = chainon (field, fields); | |
3697 field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node); | |
3698 fields = chainon (field, fields); | |
3699 //field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node); | |
3700 //fields = chainon (field, fields); | |
3701 fields = nreverse(fields); | |
3702 finish_struct (env_struct_type, fields, NULL_TREE); | |
3703 | |
3704 env_struct = build_c_cast (build_pointer_type(env_struct_type), env.value); | |
3705 //build_component_ref (cbc_env, get_identifier("argsp")); | |
3706 ebp = build_component_ref (build_indirect_ref (loc,env_struct, "CbCenv->sp"), get_identifier("sp")); | |
3707 argsp = build_component_ref (build_indirect_ref (loc, env_struct, "CbCenv->sp"), get_identifier("argsp")); | |
3708 //ebp = chainon (ebp, argsp); | |
3709 tmp = build_tree_list (ebp, argsp); | |
3710 | |
3711 return tmp; | |
3712 } | |
3713 #endif | |
3714 | |
3679 /* Parse a statement, other than a labeled statement. */ | 3715 /* Parse a statement, other than a labeled statement. */ |
3680 | 3716 |
3681 static void | 3717 static void |
3682 c_parser_statement_after_labels (c_parser *parser) | 3718 c_parser_statement_after_labels (c_parser *parser) |
3683 { | 3719 { |
3738 } | 3774 } |
3739 expr = c_parser_expr_no_commas (parser, NULL); | 3775 expr = c_parser_expr_no_commas (parser, NULL); |
3740 if (TREE_CODE(expr.value) == CALL_EXPR ) | 3776 if (TREE_CODE(expr.value) == CALL_EXPR ) |
3741 { | 3777 { |
3742 TREE_TYPE(expr.value) = void_type_node; | 3778 TREE_TYPE(expr.value) = void_type_node; |
3743 if (c_parser_next_token_is (parser, CPP_COMMA)) | 3779 tree env = NULL_TREE; |
3744 { | 3780 // if (c_parser_next_token_is (parser, CPP_COMMA)) |
3745 struct c_expr env; | 3781 // env = c_parser_cbc_make_env(parser); |
3746 tree field, fields=NULL_TREE; | |
3747 tree env_struct, env_struct_type; | |
3748 tree ebp, argsp; | |
3749 tree tmp; | |
3750 | |
3751 c_parser_consume_token (parser); | |
3752 env = c_parser_expr_no_commas (parser, NULL); | |
3753 env = default_function_array_conversion (env); | |
3754 | |
3755 /* build type_node of environment structure */ | |
3756 env_struct_type = start_struct (RECORD_TYPE, NULL_TREE); | |
3757 field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node); | |
3758 fields = chainon (field, fields); | |
3759 field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node); | |
3760 fields = chainon (field, fields); | |
3761 //field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node); | |
3762 //fields = chainon (field, fields); | |
3763 fields = nreverse(fields); | |
3764 finish_struct (env_struct_type, fields, NULL_TREE); | |
3765 | |
3766 env_struct = build_c_cast (build_pointer_type(env_struct_type), env.value); | |
3767 //build_component_ref (cbc_env, get_identifier("argsp")); | |
3768 ebp = build_component_ref (build_indirect_ref (loc,env_struct, "CbCenv->sp"), get_identifier("sp")); | |
3769 argsp = build_component_ref (build_indirect_ref (loc, env_struct, "CbCenv->sp"), get_identifier("argsp")); | |
3770 //ebp = chainon (ebp, argsp); | |
3771 tmp = build_tree_list (ebp, argsp); | |
3772 | |
3773 // TREE_OPERAND (expr.value, 2) = tmp; | |
3774 | |
3775 | |
3776 /* | |
3777 c_parser_consume_token (parser); | |
3778 expr = default_function_array_conversion (expr); | |
3779 ident = c_parser_peek_token (parser)->value; | |
3780 c_parser_consume_token (parser); | |
3781 expr.value = build_component_ref (build_indirect_ref (expr.value, | |
3782 "->"), ident); | |
3783 expr.original_code = ERROR_MARK; | |
3784 */ | |
3785 | |
3786 | |
3787 } | |
3788 // else | |
3789 // TREE_OPERAND (expr.value, 2) = NULL_TREE; | |
3790 CbC_IS_CbC_GOTO (expr.value) = 1; | 3782 CbC_IS_CbC_GOTO (expr.value) = 1; |
3791 CALL_EXPR_TAILCALL (expr.value) = 1; | 3783 CALL_EXPR_TAILCALL (expr.value) = 1; |
3792 add_stmt(expr.value); | 3784 add_stmt(expr.value); |
3793 CbC_HAVE_CbC_GOTO (current_function_decl) = 1; | 3785 CbC_HAVE_CbC_GOTO (current_function_decl) = 1; |
3794 // should be match with function type? | 3786 // should be match with function type? |
5579 } | 5571 } |
5580 break; | 5572 break; |
5581 #ifndef noCbC | 5573 #ifndef noCbC |
5582 case RID_CbC_ENV: | 5574 case RID_CbC_ENV: |
5583 { | 5575 { |
5584 #if 0 | 5576 c_parser_consume_token (parser); |
5585 tree valuep_tree; | |
5586 tree value_tree; | |
5587 tree env_tree; | |
5588 | |
5589 tree exprstmt; | |
5590 tree stmt = c_begin_stmt_expr (); | |
5591 /* | |
5592 * __value = { | |
5593 * void *ebp; | |
5594 * char args[sizeof(arguments)]; | |
5595 * }; | |
5596 * | |
5597 * __env = ({ | |
5598 * ebp = __builtin_frame_address(0); | |
5599 * *__value=ebp; | |
5600 * __value; | |
5601 * }) | |
5602 */ | |
5603 | |
5604 /* get value of %ebp. */ | 5577 /* get value of %ebp. */ |
5605 env_tree = build_external_ref ( | 5578 tree env_tree = build_external_ref ( |
5606 get_identifier ("__builtin_frame_address"), 0, | 5579 get_identifier ("__builtin_frame_address"), 0, |
5607 c_parser_peek_token (parser)->location); | 5580 c_parser_peek_token (parser)->location); |
5608 env_tree = build_function_call(env_tree, | 5581 expr.value = build_function_call(env_tree, |
5609 build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0))); | 5582 build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0))); |
5610 | 5583 expr.original_code = ERROR_MARK; |
5611 /* ebp = __builtin_frame_address(0) */ | 5584 |
5612 valuep_tree = build_decl (VAR_DECL, get_identifier("__value"), intTI_type_node); | |
5613 TREE_STATIC (valuep_tree) = 1; | |
5614 lang_hooks.decls.pushdecl(valuep_tree); | |
5615 /* cast __value to pointer to pointer to void. */ | |
5616 valuep_tree = build_c_cast (build_pointer_type(ptr_type_node), valuep_tree); | |
5617 value_tree = build_indirect_ref (valuep_tree, "cbc: *__value"); | |
5618 | |
5619 /* *__value = ebp; */ | |
5620 exprstmt = build_modify_expr (value_tree, NOP_EXPR, env_tree); | |
5621 add_stmt(exprstmt); | |
5622 | |
5623 /* __value; */ | |
5624 add_stmt(valuep_tree); | |
5625 #else | |
5626 | |
5627 //tree env; // environment structure | |
5628 tree env_struct; // type of environment structure | |
5629 tree field; | |
5630 tree fields=NULL_TREE; | |
5631 tree comp, comp0; // component of environment | |
5632 tree ebp; | |
5633 | |
5634 tree stmt = c_begin_stmt_expr (); | |
5635 | |
5636 /* | |
5637 * struct { | |
5638 * void *sp; <= %ebp | |
5639 * void *argp; <= &__environment.retval | |
5640 * int retval; // int? or return type of this function | |
5641 * } __CbCenv; | |
5642 * | |
5643 * __environment = &__CbCenv; | |
5644 * | |
5645 */ | |
5646 | |
5647 if (!cbc_env) | |
5648 { | |
5649 /* build type_node of environment structure */ | |
5650 env_struct = start_struct (RECORD_TYPE, NULL_TREE); | |
5651 field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node); | |
5652 fields = chainon (field, fields); | |
5653 field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node); | |
5654 fields = chainon (field, fields); | |
5655 field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node); | |
5656 fields = chainon (field, fields); | |
5657 fields = nreverse(fields); | |
5658 //env_struct = make_node(RECORD_TYPE); | |
5659 //TYPE_FIELDS (env_struct) = fields; | |
5660 finish_struct (env_struct, fields, NULL_TREE); | |
5661 | |
5662 /* declare __environment structure. */ | |
5663 cbc_env = build_decl (VAR_DECL, get_identifier("__CbCenv"), env_struct); | |
5664 TREE_STATIC (cbc_env) = 1; | |
5665 lang_hooks.decls.pushdecl(cbc_env); | |
5666 } | |
5667 | |
5668 /* get value of %ebp. */ | |
5669 ebp = build_external_ref ( | |
5670 get_identifier ("__builtin_frame_address"), 0, | |
5671 (loc = c_parser_peek_token (parser)->location)); | |
5672 ebp = build_function_call(ebp, | |
5673 build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0))); | |
5674 | |
5675 /* assignment void *sp = %ebp */ | |
5676 comp = build_component_ref (cbc_env, get_identifier("sp")); | |
5677 add_stmt (build_modify_expr (loc, comp, NOP_EXPR, ebp)); | |
5678 | |
5679 /* void *argsp = &__environment.retval */ | |
5680 comp = build_component_ref (cbc_env, get_identifier("argsp")); | |
5681 comp0 = build_component_ref (cbc_env, get_identifier("retval")); | |
5682 comp0 = build_unary_op (loc, ADDR_EXPR, comp0, 0); | |
5683 add_stmt (build_modify_expr (loc, comp, NOP_EXPR, comp0)); | |
5684 | |
5685 | |
5686 /* &__environment for value of stmt_expr. */ | |
5687 add_stmt (build_unary_op (loc, ADDR_EXPR, cbc_env, 0)); | |
5688 #endif | |
5689 //expr.value = valuep_tree; | |
5690 TREE_SIDE_EFFECTS (stmt) = 1; | |
5691 expr.value = c_finish_stmt_expr (stmt); | |
5692 //expr.value = build_unary_op (ADDR_EXPR, env, 0); | |
5693 c_parser_consume_token (parser); | |
5694 } | 5585 } |
5695 break; | 5586 break; |
5696 case RID_CbC_RET: | 5587 case RID_CbC_RET: |
5697 case RID_RETURN: | 5588 case RID_RETURN: |
5698 #if 1 | 5589 |
5699 if (cbc_return_f==0) { | 5590 if (cbc_return_f==0) { tree retval; |
5700 tree retval; | |
5701 | 5591 |
5702 /* | 5592 /* |
5703 Generates something like... | 5593 Generates something like... |
5704 | 5594 |
5705 __return = ({ | 5595 int retval = 1; |
5706 static volatile int __return; | 5596 void (*ret)(int retval_,void *fp) ; |
5707 if (__return) { | 5597 |
5708 return_label: | 5598 ret = ({ |
5709 return value; | 5599 __label__ exit0; |
5710 } | 5600 volatile static flag = 0; |
5711 &&return_label; | 5601 void __return_func(int retval_,void *fp) { |
5712 }) | 5602 retval = retval_; |
5603 goto exit0; | |
5604 } | |
5605 if (flag) { | |
5606 exit0: | |
5607 printf("f1: fp = 0x%x\n",__builtin_frame_address(0)); | |
5608 return retval; | |
5609 } | |
5610 __return_func; | |
5611 }); | |
5612 | |
5713 */ | 5613 */ |
5714 | 5614 |
5715 tree stmt = c_begin_stmt_expr (); | 5615 tree stmt = c_begin_stmt_expr (); |
5716 cbc_return_f = c_parser_peek_token (parser)->value; | 5616 cbc_return_f = c_parser_peek_token (parser)->value; |
5717 cbc_return = c_parser_peek_token (parser)->location; | 5617 cbc_return = c_parser_peek_token (parser)->location; |
5748 tree decl= build_stmt (LABEL_EXPR, tlab); | 5648 tree decl= build_stmt (LABEL_EXPR, tlab); |
5749 //TREE_USED(decl) = 1; | 5649 //TREE_USED(decl) = 1; |
5750 add_stmt(decl); | 5650 add_stmt(decl); |
5751 | 5651 |
5752 //tree hoge = build_int_cst(NULL_TREE,55); | 5652 //tree hoge = build_int_cst(NULL_TREE,55); |
5753 if (!cbc_env) | |
5754 { | |
5755 tree field,fields=NULL_TREE,env_struct; | |
5756 /* build type_node of environment structure */ | |
5757 env_struct = start_struct (RECORD_TYPE, NULL_TREE); | |
5758 field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node); | |
5759 fields = chainon (field, fields); | |
5760 field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node); | |
5761 fields = chainon (field, fields); | |
5762 field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node); | |
5763 fields = chainon (field, fields); | |
5764 fields = nreverse(fields); | |
5765 //env_struct = make_node(RECORD_TYPE); | |
5766 //TYPE_FIELDS (env_struct) = fields; | |
5767 finish_struct (env_struct, fields, NULL_TREE); | |
5768 | |
5769 /* declare __environment structure. */ | |
5770 cbc_env = build_decl (VAR_DECL, get_identifier("__CbCenv"), env_struct); | |
5771 TREE_STATIC (cbc_env) = 1; | |
5772 lang_hooks.decls.pushdecl(cbc_env); | |
5773 } | |
5774 retval = build_component_ref (cbc_env, get_identifier("retval")); | 5653 retval = build_component_ref (cbc_env, get_identifier("retval")); |
5775 tree ret = c_finish_return (retval); | 5654 tree ret = c_finish_return (retval); |
5776 TREE_USED(ret) = 1; | 5655 TREE_USED(ret) = 1; |
5777 tree first_body = c_end_compound_stmt (block, flag_isoc99); | 5656 tree first_body = c_end_compound_stmt (block, flag_isoc99); |
5778 | 5657 |
5796 add_stmt(value); | 5675 add_stmt(value); |
5797 | 5676 |
5798 TREE_SIDE_EFFECTS (stmt) = 1; | 5677 TREE_SIDE_EFFECTS (stmt) = 1; |
5799 expr.value = c_finish_stmt_expr (stmt); | 5678 expr.value = c_finish_stmt_expr (stmt); |
5800 expr.original_code = ERROR_MARK; | 5679 expr.original_code = ERROR_MARK; |
5801 | |
5802 // cbc_return_f =0; | |
5803 | 5680 |
5804 } else { | 5681 } else { |
5805 //tree label = lookup_label(c_parser_peek_token (parser)->value); | 5682 //tree label = lookup_label(c_parser_peek_token (parser)->value); |
5806 //TREE_USED(label) = 1; | 5683 //TREE_USED(label) = 1; |
5807 //expr.value = build1(ADDR_EXPR, ptr_type_node, label); | 5684 //expr.value = build1(ADDR_EXPR, ptr_type_node, label); |
5808 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1); | 5685 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1); |
5809 c_parser_consume_token (parser); | 5686 c_parser_consume_token (parser); |
5810 } | 5687 } |
5811 break; | 5688 break; |
5812 #endif | |
5813 #endif | 5689 #endif |
5814 default: | 5690 default: |
5815 c_parser_error (parser, "expected expression"); | 5691 c_parser_error (parser, "expected expression"); |
5816 expr.value = error_mark_node; | 5692 expr.value = error_mark_node; |
5817 expr.original_code = ERROR_MARK; | 5693 expr.original_code = ERROR_MARK; |