Index: src/wasm/ast-decoder.h |
diff --git a/src/wasm/ast-decoder.h b/src/wasm/ast-decoder.h |
index 861733b3695cdf92acca040893b1ff24c179bd93..257b2334fd4d26843ef07d9abf3c8f7897ab1845 100644 |
--- a/src/wasm/ast-decoder.h |
+++ b/src/wasm/ast-decoder.h |
@@ -22,6 +22,7 @@ class WasmGraphBuilder; |
namespace wasm { |
const uint32_t kMaxNumWasmLocals = 8000000; |
+struct WasmGlobal; |
// Helpers for decoding different kinds of operands which follow bytecodes. |
struct LocalIndexOperand { |
@@ -81,39 +82,104 @@ struct ImmF64Operand { |
struct GlobalIndexOperand { |
uint32_t index; |
LocalType type; |
+ const WasmGlobal* global; |
unsigned length; |
inline GlobalIndexOperand(Decoder* decoder, const byte* pc) { |
index = decoder->checked_read_u32v(pc, 1, &length, "global index"); |
+ global = nullptr; |
type = kAstStmt; |
} |
}; |
+struct BlockTypeOperand { |
+ uint32_t arity; |
+ const byte* types; |
ahaas
2016/09/16 11:21:31
What does {types} actually contain? I'm quite sure
titzer
2016/09/16 12:13:21
It points to the first byte where the encoded type
ahaas
2016/09/19 11:36:02
Could you add that as a comment, or call it start_
|
+ unsigned length; |
+ |
+ inline BlockTypeOperand(Decoder* decoder, const byte* pc) { |
+ uint8_t val = decoder->checked_read_u8(pc, 1, "block type"); |
+ LocalType type; |
+ length = 1; |
+ arity = 0; |
+ types = nullptr; |
+ if (decode_local_type(val, &type)) { |
+ arity = type == kAstStmt ? 0 : 1; |
+ types = pc + 1; |
+ } else { |
ahaas
2016/09/16 11:21:31
Could you add a comment about what is happening in
titzer
2016/09/16 12:13:21
Done.
|
+ if (!FLAG_wasm_mv_prototype) { |
+ decoder->error(pc, pc + 1, "invalid block arity > 1"); |
+ return; |
+ } |
+ if (val != kMultivalBlock) { |
+ decoder->error(pc, pc + 1, "invalid block type"); |
+ return; |
+ } |
+ unsigned len = 0; |
+ uint32_t count = decoder->checked_read_u32v(pc, 2, &len, "block arity"); |
+ arity = count + 2; |
ahaas
2016/09/16 11:21:31
please add a comment why arity = count + 2
titzer
2016/09/16 12:13:21
Done.
|
+ length = 1 + len + arity; |
+ types = pc + 1 + 1 + len; |
+ |
+ for (uint32_t i = 0; i < arity; i++) { |
+ uint32_t offset = 1 + 1 + len + i; |
+ val = decoder->checked_read_u8(pc, offset, "block type"); |
+ decode_local_type(val, &type); |
+ if (type == kAstStmt) { |
+ decoder->error(pc, pc + offset, "invalid block type"); |
+ return; |
+ } |
+ } |
+ } |
+ } |
+ bool decode_local_type(uint8_t val, LocalType* result) { |
ahaas
2016/09/16 11:21:31
Could you add a comment which describes the return
titzer
2016/09/16 12:13:21
Done.
|
+ switch (static_cast<LocalTypeCode>(val)) { |
+ case kLocalVoid: |
+ *result = kAstStmt; |
+ return true; |
+ case kLocalI32: |
+ *result = kAstI32; |
+ return true; |
+ case kLocalI64: |
+ *result = kAstI64; |
+ return true; |
+ case kLocalF32: |
+ *result = kAstF32; |
+ return true; |
+ case kLocalF64: |
+ *result = kAstF64; |
+ return true; |
+ default: |
+ *result = kAstStmt; |
+ return false; |
+ } |
+ } |
+ LocalType read_entry(unsigned index) { |
+ DCHECK_LT(index, arity); |
+ LocalType result; |
+ CHECK(decode_local_type(types[index], &result)); |
+ return result; |
+ } |
+}; |
+ |
struct Control; |
struct BreakDepthOperand { |
- uint32_t arity; |
uint32_t depth; |
Control* target; |
unsigned length; |
inline BreakDepthOperand(Decoder* decoder, const byte* pc) { |
- unsigned len1 = 0; |
- unsigned len2 = 0; |
- arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count"); |
- depth = decoder->checked_read_u32v(pc, 1 + len1, &len2, "break depth"); |
- length = len1 + len2; |
+ depth = decoder->checked_read_u32v(pc, 1, &length, "break depth"); |
target = nullptr; |
} |
}; |
struct CallIndirectOperand { |
- uint32_t arity; |
uint32_t index; |
FunctionSig* sig; |
unsigned length; |
inline CallIndirectOperand(Decoder* decoder, const byte* pc) { |
unsigned len1 = 0; |
unsigned len2 = 0; |
- arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count"); |
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "signature index"); |
length = len1 + len2; |
sig = nullptr; |
@@ -121,53 +187,32 @@ struct CallIndirectOperand { |
}; |
struct CallFunctionOperand { |
- uint32_t arity; |
uint32_t index; |
FunctionSig* sig; |
unsigned length; |
inline CallFunctionOperand(Decoder* decoder, const byte* pc) { |
unsigned len1 = 0; |
unsigned len2 = 0; |
- arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count"); |
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "function index"); |
length = len1 + len2; |
sig = nullptr; |
} |
}; |
-struct CallImportOperand { |
- uint32_t arity; |
- uint32_t index; |
- FunctionSig* sig; |
- unsigned length; |
- inline CallImportOperand(Decoder* decoder, const byte* pc) { |
- unsigned len1 = 0; |
- unsigned len2 = 0; |
- arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count"); |
- index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "import index"); |
- length = len1 + len2; |
- sig = nullptr; |
- } |
-}; |
- |
struct BranchTableOperand { |
- uint32_t arity; |
uint32_t table_count; |
const byte* table; |
unsigned length; |
inline BranchTableOperand(Decoder* decoder, const byte* pc) { |
unsigned len1 = 0; |
- unsigned len2 = 0; |
- arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count"); |
- table_count = |
- decoder->checked_read_u32v(pc, 1 + len1, &len2, "table count"); |
+ table_count = decoder->checked_read_u32v(pc, 1, &len1, "table count"); |
if (table_count > (UINT_MAX / sizeof(uint32_t)) - 1 || |
- len1 + len2 > UINT_MAX - (table_count + 1) * sizeof(uint32_t)) { |
+ len1 > UINT_MAX - (table_count + 1) * sizeof(uint32_t)) { |
decoder->error(pc, "branch table size overflow"); |
} |
- length = len1 + len2 + (table_count + 1) * sizeof(uint32_t); |
+ length = len1 + (table_count + 1) * sizeof(uint32_t); |
- uint32_t table_start = 1 + len1 + len2; |
+ uint32_t table_start = 1 + len1; |
if (decoder->check(pc, table_start, (table_count + 1) * sizeof(uint32_t), |
"expected <table entries>")) { |
table = pc + table_start; |
@@ -203,15 +248,6 @@ struct MemoryAccessOperand { |
} |
}; |
-struct ReturnArityOperand { |
- uint32_t arity; |
- unsigned length; |
- |
- inline ReturnArityOperand(Decoder* decoder, const byte* pc) { |
- arity = decoder->checked_read_u32v(pc, 1, &length, "return count"); |
- } |
-}; |
- |
typedef compiler::WasmGraphBuilder TFBuilder; |
struct ModuleEnv; // forward declaration of module interface. |
@@ -285,9 +321,6 @@ BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
// Computes the length of the opcode at the given address. |
unsigned OpcodeLength(const byte* pc, const byte* end); |
-// Computes the arity (number of sub-nodes) of the opcode at the given address. |
-unsigned OpcodeArity(const byte* pc, const byte* end); |
- |
// A simple forward iterator for bytecodes. |
class BytecodeIterator : public Decoder { |
public: |