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 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 function IntTest() { | 7 function IntTest() { |
8 "use asm"; | 8 "use asm"; |
9 function sum(a, b) { | 9 function sum(a, b) { |
10 a = a|0; | 10 a = a|0; |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 662 |
663 function caller() { | 663 function caller() { |
664 var x = 1; | 664 var x = 1; |
665 return ((x > 0) ? 41 : 71)|0; | 665 return ((x > 0) ? 41 : 71)|0; |
666 } | 666 } |
667 | 667 |
668 return {caller:caller}; | 668 return {caller:caller}; |
669 } | 669 } |
670 | 670 |
671 assertEquals(41, WASM.asmCompileRun(TestConditional.toString())); | 671 assertEquals(41, WASM.asmCompileRun(TestConditional.toString())); |
| 672 |
| 673 function TestSwitch() { |
| 674 "use asm" |
| 675 |
| 676 function caller() { |
| 677 var ret = 0; |
| 678 var x = 7; |
| 679 switch (x) { |
| 680 case 1: return 0; |
| 681 case 7: { |
| 682 ret = 12; |
| 683 break; |
| 684 } |
| 685 default: return 0; |
| 686 } |
| 687 switch (x) { |
| 688 case 1: return 0; |
| 689 case 8: return 0; |
| 690 default: ret = (ret + 11)|0; |
| 691 } |
| 692 return ret|0; |
| 693 } |
| 694 |
| 695 return {caller:caller}; |
| 696 } |
| 697 |
| 698 assertEquals(23, WASM.asmCompileRun(TestSwitch.toString())); |
| 699 |
| 700 function TestSwitchFallthrough() { |
| 701 "use asm" |
| 702 |
| 703 function caller() { |
| 704 var x = 17; |
| 705 var ret = 0; |
| 706 switch (x) { |
| 707 case 17: |
| 708 case 14: ret = 39; |
| 709 case 1: ret = (ret + 3)|0; |
| 710 case 4: break; |
| 711 default: ret = (ret + 1)|0; |
| 712 } |
| 713 return ret|0; |
| 714 } |
| 715 |
| 716 return {caller:caller}; |
| 717 } |
| 718 |
| 719 assertEquals(42, WASM.asmCompileRun(TestSwitchFallthrough.toString())); |
| 720 |
| 721 function TestNestedSwitch() { |
| 722 "use asm" |
| 723 |
| 724 function caller() { |
| 725 var x = 3; |
| 726 var y = -13; |
| 727 switch (x) { |
| 728 case 1: return 0; |
| 729 case 3: { |
| 730 switch (y) { |
| 731 case 2: return 0; |
| 732 case -13: return 43; |
| 733 default: return 0; |
| 734 } |
| 735 } |
| 736 default: return 0; |
| 737 } |
| 738 return 0; |
| 739 } |
| 740 |
| 741 return {caller:caller}; |
| 742 } |
| 743 |
| 744 assertEquals(43, WASM.asmCompileRun(TestNestedSwitch.toString())); |
OLD | NEW |