| ... | @@ -756,57 +756,22 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -756,57 +756,22 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 756 | zig_panic("TODO cast expression"); | 756 | zig_panic("TODO cast expression"); |
| 757 | } | 757 | } |
| 758 | | 758 | |
| 759 | static LLVMValueRef gen_mult_expr(CodeGen *g, AstNode *node) { | 759 | static LLVMValueRef gen_arithmetic_bin_op_expr(CodeGen *g, AstNode *node) { |
| 760 | assert(node->type == NodeTypeBinOpExpr); | 760 | assert(node->type == NodeTypeBinOpExpr); |
| 761 | | 761 | |
| 762 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | 762 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); |
| 763 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | 763 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); |
| 764 | | 764 | |
| 765 | switch (node->data.bin_op_expr.bin_op) { | 765 | switch (node->data.bin_op_expr.bin_op) { |
| 766 | case BinOpTypeMult: | 766 | case BinOpTypeBinOr: |
| 767 | // TODO types so we know float vs int | | |
| 768 | add_debug_source_node(g, node); | | |
| 769 | return LLVMBuildMul(g->builder, val1, val2, ""); | | |
| 770 | case BinOpTypeDiv: | | |
| 771 | // TODO types so we know float vs int and signed vs unsigned | | |
| 772 | add_debug_source_node(g, node); | | |
| 773 | return LLVMBuildSDiv(g->builder, val1, val2, ""); | | |
| 774 | case BinOpTypeMod: | | |
| 775 | // TODO types so we know float vs int and signed vs unsigned | | |
| 776 | add_debug_source_node(g, node); | 767 | add_debug_source_node(g, node); |
| 777 | return LLVMBuildSRem(g->builder, val1, val2, ""); | 768 | return LLVMBuildOr(g->builder, val1, val2, ""); |
| 778 | default: | 769 | case BinOpTypeBinXor: |
| 779 | zig_unreachable(); | | |
| 780 | } | | |
| 781 | zig_unreachable(); | | |
| 782 | } | | |
| 783 | | | |
| 784 | static LLVMValueRef gen_add_expr(CodeGen *g, AstNode *node) { | | |
| 785 | assert(node->type == NodeTypeBinOpExpr); | | |
| 786 | | | |
| 787 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | | |
| 788 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | | |
| 789 | | | |
| 790 | switch (node->data.bin_op_expr.bin_op) { | | |
| 791 | case BinOpTypeAdd: | | |
| 792 | add_debug_source_node(g, node); | 770 | add_debug_source_node(g, node); |
| 793 | return LLVMBuildAdd(g->builder, val1, val2, ""); | 771 | return LLVMBuildXor(g->builder, val1, val2, ""); |
| 794 | case BinOpTypeSub: | 772 | case BinOpTypeBinAnd: |
| 795 | add_debug_source_node(g, node); | 773 | add_debug_source_node(g, node); |
| 796 | return LLVMBuildSub(g->builder, val1, val2, ""); | 774 | return LLVMBuildAnd(g->builder, val1, val2, ""); |
| 797 | default: | | |
| 798 | zig_unreachable(); | | |
| 799 | } | | |
| 800 | zig_unreachable(); | | |
| 801 | } | | |
| 802 | | | |
| 803 | static LLVMValueRef gen_bit_shift_expr(CodeGen *g, AstNode *node) { | | |
| 804 | assert(node->type == NodeTypeBinOpExpr); | | |
| 805 | | | |
| 806 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | | |
| 807 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | | |
| 808 | | | |
| 809 | switch (node->data.bin_op_expr.bin_op) { | | |
| 810 | case BinOpTypeBitShiftLeft: | 775 | case BinOpTypeBitShiftLeft: |
| 811 | add_debug_source_node(g, node); | 776 | add_debug_source_node(g, node); |
| 812 | return LLVMBuildShl(g->builder, val1, val2, ""); | 777 | return LLVMBuildShl(g->builder, val1, val2, ""); |
| ... | @@ -816,46 +781,40 @@ static LLVMValueRef gen_bit_shift_expr(CodeGen *g, AstNode *node) { | ... | @@ -816,46 +781,40 @@ static LLVMValueRef gen_bit_shift_expr(CodeGen *g, AstNode *node) { |
| 816 | // signed -> arithmetic, unsigned -> logical | 781 | // signed -> arithmetic, unsigned -> logical |
| 817 | add_debug_source_node(g, node); | 782 | add_debug_source_node(g, node); |
| 818 | return LLVMBuildLShr(g->builder, val1, val2, ""); | 783 | return LLVMBuildLShr(g->builder, val1, val2, ""); |
| 819 | default: | 784 | case BinOpTypeAdd: |
| | 785 | add_debug_source_node(g, node); |
| | 786 | return LLVMBuildAdd(g->builder, val1, val2, ""); |
| | 787 | case BinOpTypeSub: |
| | 788 | add_debug_source_node(g, node); |
| | 789 | return LLVMBuildSub(g->builder, val1, val2, ""); |
| | 790 | case BinOpTypeMult: |
| | 791 | // TODO types so we know float vs int |
| | 792 | add_debug_source_node(g, node); |
| | 793 | return LLVMBuildMul(g->builder, val1, val2, ""); |
| | 794 | case BinOpTypeDiv: |
| | 795 | // TODO types so we know float vs int and signed vs unsigned |
| | 796 | add_debug_source_node(g, node); |
| | 797 | return LLVMBuildSDiv(g->builder, val1, val2, ""); |
| | 798 | case BinOpTypeMod: |
| | 799 | // TODO types so we know float vs int and signed vs unsigned |
| | 800 | add_debug_source_node(g, node); |
| | 801 | return LLVMBuildSRem(g->builder, val1, val2, ""); |
| | 802 | case BinOpTypeBoolOr: |
| | 803 | case BinOpTypeBoolAnd: |
| | 804 | case BinOpTypeCmpEq: |
| | 805 | case BinOpTypeCmpNotEq: |
| | 806 | case BinOpTypeCmpLessThan: |
| | 807 | case BinOpTypeCmpGreaterThan: |
| | 808 | case BinOpTypeCmpLessOrEq: |
| | 809 | case BinOpTypeCmpGreaterOrEq: |
| | 810 | case BinOpTypeInvalid: |
| 820 | zig_unreachable(); | 811 | zig_unreachable(); |
| 821 | } | 812 | } |
| 822 | zig_unreachable(); | 813 | zig_unreachable(); |
| 823 | } | 814 | } |
| 824 | | 815 | |
| 825 | static LLVMValueRef gen_bin_and_expr(CodeGen *g, AstNode *node) { | | |
| 826 | assert(node->type == NodeTypeBinOpExpr); | | |
| 827 | | | |
| 828 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | | |
| 829 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | | |
| 830 | | | |
| 831 | add_debug_source_node(g, node); | | |
| 832 | return LLVMBuildAnd(g->builder, val1, val2, ""); | | |
| 833 | } | | |
| 834 | | | |
| 835 | static LLVMValueRef gen_bin_xor_expr(CodeGen *g, AstNode *node) { | | |
| 836 | assert(node->type == NodeTypeBinOpExpr); | | |
| 837 | | | |
| 838 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | | |
| 839 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | | |
| 840 | | | |
| 841 | add_debug_source_node(g, node); | | |
| 842 | return LLVMBuildXor(g->builder, val1, val2, ""); | | |
| 843 | } | | |
| 844 | | | |
| 845 | static LLVMValueRef gen_bin_or_expr(CodeGen *g, AstNode *node) { | | |
| 846 | assert(node->type == NodeTypeBinOpExpr); | | |
| 847 | | | |
| 848 | LLVMValueRef val1 = gen_expr(g, node->data.bin_op_expr.op1); | | |
| 849 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | | |
| 850 | | | |
| 851 | add_debug_source_node(g, node); | | |
| 852 | return LLVMBuildOr(g->builder, val1, val2, ""); | | |
| 853 | } | | |
| 854 | | | |
| 855 | static LLVMIntPredicate cmp_op_to_int_predicate(BinOpType cmp_op, bool is_signed) { | 816 | static LLVMIntPredicate cmp_op_to_int_predicate(BinOpType cmp_op, bool is_signed) { |
| 856 | switch (cmp_op) { | 817 | switch (cmp_op) { |
| 857 | case BinOpTypeInvalid: | | |
| 858 | zig_unreachable(); | | |
| 859 | case BinOpTypeCmpEq: | 818 | case BinOpTypeCmpEq: |
| 860 | return LLVMIntEQ; | 819 | return LLVMIntEQ; |
| 861 | case BinOpTypeCmpNotEq: | 820 | case BinOpTypeCmpNotEq: |
| ... | @@ -963,21 +922,16 @@ static LLVMValueRef gen_bin_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -963,21 +922,16 @@ static LLVMValueRef gen_bin_op_expr(CodeGen *g, AstNode *node) { |
| 963 | case BinOpTypeCmpGreaterOrEq: | 922 | case BinOpTypeCmpGreaterOrEq: |
| 964 | return gen_cmp_expr(g, node); | 923 | return gen_cmp_expr(g, node); |
| 965 | case BinOpTypeBinOr: | 924 | case BinOpTypeBinOr: |
| 966 | return gen_bin_or_expr(g, node); | | |
| 967 | case BinOpTypeBinXor: | 925 | case BinOpTypeBinXor: |
| 968 | return gen_bin_xor_expr(g, node); | | |
| 969 | case BinOpTypeBinAnd: | 926 | case BinOpTypeBinAnd: |
| 970 | return gen_bin_and_expr(g, node); | | |
| 971 | case BinOpTypeBitShiftLeft: | 927 | case BinOpTypeBitShiftLeft: |
| 972 | case BinOpTypeBitShiftRight: | 928 | case BinOpTypeBitShiftRight: |
| 973 | return gen_bit_shift_expr(g, node); | | |
| 974 | case BinOpTypeAdd: | 929 | case BinOpTypeAdd: |
| 975 | case BinOpTypeSub: | 930 | case BinOpTypeSub: |
| 976 | return gen_add_expr(g, node); | | |
| 977 | case BinOpTypeMult: | 931 | case BinOpTypeMult: |
| 978 | case BinOpTypeDiv: | 932 | case BinOpTypeDiv: |
| 979 | case BinOpTypeMod: | 933 | case BinOpTypeMod: |
| 980 | return gen_mult_expr(g, node); | 934 | return gen_arithmetic_bin_op_expr(g, node); |
| 981 | } | 935 | } |
| 982 | zig_unreachable(); | 936 | zig_unreachable(); |
| 983 | } | 937 | } |