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 <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // limit number of globals. | 214 // limit number of globals. |
215 CHECK_LT(global_offset, kMaxGlobalsSize); | 215 CHECK_LT(global_offset, kMaxGlobalsSize); |
216 return &module->globals.back(); | 216 return &module->globals.back(); |
217 } | 217 } |
218 }; | 218 }; |
219 | 219 |
220 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 220 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
221 FunctionSig* sig, const byte* start, | 221 FunctionSig* sig, const byte* start, |
222 const byte* end) { | 222 const byte* end) { |
223 compiler::WasmGraphBuilder builder(zone, jsgraph, sig); | 223 compiler::WasmGraphBuilder builder(zone, jsgraph, sig); |
224 TreeResult result = BuildTFGraph(&builder, module, sig, start, end); | 224 TreeResult result = |
| 225 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); |
225 if (result.failed()) { | 226 if (result.failed()) { |
226 ptrdiff_t pc = result.error_pc - result.start; | 227 ptrdiff_t pc = result.error_pc - result.start; |
227 ptrdiff_t pt = result.error_pt - result.start; | 228 ptrdiff_t pt = result.error_pt - result.start; |
228 std::ostringstream str; | 229 std::ostringstream str; |
229 str << "Verification failed: " << result.error_code << " pc = +" << pc; | 230 str << "Verification failed: " << result.error_code << " pc = +" << pc; |
230 if (result.error_pt) str << ", pt = +" << pt; | 231 if (result.error_pt) str << ", pt = +" << pt; |
231 str << ", msg = " << result.error_msg.get(); | 232 str << ", msg = " << result.error_msg.get(); |
232 FATAL(str.str().c_str()); | 233 FATAL(str.str().c_str()); |
233 } | 234 } |
234 builder.Int64LoweringForTesting(); | 235 builder.Int64LoweringForTesting(); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 479 |
479 // A helper class to build graphs from Wasm bytecode, generate machine | 480 // A helper class to build graphs from Wasm bytecode, generate machine |
480 // code, and run that code. | 481 // code, and run that code. |
481 template <typename ReturnType> | 482 template <typename ReturnType> |
482 class WasmRunner { | 483 class WasmRunner { |
483 public: | 484 public: |
484 WasmRunner(MachineType p0 = MachineType::None(), | 485 WasmRunner(MachineType p0 = MachineType::None(), |
485 MachineType p1 = MachineType::None(), | 486 MachineType p1 = MachineType::None(), |
486 MachineType p2 = MachineType::None(), | 487 MachineType p2 = MachineType::None(), |
487 MachineType p3 = MachineType::None()) | 488 MachineType p3 = MachineType::None()) |
488 : compiled_(false), | 489 : zone(&allocator_), |
489 | 490 compiled_(false), |
490 signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1, | 491 signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1, |
491 GetParameterCount(p0, p1, p2, p3), storage_), | 492 GetParameterCount(p0, p1, p2, p3), storage_), |
492 compiler_(&signature_, nullptr) { | 493 compiler_(&signature_, nullptr) { |
493 InitSigStorage(p0, p1, p2, p3); | 494 InitSigStorage(p0, p1, p2, p3); |
494 } | 495 } |
495 | 496 |
496 WasmRunner(TestingModule* module, MachineType p0 = MachineType::None(), | 497 WasmRunner(TestingModule* module, MachineType p0 = MachineType::None(), |
497 MachineType p1 = MachineType::None(), | 498 MachineType p1 = MachineType::None(), |
498 MachineType p2 = MachineType::None(), | 499 MachineType p2 = MachineType::None(), |
499 MachineType p3 = MachineType::None()) | 500 MachineType p3 = MachineType::None()) |
500 : compiled_(false), | 501 : zone(&allocator_), |
| 502 compiled_(false), |
501 signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1, | 503 signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1, |
502 GetParameterCount(p0, p1, p2, p3), storage_), | 504 GetParameterCount(p0, p1, p2, p3), storage_), |
503 compiler_(&signature_, module) { | 505 compiler_(&signature_, module) { |
504 DCHECK(module); | 506 DCHECK(module); |
505 InitSigStorage(p0, p1, p2, p3); | 507 InitSigStorage(p0, p1, p2, p3); |
506 } | 508 } |
507 | 509 |
508 void InitSigStorage(MachineType p0, MachineType p1, MachineType p2, | 510 void InitSigStorage(MachineType p0, MachineType p1, MachineType p2, |
509 MachineType p3) { | 511 MachineType p3) { |
510 int index = 0; | 512 int index = 0; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 ReturnType return_value; | 572 ReturnType return_value; |
571 int32_t result = runner.Call<void*, void*, void*, void*, void*>( | 573 int32_t result = runner.Call<void*, void*, void*, void*, void*>( |
572 &p0, &p1, &p2, &p3, &return_value); | 574 &p0, &p1, &p2, &p3, &return_value); |
573 CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result); | 575 CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result); |
574 return return_value; | 576 return return_value; |
575 } | 577 } |
576 | 578 |
577 byte AllocateLocal(LocalType type) { return compiler_.AllocateLocal(type); } | 579 byte AllocateLocal(LocalType type) { return compiler_.AllocateLocal(type); } |
578 | 580 |
579 protected: | 581 protected: |
| 582 v8::base::AccountingAllocator allocator_; |
580 Zone zone; | 583 Zone zone; |
581 bool compiled_; | 584 bool compiled_; |
582 LocalType storage_[WASM_RUNNER_MAX_NUM_PARAMETERS]; | 585 LocalType storage_[WASM_RUNNER_MAX_NUM_PARAMETERS]; |
583 FunctionSig signature_; | 586 FunctionSig signature_; |
584 WasmFunctionCompiler compiler_; | 587 WasmFunctionCompiler compiler_; |
585 WasmFunctionWrapper<ReturnType> wrapper_; | 588 WasmFunctionWrapper<ReturnType> wrapper_; |
586 | 589 |
587 static size_t GetParameterCount(MachineType p0, MachineType p1, | 590 static size_t GetParameterCount(MachineType p0, MachineType p1, |
588 MachineType p2, MachineType p3) { | 591 MachineType p2, MachineType p3) { |
589 if (p0 == MachineType::None()) return 0; | 592 if (p0 == MachineType::None()) return 0; |
590 if (p1 == MachineType::None()) return 1; | 593 if (p1 == MachineType::None()) return 1; |
591 if (p2 == MachineType::None()) return 2; | 594 if (p2 == MachineType::None()) return 2; |
592 if (p3 == MachineType::None()) return 3; | 595 if (p3 == MachineType::None()) return 3; |
593 return 4; | 596 return 4; |
594 } | 597 } |
595 }; | 598 }; |
596 | 599 |
597 } // namespace | 600 } // namespace |
598 | 601 |
599 #endif | 602 #endif |
OLD | NEW |