| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 TEST(Run_WasmModule_Return114) { | 68 TEST(Run_WasmModule_Return114) { |
| 69 { | 69 { |
| 70 static const int32_t kReturnValue = 114; | 70 static const int32_t kReturnValue = 114; |
| 71 TestSignatures sigs; | 71 TestSignatures sigs; |
| 72 v8::internal::AccountingAllocator allocator; | 72 v8::internal::AccountingAllocator allocator; |
| 73 Zone zone(&allocator, ZONE_NAME); | 73 Zone zone(&allocator, ZONE_NAME); |
| 74 | 74 |
| 75 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 75 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 76 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 76 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 77 ExportAsMain(f); | 77 ExportAsMain(f); |
| 78 byte code[] = {WASM_I8(kReturnValue)}; | 78 byte code[] = {WASM_I32V_2(kReturnValue)}; |
| 79 f->EmitCode(code, sizeof(code)); | 79 f->EmitCode(code, sizeof(code)); |
| 80 TestModule(&zone, builder, kReturnValue); | 80 TestModule(&zone, builder, kReturnValue); |
| 81 } | 81 } |
| 82 Cleanup(); | 82 Cleanup(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 TEST(Run_WasmModule_CallAdd) { | 85 TEST(Run_WasmModule_CallAdd) { |
| 86 { | 86 { |
| 87 v8::internal::AccountingAllocator allocator; | 87 v8::internal::AccountingAllocator allocator; |
| 88 Zone zone(&allocator, ZONE_NAME); | 88 Zone zone(&allocator, ZONE_NAME); |
| 89 TestSignatures sigs; | 89 TestSignatures sigs; |
| 90 | 90 |
| 91 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 91 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 92 | 92 |
| 93 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); | 93 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); |
| 94 uint16_t param1 = 0; | 94 uint16_t param1 = 0; |
| 95 uint16_t param2 = 1; | 95 uint16_t param2 = 1; |
| 96 byte code1[] = { | 96 byte code1[] = { |
| 97 WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; | 97 WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; |
| 98 f1->EmitCode(code1, sizeof(code1)); | 98 f1->EmitCode(code1, sizeof(code1)); |
| 99 | 99 |
| 100 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); | 100 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
| 101 | 101 |
| 102 ExportAsMain(f2); | 102 ExportAsMain(f2); |
| 103 byte code2[] = { | 103 byte code2[] = { |
| 104 WASM_CALL_FUNCTION(f1->func_index(), WASM_I8(77), WASM_I8(22))}; | 104 WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))}; |
| 105 f2->EmitCode(code2, sizeof(code2)); | 105 f2->EmitCode(code2, sizeof(code2)); |
| 106 TestModule(&zone, builder, 99); | 106 TestModule(&zone, builder, 99); |
| 107 } | 107 } |
| 108 Cleanup(); | 108 Cleanup(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST(Run_WasmModule_ReadLoadedDataSegment) { | 111 TEST(Run_WasmModule_ReadLoadedDataSegment) { |
| 112 { | 112 { |
| 113 static const byte kDataSegmentDest0 = 12; | 113 static const byte kDataSegmentDest0 = 12; |
| 114 v8::internal::AccountingAllocator allocator; | 114 v8::internal::AccountingAllocator allocator; |
| 115 Zone zone(&allocator, ZONE_NAME); | 115 Zone zone(&allocator, ZONE_NAME); |
| 116 TestSignatures sigs; | 116 TestSignatures sigs; |
| 117 | 117 |
| 118 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 118 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 119 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 119 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 120 | 120 |
| 121 ExportAsMain(f); | 121 ExportAsMain(f); |
| 122 byte code[] = { | 122 byte code[] = { |
| 123 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; | 123 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))}; |
| 124 f->EmitCode(code, sizeof(code)); | 124 f->EmitCode(code, sizeof(code)); |
| 125 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; | 125 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 126 builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); | 126 builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); |
| 127 TestModule(&zone, builder, 0xddccbbaa); | 127 TestModule(&zone, builder, 0xddccbbaa); |
| 128 } | 128 } |
| 129 Cleanup(); | 129 Cleanup(); |
| 130 } | 130 } |
| 131 | 131 |
| 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(kWasmI32); | 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_I32V_1(-1)), |
| 150 WASM_I8(11))}; | 150 WASM_INC_LOCAL_BY(localIndex, 4))), |
| 151 WASM_I32V_1(11))}; |
| 151 f->EmitCode(code, sizeof(code)); | 152 f->EmitCode(code, sizeof(code)); |
| 152 TestModule(&zone, builder, 11); | 153 TestModule(&zone, builder, 11); |
| 153 } | 154 } |
| 154 Cleanup(); | 155 Cleanup(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 TEST(Run_WasmModule_CallMain_recursive) { | 158 TEST(Run_WasmModule_CallMain_recursive) { |
| 158 { | 159 { |
| 159 v8::internal::AccountingAllocator allocator; | 160 v8::internal::AccountingAllocator allocator; |
| 160 Zone zone(&allocator, ZONE_NAME); | 161 Zone zone(&allocator, ZONE_NAME); |
| 161 TestSignatures sigs; | 162 TestSignatures sigs; |
| 162 | 163 |
| 163 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 164 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 164 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 165 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 165 | 166 |
| 166 uint16_t localIndex = f->AddLocal(kWasmI32); | 167 uint16_t localIndex = f->AddLocal(kWasmI32); |
| 167 ExportAsMain(f); | 168 ExportAsMain(f); |
| 168 byte code[] = { | 169 byte code[] = { |
| 169 WASM_SET_LOCAL(localIndex, | 170 WASM_SET_LOCAL(localIndex, |
| 170 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 171 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
| 171 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), | 172 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_1(5)), |
| 172 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 173 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
| 173 WASM_INC_LOCAL(localIndex)), | 174 WASM_INC_LOCAL(localIndex)), |
| 174 WASM_CALL_FUNCTION0(0)), | 175 WASM_CALL_FUNCTION0(0)), |
| 175 WASM_I8(55))}; | 176 WASM_I32V_1(55))}; |
| 176 f->EmitCode(code, sizeof(code)); | 177 f->EmitCode(code, sizeof(code)); |
| 177 TestModule(&zone, builder, 55); | 178 TestModule(&zone, builder, 55); |
| 178 } | 179 } |
| 179 Cleanup(); | 180 Cleanup(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 TEST(Run_WasmModule_Global) { | 183 TEST(Run_WasmModule_Global) { |
| 183 { | 184 { |
| 184 v8::internal::AccountingAllocator allocator; | 185 v8::internal::AccountingAllocator allocator; |
| 185 Zone zone(&allocator, ZONE_NAME); | 186 Zone zone(&allocator, ZONE_NAME); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 { | 435 { |
| 435 // Initial memory size = 16 + GrowMemory(10) | 436 // Initial memory size = 16 + GrowMemory(10) |
| 436 static const int kExpectedValue = 26; | 437 static const int kExpectedValue = 26; |
| 437 TestSignatures sigs; | 438 TestSignatures sigs; |
| 438 v8::internal::AccountingAllocator allocator; | 439 v8::internal::AccountingAllocator allocator; |
| 439 Zone zone(&allocator, ZONE_NAME); | 440 Zone zone(&allocator, ZONE_NAME); |
| 440 | 441 |
| 441 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 442 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 442 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 443 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 443 ExportAsMain(f); | 444 ExportAsMain(f); |
| 444 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_DROP, WASM_MEMORY_SIZE}; | 445 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP, |
| 446 WASM_MEMORY_SIZE}; |
| 445 f->EmitCode(code, sizeof(code)); | 447 f->EmitCode(code, sizeof(code)); |
| 446 TestModule(&zone, builder, kExpectedValue); | 448 TestModule(&zone, builder, kExpectedValue); |
| 447 } | 449 } |
| 448 Cleanup(); | 450 Cleanup(); |
| 449 } | 451 } |
| 450 | 452 |
| 451 TEST(GrowMemoryZero) { | 453 TEST(GrowMemoryZero) { |
| 452 { | 454 { |
| 453 // Initial memory size is 16, see wasm-module-builder.cc | 455 // Initial memory size is 16, see wasm-module-builder.cc |
| 454 static const int kExpectedValue = 16; | 456 static const int kExpectedValue = 16; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 // Initial memory size = 16 + GrowMemory(10) | 584 // Initial memory size = 16 + GrowMemory(10) |
| 583 static const int index = kPageSize * 17 + 4; | 585 static const int index = kPageSize * 17 + 4; |
| 584 int value = 0xaced; | 586 int value = 0xaced; |
| 585 TestSignatures sigs; | 587 TestSignatures sigs; |
| 586 v8::internal::AccountingAllocator allocator; | 588 v8::internal::AccountingAllocator allocator; |
| 587 Zone zone(&allocator, ZONE_NAME); | 589 Zone zone(&allocator, ZONE_NAME); |
| 588 | 590 |
| 589 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 591 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 590 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 592 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 591 ExportAsMain(f); | 593 ExportAsMain(f); |
| 592 byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)), | 594 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), |
| 593 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), | 595 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), |
| 594 WASM_I32V(value))}; | 596 WASM_I32V(value))}; |
| 595 f->EmitCode(code, sizeof(code)); | 597 f->EmitCode(code, sizeof(code)); |
| 596 TestModuleException(&zone, builder); | 598 TestModuleException(&zone, builder); |
| 597 } | 599 } |
| 598 Cleanup(); | 600 Cleanup(); |
| 599 } | 601 } |
| 600 | 602 |
| 601 TEST(Run_WasmModule_GrowMemOobFixedIndex) { | 603 TEST(Run_WasmModule_GrowMemOobFixedIndex) { |
| 602 { | 604 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 static const int kPageSize = 0x10000; | 654 static const int kPageSize = 0x10000; |
| 653 int value = 0xaced; | 655 int value = 0xaced; |
| 654 TestSignatures sigs; | 656 TestSignatures sigs; |
| 655 Isolate* isolate = CcTest::InitIsolateOnce(); | 657 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 656 v8::internal::AccountingAllocator allocator; | 658 v8::internal::AccountingAllocator allocator; |
| 657 Zone zone(&allocator, ZONE_NAME); | 659 Zone zone(&allocator, ZONE_NAME); |
| 658 | 660 |
| 659 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 661 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 660 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); | 662 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); |
| 661 ExportAsMain(f); | 663 ExportAsMain(f); |
| 662 byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP, | 664 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP, |
| 663 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), | 665 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), |
| 664 WASM_I32V(value)), | 666 WASM_I32V(value)), |
| 665 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; | 667 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; |
| 666 f->EmitCode(code, sizeof(code)); | 668 f->EmitCode(code, sizeof(code)); |
| 667 | 669 |
| 668 HandleScope scope(isolate); | 670 HandleScope scope(isolate); |
| 669 ZoneBuffer buffer(&zone); | 671 ZoneBuffer buffer(&zone); |
| 670 builder->WriteTo(buffer); | 672 builder->WriteTo(buffer); |
| 671 testing::SetupIsolateForWasmModule(isolate); | 673 testing::SetupIsolateForWasmModule(isolate); |
| 672 | 674 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 }; | 911 }; |
| 910 | 912 |
| 911 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, | 913 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
| 912 data + arraysize(data), | 914 data + arraysize(data), |
| 913 ModuleOrigin::kWasmOrigin); | 915 ModuleOrigin::kWasmOrigin); |
| 914 // It should be possible to instantiate this module. | 916 // It should be possible to instantiate this module. |
| 915 CHECK(!thrower.error()); | 917 CHECK(!thrower.error()); |
| 916 } | 918 } |
| 917 Cleanup(); | 919 Cleanup(); |
| 918 } | 920 } |
| OLD | NEW |