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

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

Issue 2050213002: [wasm] Implement AST printing into an ostream (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@refactor-function-names-table
Patch Set: see if adding <functional> include fixes this Created 4 years, 6 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
« src/wasm/ast-decoder.h ('K') | « src/wasm/ast-decoder.h ('k') | no next file » | 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 390a67300a34a22640952dc5bc92339d341217f7..9d1debcbcaab68bb0b955cf2ec1dac923cdbc2aa 100644
--- a/src/wasm/ast-decoder.cc
+++ b/src/wasm/ast-decoder.cc
@@ -148,7 +148,8 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc, GlobalIndexOperand& operand) {
ModuleEnv* m = module_;
- if (m && m->module && operand.index < m->module->globals.size()) {
+ if (!m || !m->module) return false;
titzer 2016/06/10 10:57:40 This change means that there will not be an error
Clemens Hammacher 2016/06/13 09:45:17 I changed it to have a Complete() and a Validate()
+ if (operand.index < m->module->globals.size()) {
operand.machine_type = m->module->globals[operand.index].type;
operand.type = WasmOpcodes::LocalTypeFor(operand.machine_type);
return true;
@@ -159,7 +160,8 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc, CallFunctionOperand& operand) {
ModuleEnv* m = module_;
- if (m && m->module && operand.index < m->module->functions.size()) {
+ if (!m || !m->module) return false;
+ if (operand.index < m->module->functions.size()) {
operand.sig = m->module->functions[operand.index].sig;
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
@@ -176,7 +178,8 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc, CallIndirectOperand& operand) {
ModuleEnv* m = module_;
- if (m && m->module && operand.index < m->module->signatures.size()) {
+ if (!m || !m->module) return false;
+ if (operand.index < m->module->signatures.size()) {
operand.sig = m->module->signatures[operand.index];
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
@@ -193,7 +196,8 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc, CallImportOperand& operand) {
ModuleEnv* m = module_;
- if (m && m->module && operand.index < m->module->import_table.size()) {
+ if (!m || !m->module) return false;
+ if (operand.index < m->module->import_table.size()) {
operand.sig = m->module->import_table[operand.index].sig;
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
@@ -391,7 +395,7 @@ class WasmDecoder : public Decoder {
// shift-reduce strategy with multiple internal stacks.
class SR_WasmDecoder : public WasmDecoder {
public:
- SR_WasmDecoder(Zone* zone, TFBuilder* builder, FunctionBody& body)
+ SR_WasmDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body)
: WasmDecoder(body.module, body.sig, body.start, body.end),
zone_(zone),
builder_(builder),
@@ -1526,17 +1530,17 @@ int OpcodeArity(const byte* pc, const byte* end) {
}
void PrintAstForDebugging(const byte* start, const byte* end) {
- FunctionBody body = {nullptr, nullptr, start, start, end};
base::AccountingAllocator allocator;
- PrintAst(&allocator, body);
+ OFStream os(stdout);
+ PrintAst(&allocator, FunctionBody::ForTesting(start, end), os);
}
-void PrintAst(base::AccountingAllocator* allocator, FunctionBody& body) {
+bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
+ std::ostream& os,
+ std::function<void(uint32_t)> instruction_callback) {
Zone zone(allocator);
SR_WasmDecoder decoder(&zone, nullptr, body);
- OFStream os(stdout);
-
// Print the function signature.
if (body.sig) {
os << "// signature: " << *body.sig << std::endl;
@@ -1556,24 +1560,29 @@ void PrintAst(base::AccountingAllocator* allocator, FunctionBody& body) {
os << std::endl;
for (const byte* locals = body.start; locals < pc; locals++) {
- printf(" 0x%02x,", *locals);
+ os << (locals == body.start ? "0x" : " 0x") << AsHex(*locals, 2) << ",";
}
os << std::endl;
}
os << "// body: \n";
- int control_depth = 0;
+ unsigned control_depth = 0;
while (pc < body.end) {
size_t length = decoder.OpcodeLength(pc);
WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
if (opcode == kExprElse) control_depth--;
- for (int i = 0; i < control_depth && i < 32; i++) printf(" ");
- printf("k%s,", WasmOpcodes::OpcodeName(opcode));
+ // 32 whitespaces
+ const char* padding = " ";
+ os.write(padding, control_depth < 32 ? control_depth : 32);
+ if (instruction_callback) {
+ instruction_callback(static_cast<int>(pc - body.start));
+ }
+ os << "k" << WasmOpcodes::OpcodeName(opcode) << ",";
for (size_t i = 1; i < length; i++) {
- printf(" 0x%02x,", pc[i]);
+ os << " " << AsHex(pc[i], 2) << ",";
}
switch (opcode) {
@@ -1643,6 +1652,8 @@ void PrintAst(base::AccountingAllocator* allocator, FunctionBody& body) {
pc += length;
os << std::endl;
}
+
+ return decoder.ok();
}
BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
« src/wasm/ast-decoder.h ('K') | « src/wasm/ast-decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698