| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 235 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
| 236 module->globals.push_back({0, 0, mem_type, global_offset, false}); | 236 module->globals.push_back({0, 0, mem_type, global_offset, false}); |
| 237 global_offset += size; | 237 global_offset += size; |
| 238 // limit number of globals. | 238 // limit number of globals. |
| 239 CHECK_LT(global_offset, kMaxGlobalsSize); | 239 CHECK_LT(global_offset, kMaxGlobalsSize); |
| 240 return &module->globals.back(); | 240 return &module->globals.back(); |
| 241 } | 241 } |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 244 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
| 245 FunctionSig* sig, const byte* start, | 245 FunctionSig* sig, |
| 246 const byte* end) { | 246 SourcePositionTable* source_position_table, |
| 247 compiler::WasmGraphBuilder builder(zone, jsgraph, sig); | 247 const byte* start, const byte* end) { |
| 248 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); |
| 248 TreeResult result = | 249 TreeResult result = |
| 249 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); | 250 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); |
| 250 if (result.failed()) { | 251 if (result.failed()) { |
| 251 ptrdiff_t pc = result.error_pc - result.start; | 252 ptrdiff_t pc = result.error_pc - result.start; |
| 252 ptrdiff_t pt = result.error_pt - result.start; | 253 ptrdiff_t pt = result.error_pt - result.start; |
| 253 std::ostringstream str; | 254 std::ostringstream str; |
| 254 str << "Verification failed: " << result.error_code << " pc = +" << pc; | 255 str << "Verification failed: " << result.error_code << " pc = +" << pc; |
| 255 if (result.error_pt) str << ", pt = +" << pt; | 256 if (result.error_pt) str << ", pt = +" << pt; |
| 256 str << ", msg = " << result.error_msg.get(); | 257 str << ", msg = " << result.error_msg.get(); |
| 257 FATAL(str.str().c_str()); | 258 FATAL(str.str().c_str()); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 private GraphAndBuilders { | 412 private GraphAndBuilders { |
| 412 public: | 413 public: |
| 413 explicit WasmFunctionCompiler(FunctionSig* sig, TestingModule* module, | 414 explicit WasmFunctionCompiler(FunctionSig* sig, TestingModule* module, |
| 414 const char* debug_name = "<WASM UNNAMED>") | 415 const char* debug_name = "<WASM UNNAMED>") |
| 415 : GraphAndBuilders(main_zone()), | 416 : GraphAndBuilders(main_zone()), |
| 416 jsgraph(this->isolate(), this->graph(), this->common(), nullptr, | 417 jsgraph(this->isolate(), this->graph(), this->common(), nullptr, |
| 417 nullptr, this->machine()), | 418 nullptr, this->machine()), |
| 418 sig(sig), | 419 sig(sig), |
| 419 descriptor_(nullptr), | 420 descriptor_(nullptr), |
| 420 testing_module_(module), | 421 testing_module_(module), |
| 421 debug_name_(debug_name) { | 422 debug_name_(debug_name), |
| 423 source_position_table_(this->graph()) { |
| 422 if (module) { | 424 if (module) { |
| 423 // Get a new function from the testing module. | 425 // Get a new function from the testing module. |
| 424 function_ = nullptr; | 426 function_ = nullptr; |
| 425 function_index_ = module->AddFunction(sig, Handle<Code>::null()); | 427 function_index_ = module->AddFunction(sig, Handle<Code>::null()); |
| 426 } else { | 428 } else { |
| 427 // Create our own function. | 429 // Create our own function. |
| 428 function_ = new WasmFunction(); | 430 function_ = new WasmFunction(); |
| 429 function_->sig = sig; | 431 function_->sig = sig; |
| 430 function_index_ = 0; | 432 function_index_ = 0; |
| 431 } | 433 } |
| 432 } | 434 } |
| 433 | 435 |
| 434 ~WasmFunctionCompiler() { | 436 ~WasmFunctionCompiler() { |
| 435 if (function_) delete function_; | 437 if (function_) delete function_; |
| 436 } | 438 } |
| 437 | 439 |
| 438 JSGraph jsgraph; | 440 JSGraph jsgraph; |
| 439 FunctionSig* sig; | 441 FunctionSig* sig; |
| 440 // The call descriptor is initialized when the function is compiled. | 442 // The call descriptor is initialized when the function is compiled. |
| 441 CallDescriptor* descriptor_; | 443 CallDescriptor* descriptor_; |
| 442 TestingModule* testing_module_; | 444 TestingModule* testing_module_; |
| 443 const char* debug_name_; | 445 const char* debug_name_; |
| 444 WasmFunction* function_; | 446 WasmFunction* function_; |
| 445 int function_index_; | 447 int function_index_; |
| 446 LocalDeclEncoder local_decls; | 448 LocalDeclEncoder local_decls; |
| 449 SourcePositionTable source_position_table_; |
| 447 | 450 |
| 448 Isolate* isolate() { return main_isolate(); } | 451 Isolate* isolate() { return main_isolate(); } |
| 449 Graph* graph() const { return main_graph_; } | 452 Graph* graph() const { return main_graph_; } |
| 450 Zone* zone() const { return graph()->zone(); } | 453 Zone* zone() const { return graph()->zone(); } |
| 451 CommonOperatorBuilder* common() { return &main_common_; } | 454 CommonOperatorBuilder* common() { return &main_common_; } |
| 452 MachineOperatorBuilder* machine() { return &main_machine_; } | 455 MachineOperatorBuilder* machine() { return &main_machine_; } |
| 453 void InitializeDescriptor() { | 456 void InitializeDescriptor() { |
| 454 if (descriptor_ == nullptr) { | 457 if (descriptor_ == nullptr) { |
| 455 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig); | 458 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig); |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 CallDescriptor* descriptor() { return descriptor_; } | 461 CallDescriptor* descriptor() { return descriptor_; } |
| 459 | 462 |
| 460 void Build(const byte* start, const byte* end) { | 463 void Build(const byte* start, const byte* end) { |
| 461 // Build the TurboFan graph. | 464 // Build the TurboFan graph. |
| 462 local_decls.Prepend(&start, &end); | 465 local_decls.Prepend(&start, &end); |
| 463 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig, start, end); | 466 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig, |
| 467 &source_position_table_, start, end); |
| 464 delete[] start; | 468 delete[] start; |
| 465 } | 469 } |
| 466 | 470 |
| 467 byte AllocateLocal(LocalType type) { | 471 byte AllocateLocal(LocalType type) { |
| 468 uint32_t index = local_decls.AddLocals(1, type, sig); | 472 uint32_t index = local_decls.AddLocals(1, type, sig); |
| 469 byte result = static_cast<byte>(index); | 473 byte result = static_cast<byte>(index); |
| 470 DCHECK_EQ(index, result); | 474 DCHECK_EQ(index, result); |
| 471 return result; | 475 return result; |
| 472 } | 476 } |
| 473 | 477 |
| 474 Handle<Code> Compile() { | 478 Handle<Code> Compile() { |
| 475 InitializeDescriptor(); | 479 InitializeDescriptor(); |
| 476 CallDescriptor* desc = descriptor_; | 480 CallDescriptor* desc = descriptor_; |
| 477 if (kPointerSize == 4) { | 481 if (kPointerSize == 4) { |
| 478 desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc); | 482 desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc); |
| 479 } | 483 } |
| 480 CompilationInfo info(debug_name_, this->isolate(), this->zone(), | 484 CompilationInfo info(debug_name_, this->isolate(), this->zone(), |
| 481 Code::ComputeFlags(Code::WASM_FUNCTION)); | 485 Code::ComputeFlags(Code::WASM_FUNCTION)); |
| 482 Handle<Code> result = | 486 Handle<Code> result = Pipeline::GenerateWASMCode(&info, desc, this->graph(), |
| 483 Pipeline::GenerateCodeForTesting(&info, desc, this->graph()); | 487 &source_position_table_); |
| 484 #ifdef ENABLE_DISASSEMBLER | 488 #ifdef ENABLE_DISASSEMBLER |
| 485 if (!result.is_null() && FLAG_print_opt_code) { | 489 if (!result.is_null() && FLAG_print_opt_code) { |
| 486 OFStream os(stdout); | 490 OFStream os(stdout); |
| 487 result->Disassemble("wasm code", os); | 491 result->Disassemble("wasm code", os); |
| 488 } | 492 } |
| 489 #endif | 493 #endif |
| 490 | 494 |
| 491 return result; | 495 return result; |
| 492 } | 496 } |
| 493 | 497 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 if (p1 == MachineType::None()) return 1; | 635 if (p1 == MachineType::None()) return 1; |
| 632 if (p2 == MachineType::None()) return 2; | 636 if (p2 == MachineType::None()) return 2; |
| 633 if (p3 == MachineType::None()) return 3; | 637 if (p3 == MachineType::None()) return 3; |
| 634 return 4; | 638 return 4; |
| 635 } | 639 } |
| 636 }; | 640 }; |
| 637 | 641 |
| 638 } // namespace | 642 } // namespace |
| 639 | 643 |
| 640 #endif | 644 #endif |
| OLD | NEW |