OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-expression-visitor.h" | 8 #include "src/ast-expression-visitor.h" |
9 #include "src/parser.h" | 9 #include "src/parser.h" |
10 #include "src/rewriter.h" | 10 #include "src/rewriter.h" |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 509 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
510 CHECK_EXPR(Call, Bounds(Type::Undefined())) { | 510 CHECK_EXPR(Call, Bounds(Type::Undefined())) { |
511 CHECK_VAR(bar, FUNC_V_TYPE); | 511 CHECK_VAR(bar, FUNC_V_TYPE); |
512 } | 512 } |
513 } | 513 } |
514 } | 514 } |
515 CHECK_FUNC_TYPES_END | 515 CHECK_FUNC_TYPES_END |
516 } | 516 } |
517 | 517 |
518 | 518 |
| 519 TEST(EmptyBody) { |
| 520 CHECK_FUNC_TYPES_BEGIN( |
| 521 "function bar() { }\n" |
| 522 "function foo() { bar(); }") { |
| 523 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE); |
| 524 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
| 525 CHECK_EXPR(Call, Bounds(Type::Undefined())) { |
| 526 CHECK_VAR(bar, FUNC_V_TYPE); |
| 527 } |
| 528 } |
| 529 } |
| 530 CHECK_FUNC_TYPES_END |
| 531 } |
| 532 |
| 533 |
| 534 TEST(DoesNothing) { |
| 535 CHECK_FUNC_TYPES_BEGIN( |
| 536 "function bar() { var x = 1.0; }\n" |
| 537 "function foo() { bar(); }") { |
| 538 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
| 539 CHECK_EXPR(Assignment, Bounds(cache.kFloat64)) { |
| 540 CHECK_VAR(x, Bounds(cache.kFloat64)); |
| 541 CHECK_EXPR(Literal, Bounds(cache.kFloat64)); |
| 542 } |
| 543 } |
| 544 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
| 545 CHECK_EXPR(Call, Bounds(Type::Undefined())) { |
| 546 CHECK_VAR(bar, FUNC_V_TYPE); |
| 547 } |
| 548 } |
| 549 } |
| 550 CHECK_FUNC_TYPES_END |
| 551 } |
| 552 |
| 553 |
519 TEST(ReturnInt32Literal) { | 554 TEST(ReturnInt32Literal) { |
520 CHECK_FUNC_TYPES_BEGIN( | 555 CHECK_FUNC_TYPES_BEGIN( |
521 "function bar() { return 1; }\n" | 556 "function bar() { return 1; }\n" |
522 "function foo() { bar(); }") { | 557 "function foo() { bar(); }") { |
523 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 558 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
524 // return 1; | 559 // return 1; |
525 CHECK_EXPR(Literal, Bounds(cache.kInt32)); | 560 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
526 } | 561 } |
527 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 562 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
528 CHECK_EXPR(Call, Bounds(cache.kInt32)) { CHECK_VAR(bar, FUNC_I_TYPE); } | 563 CHECK_EXPR(Call, Bounds(cache.kInt32)) { CHECK_VAR(bar, FUNC_I_TYPE); } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 646 } |
612 CHECK_EXPR(Literal, Bounds(cache.kInt32)); | 647 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
613 } | 648 } |
614 } | 649 } |
615 CHECK_SKIP(); | 650 CHECK_SKIP(); |
616 } | 651 } |
617 CHECK_FUNC_TYPES_END | 652 CHECK_FUNC_TYPES_END |
618 } | 653 } |
619 | 654 |
620 | 655 |
| 656 TEST(UnsignedCompare) { |
| 657 CHECK_FUNC_TYPES_BEGIN( |
| 658 "function bar() { var x = 1; var y = 1; return ((x>>>0) < (y>>>0))|0; }\n" |
| 659 "function foo() { bar(); }") { |
| 660 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
| 661 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
| 662 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 663 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 664 } |
| 665 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
| 666 CHECK_VAR(y, Bounds(cache.kInt32)); |
| 667 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 668 } |
| 669 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { |
| 670 CHECK_EXPR(CompareOperation, Bounds(cache.kInt32)) { |
| 671 CHECK_EXPR(BinaryOperation, Bounds(cache.kUint32)) { |
| 672 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 673 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 674 } |
| 675 CHECK_EXPR(BinaryOperation, Bounds(cache.kUint32)) { |
| 676 CHECK_VAR(y, Bounds(cache.kInt32)); |
| 677 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 678 } |
| 679 } |
| 680 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 681 } |
| 682 } |
| 683 CHECK_SKIP(); |
| 684 } |
| 685 CHECK_FUNC_TYPES_END |
| 686 } |
| 687 |
| 688 |
| 689 TEST(UnsignedDivide) { |
| 690 CHECK_FUNC_TYPES_BEGIN( |
| 691 "function bar() { var x = 1; var y = 1; return ((x>>>0) / (y>>>0))|0; }\n" |
| 692 "function foo() { bar(); }") { |
| 693 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
| 694 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
| 695 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 696 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 697 } |
| 698 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
| 699 CHECK_VAR(y, Bounds(cache.kInt32)); |
| 700 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 701 } |
| 702 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { |
| 703 CHECK_EXPR(BinaryOperation, Bounds(Type::None(), Type::Any())) { |
| 704 CHECK_EXPR(BinaryOperation, Bounds(cache.kUint32)) { |
| 705 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 706 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 707 } |
| 708 CHECK_EXPR(BinaryOperation, Bounds(cache.kUint32)) { |
| 709 CHECK_VAR(y, Bounds(cache.kInt32)); |
| 710 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 711 } |
| 712 } |
| 713 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 714 } |
| 715 } |
| 716 CHECK_SKIP(); |
| 717 } |
| 718 CHECK_FUNC_TYPES_END |
| 719 } |
| 720 |
| 721 |
| 722 TEST(FroundFloat32) { |
| 723 CHECK_FUNC_TYPES_BEGIN( |
| 724 "function bar() { var x = 1; return fround(x); }\n" |
| 725 "function foo() { bar(); }") { |
| 726 CHECK_EXPR(FunctionLiteral, FUNC_F_TYPE) { |
| 727 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
| 728 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 729 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
| 730 } |
| 731 CHECK_EXPR(Call, Bounds(cache.kFloat32)) { |
| 732 CHECK_VAR(fround, FUNC_N2F_TYPE); |
| 733 CHECK_VAR(x, Bounds(cache.kInt32)); |
| 734 } |
| 735 } |
| 736 CHECK_SKIP(); |
| 737 } |
| 738 CHECK_FUNC_TYPES_END |
| 739 } |
| 740 |
| 741 |
621 TEST(Addition4) { | 742 TEST(Addition4) { |
622 CHECK_FUNC_TYPES_BEGIN( | 743 CHECK_FUNC_TYPES_BEGIN( |
623 "function bar() { var x = 1; var y = 2; return (x+y+x+y)|0; }\n" | 744 "function bar() { var x = 1; var y = 2; return (x+y+x+y)|0; }\n" |
624 "function foo() { bar(); }") { | 745 "function foo() { bar(); }") { |
625 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 746 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
626 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { | 747 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
627 CHECK_VAR(x, Bounds(cache.kInt32)); | 748 CHECK_VAR(x, Bounds(cache.kInt32)); |
628 CHECK_EXPR(Literal, Bounds(cache.kInt32)); | 749 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
629 } | 750 } |
630 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { | 751 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
(...skipping 29 matching lines...) Expand all Loading... |
660 | 781 |
661 | 782 |
662 TEST(Division4) { | 783 TEST(Division4) { |
663 CHECK_FUNC_ERROR( | 784 CHECK_FUNC_ERROR( |
664 "function bar() { var x = 1; var y = 2; return (x/y/x/y)|0; }\n" | 785 "function bar() { var x = 1; var y = 2; return (x/y/x/y)|0; }\n" |
665 "function foo() { bar(); }", | 786 "function foo() { bar(); }", |
666 "asm: line 39: too many consecutive multiplicative ops\n"); | 787 "asm: line 39: too many consecutive multiplicative ops\n"); |
667 } | 788 } |
668 | 789 |
669 | 790 |
| 791 TEST(CompareMismatchInt32Float64) { |
| 792 CHECK_FUNC_ERROR( |
| 793 "function bar() { var x = 1; var y = 2.0; return (x < y)|0; }\n" |
| 794 "function foo() { bar(); }", |
| 795 "asm: line 39: ill-typed comparison operation\n"); |
| 796 } |
| 797 |
| 798 |
| 799 TEST(CompareMismatchInt32Uint32) { |
| 800 CHECK_FUNC_ERROR( |
| 801 "function bar() { var x = 1; var y = 2; return (x < (y>>>0))|0; }\n" |
| 802 "function foo() { bar(); }", |
| 803 "asm: line 39: ill-typed comparison operation\n"); |
| 804 } |
| 805 |
| 806 |
| 807 TEST(CompareMismatchInt32Float32) { |
| 808 CHECK_FUNC_ERROR( |
| 809 "function bar() { var x = 1; var y = 2; return (x < fround(y))|0; }\n" |
| 810 "function foo() { bar(); }", |
| 811 "asm: line 39: ill-typed comparison operation\n"); |
| 812 } |
| 813 |
| 814 |
670 TEST(Load1) { | 815 TEST(Load1) { |
671 CHECK_FUNC_TYPES_BEGIN( | 816 CHECK_FUNC_TYPES_BEGIN( |
672 "function bar() { var x = 1; var y = i8[x>>0]|0; }\n" | 817 "function bar() { var x = 1; var y = i8[x>>0]|0; }\n" |
673 "function foo() { bar(); }") { | 818 "function foo() { bar(); }") { |
674 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 819 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
675 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { | 820 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
676 CHECK_VAR(x, Bounds(cache.kInt32)); | 821 CHECK_VAR(x, Bounds(cache.kInt32)); |
677 CHECK_EXPR(Literal, Bounds(cache.kInt32)); | 822 CHECK_EXPR(Literal, Bounds(cache.kInt32)); |
678 } | 823 } |
679 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { | 824 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 "return {foo: foo, bar: 1};" | 1052 "return {foo: foo, bar: 1};" |
908 "}\n"; | 1053 "}\n"; |
909 | 1054 |
910 v8::V8::Initialize(); | 1055 v8::V8::Initialize(); |
911 HandleAndZoneScope handles; | 1056 HandleAndZoneScope handles; |
912 Zone* zone = handles.main_zone(); | 1057 Zone* zone = handles.main_zone(); |
913 ZoneVector<ExpressionTypeEntry> types(zone); | 1058 ZoneVector<ExpressionTypeEntry> types(zone); |
914 CHECK_EQ("asm: line 40: non-function in function table\n", | 1059 CHECK_EQ("asm: line 40: non-function in function table\n", |
915 Validate(zone, test_function, &types)); | 1060 Validate(zone, test_function, &types)); |
916 } | 1061 } |
OLD | NEW |