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

Unified Diff: src/wasm/ast-decoder.cc

Issue 1616973004: [wasm] Add utilities to print out WASM ast directly from the bytes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arm64, use AddIndirectFunctionTable() more. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/ast-decoder.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/ast-decoder.cc
diff --git a/src/wasm/ast-decoder.cc b/src/wasm/ast-decoder.cc
index ffb815771a7c5061a94e15b5925d2c3a9810d4e6..3721ff1cfaf4d07f46d171ddd8369314ad622bce 100644
--- a/src/wasm/ast-decoder.cc
+++ b/src/wasm/ast-decoder.cc
@@ -151,15 +151,20 @@ class LR_WasmDecoder : public Decoder {
}
if (ok()) {
+ if (FLAG_trace_wasm_ast) {
+ PrintAst(function_env, pc, end);
+ }
if (FLAG_trace_wasm_decode_time) {
double ms = decode_timer.Elapsed().InMillisecondsF();
- PrintF(" - decoding took %0.3f ms\n", ms);
+ PrintF("wasm-decode ok (%0.3f ms)\n\n", ms);
+ } else {
+ TRACE("wasm-decode ok\n\n");
}
- TRACE("wasm-decode ok\n\n");
} else {
TRACE("wasm-error module+%-6d func+%d: %s\n\n", baserel(error_pc_),
startrel(error_pc_), error_msg_.get());
}
+
return toResult(tree);
}
@@ -1477,7 +1482,17 @@ int OpcodeLength(const byte* pc) {
FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE)
#undef DECLARE_OPCODE_CASE
-
+ {
+ // Loads and stores have an optional offset.
+ byte bitfield = pc[1];
+ if (MemoryAccess::OffsetField::decode(bitfield)) {
+ int length;
+ uint32_t result = 0;
+ ReadUnsignedLEB128Operand(pc + 2, pc + 7, &length, &result);
+ return 2 + length;
+ }
+ return 2;
+ }
case kExprI8Const:
case kExprBlock:
case kExprLoop:
@@ -1578,6 +1593,37 @@ int OpcodeArity(FunctionEnv* env, const byte* pc) {
UNREACHABLE();
return 0;
}
+
+
+void PrintAst(FunctionEnv* env, const byte* start, const byte* end) {
+ const byte* pc = start;
+ std::vector<int> arity_stack;
+ while (pc < end) {
+ int arity = OpcodeArity(env, pc);
+ size_t length = OpcodeLength(pc);
+
+ for (auto arity : arity_stack) {
+ printf(" ");
+ USE(arity);
+ }
+
+ WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
+ printf("k%s,", WasmOpcodes::OpcodeName(opcode));
+
+ for (size_t i = 1; i < length; i++) {
+ printf(" 0x%02x,", pc[i]);
+ }
+ pc += length;
+ printf("\n");
+
+ arity_stack.push_back(arity);
+ while (arity_stack.back() == 0) {
+ arity_stack.pop_back();
+ if (arity_stack.empty()) break;
+ arity_stack.back()--;
+ }
+ }
+}
} // namespace wasm
} // namespace internal
} // namespace v8
« no previous file with comments | « src/wasm/ast-decoder.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698