Commit e38efdef authored by titzer's avatar titzer Committed by Commit bot

[wasm] Add --trace-wasm-ast-start and --trace-wasm-ast-end options and improve tracing.

R=ahaas@chromium.org,mtrofin@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1802353002

Cr-Commit-Position: refs/heads/master@{#34843}
parent 479a2df3
......@@ -2594,6 +2594,11 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
return Handle<Code>::null();
}
int index = static_cast<int>(function.func_index);
if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
PrintAst(body);
}
if (FLAG_trace_wasm_decode_time) {
decode_ms = decode_timer.Elapsed().InMillisecondsF();
}
......
......@@ -467,7 +467,10 @@ DEFINE_BOOL(trace_wasm_encoder, false, "trace encoding of wasm code")
DEFINE_BOOL(trace_wasm_decoder, false, "trace decoding of wasm code")
DEFINE_BOOL(trace_wasm_decode_time, false, "trace decoding time of wasm code")
DEFINE_BOOL(trace_wasm_compiler, false, "trace compiling of wasm code")
DEFINE_BOOL(trace_wasm_ast, false, "dump AST after WASM decode")
DEFINE_INT(trace_wasm_ast_start, 0,
"start function for WASM AST trace (inclusive)")
DEFINE_INT(trace_wasm_ast_end, 0, "end function for WASM AST trace (exclusive)")
DEFINE_INT(skip_compiling_wasm_funcs, 0, "start compiling at function N")
DEFINE_BOOL(wasm_break_on_decoder_error, false,
"debug break when wasm decoder encounters an error")
DEFINE_BOOL(wasm_loop_assignment_analysis, false,
......
......@@ -14,6 +14,8 @@
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/ostreams.h"
#include "src/compiler/wasm-compiler.h"
namespace v8 {
......@@ -401,10 +403,6 @@ class SR_WasmDecoder : public WasmDecoder {
}
if (ok()) {
if (FLAG_trace_wasm_ast) {
FunctionBody body = {module_, sig_, base_, start_, end_};
PrintAst(body);
}
TRACE("wasm-decode ok\n");
} else {
TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_),
......@@ -1689,8 +1687,42 @@ int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc,
}
void PrintAst(FunctionBody& body) {
WasmDecoder decoder(body.module, body.sig, body.start, body.end);
const byte* pc = body.start;
Zone zone;
SR_WasmDecoder decoder(&zone, nullptr, body);
OFStream os(stdout);
// Print the function signature.
if (body.sig) {
os << "// signature: " << *body.sig << std::endl;
}
// Print the local declarations.
std::vector<LocalType>* decls = decoder.DecodeLocalDeclsForTesting();
const byte* pc = decoder.pc();
if (body.start != decoder.pc()) {
printf("// locals:");
size_t pos = 0;
while (pos < decls->size()) {
LocalType type = decls->at(pos++);
size_t count = 1;
while (pos < decls->size() && decls->at(pos) == type) {
pos++;
count++;
}
os << " " << count << " " << WasmOpcodes::TypeName(type);
}
os << std::endl;
for (const byte* locals = body.start; locals < pc; locals++) {
printf(" 0x%02x,", *locals);
}
printf("\n");
}
delete decls;
printf("// body: \n");
std::vector<int> arity_stack;
while (pc < body.end) {
int arity = decoder.OpcodeArity(pc);
......@@ -1707,6 +1739,35 @@ void PrintAst(FunctionBody& body) {
for (size_t i = 1; i < length; i++) {
printf(" 0x%02x,", pc[i]);
}
if (body.module) {
switch (opcode) {
case kExprCallIndirect: {
SignatureIndexOperand operand(&decoder, pc);
if (decoder.Validate(pc, operand)) {
os << " // sig #" << operand.index << ": " << *operand.sig;
}
break;
}
case kExprCallImport: {
ImportIndexOperand operand(&decoder, pc);
if (decoder.Validate(pc, operand)) {
os << " // import #" << operand.index << ": " << *operand.sig;
}
break;
}
case kExprCallFunction: {
FunctionIndexOperand operand(&decoder, pc);
if (decoder.Validate(pc, operand)) {
os << " // function #" << operand.index << ": " << *operand.sig;
}
break;
}
default:
break;
}
}
pc += length;
printf("\n");
......
......@@ -459,8 +459,9 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
//-------------------------------------------------------------------------
// First pass: compile each function and initialize the code table.
index = 0;
for (const WasmFunction& func : functions) {
index = FLAG_skip_compiling_wasm_funcs;
while (index < functions.size()) {
const WasmFunction& func = functions[index];
if (thrower.error()) break;
DCHECK_EQ(index, func.func_index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment