[wasm] Fix the --wasm_code_fuzzer_gen_test again.
R=titzer@chromium.org, clemensh@chromium.org Review-Url: https://codereview.chromium.org/2657443003 Cr-Commit-Position: refs/heads/master@{#42658}
This commit is contained in:
parent
bf782ec512
commit
1c1742f38d
@ -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);
|
||||
|
@ -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<std::tuple<uint32_t, int, int>>* 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) << ",";
|
||||
|
@ -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<std::tuple<uint32_t, int, int>>* 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,
|
||||
|
@ -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();
|
||||
|
@ -103,6 +103,11 @@ class WasmFunctionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
addBodyWithEnd(body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
addLocals(locals) {
|
||||
this.locals = locals;
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user