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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 TEST(Run_WasmModule_CheckMemoryIsZero) { | 132 TEST(Run_WasmModule_CheckMemoryIsZero) { |
133 { | 133 { |
134 static const int kCheckSize = 16 * 1024; | 134 static const int kCheckSize = 16 * 1024; |
135 v8::internal::AccountingAllocator allocator; | 135 v8::internal::AccountingAllocator allocator; |
136 Zone zone(&allocator, ZONE_NAME); | 136 Zone zone(&allocator, ZONE_NAME); |
137 TestSignatures sigs; | 137 TestSignatures sigs; |
138 | 138 |
139 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 139 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
140 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 140 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
141 | 141 |
142 uint16_t localIndex = f->AddLocal(kAstI32); | 142 uint16_t localIndex = f->AddLocal(kWasmI32); |
143 ExportAsMain(f); | 143 ExportAsMain(f); |
144 byte code[] = {WASM_BLOCK_I( | 144 byte code[] = {WASM_BLOCK_I( |
145 WASM_WHILE( | 145 WASM_WHILE( |
146 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), | 146 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), |
147 WASM_IF_ELSE( | 147 WASM_IF_ELSE( |
148 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), | 148 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), |
149 WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), | 149 WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), |
150 WASM_I8(11))}; | 150 WASM_I8(11))}; |
151 f->EmitCode(code, sizeof(code)); | 151 f->EmitCode(code, sizeof(code)); |
152 TestModule(&zone, builder, 11); | 152 TestModule(&zone, builder, 11); |
153 } | 153 } |
154 Cleanup(); | 154 Cleanup(); |
155 } | 155 } |
156 | 156 |
157 TEST(Run_WasmModule_CallMain_recursive) { | 157 TEST(Run_WasmModule_CallMain_recursive) { |
158 { | 158 { |
159 v8::internal::AccountingAllocator allocator; | 159 v8::internal::AccountingAllocator allocator; |
160 Zone zone(&allocator, ZONE_NAME); | 160 Zone zone(&allocator, ZONE_NAME); |
161 TestSignatures sigs; | 161 TestSignatures sigs; |
162 | 162 |
163 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 163 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
164 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 164 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
165 | 165 |
166 uint16_t localIndex = f->AddLocal(kAstI32); | 166 uint16_t localIndex = f->AddLocal(kWasmI32); |
167 ExportAsMain(f); | 167 ExportAsMain(f); |
168 byte code[] = { | 168 byte code[] = { |
169 WASM_SET_LOCAL(localIndex, | 169 WASM_SET_LOCAL(localIndex, |
170 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 170 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
171 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), | 171 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), |
172 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 172 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
173 WASM_INC_LOCAL(localIndex)), | 173 WASM_INC_LOCAL(localIndex)), |
174 WASM_CALL_FUNCTION0(0)), | 174 WASM_CALL_FUNCTION0(0)), |
175 WASM_I8(55))}; | 175 WASM_I8(55))}; |
176 f->EmitCode(code, sizeof(code)); | 176 f->EmitCode(code, sizeof(code)); |
177 TestModule(&zone, builder, 55); | 177 TestModule(&zone, builder, 55); |
178 } | 178 } |
179 Cleanup(); | 179 Cleanup(); |
180 } | 180 } |
181 | 181 |
182 TEST(Run_WasmModule_Global) { | 182 TEST(Run_WasmModule_Global) { |
183 { | 183 { |
184 v8::internal::AccountingAllocator allocator; | 184 v8::internal::AccountingAllocator allocator; |
185 Zone zone(&allocator, ZONE_NAME); | 185 Zone zone(&allocator, ZONE_NAME); |
186 TestSignatures sigs; | 186 TestSignatures sigs; |
187 | 187 |
188 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 188 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
189 uint32_t global1 = builder->AddGlobal(kAstI32, 0); | 189 uint32_t global1 = builder->AddGlobal(kWasmI32, 0); |
190 uint32_t global2 = builder->AddGlobal(kAstI32, 0); | 190 uint32_t global2 = builder->AddGlobal(kWasmI32, 0); |
191 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); | 191 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
192 byte code1[] = { | 192 byte code1[] = { |
193 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; | 193 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
194 f1->EmitCode(code1, sizeof(code1)); | 194 f1->EmitCode(code1, sizeof(code1)); |
195 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); | 195 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
196 ExportAsMain(f2); | 196 ExportAsMain(f2); |
197 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), | 197 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), |
198 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), | 198 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), |
199 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; | 199 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; |
200 f2->EmitCode(code2, sizeof(code2)); | 200 f2->EmitCode(code2, sizeof(code2)); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 709 } |
710 | 710 |
711 TEST(Run_WasmModule_Global_init) { | 711 TEST(Run_WasmModule_Global_init) { |
712 { | 712 { |
713 v8::internal::AccountingAllocator allocator; | 713 v8::internal::AccountingAllocator allocator; |
714 Zone zone(&allocator, ZONE_NAME); | 714 Zone zone(&allocator, ZONE_NAME); |
715 TestSignatures sigs; | 715 TestSignatures sigs; |
716 | 716 |
717 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 717 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
718 uint32_t global1 = | 718 uint32_t global1 = |
719 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(777777)); | 719 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(777777)); |
720 uint32_t global2 = | 720 uint32_t global2 = |
721 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(222222)); | 721 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(222222)); |
722 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); | 722 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
723 byte code[] = { | 723 byte code[] = { |
724 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; | 724 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
725 f1->EmitCode(code, sizeof(code)); | 725 f1->EmitCode(code, sizeof(code)); |
726 ExportAsMain(f1); | 726 ExportAsMain(f1); |
727 TestModule(&zone, builder, 999999); | 727 TestModule(&zone, builder, 999999); |
728 } | 728 } |
729 Cleanup(); | 729 Cleanup(); |
730 } | 730 } |
731 | 731 |
732 template <typename CType> | 732 template <typename CType> |
733 static void RunWasmModuleGlobalInitTest(LocalType type, CType expected) { | 733 static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) { |
734 { | 734 { |
735 v8::internal::AccountingAllocator allocator; | 735 v8::internal::AccountingAllocator allocator; |
736 Zone zone(&allocator, ZONE_NAME); | 736 Zone zone(&allocator, ZONE_NAME); |
737 TestSignatures sigs; | 737 TestSignatures sigs; |
738 | 738 |
739 LocalType types[] = {type}; | 739 ValueType types[] = {type}; |
740 FunctionSig sig(1, 0, types); | 740 FunctionSig sig(1, 0, types); |
741 | 741 |
742 for (int padding = 0; padding < 5; padding++) { | 742 for (int padding = 0; padding < 5; padding++) { |
743 // Test with a simple initializer | 743 // Test with a simple initializer |
744 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 744 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
745 | 745 |
746 for (int i = 0; i < padding; i++) { // pad global before | 746 for (int i = 0; i < padding; i++) { // pad global before |
747 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 20000)); | 747 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 20000)); |
748 } | 748 } |
749 uint32_t global = | 749 uint32_t global = |
750 builder->AddGlobal(type, false, false, WasmInitExpr(expected)); | 750 builder->AddGlobal(type, false, false, WasmInitExpr(expected)); |
751 for (int i = 0; i < padding; i++) { // pad global after | 751 for (int i = 0; i < padding; i++) { // pad global after |
752 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 30000)); | 752 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 30000)); |
753 } | 753 } |
754 | 754 |
755 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); | 755 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); |
756 byte code[] = {WASM_GET_GLOBAL(global)}; | 756 byte code[] = {WASM_GET_GLOBAL(global)}; |
757 f1->EmitCode(code, sizeof(code)); | 757 f1->EmitCode(code, sizeof(code)); |
758 ExportAsMain(f1); | 758 ExportAsMain(f1); |
759 TestModule(&zone, builder, expected); | 759 TestModule(&zone, builder, expected); |
760 } | 760 } |
761 } | 761 } |
762 Cleanup(); | 762 Cleanup(); |
763 } | 763 } |
764 | 764 |
765 TEST(Run_WasmModule_Global_i32) { | 765 TEST(Run_WasmModule_Global_i32) { |
766 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, -983489); | 766 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, -983489); |
767 RunWasmModuleGlobalInitTest<int32_t>(kAstI32, 11223344); | 767 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, 11223344); |
768 } | 768 } |
769 | 769 |
770 TEST(Run_WasmModule_Global_f32) { | 770 TEST(Run_WasmModule_Global_f32) { |
771 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); | 771 RunWasmModuleGlobalInitTest<float>(kWasmF32, -983.9f); |
772 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); | 772 RunWasmModuleGlobalInitTest<float>(kWasmF32, 1122.99f); |
773 } | 773 } |
774 | 774 |
775 TEST(Run_WasmModule_Global_f64) { | 775 TEST(Run_WasmModule_Global_f64) { |
776 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); | 776 RunWasmModuleGlobalInitTest<double>(kWasmF64, -833.9); |
777 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); | 777 RunWasmModuleGlobalInitTest<double>(kWasmF64, 86374.25); |
778 } | 778 } |
779 | 779 |
780 TEST(InitDataAtTheUpperLimit) { | 780 TEST(InitDataAtTheUpperLimit) { |
781 { | 781 { |
782 Isolate* isolate = CcTest::InitIsolateOnce(); | 782 Isolate* isolate = CcTest::InitIsolateOnce(); |
783 HandleScope scope(isolate); | 783 HandleScope scope(isolate); |
784 testing::SetupIsolateForWasmModule(isolate); | 784 testing::SetupIsolateForWasmModule(isolate); |
785 | 785 |
786 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit"); | 786 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit"); |
787 | 787 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 }; | 909 }; |
910 | 910 |
911 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, | 911 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
912 data + arraysize(data), | 912 data + arraysize(data), |
913 ModuleOrigin::kWasmOrigin); | 913 ModuleOrigin::kWasmOrigin); |
914 // It should be possible to instantiate this module. | 914 // It should be possible to instantiate this module. |
915 CHECK(!thrower.error()); | 915 CHECK(!thrower.error()); |
916 } | 916 } |
917 Cleanup(); | 917 Cleanup(); |
918 } | 918 } |
OLD | NEW |