diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 1bc86ed8f9..600b61d108 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -3719,8 +3719,8 @@ SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction( if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { OFStream os(stdout); - PrintWasmCode(isolate_->allocator(), body, module_env_->module_env.module, - os, nullptr); + PrintRawWasmCode(isolate_->allocator(), body, + module_env_->module_env.module); } if (index >= FLAG_trace_wasm_text_start && index < FLAG_trace_wasm_text_end) { OFStream os(stdout); diff --git a/src/wasm/function-body-decoder.cc b/src/wasm/function-body-decoder.cc index 00612b8fde..752ba4a4e7 100644 --- a/src/wasm/function-body-decoder.cc +++ b/src/wasm/function-body-decoder.cc @@ -470,7 +470,7 @@ class WasmFullDecoder : public WasmDecoder { bool Decode() { if (FLAG_wasm_code_fuzzer_gen_test) { - PrintWasmCodeForDebugging(start_, end_); + PrintRawWasmCode(start_, end_); } base::ElapsedTimer decode_timer; if (FLAG_trace_wasm_decode_time) { @@ -1879,16 +1879,29 @@ unsigned OpcodeLength(const byte* pc, const byte* end) { return WasmDecoder::OpcodeLength(&decoder, pc); } -void PrintWasmCodeForDebugging(const byte* start, const byte* end) { +void PrintRawWasmCode(const byte* start, const byte* end) { AccountingAllocator allocator; - OFStream os(stdout); - PrintWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr, os, - nullptr); + PrintRawWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr); } -bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body, - const wasm::WasmModule* module, std::ostream& os, - std::vector>* offset_table) { +namespace { +const char* RawOpcodeName(WasmOpcode opcode) { + switch (opcode) { +#define DECLARE_NAME_CASE(name, opcode, sig) \ + case kExpr##name: \ + return "kExpr" #name; + FOREACH_OPCODE(DECLARE_NAME_CASE) +#undef DECLARE_NAME_CASE + default: + break; + } + return "Unknown"; +} +} // namespace + +bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, + const wasm::WasmModule* module) { + OFStream os(stdout); Zone zone(allocator, ZONE_NAME); WasmFullDecoder decoder(&zone, module, body); int line_nr = 0; @@ -1937,16 +1950,13 @@ bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body, if (opcode == kExprElse) control_depth--; int num_whitespaces = control_depth < 32 ? 2 * control_depth : 64; - if (offset_table) { - offset_table->push_back( - std::make_tuple(i.pc_offset(), line_nr, num_whitespaces)); - } // 64 whitespaces const char* padding = " "; os.write(padding, num_whitespaces); - os << "k" << WasmOpcodes::OpcodeName(opcode) << ","; + + os << RawOpcodeName(opcode) << ","; for (size_t j = 1; j < length; ++j) { os << " 0x" << AsHex(i.pc()[j], 2) << ","; diff --git a/src/wasm/function-body-decoder.h b/src/wasm/function-body-decoder.h index b4faf576d3..1115b1a450 100644 --- a/src/wasm/function-body-decoder.h +++ b/src/wasm/function-body-decoder.h @@ -340,12 +340,11 @@ V8_EXPORT_PRIVATE DecodeResult VerifyWasmCode(AccountingAllocator* allocator, FunctionBody& body); DecodeResult BuildTFGraph(AccountingAllocator* allocator, TFBuilder* builder, FunctionBody& body); -bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body, - const wasm::WasmModule* module, std::ostream& os, - std::vector>* offset_table); +bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, + const wasm::WasmModule* module); // A simplified form of AST printing, e.g. from a debugger. -void PrintWasmCodeForDebugging(const byte* start, const byte* end); +void PrintRawWasmCode(const byte* start, const byte* end); inline DecodeResult VerifyWasmCode(AccountingAllocator* allocator, const WasmModule* module, FunctionSig* sig, diff --git a/test/fuzzer/wasm-code.cc b/test/fuzzer/wasm-code.cc index 41e12987e0..167680faf2 100644 --- a/test/fuzzer/wasm-code.cc +++ b/test/fuzzer/wasm-code.cc @@ -26,22 +26,21 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (generate_test) { v8::internal::OFStream os(stdout); - os << "// Copyright 2016 the V8 project authors. All rights reserved." + os << "// Copyright 2017 the V8 project authors. All rights reserved." << std::endl; os << "// Use of this source code is governed by a BSD-style license that " "can be" << std::endl; os << "// found in the LICENSE file." << std::endl; os << std::endl; - os << "// Flags: --expose-wasm" << std::endl; - os << std::endl; os << "load(\"test/mjsunit/wasm/wasm-constants.js\");" << std::endl; os << "load(\"test/mjsunit/wasm/wasm-module-builder.js\");" << std::endl; os << std::endl; os << "(function() {" << std::endl; os << " var builder = new WasmModuleBuilder();" << std::endl; + os << " builder.addMemory(32, 32, false);" << std::endl; os << " builder.addFunction(\"test\", kSig_i_iii)" << std::endl; - os << " .addBody([" << std::endl; + os << " .addBodyWithEnd([" << std::endl; } v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); v8::Isolate* isolate = support->GetIsolate(); diff --git a/test/mjsunit/wasm/wasm-module-builder.js b/test/mjsunit/wasm/wasm-module-builder.js index 1e05a52a65..68de66bf4a 100644 --- a/test/mjsunit/wasm/wasm-module-builder.js +++ b/test/mjsunit/wasm/wasm-module-builder.js @@ -103,6 +103,11 @@ class WasmFunctionBuilder { return this; } + addBodyWithEnd(body) { + this.body = body; + return this; + } + addLocals(locals) { this.locals = locals; return this;