Commit 1eef0262 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Rename LookupBlockType to Validate

For consistency with the existing Validate/Complete methodology.

Drive-by: Use it in {PrintRawWasmCode}.

R=titzer@chromium.org

Bug: v8:7754
Change-Id: I6f08ad7456ded2bdb9b06bb9f288e2609d4010e7
Reviewed-on: https://chromium-review.googlesource.com/1109793Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53922}
parent bededee4
......@@ -940,8 +940,9 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc,
Simd8x16ShuffleImmediate<validate>& imm) {
uint8_t max_lane = 0;
for (uint32_t i = 0; i < kSimd128Size; ++i)
for (uint32_t i = 0; i < kSimd128Size; ++i) {
max_lane = std::max(max_lane, imm.shuffle[i]);
}
// Shuffle indices must be in [0..31] for a 16 lane shuffle.
if (!VALIDATE(max_lane <= 2 * kSimd128Size)) {
error(pc_ + 2, "invalid shuffle mask");
......@@ -950,6 +951,24 @@ class WasmDecoder : public Decoder {
return true;
}
inline bool Complete(BlockTypeImmediate<validate>& imm) {
if (imm.type != kWasmVar) return true;
if (!VALIDATE((module_ && imm.sig_index < module_->signatures.size()))) {
return false;
}
imm.sig = module_->signatures[imm.sig_index];
return true;
}
inline bool Validate(BlockTypeImmediate<validate>& imm) {
if (!Complete(imm)) {
errorf(pc_, "block type index %u out of bounds (%zu signatures)",
imm.sig_index, module_ ? module_->signatures.size() : 0);
return false;
}
return true;
}
static unsigned OpcodeLength(Decoder* decoder, const byte* pc) {
WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
switch (opcode) {
......@@ -1410,7 +1429,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
case kExprBlock: {
BlockTypeImmediate<validate> imm(this, this->pc_);
if (!LookupBlockType(&imm)) break;
if (!this->Validate(imm)) break;
PopArgs(imm.sig);
auto* block = PushBlock();
SetBlockType(block, imm);
......@@ -1439,7 +1458,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprTry: {
CHECK_PROTOTYPE_OPCODE(eh);
BlockTypeImmediate<validate> imm(this, this->pc_);
if (!LookupBlockType(&imm)) break;
if (!this->Validate(imm)) break;
PopArgs(imm.sig);
auto* try_block = PushTry();
SetBlockType(try_block, imm);
......@@ -1492,7 +1511,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
case kExprLoop: {
BlockTypeImmediate<validate> imm(this, this->pc_);
if (!LookupBlockType(&imm)) break;
if (!this->Validate(imm)) break;
PopArgs(imm.sig);
auto* block = PushLoop();
SetBlockType(&control_.back(), imm);
......@@ -1503,7 +1522,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
case kExprIf: {
BlockTypeImmediate<validate> imm(this, this->pc_);
if (!LookupBlockType(&imm)) break;
if (!this->Validate(imm)) break;
auto cond = Pop(0, kWasmI32);
PopArgs(imm.sig);
if (!VALIDATE(this->ok())) break;
......@@ -2006,22 +2025,6 @@ class WasmFullDecoder : public WasmDecoder<validate> {
current->reachability = kUnreachable;
}
bool LookupBlockType(BlockTypeImmediate<validate>* imm) {
if (imm->type == kWasmVar) {
if (!VALIDATE(this->module_ &&
imm->sig_index < this->module_->signatures.size())) {
this->errorf(
this->pc_, "block type index %u out of bounds (%d signatures)",
imm->sig_index,
static_cast<int>(this->module_ ? this->module_->signatures.size()
: 0));
return false;
}
imm->sig = this->module_->signatures[imm->sig_index];
}
return true;
}
template<typename func>
void InitMerge(Merge<Value>* merge, uint32_t arity, func get_val) {
merge->arity = arity;
......
......@@ -1017,8 +1017,10 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
case kExprTry: {
BlockTypeImmediate<Decoder::kNoValidate> imm(&i, i.pc());
os << " // @" << i.pc_offset();
for (unsigned i = 0; i < imm.out_arity(); i++) {
os << " " << ValueTypes::TypeName(imm.out_type(i));
if (decoder.Complete(imm)) {
for (unsigned i = 0; i < imm.out_arity(); i++) {
os << " " << ValueTypes::TypeName(imm.out_type(i));
}
}
control_depth++;
break;
......
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