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

[wasm] Cleanup AST decoder. Remove Tree and TreeResult.

R=ahaas@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2110053002
Cr-Commit-Position: refs/heads/master@{#37387}
parent e0c87cfc
......@@ -29,7 +29,7 @@ namespace wasm {
struct ModuleEnv;
struct WasmFunction;
class ErrorThrower;
struct Tree;
struct DecodeStruct;
// Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}.
typedef compiler::Node TFNode;
......@@ -72,7 +72,7 @@ class WasmCompilationUnit final {
CompilationInfo info_;
base::SmartPointer<CompilationJob> job_;
uint32_t index_;
wasm::Result<wasm::Tree*> graph_construction_result_;
wasm::Result<wasm::DecodeStruct*> graph_construction_result_;
bool ok_;
};
......
......@@ -31,17 +31,6 @@ namespace wasm {
#define TRACE(...)
#endif
// The root of a decoded tree.
struct Tree {
LocalType type; // tree type.
uint32_t count; // number of children.
const byte* pc; // start of the syntax tree.
TFNode* node; // node in the TurboFan graph.
Tree* children[1]; // pointers to children.
WasmOpcode opcode() const { return static_cast<WasmOpcode>(*pc); }
};
// An SsaEnv environment carries the current local variable renaming
// as well as the current effect and control dependency in the TF graph.
// It maintains a control state that tracks whether the environment
......@@ -385,11 +374,11 @@ class WasmDecoder : public Decoder {
}
};
// A shift-reduce-parser strategy for decoding Wasm code that uses an explicit
// shift-reduce strategy with multiple internal stacks.
class SR_WasmDecoder : public WasmDecoder {
// The full WASM decoder for bytecode. Both verifies bytecode and generates
// a TurboFan IR graph.
class WasmFullDecoder : public WasmDecoder {
public:
SR_WasmDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body)
WasmFullDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body)
: WasmDecoder(body.module, body.sig, body.start, body.end),
zone_(zone),
builder_(builder),
......@@ -1471,39 +1460,24 @@ bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start,
base::AccountingAllocator allocator;
Zone tmp(&allocator);
FunctionBody body = {nullptr, nullptr, nullptr, start, end};
SR_WasmDecoder decoder(&tmp, nullptr, body);
WasmFullDecoder decoder(&tmp, nullptr, body);
return decoder.DecodeLocalDecls(decls);
}
TreeResult VerifyWasmCode(base::AccountingAllocator* allocator,
FunctionBody& body) {
DecodeResult VerifyWasmCode(base::AccountingAllocator* allocator,
FunctionBody& body) {
Zone zone(allocator);
SR_WasmDecoder decoder(&zone, nullptr, body);
WasmFullDecoder decoder(&zone, nullptr, body);
decoder.Decode();
return decoder.toResult<Tree*>(nullptr);
return decoder.toResult<DecodeStruct*>(nullptr);
}
TreeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, FunctionBody& body) {
DecodeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, FunctionBody& body) {
Zone zone(allocator);
SR_WasmDecoder decoder(&zone, builder, body);
WasmFullDecoder decoder(&zone, builder, body);
decoder.Decode();
return decoder.toResult<Tree*>(nullptr);
}
std::ostream& operator<<(std::ostream& os, const Tree& tree) {
if (tree.pc == nullptr) {
os << "null";
return os;
}
PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode()));
if (tree.count > 0) os << "(";
for (uint32_t i = 0; i < tree.count; ++i) {
if (i > 0) os << ", ";
os << *tree.children[i];
}
if (tree.count > 0) os << ")";
return os;
return decoder.toResult<DecodeStruct*>(nullptr);
}
unsigned OpcodeLength(const byte* pc, const byte* end) {
......@@ -1526,7 +1500,7 @@ bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
std::ostream& os,
std::vector<std::tuple<uint32_t, int, int>>* offset_table) {
Zone zone(allocator);
SR_WasmDecoder decoder(&zone, nullptr, body);
WasmFullDecoder decoder(&zone, nullptr, body);
int line_nr = 0;
// Print the function signature.
......@@ -1655,7 +1629,7 @@ bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
const byte* start, const byte* end) {
FunctionBody body = {nullptr, nullptr, nullptr, start, end};
SR_WasmDecoder decoder(zone, nullptr, body);
WasmFullDecoder decoder(zone, nullptr, body);
return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
}
......
......@@ -222,15 +222,18 @@ static inline FunctionBody FunctionBodyForTesting(const byte* start,
return {nullptr, nullptr, start, start, end};
}
struct Tree;
typedef Result<Tree*> TreeResult;
std::ostream& operator<<(std::ostream& os, const Tree& tree);
struct DecodeStruct {
int unused;
};
typedef Result<DecodeStruct*> DecodeResult;
inline std::ostream& operator<<(std::ostream& os, const DecodeStruct& tree) {
return os;
}
TreeResult VerifyWasmCode(base::AccountingAllocator* allocator,
FunctionBody& body);
TreeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, FunctionBody& body);
DecodeResult VerifyWasmCode(base::AccountingAllocator* allocator,
FunctionBody& body);
DecodeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, FunctionBody& body);
bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
std::ostream& os,
std::vector<std::tuple<uint32_t, int, int>>* offset_table);
......@@ -238,17 +241,17 @@ bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
// A simplified form of AST printing, e.g. from a debugger.
void PrintAstForDebugging(const byte* start, const byte* end);
inline TreeResult VerifyWasmCode(base::AccountingAllocator* allocator,
ModuleEnv* module, FunctionSig* sig,
const byte* start, const byte* end) {
inline DecodeResult VerifyWasmCode(base::AccountingAllocator* allocator,
ModuleEnv* module, FunctionSig* sig,
const byte* start, const byte* end) {
FunctionBody body = {module, sig, nullptr, start, end};
return VerifyWasmCode(allocator, body);
}
inline TreeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, ModuleEnv* module,
FunctionSig* sig, const byte* start,
const byte* end) {
inline DecodeResult BuildTFGraph(base::AccountingAllocator* allocator,
TFBuilder* builder, ModuleEnv* module,
FunctionSig* sig, const byte* start,
const byte* end) {
FunctionBody body = {module, sig, nullptr, start, end};
return BuildTFGraph(allocator, builder, body);
}
......
......@@ -546,7 +546,7 @@ class ModuleDecoder : public Decoder {
FunctionBody body = {menv, function->sig, start_,
start_ + function->code_start_offset,
start_ + function->code_end_offset};
TreeResult result = VerifyWasmCode(module_zone->allocator(), body);
DecodeResult result = VerifyWasmCode(module_zone->allocator(), body);
if (result.failed()) {
// Wrap the error message from the function decoder.
std::ostringstream str;
......
......@@ -269,7 +269,7 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
SourcePositionTable* source_position_table,
const byte* start, const byte* end) {
compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table);
TreeResult result =
DecodeResult result =
BuildTFGraph(zone->allocator(), &builder, module, sig, start, end);
if (result.failed()) {
ptrdiff_t pc = result.error_pc - result.start;
......
......@@ -84,7 +84,7 @@ class AstDecoderTest : public TestWithZone {
const byte* end) {
local_decls.Prepend(zone(), &start, &end);
// Verify the code.
TreeResult result =
DecodeResult result =
VerifyWasmCode(zone()->allocator(), module, sig, start, end);
if (result.error_code != expected) {
......
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