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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/snapshot/code-serializer.h" | 8 #include "src/snapshot/code-serializer.h" |
9 #include "src/version.h" | 9 #include "src/version.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 for (int i = 0; i < padding; i++) { // pad global after | 748 for (int i = 0; i < padding; i++) { // pad global after |
749 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 30000)); | 749 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 30000)); |
750 } | 750 } |
751 | 751 |
752 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); | 752 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); |
753 byte code[] = {WASM_GET_GLOBAL(global)}; | 753 byte code[] = {WASM_GET_GLOBAL(global)}; |
754 f1->EmitCode(code, sizeof(code)); | 754 f1->EmitCode(code, sizeof(code)); |
755 ExportAsMain(f1); | 755 ExportAsMain(f1); |
756 TestModule(&zone, builder, expected); | 756 TestModule(&zone, builder, expected); |
757 } | 757 } |
758 | |
759 for (int padding = 0; padding < 5; padding++) { | |
760 // Test with a global index | |
761 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | |
762 for (int i = 0; i < padding; i++) { // pad global before | |
763 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 40000)); | |
764 } | |
765 | |
766 uint32_t global1 = | |
767 builder->AddGlobal(type, false, false, WasmInitExpr(expected)); | |
768 | |
769 for (int i = 0; i < padding; i++) { // pad global middle | |
770 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 50000)); | |
771 } | |
772 | |
773 uint32_t global2 = | |
774 builder->AddGlobal(type, false, false, | |
775 WasmInitExpr(WasmInitExpr::kGlobalIndex, global1)); | |
776 | |
777 for (int i = 0; i < padding; i++) { // pad global after | |
778 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 60000)); | |
779 } | |
780 | |
781 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); | |
782 byte code[] = {WASM_GET_GLOBAL(global2)}; | |
783 f1->EmitCode(code, sizeof(code)); | |
784 ExportAsMain(f1); | |
785 TestModule(&zone, builder, expected); | |
786 } | |
787 } | 758 } |
788 Cleanup(); | 759 Cleanup(); |
789 } | 760 } |
790 | 761 |
791 TEST(Run_WasmModule_Global_i32) { | 762 TEST(Run_WasmModule_Global_i32) { |
792 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, -983489); | 763 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, -983489); |
793 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, 11223344); | 764 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, 11223344); |
794 } | 765 } |
795 | 766 |
796 TEST(Run_WasmModule_Global_f32) { | 767 TEST(Run_WasmModule_Global_f32) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, | 803 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
833 data + arraysize(data), | 804 data + arraysize(data), |
834 ModuleOrigin::kWasmOrigin); | 805 ModuleOrigin::kWasmOrigin); |
835 if (thrower.error()) { | 806 if (thrower.error()) { |
836 thrower.Reify()->Print(); | 807 thrower.Reify()->Print(); |
837 CHECK(false); | 808 CHECK(false); |
838 } | 809 } |
839 } | 810 } |
840 Cleanup(); | 811 Cleanup(); |
841 } | 812 } |
OLD | NEW |