Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: test/cctest/wasm/wasm-run-utils.h

Issue 1890803002: [wasm] Generate source position information (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-throw-error
Patch Set: some doc and fixes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
249 builder.EnterSourcePositionScope();
248 TreeResult result = 250 TreeResult result =
249 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); 251 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end);
252 builder.LeaveSourcePositionScope();
250 if (result.failed()) { 253 if (result.failed()) {
251 ptrdiff_t pc = result.error_pc - result.start; 254 ptrdiff_t pc = result.error_pc - result.start;
252 ptrdiff_t pt = result.error_pt - result.start; 255 ptrdiff_t pt = result.error_pt - result.start;
253 std::ostringstream str; 256 std::ostringstream str;
254 str << "Verification failed: " << result.error_code << " pc = +" << pc; 257 str << "Verification failed: " << result.error_code << " pc = +" << pc;
255 if (result.error_pt) str << ", pt = +" << pt; 258 if (result.error_pt) str << ", pt = +" << pt;
256 str << ", msg = " << result.error_msg.get(); 259 str << ", msg = " << result.error_msg.get();
257 FATAL(str.str().c_str()); 260 FATAL(str.str().c_str());
258 } 261 }
259 builder.Int64LoweringForTesting(); 262 builder.Int64LoweringForTesting();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // TurboFan graph) and, later, interpretation. 412 // TurboFan graph) and, later, interpretation.
410 class WasmFunctionCompiler : public HandleAndZoneScope, 413 class WasmFunctionCompiler : public HandleAndZoneScope,
411 private GraphAndBuilders { 414 private GraphAndBuilders {
412 public: 415 public:
413 explicit WasmFunctionCompiler(FunctionSig* sig, TestingModule* module) 416 explicit WasmFunctionCompiler(FunctionSig* sig, TestingModule* module)
414 : GraphAndBuilders(main_zone()), 417 : GraphAndBuilders(main_zone()),
415 jsgraph(this->isolate(), this->graph(), this->common(), nullptr, 418 jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
416 nullptr, this->machine()), 419 nullptr, this->machine()),
417 sig(sig), 420 sig(sig),
418 descriptor_(nullptr), 421 descriptor_(nullptr),
419 testing_module_(module) { 422 testing_module_(module),
423 source_position_table_(this->graph()) {
420 if (module) { 424 if (module) {
421 // Get a new function from the testing module. 425 // Get a new function from the testing module.
422 function_ = nullptr; 426 function_ = nullptr;
423 function_index_ = module->AddFunction(sig, Handle<Code>::null()); 427 function_index_ = module->AddFunction(sig, Handle<Code>::null());
424 } else { 428 } else {
425 // Create our own function. 429 // Create our own function.
426 function_ = new WasmFunction(); 430 function_ = new WasmFunction();
427 function_->sig = sig; 431 function_->sig = sig;
428 function_index_ = 0; 432 function_index_ = 0;
429 } 433 }
430 } 434 }
431 435
432 ~WasmFunctionCompiler() { 436 ~WasmFunctionCompiler() {
433 if (function_) delete function_; 437 if (function_) delete function_;
434 } 438 }
435 439
436 JSGraph jsgraph; 440 JSGraph jsgraph;
437 FunctionSig* sig; 441 FunctionSig* sig;
438 // The call descriptor is initialized when the function is compiled. 442 // The call descriptor is initialized when the function is compiled.
439 CallDescriptor* descriptor_; 443 CallDescriptor* descriptor_;
440 TestingModule* testing_module_; 444 TestingModule* testing_module_;
441 WasmFunction* function_; 445 WasmFunction* function_;
442 int function_index_; 446 int function_index_;
443 LocalDeclEncoder local_decls; 447 LocalDeclEncoder local_decls;
448 SourcePositionTable source_position_table_;
444 449
445 Isolate* isolate() { return main_isolate(); } 450 Isolate* isolate() { return main_isolate(); }
446 Graph* graph() const { return main_graph_; } 451 Graph* graph() const { return main_graph_; }
447 Zone* zone() const { return graph()->zone(); } 452 Zone* zone() const { return graph()->zone(); }
448 CommonOperatorBuilder* common() { return &main_common_; } 453 CommonOperatorBuilder* common() { return &main_common_; }
449 MachineOperatorBuilder* machine() { return &main_machine_; } 454 MachineOperatorBuilder* machine() { return &main_machine_; }
450 void InitializeDescriptor() { 455 void InitializeDescriptor() {
451 if (descriptor_ == nullptr) { 456 if (descriptor_ == nullptr) {
452 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig); 457 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig);
453 } 458 }
454 } 459 }
455 CallDescriptor* descriptor() { return descriptor_; } 460 CallDescriptor* descriptor() { return descriptor_; }
456 461
457 void Build(const byte* start, const byte* end) { 462 void Build(const byte* start, const byte* end) {
458 // Build the TurboFan graph. 463 // Build the TurboFan graph.
459 local_decls.Prepend(&start, &end); 464 local_decls.Prepend(&start, &end);
460 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig, start, end); 465 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
466 &source_position_table_, start, end);
461 delete[] start; 467 delete[] start;
462 } 468 }
463 469
464 byte AllocateLocal(LocalType type) { 470 byte AllocateLocal(LocalType type) {
465 uint32_t index = local_decls.AddLocals(1, type, sig); 471 uint32_t index = local_decls.AddLocals(1, type, sig);
466 byte result = static_cast<byte>(index); 472 byte result = static_cast<byte>(index);
467 DCHECK_EQ(index, result); 473 DCHECK_EQ(index, result);
468 return result; 474 return result;
469 } 475 }
470 476
471 Handle<Code> Compile() { 477 Handle<Code> Compile() {
472 InitializeDescriptor(); 478 InitializeDescriptor();
473 CallDescriptor* desc = descriptor_; 479 CallDescriptor* desc = descriptor_;
474 if (kPointerSize == 4) { 480 if (kPointerSize == 4) {
475 desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc); 481 desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc);
476 } 482 }
477 CompilationInfo info("wasm compile", this->isolate(), this->zone(), 483 CompilationInfo info("wasm compile", this->isolate(), this->zone(),
478 Code::ComputeFlags(Code::WASM_FUNCTION)); 484 Code::ComputeFlags(Code::WASM_FUNCTION));
485 info.MarkAsSourcePositionsEnabled();
486 info.SetSourcePositionTable(&source_position_table_);
479 Handle<Code> result = 487 Handle<Code> result =
480 Pipeline::GenerateCodeForTesting(&info, desc, this->graph()); 488 Pipeline::GenerateCodeForTesting(&info, desc, this->graph());
481 #ifdef ENABLE_DISASSEMBLER 489 #ifdef ENABLE_DISASSEMBLER
482 if (!result.is_null() && FLAG_print_opt_code) { 490 if (!result.is_null() && FLAG_print_opt_code) {
483 OFStream os(stdout); 491 OFStream os(stdout);
484 result->Disassemble("wasm code", os); 492 result->Disassemble("wasm code", os);
485 } 493 }
486 #endif 494 #endif
487 495
488 return result; 496 return result;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (p1 == MachineType::None()) return 1; 626 if (p1 == MachineType::None()) return 1;
619 if (p2 == MachineType::None()) return 2; 627 if (p2 == MachineType::None()) return 2;
620 if (p3 == MachineType::None()) return 3; 628 if (p3 == MachineType::None()) return 3;
621 return 4; 629 return 4;
622 } 630 }
623 }; 631 };
624 632
625 } // namespace 633 } // namespace
626 634
627 #endif 635 #endif
OLDNEW
« src/compiler/wasm-compiler.h ('K') | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698