Commit efa03836 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][cleanup] Use enums for template parameter values instead of bool

Calls like read_leb<int32_t, true, true, true>(...) can be hard to read
and understand. This CL replaces the three boolean template parameters
with enums so that the call is read_leb<int32_t, kChecked, kAdvancePC, kTrace>(...)
now.

R=clemensh@chromium.org

Bug: v8:6921
Change-Id: Id876a727d5e17df721444e7e5a117ad5395071aa
Reviewed-on: https://chromium-review.googlesource.com/718204
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48607}
parent d0e3fb4f
......@@ -43,6 +43,12 @@ using DecodeResult = Result<std::nullptr_t>;
// a buffer of bytes.
class Decoder {
public:
enum ValidateFlag : bool { kValidate = true, kNoValidate = false };
enum AdvancePCFlag : bool { kAdvancePc = true, kNoAdvancePc = false };
enum TraceFlag : bool { kTrace = true, kNoTrace = false };
Decoder(const byte* start, const byte* end, uint32_t buffer_offset = 0)
: start_(start), pc_(start), end_(end), buffer_offset_(buffer_offset) {}
Decoder(const byte* start, const byte* pc, const byte* end,
......@@ -51,7 +57,7 @@ class Decoder {
virtual ~Decoder() {}
inline bool check(const byte* pc, uint32_t length, const char* msg) {
inline bool validate_size(const byte* pc, uint32_t length, const char* msg) {
DCHECK_LE(start_, pc);
if (V8_UNLIKELY(pc + length > end_)) {
error(pc, msg);
......@@ -61,58 +67,62 @@ class Decoder {
}
// Reads an 8-bit unsigned integer.
template <bool checked>
template <ValidateFlag validate>
inline uint8_t read_u8(const byte* pc, const char* msg = "expected 1 byte") {
return read_little_endian<uint8_t, checked>(pc, msg);
return read_little_endian<uint8_t, validate>(pc, msg);
}
// Reads a 16-bit unsigned integer (little endian).
template <bool checked>
template <ValidateFlag validate>
inline uint16_t read_u16(const byte* pc,
const char* msg = "expected 2 bytes") {
return read_little_endian<uint16_t, checked>(pc, msg);
return read_little_endian<uint16_t, validate>(pc, msg);
}
// Reads a 32-bit unsigned integer (little endian).
template <bool checked>
template <ValidateFlag validate>
inline uint32_t read_u32(const byte* pc,
const char* msg = "expected 4 bytes") {
return read_little_endian<uint32_t, checked>(pc, msg);
return read_little_endian<uint32_t, validate>(pc, msg);
}
// Reads a 64-bit unsigned integer (little endian).
template <bool checked>
template <ValidateFlag validate>
inline uint64_t read_u64(const byte* pc,
const char* msg = "expected 8 bytes") {
return read_little_endian<uint64_t, checked>(pc, msg);
return read_little_endian<uint64_t, validate>(pc, msg);
}
// Reads a variable-length unsigned integer (little endian).
template <bool checked>
template <ValidateFlag validate>
uint32_t read_u32v(const byte* pc, uint32_t* length,
const char* name = "LEB32") {
return read_leb<uint32_t, checked, false, false>(pc, length, name);
return read_leb<uint32_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
}
// Reads a variable-length signed integer (little endian).
template <bool checked>
template <ValidateFlag validate>
int32_t read_i32v(const byte* pc, uint32_t* length,
const char* name = "signed LEB32") {
return read_leb<int32_t, checked, false, false>(pc, length, name);
return read_leb<int32_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
}
// Reads a variable-length unsigned integer (little endian).
template <bool checked>
template <ValidateFlag validate>
uint64_t read_u64v(const byte* pc, uint32_t* length,
const char* name = "LEB64") {
return read_leb<uint64_t, checked, false, false>(pc, length, name);
return read_leb<uint64_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
}
// Reads a variable-length signed integer (little endian).
template <bool checked>
template <ValidateFlag validate>
int64_t read_i64v(const byte* pc, uint32_t* length,
const char* name = "signed LEB64") {
return read_leb<int64_t, checked, false, false>(pc, length, name);
return read_leb<int64_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
}
// Reads a 8-bit unsigned integer (byte) and advances {pc_}.
......@@ -133,13 +143,14 @@ class Decoder {
// Reads a LEB128 variable-length unsigned 32-bit integer and advances {pc_}.
uint32_t consume_u32v(const char* name = nullptr) {
uint32_t length = 0;
return read_leb<uint32_t, true, true, true>(pc_, &length, name);
return read_leb<uint32_t, kValidate, kAdvancePc, kTrace>(pc_, &length,
name);
}
// Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}.
int32_t consume_i32v(const char* name = nullptr) {
uint32_t length = 0;
return read_leb<int32_t, true, true, true>(pc_, &length, name);
return read_leb<int32_t, kValidate, kAdvancePc, kTrace>(pc_, &length, name);
}
// Consume {size} bytes and send them to the bit bucket, advancing {pc_}.
......@@ -261,11 +272,11 @@ class Decoder {
std::string error_msg_;
private:
template <typename IntType, bool checked>
template <typename IntType, bool validate>
inline IntType read_little_endian(const byte* pc, const char* msg) {
if (!checked) {
DCHECK(check(pc, sizeof(IntType), msg));
} else if (!check(pc, sizeof(IntType), msg)) {
if (!validate) {
DCHECK(validate_size(pc, sizeof(IntType), msg));
} else if (!validate_size(pc, sizeof(IntType), msg)) {
return IntType{0};
}
return ReadLittleEndianValue<IntType>(pc);
......@@ -286,17 +297,18 @@ class Decoder {
return val;
}
template <typename IntType, bool checked, bool advance_pc, bool trace>
template <typename IntType, ValidateFlag validate, AdvancePCFlag advance_pc,
TraceFlag trace>
inline IntType read_leb(const byte* pc, uint32_t* length,
const char* name = "varint") {
DCHECK_IMPLIES(advance_pc, pc == pc_);
TRACE_IF(trace, " +%u %-20s: ", pc_offset(), name);
return read_leb_tail<IntType, checked, advance_pc, trace, 0>(pc, length,
name, 0);
return read_leb_tail<IntType, validate, advance_pc, trace, 0>(pc, length,
name, 0);
}
template <typename IntType, bool checked, bool advance_pc, bool trace,
int byte_index>
template <typename IntType, ValidateFlag validate, AdvancePCFlag advance_pc,
TraceFlag trace, int byte_index>
IntType read_leb_tail(const byte* pc, uint32_t* length, const char* name,
IntType result) {
constexpr bool is_signed = std::is_signed<IntType>::value;
......@@ -304,7 +316,7 @@ class Decoder {
static_assert(byte_index < kMaxLength, "invalid template instantiation");
constexpr int shift = byte_index * 7;
constexpr bool is_last_byte = byte_index == kMaxLength - 1;
const bool at_end = checked && pc >= end_;
const bool at_end = validate && pc >= end_;
byte b = 0;
if (!at_end) {
DCHECK_LT(pc, end_);
......@@ -317,12 +329,12 @@ class Decoder {
// Compilers are not smart enough to figure out statically that the
// following call is unreachable if is_last_byte is false.
constexpr int next_byte_index = byte_index + (is_last_byte ? 0 : 1);
return read_leb_tail<IntType, checked, advance_pc, trace,
return read_leb_tail<IntType, validate, advance_pc, trace,
next_byte_index>(pc + 1, length, name, result);
}
if (advance_pc) pc_ = pc + (at_end ? 0 : 1);
*length = byte_index + (at_end ? 0 : 1);
if (checked && (at_end || (b & 0x80))) {
if (validate && (at_end || (b & 0x80))) {
TRACE_IF(trace, at_end ? "<end> " : "<length overflow> ");
errorf(pc, "expected %s", name);
result = 0;
......@@ -341,7 +353,7 @@ class Decoder {
bool valid_extra_bits =
checked_bits == 0 ||
(is_signed && checked_bits == kSignExtendedExtraBits);
if (!checked) {
if (!validate) {
DCHECK(valid_extra_bits);
} else if (!valid_extra_bits) {
error(pc, "extra bits in varint");
......
......@@ -87,7 +87,7 @@ Vector<T> vec2vec(std::vector<T>& vec) {
}
// Helpers for decoding different kinds of operands which follow bytecodes.
template <bool validate>
template <Decoder::ValidateFlag validate>
struct LocalIndexOperand {
uint32_t index;
ValueType type = kWasmStmt;
......@@ -98,7 +98,7 @@ struct LocalIndexOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct ExceptionIndexOperand {
uint32_t index;
const WasmException* exception = nullptr;
......@@ -109,7 +109,7 @@ struct ExceptionIndexOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct ImmI32Operand {
int32_t value;
unsigned length;
......@@ -118,7 +118,7 @@ struct ImmI32Operand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct ImmI64Operand {
int64_t value;
unsigned length;
......@@ -127,7 +127,7 @@ struct ImmI64Operand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct ImmF32Operand {
float value;
unsigned length = 4;
......@@ -138,7 +138,7 @@ struct ImmF32Operand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct ImmF64Operand {
double value;
unsigned length = 8;
......@@ -149,7 +149,7 @@ struct ImmF64Operand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct GlobalIndexOperand {
uint32_t index;
ValueType type = kWasmStmt;
......@@ -161,7 +161,7 @@ struct GlobalIndexOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct BlockTypeOperand {
unsigned length = 1;
ValueType type = kWasmStmt;
......@@ -235,7 +235,7 @@ struct BlockTypeOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct BreakDepthOperand {
uint32_t depth;
unsigned length;
......@@ -244,7 +244,7 @@ struct BreakDepthOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct CallIndirectOperand {
uint32_t table_index;
uint32_t index;
......@@ -262,7 +262,7 @@ struct CallIndirectOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct CallFunctionOperand {
uint32_t index;
FunctionSig* sig = nullptr;
......@@ -272,7 +272,7 @@ struct CallFunctionOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct MemoryIndexOperand {
uint32_t index;
unsigned length = 1;
......@@ -284,7 +284,7 @@ struct MemoryIndexOperand {
}
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct BranchTableOperand {
uint32_t table_count;
const byte* start;
......@@ -299,7 +299,7 @@ struct BranchTableOperand {
};
// A helper to iterate over a branch table.
template <bool validate>
template <Decoder::ValidateFlag validate>
class BranchTableIterator {
public:
unsigned cur_index() { return index_; }
......@@ -337,7 +337,7 @@ class BranchTableIterator {
uint32_t table_count_; // the count of entries, not including default.
};
template <bool validate>
template <Decoder::ValidateFlag validate>
struct MemoryAccessOperand {
uint32_t alignment;
uint32_t offset;
......@@ -361,7 +361,7 @@ struct MemoryAccessOperand {
};
// Operand for SIMD lane operations.
template <bool validate>
template <Decoder::ValidateFlag validate>
struct SimdLaneOperand {
uint8_t lane;
unsigned length = 1;
......@@ -372,7 +372,7 @@ struct SimdLaneOperand {
};
// Operand for SIMD shift operations.
template <bool validate>
template <Decoder::ValidateFlag validate>
struct SimdShiftOperand {
uint8_t shift;
unsigned length = 1;
......@@ -383,7 +383,7 @@ struct SimdShiftOperand {
};
// Operand for SIMD S8x16 shuffle operations.
template <bool validate>
template <Decoder::ValidateFlag validate>
struct Simd8x16ShuffleOperand {
uint8_t shuffle[kSimd128Size];
......@@ -606,7 +606,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> {
// Generic Wasm bytecode decoder with utilities for decoding operands,
// lengths, etc.
template <bool validate>
template <Decoder::ValidateFlag validate>
class WasmDecoder : public Decoder {
public:
WasmDecoder(const WasmModule* module, FunctionSig* sig, const byte* start,
......@@ -703,7 +703,7 @@ class WasmDecoder : public Decoder {
break;
case kExprSetLocal: // fallthru
case kExprTeeLocal: {
LocalIndexOperand<validate> operand(decoder, pc);
LocalIndexOperand<Decoder::kValidate> operand(decoder, pc);
if (assigned->length() > 0 &&
operand.index < static_cast<uint32_t>(assigned->length())) {
// Unverified code might have an out-of-bounds index.
......@@ -733,7 +733,8 @@ class WasmDecoder : public Decoder {
return decoder->ok() ? assigned : nullptr;
}
inline bool Validate(const byte* pc, LocalIndexOperand<validate>& operand) {
inline bool Validate(const byte* pc,
LocalIndexOperand<Decoder::kValidate>& operand) {
if (!VALIDATE(operand.index < total_locals())) {
errorf(pc + 1, "invalid local index: %u", operand.index);
return false;
......@@ -943,7 +944,7 @@ class WasmDecoder : public Decoder {
case kExprSetLocal:
case kExprTeeLocal:
case kExprGetLocal: {
LocalIndexOperand<validate> operand(decoder, pc);
LocalIndexOperand<Decoder::kValidate> operand(decoder, pc);
return 1 + operand.length;
}
case kExprBrTable: {
......@@ -1103,7 +1104,7 @@ class WasmDecoder : public Decoder {
} \
} while (false)
template <bool validate, typename Interface>
template <Decoder::ValidateFlag validate, typename Interface>
class WasmFullDecoder : public WasmDecoder<validate> {
using Value = typename Interface::Value;
using Control = typename Interface::Control;
......@@ -1321,7 +1322,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
case kExprThrow: {
CHECK_PROTOTYPE_OPCODE(eh);
ExceptionIndexOperand<true> operand(this, this->pc_);
ExceptionIndexOperand<Decoder::kValidate> operand(this, this->pc_);
len = 1 + operand.length;
if (!this->Validate(this->pc_, operand)) break;
std::vector<Value> args;
......@@ -1344,7 +1345,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprCatch: {
// TODO(kschimpf): Fix to use type signature of exception.
CHECK_PROTOTYPE_OPCODE(eh);
ExceptionIndexOperand<true> operand(this, this->pc_);
ExceptionIndexOperand<Decoder::kValidate> operand(this, this->pc_);
len = 1 + operand.length;
if (!this->Validate(this->pc_, operand)) break;
......@@ -1576,7 +1577,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
case kExprGetLocal: {
LocalIndexOperand<validate> operand(this, this->pc_);
LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break;
auto* value = Push(operand.type);
CALL_INTERFACE_IF_REACHABLE(GetLocal, value, operand);
......@@ -1584,7 +1585,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
case kExprSetLocal: {
LocalIndexOperand<validate> operand(this, this->pc_);
LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break;
auto value = Pop(0, local_type_vec_[operand.index]);
CALL_INTERFACE_IF_REACHABLE(SetLocal, value, operand);
......@@ -1592,7 +1593,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
case kExprTeeLocal: {
LocalIndexOperand<validate> operand(this, this->pc_);
LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break;
auto value = Pop(0, local_type_vec_[operand.index]);
auto* result = Push(value.type);
......@@ -1822,7 +1823,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprGetLocal:
case kExprSetLocal:
case kExprTeeLocal: {
LocalIndexOperand<validate> operand(this, val.pc);
LocalIndexOperand<Decoder::kValidate> operand(this, val.pc);
PrintF("[%u]", operand.index);
break;
}
......@@ -2330,7 +2331,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
class EmptyInterface {
public:
constexpr static bool validate = true;
static constexpr wasm::Decoder::ValidateFlag validate =
wasm::Decoder::kValidate;
using Value = ValueBase;
using Control = ControlBase<Value>;
using Decoder = WasmFullDecoder<validate, EmptyInterface>;
......
This diff is collapsed.
......@@ -178,7 +178,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
}
WasmOpcode current() {
return static_cast<WasmOpcode>(read_u8<false>(pc_, "expected bytecode"));
return static_cast<WasmOpcode>(
read_u8<Decoder::kNoValidate>(pc_, "expected bytecode"));
}
void next() {
......@@ -191,8 +192,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
bool has_next() { return pc_ < end_; }
WasmOpcode prefixed_opcode() {
byte prefix = read_u8<false>(pc_, "expected prefix");
byte index = read_u8<false>(pc_ + 1, "expected index");
byte prefix = read_u8<Decoder::kNoValidate>(pc_, "expected prefix");
byte index = read_u8<Decoder::kNoValidate>(pc_ + 1, "expected index");
return static_cast<WasmOpcode>(prefix << 8 | index);
}
};
......
......@@ -1177,7 +1177,7 @@ class ModuleDecoderImpl : public Decoder {
unsigned len = 0;
switch (opcode) {
case kExprGetGlobal: {
GlobalIndexOperand<true> operand(this, pc() - 1);
GlobalIndexOperand<Decoder::kValidate> operand(this, pc() - 1);
if (module->globals.size() <= operand.index) {
error("global index is out of bounds");
expr.kind = WasmInitExpr::kNone;
......@@ -1199,28 +1199,28 @@ class ModuleDecoderImpl : public Decoder {
break;
}
case kExprI32Const: {
ImmI32Operand<true> operand(this, pc() - 1);
ImmI32Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kI32Const;
expr.val.i32_const = operand.value;
len = operand.length;
break;
}
case kExprF32Const: {
ImmF32Operand<true> operand(this, pc() - 1);
ImmF32Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kF32Const;
expr.val.f32_const = operand.value;
len = operand.length;
break;
}
case kExprI64Const: {
ImmI64Operand<true> operand(this, pc() - 1);
ImmI64Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kI64Const;
expr.val.i64_const = operand.value;
len = operand.length;
break;
}
case kExprF64Const: {
ImmF64Operand<true> operand(this, pc() - 1);
ImmF64Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kF64Const;
expr.val.f64_const = operand.value;
len = operand.length;
......
This diff is collapsed.
......@@ -101,7 +101,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
case kExprIf:
case kExprBlock:
case kExprTry: {
BlockTypeOperand<false> operand(&i, i.pc());
BlockTypeOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode);
if (operand.type == kWasmVar) {
os << " (type " << operand.sig_index << ")";
......@@ -113,7 +113,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
}
case kExprBr:
case kExprBrIf: {
BreakDepthOperand<false> operand(&i, i.pc());
BreakDepthOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.depth;
break;
}
......@@ -125,45 +125,45 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
os << "end";
break;
case kExprBrTable: {
BranchTableOperand<false> operand(&i, i.pc());
BranchTableIterator<false> iterator(&i, operand);
BranchTableOperand<Decoder::kNoValidate> operand(&i, i.pc());
BranchTableIterator<Decoder::kNoValidate> iterator(&i, operand);
os << "br_table";
while (iterator.has_next()) os << ' ' << iterator.next();
break;
}
case kExprCallIndirect: {
CallIndirectOperand<false> operand(&i, i.pc());
CallIndirectOperand<Decoder::kNoValidate> operand(&i, i.pc());
DCHECK_EQ(0, operand.table_index);
os << "call_indirect " << operand.index;
break;
}
case kExprCallFunction: {
CallFunctionOperand<false> operand(&i, i.pc());
CallFunctionOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << "call " << operand.index;
break;
}
case kExprGetLocal:
case kExprSetLocal:
case kExprTeeLocal: {
LocalIndexOperand<false> operand(&i, i.pc());
LocalIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break;
}
case kExprThrow:
case kExprCatch: {
ExceptionIndexOperand<false> operand(&i, i.pc());
ExceptionIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break;
}
case kExprGetGlobal:
case kExprSetGlobal: {
GlobalIndexOperand<false> operand(&i, i.pc());
GlobalIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break;
}
#define CASE_CONST(type, str, cast_type) \
case kExpr##type##Const: { \
Imm##type##Operand<false> operand(&i, i.pc()); \
Imm##type##Operand<Decoder::kNoValidate> operand(&i, i.pc()); \
os << #str ".const " << static_cast<cast_type>(operand.value); \
break; \
}
......@@ -176,7 +176,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
#define CASE_OPCODE(opcode, _, __) case kExpr##opcode:
FOREACH_LOAD_MEM_OPCODE(CASE_OPCODE)
FOREACH_STORE_MEM_OPCODE(CASE_OPCODE) {
MemoryAccessOperand<false> operand(&i, i.pc(), kMaxUInt32);
MemoryAccessOperand<Decoder::kNoValidate> operand(&i, i.pc(),
kMaxUInt32);
os << WasmOpcodes::OpcodeName(opcode) << " offset=" << operand.offset
<< " align=" << (1ULL << operand.alignment);
break;
......@@ -196,7 +197,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
WasmOpcode atomic_opcode = i.prefixed_opcode();
switch (atomic_opcode) {
FOREACH_ATOMIC_OPCODE(CASE_OPCODE) {
MemoryAccessOperand<false> operand(&i, i.pc(), kMaxUInt32);
MemoryAccessOperand<Decoder::kNoValidate> operand(&i, i.pc(),
kMaxUInt32);
os << WasmOpcodes::OpcodeName(atomic_opcode)
<< " offset=" << operand.offset
<< " align=" << (1ULL << operand.alignment);
......
This diff is collapsed.
......@@ -2533,15 +2533,15 @@ class BranchTableIteratorTest : public TestWithZone {
BranchTableIteratorTest() : TestWithZone() {}
void CheckBrTableSize(const byte* start, const byte* end) {
Decoder decoder(start, end);
BranchTableOperand<true> operand(&decoder, start);
BranchTableIterator<true> iterator(&decoder, operand);
BranchTableOperand<Decoder::kValidate> operand(&decoder, start);
BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand);
EXPECT_EQ(end - start - 1u, iterator.length());
EXPECT_TRUE(decoder.ok());
}
void CheckBrTableError(const byte* start, const byte* end) {
Decoder decoder(start, end);
BranchTableOperand<true> operand(&decoder, start);
BranchTableIterator<true> iterator(&decoder, operand);
BranchTableOperand<Decoder::kValidate> operand(&decoder, start);
BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand);
iterator.length();
EXPECT_FALSE(decoder.ok());
}
......
......@@ -88,19 +88,19 @@ TEST_F(LEBHelperTest, sizeof_i32v) {
}
}
#define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \
static void CheckEncodeDecode_##name(ctype val) { \
static const int kSize = 16; \
static byte buffer[kSize]; \
byte* ptr = buffer; \
LEBHelper::write_##name(&ptr, val); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), \
static_cast<size_t>(ptr - buffer)); \
Decoder decoder(buffer, buffer + kSize); \
unsigned length = 0; \
ctype result = decoder.read_##name<false>(buffer, &length); \
EXPECT_EQ(val, result); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \
#define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \
static void CheckEncodeDecode_##name(ctype val) { \
static const int kSize = 16; \
static byte buffer[kSize]; \
byte* ptr = buffer; \
LEBHelper::write_##name(&ptr, val); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), \
static_cast<size_t>(ptr - buffer)); \
Decoder decoder(buffer, buffer + kSize); \
unsigned length = 0; \
ctype result = decoder.read_##name<Decoder::kNoValidate>(buffer, &length); \
EXPECT_EQ(val, result); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \
}
DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v)
......
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