Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-parser.c @ 12:ab98828ce7a7
refactor cbc_finish_labeled_goto, cbc_finish_nested_function.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 11 Sep 2009 14:52:24 +0900 |
parents | 8f2e43f937f3 |
children | be566c4d18c5 |
comparison
equal
deleted
inserted
replaced
11:8f2e43f937f3 | 12:ab98828ce7a7 |
---|---|
57 #include "vec.h" | 57 #include "vec.h" |
58 #include "target.h" | 58 #include "target.h" |
59 #include "cgraph.h" | 59 #include "cgraph.h" |
60 #ifndef noCbC | 60 #ifndef noCbC |
61 #include "cbc-tree.h" | 61 #include "cbc-tree.h" |
62 static tree cbc_make_nested_function (location_t); | 62 static tree cbc_finish_nested_function (location_t, tree); |
63 static void cbc_make_labeled_goto (location_t loc); | 63 static void cbc_finish_labeled_goto (location_t, tree); |
64 #endif | 64 #endif |
65 | 65 |
66 | 66 |
67 /* Initialization routine for this file. */ | 67 /* Initialization routine for this file. */ |
68 | 68 |
5711 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1); | 5711 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1); |
5712 c_parser_consume_token (parser); | 5712 c_parser_consume_token (parser); |
5713 } | 5713 } |
5714 #else //by KENT. | 5714 #else //by KENT. |
5715 { | 5715 { |
5716 c_parser_consume_token (parser); | 5716 /* |
5717 | 5717 ({ |
5718 tree stmt = c_begin_stmt_expr (); | 5718 __label__ _cbc_exit0; |
5719 cbc_return_f = c_parser_peek_token (parser)->value; | 5719 void __return_func(int retval_, void *_envp){ |
5720 location_t location = c_parser_peek_token (parser)->location; | 5720 retval = retval_; |
5721 | 5721 goto exit0; |
5722 //add_stmt (cbc_make_nested_function (location)); | 5722 } |
5723 tree nested_func = cbc_make_nested_function (location); | 5723 if (0) { |
5724 add_stmt (build_stmt (DECL_EXPR, nested_func)); | 5724 _cbc_exit0: |
5725 | 5725 return retval; |
5726 cbc_make_labeled_goto (location); | 5726 } |
5727 | 5727 __return_func; |
5728 tree value = build_addr (nested_func , current_function_decl); | 5728 }); |
5729 SET_EXPR_LOCATION (value, location); | 5729 */ |
5730 add_stmt (value); | 5730 tree value, stmt, label, tlab, decl; |
5731 | 5731 c_parser_consume_token (parser); |
5732 TREE_SIDE_EFFECTS (stmt) = 1; | 5732 |
5733 expr.value = c_finish_stmt_expr (stmt); | 5733 stmt = c_begin_stmt_expr (); |
5734 expr.original_code = ERROR_MARK; | 5734 cbc_return_f = c_parser_peek_token (parser)->value; |
5735 location_t location = c_parser_peek_token (parser)->location; | |
5736 | |
5737 /* create label. (__label__ _cbc_exit0;) */ | |
5738 label = get_identifier ("_cbc_exit0"); | |
5739 tlab = declare_label (label); | |
5740 C_DECLARED_LABEL_FLAG (tlab) = 1; | |
5741 add_stmt (build_stmt (DECL_EXPR, tlab)); | |
5742 | |
5743 /* declare retval. (int retval;) */ | |
5744 tree decl_cond = | |
5745 build_decl (VAR_DECL, get_identifier ("retval"), | |
5746 intHI_type_node); | |
5747 TREE_STATIC (decl_cond) = 1; | |
5748 pushdecl (decl_cond); | |
5749 | |
5750 /* define nested function. */ | |
5751 decl = | |
5752 cbc_finish_nested_function (location, label); | |
5753 //tree nested_func = cbc_make_nested_function (location); | |
5754 | |
5755 /* define if-ed goto label and return statement. */ | |
5756 cbc_finish_labeled_goto (location, label); | |
5757 | |
5758 /* get pointer to nested function. */ | |
5759 value = build_addr (decl , current_function_decl); | |
5760 SET_EXPR_LOCATION (value, location); | |
5761 add_stmt (value); | |
5762 //value = build_external_ref (get_identifier("_cbc_internal_return"), false, location); | |
5763 //value = build_unary_op (location, ADDR_EXPR, value, 0); | |
5764 //add_stmt (value); | |
5765 | |
5766 TREE_SIDE_EFFECTS (stmt) = 1; | |
5767 expr.value = c_finish_stmt_expr (stmt); | |
5768 expr.original_code = ERROR_MARK; | |
5735 } | 5769 } |
5736 | 5770 |
5737 #endif //0 | 5771 #endif //0 |
5738 break; | 5772 break; |
5739 #endif //noCbC | 5773 #endif //noCbC |
5767 } | 5801 } |
5768 return c_parser_postfix_expression_after_primary (parser, expr); | 5802 return c_parser_postfix_expression_after_primary (parser, expr); |
5769 } | 5803 } |
5770 | 5804 |
5771 static void | 5805 static void |
5772 cbc_make_labeled_goto (location_t loc) | 5806 cbc_finish_labeled_goto (location_t loc, tree label) |
5773 { | 5807 { |
5808 /* add statement below. | |
5809 * | |
5810 * if (0) { | |
5811 * _cbc_exit0: | |
5812 * return retval; | |
5813 * } | |
5814 */ | |
5774 tree name; | 5815 tree name; |
5775 tree tlab; | 5816 tree tlab; |
5776 tree cond; | 5817 tree cond; |
5777 tree retval; | 5818 tree retval; |
5778 //tree fwlabel = create_artificial_label (); | |
5779 | 5819 |
5780 tree cstmt = c_begin_compound_stmt (true); | 5820 tree cstmt = c_begin_compound_stmt (true); |
5781 name = get_identifier("_cbc_exit0"); | 5821 |
5782 | 5822 tlab = define_label (loc, label); |
5783 tlab = define_label (loc, name); | |
5784 gcc_assert (tlab); | 5823 gcc_assert (tlab); |
5785 decl_attributes (&tlab, NULL_TREE, 0); | 5824 decl_attributes (&tlab, NULL_TREE, 0); |
5786 add_stmt (build_stmt (LABEL_EXPR, tlab)); | 5825 add_stmt (build_stmt (LABEL_EXPR, tlab)); |
5787 //TREE_USED(decl) = 1; | |
5788 | 5826 |
5789 retval = build_external_ref (get_identifier("retval"), false, loc); | 5827 retval = build_external_ref (get_identifier("retval"), false, loc); |
5790 tree ret = c_finish_return (retval); | 5828 tree ret = c_finish_return (retval); |
5791 TREE_USED(ret) = 1; | 5829 TREE_USED(ret) = 1; |
5792 | 5830 |
5795 TREE_SIDE_EFFECTS (cstmt) = 1; | 5833 TREE_SIDE_EFFECTS (cstmt) = 1; |
5796 c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); | 5834 c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); |
5797 } | 5835 } |
5798 | 5836 |
5799 static tree | 5837 static tree |
5800 cbc_make_nested_function (location_t loc) | 5838 cbc_finish_nested_function (location_t loc, tree label) |
5801 { | 5839 { |
5802 | 5840 |
5803 /* | 5841 /* add statement below. |
5804 * void __return_func(int _retval, void *fp){ | 5842 * void __return_func(int _retval, void *_envp){ |
5805 * retval = _retval; | 5843 * retval = _retval; |
5806 * goto exit0; | 5844 * goto exit0; |
5807 * } | 5845 * } |
5808 */ | 5846 */ |
5809 | 5847 |
5880 tree cstmt = c_begin_compound_stmt (true); | 5918 tree cstmt = c_begin_compound_stmt (true); |
5881 | 5919 |
5882 tree lhs = build_external_ref (get_identifier("retval"), false, loc); | 5920 tree lhs = build_external_ref (get_identifier("retval"), false, loc); |
5883 tree rhs = build_external_ref (get_identifier("_retval"), false, loc); | 5921 tree rhs = build_external_ref (get_identifier("_retval"), false, loc); |
5884 add_stmt (build_modify_expr (loc, lhs, NOP_EXPR, rhs)); | 5922 add_stmt (build_modify_expr (loc, lhs, NOP_EXPR, rhs)); |
5885 tree stmt = c_finish_goto_label (get_identifier ("_cbc_exit0")); | 5923 tree stmt = c_finish_goto_label (label); |
5886 | 5924 |
5887 /* end compound statement. */ | 5925 /* end compound statement. */ |
5888 fnbody = c_end_compound_stmt (cstmt, true); | 5926 fnbody = c_end_compound_stmt (cstmt, true); |
5889 TREE_SIDE_EFFECTS (cstmt) = 1; | 5927 TREE_SIDE_EFFECTS (cstmt) = 1; |
5890 | 5928 |
5892 tree decl = current_function_decl; | 5930 tree decl = current_function_decl; |
5893 add_stmt (fnbody); | 5931 add_stmt (fnbody); |
5894 finish_function (); | 5932 finish_function (); |
5895 c_pop_function_context (); | 5933 c_pop_function_context (); |
5896 | 5934 |
5897 //add_stmt (build_stmt (DECL_EXPR, decl)); | 5935 add_stmt (build_stmt (DECL_EXPR, decl)); |
5898 //return build_stmt (DECL_EXPR, decl); | |
5899 return decl; | 5936 return decl; |
5900 } | 5937 } |
5901 | 5938 |
5902 /* Parse a postfix expression after a parenthesized type name: the | 5939 /* Parse a postfix expression after a parenthesized type name: the |
5903 brace-enclosed initializer of a compound literal, possibly followed | 5940 brace-enclosed initializer of a compound literal, possibly followed |