| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef WASM_RUN_UTILS_H | 5 #ifndef WASM_RUN_UTILS_H |
| 6 #define WASM_RUN_UTILS_H | 6 #define WASM_RUN_UTILS_H |
| 7 | 7 |
| 8 #include <setjmp.h> | 8 #include <setjmp.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 template <typename T> | 116 template <typename T> |
| 117 T* AddMemoryElems(uint32_t count) { | 117 T* AddMemoryElems(uint32_t count) { |
| 118 AddMemory(count * sizeof(T)); | 118 AddMemory(count * sizeof(T)); |
| 119 return raw_mem_start<T>(); | 119 return raw_mem_start<T>(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 template <typename T> | 122 template <typename T> |
| 123 T* AddGlobal( | 123 T* AddGlobal( |
| 124 LocalType type = WasmOpcodes::LocalTypeFor(MachineTypeForC<T>())) { | 124 ValueType type = WasmOpcodes::ValueTypeFor(MachineTypeForC<T>())) { |
| 125 const WasmGlobal* global = AddGlobal(type); | 125 const WasmGlobal* global = AddGlobal(type); |
| 126 return reinterpret_cast<T*>(instance->globals_start + global->offset); | 126 return reinterpret_cast<T*>(instance->globals_start + global->offset); |
| 127 } | 127 } |
| 128 | 128 |
| 129 byte AddSignature(FunctionSig* sig) { | 129 byte AddSignature(FunctionSig* sig) { |
| 130 module_.signatures.push_back(sig); | 130 module_.signatures.push_back(sig); |
| 131 size_t size = module->signatures.size(); | 131 size_t size = module->signatures.size(); |
| 132 CHECK(size < 127); | 132 CHECK(size < 127); |
| 133 return static_cast<byte>(size - 1); | 133 return static_cast<byte>(size - 1); |
| 134 } | 134 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 private: | 290 private: |
| 291 WasmExecutionMode execution_mode_; | 291 WasmExecutionMode execution_mode_; |
| 292 WasmModule module_; | 292 WasmModule module_; |
| 293 WasmInstance instance_; | 293 WasmInstance instance_; |
| 294 Isolate* isolate_; | 294 Isolate* isolate_; |
| 295 uint32_t global_offset; | 295 uint32_t global_offset; |
| 296 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. | 296 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. |
| 297 WasmInterpreter* interpreter_; | 297 WasmInterpreter* interpreter_; |
| 298 Handle<WasmInstanceObject> instance_object_; | 298 Handle<WasmInstanceObject> instance_object_; |
| 299 | 299 |
| 300 const WasmGlobal* AddGlobal(LocalType type) { | 300 const WasmGlobal* AddGlobal(ValueType type) { |
| 301 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); | 301 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); |
| 302 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 302 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
| 303 module_.globals.push_back( | 303 module_.globals.push_back( |
| 304 {type, true, WasmInitExpr(), global_offset, false, false}); | 304 {type, true, WasmInitExpr(), global_offset, false, false}); |
| 305 global_offset += size; | 305 global_offset += size; |
| 306 // limit number of globals. | 306 // limit number of globals. |
| 307 CHECK_LT(global_offset, kMaxGlobalsSize); | 307 CHECK_LT(global_offset, kMaxGlobalsSize); |
| 308 return &module->globals.back(); | 308 return &module->globals.back(); |
| 309 } | 309 } |
| 310 | 310 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 return; | 517 return; |
| 518 } | 518 } |
| 519 | 519 |
| 520 // Build the TurboFan graph. | 520 // Build the TurboFan graph. |
| 521 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig, | 521 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig, |
| 522 &source_position_table_, start, end); | 522 &source_position_table_, start, end); |
| 523 Handle<Code> code = Compile(); | 523 Handle<Code> code = Compile(); |
| 524 testing_module_->SetFunctionCode(function_index(), code); | 524 testing_module_->SetFunctionCode(function_index(), code); |
| 525 } | 525 } |
| 526 | 526 |
| 527 byte AllocateLocal(LocalType type) { | 527 byte AllocateLocal(ValueType type) { |
| 528 uint32_t index = local_decls.AddLocals(1, type); | 528 uint32_t index = local_decls.AddLocals(1, type); |
| 529 byte result = static_cast<byte>(index); | 529 byte result = static_cast<byte>(index); |
| 530 DCHECK_EQ(index, result); | 530 DCHECK_EQ(index, result); |
| 531 return result; | 531 return result; |
| 532 } | 532 } |
| 533 | 533 |
| 534 void SetSigIndex(int sig_index) { function_->sig_index = sig_index; } | 534 void SetSigIndex(int sig_index) { function_->sig_index = sig_index; } |
| 535 | 535 |
| 536 private: | 536 private: |
| 537 friend class WasmRunnerBase; | 537 friend class WasmRunnerBase; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // Resets the state for building the next function. | 629 // Resets the state for building the next function. |
| 630 // The main function called will be the last generated function. | 630 // The main function called will be the last generated function. |
| 631 // Returns the index of the previously built function. | 631 // Returns the index of the previously built function. |
| 632 WasmFunctionCompiler& NewFunction(FunctionSig* sig, | 632 WasmFunctionCompiler& NewFunction(FunctionSig* sig, |
| 633 const char* name = nullptr) { | 633 const char* name = nullptr) { |
| 634 functions_.emplace_back( | 634 functions_.emplace_back( |
| 635 new WasmFunctionCompiler(&zone_, sig, &module_, name)); | 635 new WasmFunctionCompiler(&zone_, sig, &module_, name)); |
| 636 return *functions_.back(); | 636 return *functions_.back(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 byte AllocateLocal(LocalType type) { | 639 byte AllocateLocal(ValueType type) { |
| 640 return functions_[0]->AllocateLocal(type); | 640 return functions_[0]->AllocateLocal(type); |
| 641 } | 641 } |
| 642 | 642 |
| 643 WasmFunction* function() { return functions_[0]->function_; } | 643 WasmFunction* function() { return functions_[0]->function_; } |
| 644 WasmInterpreter* interpreter() { return functions_[0]->interpreter_; } | 644 WasmInterpreter* interpreter() { return functions_[0]->interpreter_; } |
| 645 bool possible_nondeterminism() { return possible_nondeterminism_; } | 645 bool possible_nondeterminism() { return possible_nondeterminism_; } |
| 646 TestingModule& module() { return module_; } | 646 TestingModule& module() { return module_; } |
| 647 Zone* zone() { return &zone_; } | 647 Zone* zone() { return &zone_; } |
| 648 | 648 |
| 649 // Set the context, such that e.g. runtime functions can be called. | 649 // Set the context, such that e.g. runtime functions can be called. |
| 650 void SetModuleContext() { | 650 void SetModuleContext() { |
| 651 if (!module_.instance->context.is_null()) { | 651 if (!module_.instance->context.is_null()) { |
| 652 CHECK(module_.instance->context.is_identical_to( | 652 CHECK(module_.instance->context.is_identical_to( |
| 653 main_isolate()->native_context())); | 653 main_isolate()->native_context())); |
| 654 return; | 654 return; |
| 655 } | 655 } |
| 656 module_.instance->context = main_isolate()->native_context(); | 656 module_.instance->context = main_isolate()->native_context(); |
| 657 } | 657 } |
| 658 | 658 |
| 659 private: | 659 private: |
| 660 FunctionSig* CreateSig(MachineType return_type, | 660 FunctionSig* CreateSig(MachineType return_type, |
| 661 Vector<MachineType> param_types) { | 661 Vector<MachineType> param_types) { |
| 662 int return_count = return_type.IsNone() ? 0 : 1; | 662 int return_count = return_type.IsNone() ? 0 : 1; |
| 663 int param_count = param_types.length(); | 663 int param_count = param_types.length(); |
| 664 | 664 |
| 665 // Allocate storage array in zone. | 665 // Allocate storage array in zone. |
| 666 LocalType* sig_types = | 666 ValueType* sig_types = |
| 667 zone_.NewArray<LocalType>(return_count + param_count); | 667 zone_.NewArray<ValueType>(return_count + param_count); |
| 668 | 668 |
| 669 // Convert machine types to local types, and check that there are no | 669 // Convert machine types to local types, and check that there are no |
| 670 // MachineType::None()'s in the parameters. | 670 // MachineType::None()'s in the parameters. |
| 671 int idx = 0; | 671 int idx = 0; |
| 672 if (return_count) sig_types[idx++] = WasmOpcodes::LocalTypeFor(return_type); | 672 if (return_count) sig_types[idx++] = WasmOpcodes::ValueTypeFor(return_type); |
| 673 for (MachineType param : param_types) { | 673 for (MachineType param : param_types) { |
| 674 CHECK_NE(MachineType::None(), param); | 674 CHECK_NE(MachineType::None(), param); |
| 675 sig_types[idx++] = WasmOpcodes::LocalTypeFor(param); | 675 sig_types[idx++] = WasmOpcodes::ValueTypeFor(param); |
| 676 } | 676 } |
| 677 return new (&zone_) FunctionSig(return_count, param_count, sig_types); | 677 return new (&zone_) FunctionSig(return_count, param_count, sig_types); |
| 678 } | 678 } |
| 679 | 679 |
| 680 template <typename ReturnType, typename... ParamTypes> | 680 template <typename ReturnType, typename... ParamTypes> |
| 681 FunctionSig* CreateSig() { | 681 FunctionSig* CreateSig() { |
| 682 std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{ | 682 std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{ |
| 683 {MachineTypeForC<ParamTypes>()...}}; | 683 {MachineTypeForC<ParamTypes>()...}}; |
| 684 Vector<MachineType> param_vec(param_machine_types.data(), | 684 Vector<MachineType> param_vec(param_machine_types.data(), |
| 685 param_machine_types.size()); | 685 param_machine_types.size()); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 void RunWasm_##name(WasmExecutionMode execution_mode) | 796 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 797 | 797 |
| 798 #define WASM_EXEC_COMPILED_TEST(name) \ | 798 #define WASM_EXEC_COMPILED_TEST(name) \ |
| 799 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 799 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 800 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 800 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 801 void RunWasm_##name(WasmExecutionMode execution_mode) | 801 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 802 | 802 |
| 803 } // namespace | 803 } // namespace |
| 804 | 804 |
| 805 #endif | 805 #endif |
| OLD | NEW |