| ... | @@ -276,18 +276,22 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const | ... | @@ -276,18 +276,22 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 276 | return get_c_int_type(c->codegen, CIntTypeLong); | 276 | return get_c_int_type(c->codegen, CIntTypeLong); |
| 277 | case BuiltinType::LongLong: | 277 | case BuiltinType::LongLong: |
| 278 | return get_c_int_type(c->codegen, CIntTypeLongLong); | 278 | return get_c_int_type(c->codegen, CIntTypeLongLong); |
| | 279 | case BuiltinType::UInt128: |
| | 280 | return c->codegen->builtin_types.entry_u128; |
| | 281 | case BuiltinType::Int128: |
| | 282 | return c->codegen->builtin_types.entry_i128; |
| 279 | case BuiltinType::Float: | 283 | case BuiltinType::Float: |
| 280 | return c->codegen->builtin_types.entry_f32; | 284 | return c->codegen->builtin_types.entry_f32; |
| 281 | case BuiltinType::Double: | 285 | case BuiltinType::Double: |
| 282 | return c->codegen->builtin_types.entry_f64; | 286 | return c->codegen->builtin_types.entry_f64; |
| | 287 | case BuiltinType::Float128: |
| | 288 | return c->codegen->builtin_types.entry_f128; |
| 283 | case BuiltinType::LongDouble: | 289 | case BuiltinType::LongDouble: |
| 284 | return c->codegen->builtin_types.entry_c_longdouble; | 290 | return c->codegen->builtin_types.entry_c_longdouble; |
| 285 | case BuiltinType::WChar_U: | 291 | case BuiltinType::WChar_U: |
| 286 | case BuiltinType::Char16: | 292 | case BuiltinType::Char16: |
| 287 | case BuiltinType::Char32: | 293 | case BuiltinType::Char32: |
| 288 | case BuiltinType::UInt128: | | |
| 289 | case BuiltinType::WChar_S: | 294 | case BuiltinType::WChar_S: |
| 290 | case BuiltinType::Int128: | | |
| 291 | case BuiltinType::Half: | 295 | case BuiltinType::Half: |
| 292 | case BuiltinType::NullPtr: | 296 | case BuiltinType::NullPtr: |
| 293 | case BuiltinType::ObjCId: | 297 | case BuiltinType::ObjCId: |
| ... | @@ -338,7 +342,6 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const | ... | @@ -338,7 +342,6 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 338 | case BuiltinType::OCLImage2dMSAADepthRW: | 342 | case BuiltinType::OCLImage2dMSAADepthRW: |
| 339 | case BuiltinType::OCLImage2dArrayMSAADepthRW: | 343 | case BuiltinType::OCLImage2dArrayMSAADepthRW: |
| 340 | case BuiltinType::OCLImage3dRW: | 344 | case BuiltinType::OCLImage3dRW: |
| 341 | case BuiltinType::Float128: | | |
| 342 | case BuiltinType::OCLSampler: | 345 | case BuiltinType::OCLSampler: |
| 343 | case BuiltinType::OCLEvent: | 346 | case BuiltinType::OCLEvent: |
| 344 | case BuiltinType::OCLClkEvent: | 347 | case BuiltinType::OCLClkEvent: |
| ... | @@ -606,13 +609,70 @@ static TypeTableEntry *resolve_qual_type(Context *c, QualType qt, const Decl *de | ... | @@ -606,13 +609,70 @@ static TypeTableEntry *resolve_qual_type(Context *c, QualType qt, const Decl *de |
| 606 | | 609 | |
| 607 | #include "ast_render.hpp" | 610 | #include "ast_render.hpp" |
| 608 | | 611 | |
| 609 | static AstNode * ast_trans_stmt(Context *c, Stmt *stmt); | 612 | static bool c_is_signed_integer(Context *c, QualType qt) { |
| | 613 | const Type *c_type = qt.getTypePtr(); |
| | 614 | if (c_type->getTypeClass() != Type::Builtin) |
| | 615 | return false; |
| | 616 | const BuiltinType *builtin_ty = static_cast<const BuiltinType*>(c_type); |
| | 617 | switch (builtin_ty->getKind()) { |
| | 618 | case BuiltinType::SChar: |
| | 619 | case BuiltinType::Short: |
| | 620 | case BuiltinType::Int: |
| | 621 | case BuiltinType::Long: |
| | 622 | case BuiltinType::LongLong: |
| | 623 | case BuiltinType::Int128: |
| | 624 | case BuiltinType::WChar_S: |
| | 625 | return true; |
| | 626 | default: |
| | 627 | return false; |
| | 628 | } |
| | 629 | } |
| | 630 | |
| | 631 | static bool c_is_unsigned_integer(Context *c, QualType qt) { |
| | 632 | const Type *c_type = qt.getTypePtr(); |
| | 633 | if (c_type->getTypeClass() != Type::Builtin) |
| | 634 | return false; |
| | 635 | const BuiltinType *builtin_ty = static_cast<const BuiltinType*>(c_type); |
| | 636 | switch (builtin_ty->getKind()) { |
| | 637 | case BuiltinType::Char_U: |
| | 638 | case BuiltinType::UChar: |
| | 639 | case BuiltinType::Char_S: |
| | 640 | case BuiltinType::UShort: |
| | 641 | case BuiltinType::UInt: |
| | 642 | case BuiltinType::ULong: |
| | 643 | case BuiltinType::ULongLong: |
| | 644 | case BuiltinType::UInt128: |
| | 645 | case BuiltinType::WChar_U: |
| | 646 | return true; |
| | 647 | default: |
| | 648 | return false; |
| | 649 | } |
| | 650 | } |
| 610 | | 651 | |
| 611 | static AstNode * ast_trans_expr(Context *c, Expr *expr) { | 652 | static bool c_is_float(Context *c, QualType qt) { |
| 612 | return ast_trans_stmt(c, expr); | 653 | const Type *c_type = qt.getTypePtr(); |
| | 654 | if (c_type->getTypeClass() != Type::Builtin) |
| | 655 | return false; |
| | 656 | const BuiltinType *builtin_ty = static_cast<const BuiltinType*>(c_type); |
| | 657 | switch (builtin_ty->getKind()) { |
| | 658 | case BuiltinType::Half: |
| | 659 | case BuiltinType::Float: |
| | 660 | case BuiltinType::Double: |
| | 661 | case BuiltinType::Float128: |
| | 662 | case BuiltinType::LongDouble: |
| | 663 | return true; |
| | 664 | default: |
| | 665 | return false; |
| | 666 | } |
| 613 | } | 667 | } |
| 614 | | 668 | |
| 615 | static AstNode * ast_create_node(Context *c, const SourceRange &range, NodeType id) { | 669 | static AstNode * trans_stmt(Context *c, Stmt *stmt); |
| | 670 | |
| | 671 | static AstNode * trans_expr(Context *c, Expr *expr) { |
| | 672 | return trans_stmt(c, expr); |
| | 673 | } |
| | 674 | |
| | 675 | static AstNode * trans_create_node(Context *c, Stmt *stmt, NodeType id) { |
| 616 | AstNode *node = allocate<AstNode>(1); | 676 | AstNode *node = allocate<AstNode>(1); |
| 617 | node->type = id; | 677 | node->type = id; |
| 618 | node->owner = c->import; | 678 | node->owner = c->import; |
| ... | @@ -620,22 +680,22 @@ static AstNode * ast_create_node(Context *c, const SourceRange &range, NodeType | ... | @@ -620,22 +680,22 @@ static AstNode * ast_create_node(Context *c, const SourceRange &range, NodeType |
| 620 | return node; | 680 | return node; |
| 621 | } | 681 | } |
| 622 | | 682 | |
| 623 | static AstNode * ast_trans_compound_stmt(Context *c, CompoundStmt *stmt) { | 683 | static AstNode * trans_compound_stmt(Context *c, CompoundStmt *stmt) { |
| 624 | AstNode *block_node = ast_create_node(c, stmt->getSourceRange(), NodeTypeBlock); | 684 | AstNode *block_node = trans_create_node(c, stmt, NodeTypeBlock); |
| 625 | for (CompoundStmt::body_iterator it = stmt->body_begin(), end_it = stmt->body_end(); it != end_it; ++it) { | 685 | for (CompoundStmt::body_iterator it = stmt->body_begin(), end_it = stmt->body_end(); it != end_it; ++it) { |
| 626 | AstNode *child_node = ast_trans_stmt(c, *it); | 686 | AstNode *child_node = trans_stmt(c, *it); |
| 627 | block_node->data.block.statements.append(child_node); | 687 | block_node->data.block.statements.append(child_node); |
| 628 | } | 688 | } |
| 629 | return block_node; | 689 | return block_node; |
| 630 | } | 690 | } |
| 631 | | 691 | |
| 632 | static AstNode *ast_trans_return_stmt(Context *c, ReturnStmt *stmt) { | 692 | static AstNode *trans_return_stmt(Context *c, ReturnStmt *stmt) { |
| 633 | Expr *value_expr = stmt->getRetValue(); | 693 | Expr *value_expr = stmt->getRetValue(); |
| 634 | if (value_expr == nullptr) { | 694 | if (value_expr == nullptr) { |
| 635 | zig_panic("TODO handle C return void"); | 695 | zig_panic("TODO handle C return void"); |
| 636 | } else { | 696 | } else { |
| 637 | AstNode *return_node = ast_create_node(c, stmt->getSourceRange(), NodeTypeReturnExpr); | 697 | AstNode *return_node = trans_create_node(c, stmt, NodeTypeReturnExpr); |
| 638 | return_node->data.return_expr.expr = ast_trans_expr(c, value_expr); | 698 | return_node->data.return_expr.expr = trans_expr(c, value_expr); |
| 639 | return return_node; | 699 | return return_node; |
| 640 | } | 700 | } |
| 641 | } | 701 | } |
| ... | @@ -656,8 +716,9 @@ static void aps_int_to_bigint(Context *c, const llvm::APSInt &aps_int, BigInt *b | ... | @@ -656,8 +716,9 @@ static void aps_int_to_bigint(Context *c, const llvm::APSInt &aps_int, BigInt *b |
| 656 | } | 716 | } |
| 657 | } | 717 | } |
| 658 | } | 718 | } |
| 659 | static AstNode * ast_trans_integer_literal(Context *c, IntegerLiteral *stmt) { | 719 | |
| 660 | AstNode *node = ast_create_node(c, stmt->getSourceRange(), NodeTypeIntLiteral); | 720 | static AstNode * trans_integer_literal(Context *c, IntegerLiteral *stmt) { |
| | 721 | AstNode *node = trans_create_node(c, stmt, NodeTypeIntLiteral); |
| 661 | llvm::APSInt result; | 722 | llvm::APSInt result; |
| 662 | if (!stmt->EvaluateAsInt(result, *c->ctx)) { | 723 | if (!stmt->EvaluateAsInt(result, *c->ctx)) { |
| 663 | fprintf(stderr, "TODO unable to convert integer literal to zig\n"); | 724 | fprintf(stderr, "TODO unable to convert integer literal to zig\n"); |
| ... | @@ -667,15 +728,305 @@ static AstNode * ast_trans_integer_literal(Context *c, IntegerLiteral *stmt) { | ... | @@ -667,15 +728,305 @@ static AstNode * ast_trans_integer_literal(Context *c, IntegerLiteral *stmt) { |
| 667 | return node; | 728 | return node; |
| 668 | } | 729 | } |
| 669 | | 730 | |
| 670 | static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | 731 | static AstNode * trans_conditional_operator(Context *c, ConditionalOperator *stmt) { |
| | 732 | AstNode *node = trans_create_node(c, stmt, NodeTypeIfBoolExpr); |
| | 733 | |
| | 734 | Expr *cond_expr = stmt->getCond(); |
| | 735 | Expr *true_expr = stmt->getTrueExpr(); |
| | 736 | Expr *false_expr = stmt->getFalseExpr(); |
| | 737 | |
| | 738 | node->data.if_bool_expr.condition = trans_expr(c, cond_expr); |
| | 739 | node->data.if_bool_expr.then_block = trans_expr(c, true_expr); |
| | 740 | node->data.if_bool_expr.else_node = trans_expr(c, false_expr); |
| | 741 | |
| | 742 | return node; |
| | 743 | } |
| | 744 | |
| | 745 | static AstNode * trans_binary_operator(Context *c, BinaryOperator *stmt) { |
| | 746 | switch (stmt->getOpcode()) { |
| | 747 | case BO_PtrMemD: |
| | 748 | zig_panic("TODO handle more C binary operators: BO_PtrMemD"); |
| | 749 | case BO_PtrMemI: |
| | 750 | zig_panic("TODO handle more C binary operators: BO_PtrMemI"); |
| | 751 | case BO_Mul: |
| | 752 | zig_panic("TODO handle more C binary operators: BO_Mul"); |
| | 753 | case BO_Div: |
| | 754 | zig_panic("TODO handle more C binary operators: BO_Div"); |
| | 755 | case BO_Rem: |
| | 756 | zig_panic("TODO handle more C binary operators: BO_Rem"); |
| | 757 | case BO_Add: |
| | 758 | zig_panic("TODO handle more C binary operators: BO_Add"); |
| | 759 | case BO_Sub: |
| | 760 | zig_panic("TODO handle more C binary operators: BO_Sub"); |
| | 761 | case BO_Shl: |
| | 762 | zig_panic("TODO handle more C binary operators: BO_Shl"); |
| | 763 | case BO_Shr: |
| | 764 | zig_panic("TODO handle more C binary operators: BO_Shr"); |
| | 765 | case BO_LT: |
| | 766 | { |
| | 767 | AstNode *node = trans_create_node(c, stmt, NodeTypeBinOpExpr); |
| | 768 | node->data.bin_op_expr.bin_op = BinOpTypeCmpLessThan; |
| | 769 | node->data.bin_op_expr.op1 = trans_expr(c, stmt->getLHS()); |
| | 770 | node->data.bin_op_expr.op2 = trans_expr(c, stmt->getRHS()); |
| | 771 | return node; |
| | 772 | } |
| | 773 | case BO_GT: |
| | 774 | zig_panic("TODO handle more C binary operators: BO_GT"); |
| | 775 | case BO_LE: |
| | 776 | zig_panic("TODO handle more C binary operators: BO_LE"); |
| | 777 | case BO_GE: |
| | 778 | zig_panic("TODO handle more C binary operators: BO_GE"); |
| | 779 | case BO_EQ: |
| | 780 | zig_panic("TODO handle more C binary operators: BO_EQ"); |
| | 781 | case BO_NE: |
| | 782 | zig_panic("TODO handle more C binary operators: BO_NE"); |
| | 783 | case BO_And: |
| | 784 | zig_panic("TODO handle more C binary operators: BO_And"); |
| | 785 | case BO_Xor: |
| | 786 | zig_panic("TODO handle more C binary operators: BO_Xor"); |
| | 787 | case BO_Or: |
| | 788 | zig_panic("TODO handle more C binary operators: BO_Or"); |
| | 789 | case BO_LAnd: |
| | 790 | zig_panic("TODO handle more C binary operators: BO_LAnd"); |
| | 791 | case BO_LOr: |
| | 792 | zig_panic("TODO handle more C binary operators: BO_LOr"); |
| | 793 | case BO_Assign: |
| | 794 | zig_panic("TODO handle more C binary operators: BO_Assign"); |
| | 795 | case BO_MulAssign: |
| | 796 | zig_panic("TODO handle more C binary operators: BO_MulAssign"); |
| | 797 | case BO_DivAssign: |
| | 798 | zig_panic("TODO handle more C binary operators: BO_DivAssign"); |
| | 799 | case BO_RemAssign: |
| | 800 | zig_panic("TODO handle more C binary operators: BO_RemAssign"); |
| | 801 | case BO_AddAssign: |
| | 802 | zig_panic("TODO handle more C binary operators: BO_AddAssign"); |
| | 803 | case BO_SubAssign: |
| | 804 | zig_panic("TODO handle more C binary operators: BO_SubAssign"); |
| | 805 | case BO_ShlAssign: |
| | 806 | zig_panic("TODO handle more C binary operators: BO_ShlAssign"); |
| | 807 | case BO_ShrAssign: |
| | 808 | zig_panic("TODO handle more C binary operators: BO_ShrAssign"); |
| | 809 | case BO_AndAssign: |
| | 810 | zig_panic("TODO handle more C binary operators: BO_AndAssign"); |
| | 811 | case BO_XorAssign: |
| | 812 | zig_panic("TODO handle more C binary operators: BO_XorAssign"); |
| | 813 | case BO_OrAssign: |
| | 814 | zig_panic("TODO handle more C binary operators: BO_OrAssign"); |
| | 815 | case BO_Comma: |
| | 816 | zig_panic("TODO handle more C binary operators: BO_Comma"); |
| | 817 | } |
| | 818 | |
| | 819 | zig_unreachable(); |
| | 820 | } |
| | 821 | |
| | 822 | static AstNode * trans_implicit_cast_expr(Context *c, ImplicitCastExpr *stmt) { |
| | 823 | switch (stmt->getCastKind()) { |
| | 824 | case CK_LValueToRValue: |
| | 825 | return trans_expr(c, stmt->getSubExpr()); |
| | 826 | case CK_Dependent: |
| | 827 | zig_panic("TODO handle C translation cast CK_Dependent"); |
| | 828 | case CK_BitCast: |
| | 829 | zig_panic("TODO handle C translation cast CK_BitCast"); |
| | 830 | case CK_LValueBitCast: |
| | 831 | zig_panic("TODO handle C translation cast CK_LValueBitCast"); |
| | 832 | case CK_NoOp: |
| | 833 | zig_panic("TODO handle C translation cast CK_NoOp"); |
| | 834 | case CK_BaseToDerived: |
| | 835 | zig_panic("TODO handle C translation cast CK_BaseToDerived"); |
| | 836 | case CK_DerivedToBase: |
| | 837 | zig_panic("TODO handle C translation cast CK_DerivedToBase"); |
| | 838 | case CK_UncheckedDerivedToBase: |
| | 839 | zig_panic("TODO handle C translation cast CK_UncheckedDerivedToBase"); |
| | 840 | case CK_Dynamic: |
| | 841 | zig_panic("TODO handle C translation cast CK_Dynamic"); |
| | 842 | case CK_ToUnion: |
| | 843 | zig_panic("TODO handle C translation cast CK_ToUnion"); |
| | 844 | case CK_ArrayToPointerDecay: |
| | 845 | zig_panic("TODO handle C translation cast CK_ArrayToPointerDecay"); |
| | 846 | case CK_FunctionToPointerDecay: |
| | 847 | zig_panic("TODO handle C translation cast CK_FunctionToPointerDecay"); |
| | 848 | case CK_NullToPointer: |
| | 849 | zig_panic("TODO handle C translation cast CK_NullToPointer"); |
| | 850 | case CK_NullToMemberPointer: |
| | 851 | zig_panic("TODO handle C translation cast CK_NullToMemberPointer"); |
| | 852 | case CK_BaseToDerivedMemberPointer: |
| | 853 | zig_panic("TODO handle C translation cast CK_BaseToDerivedMemberPointer"); |
| | 854 | case CK_DerivedToBaseMemberPointer: |
| | 855 | zig_panic("TODO handle C translation cast CK_DerivedToBaseMemberPointer"); |
| | 856 | case CK_MemberPointerToBoolean: |
| | 857 | zig_panic("TODO handle C translation cast CK_MemberPointerToBoolean"); |
| | 858 | case CK_ReinterpretMemberPointer: |
| | 859 | zig_panic("TODO handle C translation cast CK_ReinterpretMemberPointer"); |
| | 860 | case CK_UserDefinedConversion: |
| | 861 | zig_panic("TODO handle C translation cast CK_UserDefinedConversion"); |
| | 862 | case CK_ConstructorConversion: |
| | 863 | zig_panic("TODO handle C translation cast CK_ConstructorConversion"); |
| | 864 | case CK_IntegralToPointer: |
| | 865 | zig_panic("TODO handle C translation cast CK_IntegralToPointer"); |
| | 866 | case CK_PointerToIntegral: |
| | 867 | zig_panic("TODO handle C translation cast CK_PointerToIntegral"); |
| | 868 | case CK_PointerToBoolean: |
| | 869 | zig_panic("TODO handle C translation cast CK_PointerToBoolean"); |
| | 870 | case CK_ToVoid: |
| | 871 | zig_panic("TODO handle C translation cast CK_ToVoid"); |
| | 872 | case CK_VectorSplat: |
| | 873 | zig_panic("TODO handle C translation cast CK_VectorSplat"); |
| | 874 | case CK_IntegralCast: |
| | 875 | zig_panic("TODO handle C translation cast CK_IntegralCast"); |
| | 876 | case CK_IntegralToBoolean: |
| | 877 | zig_panic("TODO handle C translation cast CK_IntegralToBoolean"); |
| | 878 | case CK_IntegralToFloating: |
| | 879 | zig_panic("TODO handle C translation cast CK_IntegralToFloating"); |
| | 880 | case CK_FloatingToIntegral: |
| | 881 | zig_panic("TODO handle C translation cast CK_FloatingToIntegral"); |
| | 882 | case CK_FloatingToBoolean: |
| | 883 | zig_panic("TODO handle C translation cast CK_FloatingToBoolean"); |
| | 884 | case CK_BooleanToSignedIntegral: |
| | 885 | zig_panic("TODO handle C translation cast CK_BooleanToSignedIntegral"); |
| | 886 | case CK_FloatingCast: |
| | 887 | zig_panic("TODO handle C translation cast CK_FloatingCast"); |
| | 888 | case CK_CPointerToObjCPointerCast: |
| | 889 | zig_panic("TODO handle C translation cast CK_CPointerToObjCPointerCast"); |
| | 890 | case CK_BlockPointerToObjCPointerCast: |
| | 891 | zig_panic("TODO handle C translation cast CK_BlockPointerToObjCPointerCast"); |
| | 892 | case CK_AnyPointerToBlockPointerCast: |
| | 893 | zig_panic("TODO handle C translation cast CK_AnyPointerToBlockPointerCast"); |
| | 894 | case CK_ObjCObjectLValueCast: |
| | 895 | zig_panic("TODO handle C translation cast CK_ObjCObjectLValueCast"); |
| | 896 | case CK_FloatingRealToComplex: |
| | 897 | zig_panic("TODO handle C translation cast CK_FloatingRealToComplex"); |
| | 898 | case CK_FloatingComplexToReal: |
| | 899 | zig_panic("TODO handle C translation cast CK_FloatingComplexToReal"); |
| | 900 | case CK_FloatingComplexToBoolean: |
| | 901 | zig_panic("TODO handle C translation cast CK_FloatingComplexToBoolean"); |
| | 902 | case CK_FloatingComplexCast: |
| | 903 | zig_panic("TODO handle C translation cast CK_FloatingComplexCast"); |
| | 904 | case CK_FloatingComplexToIntegralComplex: |
| | 905 | zig_panic("TODO handle C translation cast CK_FloatingComplexToIntegralComplex"); |
| | 906 | case CK_IntegralRealToComplex: |
| | 907 | zig_panic("TODO handle C translation cast CK_IntegralRealToComplex"); |
| | 908 | case CK_IntegralComplexToReal: |
| | 909 | zig_panic("TODO handle C translation cast CK_IntegralComplexToReal"); |
| | 910 | case CK_IntegralComplexToBoolean: |
| | 911 | zig_panic("TODO handle C translation cast CK_IntegralComplexToBoolean"); |
| | 912 | case CK_IntegralComplexCast: |
| | 913 | zig_panic("TODO handle C translation cast CK_IntegralComplexCast"); |
| | 914 | case CK_IntegralComplexToFloatingComplex: |
| | 915 | zig_panic("TODO handle C translation cast CK_IntegralComplexToFloatingComplex"); |
| | 916 | case CK_ARCProduceObject: |
| | 917 | zig_panic("TODO handle C translation cast CK_ARCProduceObject"); |
| | 918 | case CK_ARCConsumeObject: |
| | 919 | zig_panic("TODO handle C translation cast CK_ARCConsumeObject"); |
| | 920 | case CK_ARCReclaimReturnedObject: |
| | 921 | zig_panic("TODO handle C translation cast CK_ARCReclaimReturnedObject"); |
| | 922 | case CK_ARCExtendBlockObject: |
| | 923 | zig_panic("TODO handle C translation cast CK_ARCExtendBlockObject"); |
| | 924 | case CK_AtomicToNonAtomic: |
| | 925 | zig_panic("TODO handle C translation cast CK_AtomicToNonAtomic"); |
| | 926 | case CK_NonAtomicToAtomic: |
| | 927 | zig_panic("TODO handle C translation cast CK_NonAtomicToAtomic"); |
| | 928 | case CK_CopyAndAutoreleaseBlockObject: |
| | 929 | zig_panic("TODO handle C translation cast CK_CopyAndAutoreleaseBlockObject"); |
| | 930 | case CK_BuiltinFnToFnPtr: |
| | 931 | zig_panic("TODO handle C translation cast CK_BuiltinFnToFnPtr"); |
| | 932 | case CK_ZeroToOCLEvent: |
| | 933 | zig_panic("TODO handle C translation cast CK_ZeroToOCLEvent"); |
| | 934 | case CK_ZeroToOCLQueue: |
| | 935 | zig_panic("TODO handle C translation cast CK_ZeroToOCLQueue"); |
| | 936 | case CK_AddressSpaceConversion: |
| | 937 | zig_panic("TODO handle C translation cast CK_AddressSpaceConversion"); |
| | 938 | case CK_IntToOCLSampler: |
| | 939 | zig_panic("TODO handle C translation cast CK_IntToOCLSampler"); |
| | 940 | } |
| | 941 | zig_unreachable(); |
| | 942 | } |
| | 943 | |
| | 944 | static AstNode * trans_decl_ref_expr(Context *c, DeclRefExpr *stmt) { |
| | 945 | ValueDecl *value_decl = stmt->getDecl(); |
| | 946 | const char *name = decl_name(value_decl); |
| | 947 | |
| | 948 | AstNode *node = trans_create_node(c, stmt, NodeTypeSymbol); |
| | 949 | node->data.symbol_expr.symbol = buf_create_from_str(name); |
| | 950 | return node; |
| | 951 | } |
| | 952 | |
| | 953 | static AstNode * trans_create_num_lit_node_unsigned(Context *c, Stmt *stmt, uint64_t x) { |
| | 954 | AstNode *node = trans_create_node(c, stmt, NodeTypeIntLiteral); |
| | 955 | node->data.int_literal.bigint = allocate<BigInt>(1); |
| | 956 | bigint_init_unsigned(node->data.int_literal.bigint, x); |
| | 957 | return node; |
| | 958 | } |
| | 959 | |
| | 960 | static AstNode * trans_unary_operator(Context *c, UnaryOperator *stmt) { |
| | 961 | switch (stmt->getOpcode()) { |
| | 962 | case UO_PostInc: |
| | 963 | zig_panic("TODO handle C translation UO_PostInc"); |
| | 964 | case UO_PostDec: |
| | 965 | zig_panic("TODO handle C translation UO_PostDec"); |
| | 966 | case UO_PreInc: |
| | 967 | zig_panic("TODO handle C translation UO_PreInc"); |
| | 968 | case UO_PreDec: |
| | 969 | zig_panic("TODO handle C translation UO_PreDec"); |
| | 970 | case UO_AddrOf: |
| | 971 | zig_panic("TODO handle C translation UO_AddrOf"); |
| | 972 | case UO_Deref: |
| | 973 | zig_panic("TODO handle C translation UO_Deref"); |
| | 974 | case UO_Plus: |
| | 975 | zig_panic("TODO handle C translation UO_Plus"); |
| | 976 | case UO_Minus: |
| | 977 | { |
| | 978 | Expr *op_expr = stmt->getSubExpr(); |
| | 979 | if (c_is_signed_integer(c, op_expr->getType()) || c_is_float(c, op_expr->getType())) { |
| | 980 | AstNode *node = trans_create_node(c, stmt, NodeTypePrefixOpExpr); |
| | 981 | node->data.prefix_op_expr.prefix_op = PrefixOpNegation; |
| | 982 | node->data.prefix_op_expr.primary_expr = trans_expr(c, op_expr); |
| | 983 | return node; |
| | 984 | } else if (c_is_unsigned_integer(c, op_expr->getType())) { |
| | 985 | // we gotta emit 0 -% x |
| | 986 | AstNode *node = trans_create_node(c, stmt, NodeTypeBinOpExpr); |
| | 987 | node->data.bin_op_expr.op1 = trans_create_num_lit_node_unsigned(c, stmt, 0); |
| | 988 | node->data.bin_op_expr.op2 = trans_expr(c, op_expr); |
| | 989 | node->data.bin_op_expr.bin_op = BinOpTypeSubWrap; |
| | 990 | return node; |
| | 991 | } else { |
| | 992 | zig_panic("TODO translate C negation with non float non integer"); |
| | 993 | } |
| | 994 | } |
| | 995 | case UO_Not: |
| | 996 | zig_panic("TODO handle C translation UO_Not"); |
| | 997 | case UO_LNot: |
| | 998 | zig_panic("TODO handle C translation UO_LNot"); |
| | 999 | case UO_Real: |
| | 1000 | zig_panic("TODO handle C translation UO_Real"); |
| | 1001 | case UO_Imag: |
| | 1002 | zig_panic("TODO handle C translation UO_Imag"); |
| | 1003 | case UO_Extension: |
| | 1004 | zig_panic("TODO handle C translation UO_Extension"); |
| | 1005 | case UO_Coawait: |
| | 1006 | zig_panic("TODO handle C translation UO_Coawait"); |
| | 1007 | } |
| | 1008 | zig_unreachable(); |
| | 1009 | } |
| | 1010 | |
| | 1011 | static AstNode *trans_stmt(Context *c, Stmt *stmt) { |
| 671 | Stmt::StmtClass sc = stmt->getStmtClass(); | 1012 | Stmt::StmtClass sc = stmt->getStmtClass(); |
| 672 | switch (sc) { | 1013 | switch (sc) { |
| 673 | case Stmt::ReturnStmtClass: | 1014 | case Stmt::ReturnStmtClass: |
| 674 | return ast_trans_return_stmt(c, (ReturnStmt *)stmt); | 1015 | return trans_return_stmt(c, (ReturnStmt *)stmt); |
| 675 | case Stmt::CompoundStmtClass: | 1016 | case Stmt::CompoundStmtClass: |
| 676 | return ast_trans_compound_stmt(c, (CompoundStmt *)stmt); | 1017 | return trans_compound_stmt(c, (CompoundStmt *)stmt); |
| 677 | case Stmt::IntegerLiteralClass: | 1018 | case Stmt::IntegerLiteralClass: |
| 678 | return ast_trans_integer_literal(c, (IntegerLiteral *)stmt); | 1019 | return trans_integer_literal(c, (IntegerLiteral *)stmt); |
| | 1020 | case Stmt::ConditionalOperatorClass: |
| | 1021 | return trans_conditional_operator(c, (ConditionalOperator *)stmt); |
| | 1022 | case Stmt::BinaryOperatorClass: |
| | 1023 | return trans_binary_operator(c, (BinaryOperator *)stmt); |
| | 1024 | case Stmt::ImplicitCastExprClass: |
| | 1025 | return trans_implicit_cast_expr(c, (ImplicitCastExpr *)stmt); |
| | 1026 | case Stmt::DeclRefExprClass: |
| | 1027 | return trans_decl_ref_expr(c, (DeclRefExpr *)stmt); |
| | 1028 | case Stmt::UnaryOperatorClass: |
| | 1029 | return trans_unary_operator(c, (UnaryOperator *)stmt); |
| 679 | case Stmt::CaseStmtClass: | 1030 | case Stmt::CaseStmtClass: |
| 680 | zig_panic("TODO handle C CaseStmtClass"); | 1031 | zig_panic("TODO handle C CaseStmtClass"); |
| 681 | case Stmt::DefaultStmtClass: | 1032 | case Stmt::DefaultStmtClass: |
| ... | @@ -714,8 +1065,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | ... | @@ -714,8 +1065,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { |
| 714 | zig_panic("TODO handle C DoStmtClass"); | 1065 | zig_panic("TODO handle C DoStmtClass"); |
| 715 | case Stmt::BinaryConditionalOperatorClass: | 1066 | case Stmt::BinaryConditionalOperatorClass: |
| 716 | zig_panic("TODO handle C BinaryConditionalOperatorClass"); | 1067 | zig_panic("TODO handle C BinaryConditionalOperatorClass"); |
| 717 | case Stmt::ConditionalOperatorClass: | | |
| 718 | zig_panic("TODO handle C ConditionalOperatorClass"); | | |
| 719 | case Stmt::AddrLabelExprClass: | 1068 | case Stmt::AddrLabelExprClass: |
| 720 | zig_panic("TODO handle C AddrLabelExprClass"); | 1069 | zig_panic("TODO handle C AddrLabelExprClass"); |
| 721 | case Stmt::ArrayInitIndexExprClass: | 1070 | case Stmt::ArrayInitIndexExprClass: |
| ... | @@ -730,8 +1079,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | ... | @@ -730,8 +1079,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { |
| 730 | zig_panic("TODO handle C AsTypeExprClass"); | 1079 | zig_panic("TODO handle C AsTypeExprClass"); |
| 731 | case Stmt::AtomicExprClass: | 1080 | case Stmt::AtomicExprClass: |
| 732 | zig_panic("TODO handle C AtomicExprClass"); | 1081 | zig_panic("TODO handle C AtomicExprClass"); |
| 733 | case Stmt::BinaryOperatorClass: | | |
| 734 | zig_panic("TODO handle C BinaryOperatorClass"); | | |
| 735 | case Stmt::CompoundAssignOperatorClass: | 1082 | case Stmt::CompoundAssignOperatorClass: |
| 736 | zig_panic("TODO handle C CompoundAssignOperatorClass"); | 1083 | zig_panic("TODO handle C CompoundAssignOperatorClass"); |
| 737 | case Stmt::BlockExprClass: | 1084 | case Stmt::BlockExprClass: |
| ... | @@ -802,8 +1149,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | ... | @@ -802,8 +1149,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { |
| 802 | zig_panic("TODO handle C CXXStaticCastExprClass"); | 1149 | zig_panic("TODO handle C CXXStaticCastExprClass"); |
| 803 | case Stmt::ObjCBridgedCastExprClass: | 1150 | case Stmt::ObjCBridgedCastExprClass: |
| 804 | zig_panic("TODO handle C ObjCBridgedCastExprClass"); | 1151 | zig_panic("TODO handle C ObjCBridgedCastExprClass"); |
| 805 | case Stmt::ImplicitCastExprClass: | | |
| 806 | zig_panic("TODO handle C ImplicitCastExprClass"); | | |
| 807 | case Stmt::CharacterLiteralClass: | 1152 | case Stmt::CharacterLiteralClass: |
| 808 | zig_panic("TODO handle C CharacterLiteralClass"); | 1153 | zig_panic("TODO handle C CharacterLiteralClass"); |
| 809 | case Stmt::ChooseExprClass: | 1154 | case Stmt::ChooseExprClass: |
| ... | @@ -816,8 +1161,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | ... | @@ -816,8 +1161,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { |
| 816 | zig_panic("TODO handle C CoawaitExprClass"); | 1161 | zig_panic("TODO handle C CoawaitExprClass"); |
| 817 | case Stmt::CoyieldExprClass: | 1162 | case Stmt::CoyieldExprClass: |
| 818 | zig_panic("TODO handle C CoyieldExprClass"); | 1163 | zig_panic("TODO handle C CoyieldExprClass"); |
| 819 | case Stmt::DeclRefExprClass: | | |
| 820 | zig_panic("TODO handle C DeclRefExprClass"); | | |
| 821 | case Stmt::DependentCoawaitExprClass: | 1164 | case Stmt::DependentCoawaitExprClass: |
| 822 | zig_panic("TODO handle C DependentCoawaitExprClass"); | 1165 | zig_panic("TODO handle C DependentCoawaitExprClass"); |
| 823 | case Stmt::DependentScopeDeclRefExprClass: | 1166 | case Stmt::DependentScopeDeclRefExprClass: |
| ... | @@ -926,8 +1269,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { | ... | @@ -926,8 +1269,6 @@ static AstNode *ast_trans_stmt(Context *c, Stmt *stmt) { |
| 926 | zig_panic("TODO handle C TypoExprClass"); | 1269 | zig_panic("TODO handle C TypoExprClass"); |
| 927 | case Stmt::UnaryExprOrTypeTraitExprClass: | 1270 | case Stmt::UnaryExprOrTypeTraitExprClass: |
| 928 | zig_panic("TODO handle C UnaryExprOrTypeTraitExprClass"); | 1271 | zig_panic("TODO handle C UnaryExprOrTypeTraitExprClass"); |
| 929 | case Stmt::UnaryOperatorClass: | | |
| 930 | zig_panic("TODO handle C UnaryOperatorClass"); | | |
| 931 | case Stmt::VAArgExprClass: | 1272 | case Stmt::VAArgExprClass: |
| 932 | zig_panic("TODO handle C VAArgExprClass"); | 1273 | zig_panic("TODO handle C VAArgExprClass"); |
| 933 | case Stmt::ForStmtClass: | 1274 | case Stmt::ForStmtClass: |
| ... | @@ -1070,7 +1411,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) { | ... | @@ -1070,7 +1411,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) { |
| 1070 | if (fn_decl->hasBody()) { | 1411 | if (fn_decl->hasBody()) { |
| 1071 | fprintf(stderr, "fn %s\n", buf_ptr(fn_name)); | 1412 | fprintf(stderr, "fn %s\n", buf_ptr(fn_name)); |
| 1072 | Stmt *body = fn_decl->getBody(); | 1413 | Stmt *body = fn_decl->getBody(); |
| 1073 | AstNode *body_node = ast_trans_stmt(c, body); | 1414 | AstNode *body_node = trans_stmt(c, body); |
| 1074 | ast_render(c->codegen, stderr, body_node, 4); | 1415 | ast_render(c->codegen, stderr, body_node, 4); |
| 1075 | fprintf(stderr, "\n"); | 1416 | fprintf(stderr, "\n"); |
| 1076 | } | 1417 | } |