Commit 3a56441a authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][cleanup] Move ValueType into its own header file

This CL splits the definition of ValueType and its helper functions
into its own header file.

R=clemensh@chromium.org

Bug: v8:7570
Change-Id: I3aa776edb45839d7d38836e131df45732c685310
Reviewed-on: https://chromium-review.googlesource.com/1021810
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52758}
parent 5043ab6f
......@@ -2336,6 +2336,7 @@ v8_source_set("v8_base") {
"src/wasm/signature-map.h",
"src/wasm/streaming-decoder.cc",
"src/wasm/streaming-decoder.h",
"src/wasm/value-type.h",
"src/wasm/wasm-code-manager.cc",
"src/wasm/wasm-code-manager.h",
"src/wasm/wasm-code-specialization.cc",
......
......@@ -3348,7 +3348,7 @@ void WasmGraphBuilder::BuildWasmInterpreterEntry(uint32_t func_index) {
} else {
// TODO(wasm): Implement multi-return.
DCHECK_EQ(1, sig_->return_count());
MachineType load_rep = wasm::WasmOpcodes::MachineTypeFor(sig_->GetReturn());
MachineType load_rep = wasm::ValueTypes::MachineTypeFor(sig_->GetReturn());
Node* val =
graph()->NewNode(jsgraph()->machine()->Load(load_rep), arg_buffer,
Int32Constant(0), *effect_, *control_);
......@@ -3661,7 +3661,7 @@ Node* WasmGraphBuilder::BuildCallToRuntime(Runtime::FunctionId f,
Node* WasmGraphBuilder::GetGlobal(uint32_t index) {
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(env_->module->globals[index].type);
wasm::ValueTypes::MachineTypeFor(env_->module->globals[index].type);
Node* base = nullptr;
Node* offset = nullptr;
GetGlobalBaseAndOffset(mem_type, env_->module->globals[index].offset, &base,
......@@ -3674,7 +3674,7 @@ Node* WasmGraphBuilder::GetGlobal(uint32_t index) {
Node* WasmGraphBuilder::SetGlobal(uint32_t index, Node* val) {
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(env_->module->globals[index].type);
wasm::ValueTypes::MachineTypeFor(env_->module->globals[index].type);
Node* base = nullptr;
Node* offset = nullptr;
GetGlobalBaseAndOffset(mem_type, env_->module->globals[index].offset, &base,
......@@ -3770,7 +3770,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
const Operator* WasmGraphBuilder::GetSafeLoadOperator(int offset,
wasm::ValueType type) {
int alignment = offset % (1 << ElementSizeLog2Of(type));
MachineType mach_type = wasm::WasmOpcodes::MachineTypeFor(type);
MachineType mach_type = wasm::ValueTypes::MachineTypeFor(type);
if (alignment == 0 || jsgraph()->machine()->UnalignedLoadSupported(type)) {
return jsgraph()->machine()->Load(mach_type);
}
......@@ -3826,7 +3826,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
// Wasm semantics throw on OOB. Introduce explicit bounds check and
// conditioning when not using the trap handler.
index = BoundsCheckMem(wasm::WasmOpcodes::MemSize(memtype), index, offset,
index = BoundsCheckMem(wasm::ValueTypes::MemSize(memtype), index, offset,
position, kCanOmitBoundsCheck);
if (memtype.representation() == MachineRepresentation::kWord8 ||
......@@ -3879,7 +3879,7 @@ Node* WasmGraphBuilder::StoreMem(MachineRepresentation mem_rep, Node* index,
wasm::ValueType type) {
Node* store;
index = BoundsCheckMem(wasm::WasmOpcodes::MemSize(mem_rep), index, offset,
index = BoundsCheckMem(wasm::ValueTypes::MemSize(mem_rep), index, offset,
position, kCanOmitBoundsCheck);
#if defined(V8_TARGET_BIG_ENDIAN)
......@@ -4531,7 +4531,7 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_BINOP(Name, Operation, Type, Prefix) \
case wasm::kExpr##Name: { \
Node* index = \
BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), \
BoundsCheckMem(wasm::ValueTypes::MemSize(MachineType::Type()), \
inputs[0], offset, position, kNeedsBoundsCheck); \
node = graph()->NewNode( \
jsgraph()->machine()->Prefix##Atomic##Operation(MachineType::Type()), \
......@@ -4544,7 +4544,7 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_CMP_EXCHG(Name, Type, Prefix) \
case wasm::kExpr##Name: { \
Node* index = \
BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), \
BoundsCheckMem(wasm::ValueTypes::MemSize(MachineType::Type()), \
inputs[0], offset, position, kNeedsBoundsCheck); \
node = graph()->NewNode( \
jsgraph()->machine()->Prefix##AtomicCompareExchange( \
......@@ -4558,7 +4558,7 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_LOAD_OP(Name, Type, Prefix) \
case wasm::kExpr##Name: { \
Node* index = \
BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), \
BoundsCheckMem(wasm::ValueTypes::MemSize(MachineType::Type()), \
inputs[0], offset, position, kNeedsBoundsCheck); \
node = graph()->NewNode( \
jsgraph()->machine()->Prefix##AtomicLoad(MachineType::Type()), \
......@@ -4571,7 +4571,7 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_STORE_OP(Name, Type, Rep, Prefix) \
case wasm::kExpr##Name: { \
Node* index = \
BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), \
BoundsCheckMem(wasm::ValueTypes::MemSize(MachineType::Type()), \
inputs[0], offset, position, kNeedsBoundsCheck); \
node = graph()->NewNode( \
jsgraph()->machine()->Prefix##AtomicStore(MachineRepresentation::Rep), \
......@@ -4900,11 +4900,11 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
if (name_len + 1 < kMaxNameLen) debug_name[name_len++] = c;
};
for (wasm::ValueType t : sig->parameters()) {
append_name_char(wasm::WasmOpcodes::ShortNameOf(t));
append_name_char(wasm::ValueTypes::ShortNameOf(t));
}
append_name_char(':');
for (wasm::ValueType t : sig->returns()) {
append_name_char(wasm::WasmOpcodes::ShortNameOf(t));
append_name_char(wasm::ValueTypes::ShortNameOf(t));
}
debug_name[name_len] = '\0';
Vector<const char> debug_name_vec(debug_name, name_len);
......
......@@ -8,7 +8,7 @@
#include "src/wasm/baseline/liftoff-assembler.h"
#include "src/assembler.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/value-type.h"
namespace v8 {
namespace internal {
......@@ -1385,7 +1385,7 @@ void LiftoffAssembler::CallC(wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, esp, arg_bytes, *args++, param_type);
arg_bytes += WasmOpcodes::MemSize(param_type);
arg_bytes += ValueTypes::MemSize(param_type);
}
DCHECK_LE(arg_bytes, stack_bytes);
......
......@@ -629,7 +629,7 @@ void LiftoffAssembler::set_num_locals(uint32_t num_locals) {
}
std::ostream& operator<<(std::ostream& os, VarState slot) {
os << WasmOpcodes::TypeName(slot.type()) << ":";
os << ValueTypes::TypeName(slot.type()) << ":";
switch (slot.loc()) {
case VarState::kStack:
return os << "s";
......
......@@ -170,8 +170,7 @@ class LiftoffCompiler {
for (ValueType supported : supported_types) {
if (type == supported) return true;
}
SNPrintF(ArrayVector(buffer), "%s %s", WasmOpcodes::TypeName(type),
context);
SNPrintF(ArrayVector(buffer), "%s %s", ValueTypes::TypeName(type), context);
unsupported(decoder, buffer);
return false;
}
......@@ -578,11 +577,11 @@ class LiftoffCompiler {
// Store arguments on our stack, then align the stack for calling to C.
int param_bytes = 0;
for (ValueType param_type : sig->parameters()) {
param_bytes += WasmOpcodes::MemSize(param_type);
param_bytes += ValueTypes::MemSize(param_type);
}
int out_arg_bytes = out_argument_type == kWasmStmt
? 0
: WasmOpcodes::MemSize(out_argument_type);
: ValueTypes::MemSize(out_argument_type);
int stack_bytes = std::max(param_bytes, out_arg_bytes);
__ CallC(sig, arg_regs, result_regs, out_argument_type, stack_bytes,
ext_ref);
......
......@@ -1110,7 +1110,7 @@ void LiftoffAssembler::CallC(wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, sp, arg_bytes, *args++, param_type);
arg_bytes += WasmOpcodes::MemSize(param_type);
arg_bytes += ValueTypes::MemSize(param_type);
}
DCHECK_LE(arg_bytes, stack_bytes);
......
......@@ -902,7 +902,7 @@ void LiftoffAssembler::CallC(wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, sp, arg_bytes, *args++, param_type);
arg_bytes += WasmOpcodes::MemSize(param_type);
arg_bytes += ValueTypes::MemSize(param_type);
}
DCHECK_LE(arg_bytes, stack_bytes);
......
......@@ -8,7 +8,7 @@
#include "src/wasm/baseline/liftoff-assembler.h"
#include "src/assembler.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/value-type.h"
namespace v8 {
namespace internal {
......@@ -1209,7 +1209,7 @@ void LiftoffAssembler::CallC(wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, Operand(rsp, arg_bytes), *args++, param_type);
arg_bytes += WasmOpcodes::MemSize(param_type);
arg_bytes += ValueTypes::MemSize(param_type);
}
DCHECK_LE(arg_bytes, stack_bytes);
......
......@@ -1957,7 +1957,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (WasmOpcodes::IsPrefixOpcode(opcode)) {
opcode = static_cast<WasmOpcode>(opcode << 8 | *(val.pc + 1));
}
TRACE_PART(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type),
TRACE_PART(" %c@%d:%s", ValueTypes::ShortNameOf(val.type),
static_cast<int>(val.pc - this->start_),
WasmOpcodes::OpcodeName(opcode));
// If the decoder failed, don't try to decode the operands, as this
......@@ -2311,8 +2311,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
expected == kWasmVar)) {
this->errorf(val.pc, "%s[%d] expected type %s, found %s of type %s",
SafeOpcodeNameAt(this->pc_), index,
WasmOpcodes::TypeName(expected), SafeOpcodeNameAt(val.pc),
WasmOpcodes::TypeName(val.type));
ValueTypes::TypeName(expected), SafeOpcodeNameAt(val.pc),
ValueTypes::TypeName(val.type));
}
return val;
}
......@@ -2358,7 +2358,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (!VALIDATE(val.type == kWasmVar)) {
this->errorf(
this->pc_, "type error in merge[%u] (expected %s, got %s)", i,
WasmOpcodes::TypeName(old.type), WasmOpcodes::TypeName(val.type));
ValueTypes::TypeName(old.type), ValueTypes::TypeName(val.type));
return false;
}
val.type = old.type;
......
......@@ -929,7 +929,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
if (decls.type_list[pos] == type) {
++count;
} else {
os << " " << count << " " << WasmOpcodes::TypeName(type);
os << " " << count << " " << ValueTypes::TypeName(type);
type = decls.type_list[pos];
count = 1;
}
......@@ -1003,7 +1003,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
BlockTypeOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << " // @" << i.pc_offset();
for (unsigned i = 0; i < operand.out_arity(); i++) {
os << " " << WasmOpcodes::TypeName(operand.out_type(i));
os << " " << ValueTypes::TypeName(operand.out_type(i));
}
control_depth++;
break;
......
......@@ -26,7 +26,7 @@ size_t LocalDeclEncoder::Emit(byte* buffer) const {
LEBHelper::write_u32v(&pos, static_cast<uint32_t>(local_decls.size()));
for (auto& local_decl : local_decls) {
LEBHelper::write_u32v(&pos, local_decl.first);
*pos = WasmOpcodes::ValueTypeCodeFor(local_decl.second);
*pos = ValueTypes::ValueTypeCodeFor(local_decl.second);
++pos;
}
DCHECK_EQ(Size(), pos - buffer);
......
......@@ -1811,7 +1811,7 @@ void InstanceBuilder::WriteGlobalValue(WasmGlobal& global,
double num = value->Number();
TRACE("init [globals_start=%p + %u] = %lf, type = %s\n",
reinterpret_cast<void*>(raw_buffer_ptr(globals_, 0)), global.offset,
num, WasmOpcodes::TypeName(global.type));
num, ValueTypes::TypeName(global.type));
switch (global.type) {
case kWasmI32:
*GetRawGlobalPtr<int32_t>(global) = static_cast<int32_t>(num);
......
......@@ -958,14 +958,14 @@ class ModuleDecoderImpl : public Decoder {
errorf(pos,
"type mismatch in global initialization "
"(from global #%u), expected %s, got %s",
other_index, WasmOpcodes::TypeName(global->type),
WasmOpcodes::TypeName(module->globals[other_index].type));
other_index, ValueTypes::TypeName(global->type),
ValueTypes::TypeName(module->globals[other_index].type));
}
} else {
if (global->type != TypeOf(module, global->init)) {
errorf(pos, "type error in global initialization, expected %s, got %s",
WasmOpcodes::TypeName(global->type),
WasmOpcodes::TypeName(TypeOf(module, global->init)));
ValueTypes::TypeName(global->type),
ValueTypes::TypeName(TypeOf(module, global->init)));
}
}
}
......@@ -991,8 +991,7 @@ class ModuleDecoderImpl : public Decoder {
return;
}
for (WasmGlobal& global : module->globals) {
byte size =
WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(global.type));
byte size = ValueTypes::MemSize(ValueTypes::MachineTypeFor(global.type));
offset = (offset + size - 1) & ~(size - 1); // align
global.offset = offset;
offset += size;
......@@ -1223,8 +1222,8 @@ class ModuleDecoderImpl : public Decoder {
}
if (expected != kWasmStmt && TypeOf(module, expr) != kWasmI32) {
errorf(pos, "type error in init expression, expected %s, got %s",
WasmOpcodes::TypeName(expected),
WasmOpcodes::TypeName(TypeOf(module, expr)));
ValueTypes::TypeName(expected),
ValueTypes::TypeName(TypeOf(module, expr)));
}
return expr;
}
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_VALUE_TYPE_H_
#define V8_WASM_VALUE_TYPE_H_
#include "src/machine-type.h"
#include "src/wasm/wasm-constants.h"
namespace v8 {
namespace internal {
namespace wasm {
// We reuse the internal machine type to represent WebAssembly types.
// A typedef improves readability without adding a whole new type system.
using ValueType = MachineRepresentation;
constexpr ValueType kWasmStmt = MachineRepresentation::kNone;
constexpr ValueType kWasmI32 = MachineRepresentation::kWord32;
constexpr ValueType kWasmI64 = MachineRepresentation::kWord64;
constexpr ValueType kWasmF32 = MachineRepresentation::kFloat32;
constexpr ValueType kWasmF64 = MachineRepresentation::kFloat64;
constexpr ValueType kWasmS128 = MachineRepresentation::kSimd128;
constexpr ValueType kWasmAnyRef = MachineRepresentation::kTaggedPointer;
constexpr ValueType kWasmVar = MachineRepresentation::kTagged;
// TODO(clemensh): Compute memtype and size from ValueType once we have c++14
// constexpr support.
#define FOREACH_LOAD_TYPE(V) \
V(I32, , Int32, 2) \
V(I32, 8S, Int8, 0) \
V(I32, 8U, Uint8, 0) \
V(I32, 16S, Int16, 1) \
V(I32, 16U, Uint16, 1) \
V(I64, , Int64, 3) \
V(I64, 8S, Int8, 0) \
V(I64, 8U, Uint8, 0) \
V(I64, 16S, Int16, 1) \
V(I64, 16U, Uint16, 1) \
V(I64, 32S, Int32, 2) \
V(I64, 32U, Uint32, 2) \
V(F32, , Float32, 2) \
V(F64, , Float64, 3) \
V(S128, , Simd128, 4)
class LoadType {
public:
enum LoadTypeValue : uint8_t {
#define DEF_ENUM(type, suffix, ...) k##type##Load##suffix,
FOREACH_LOAD_TYPE(DEF_ENUM)
#undef DEF_ENUM
};
// Allow implicit convertion of the enum value to this wrapper.
constexpr LoadType(LoadTypeValue val) // NOLINT(runtime/explicit)
: val_(val) {}
constexpr LoadTypeValue value() const { return val_; }
constexpr unsigned size_log_2() const { return kLoadSizeLog2[val_]; }
constexpr unsigned size() const { return 1 << size_log_2(); }
constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr MachineType mem_type() const { return kMemType[val_]; }
static LoadType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Load;
case kWasmI64:
return kI64Load;
case kWasmF32:
return kF32Load;
case kWasmF64:
return kF64Load;
default:
UNREACHABLE();
}
}
private:
const LoadTypeValue val_;
static constexpr uint8_t kLoadSizeLog2[] = {
#define LOAD_SIZE(_, __, ___, size) size,
FOREACH_LOAD_TYPE(LOAD_SIZE)
#undef LOAD_SIZE
};
static constexpr ValueType kValueType[] = {
#define VALUE_TYPE(type, ...) kWasm##type,
FOREACH_LOAD_TYPE(VALUE_TYPE)
#undef VALUE_TYPE
};
static constexpr MachineType kMemType[] = {
#define MEMTYPE(_, __, memtype, ___) MachineType::memtype(),
FOREACH_LOAD_TYPE(MEMTYPE)
#undef MEMTYPE
};
};
#define FOREACH_STORE_TYPE(V) \
V(I32, , Word32, 2) \
V(I32, 8, Word8, 0) \
V(I32, 16, Word16, 1) \
V(I64, , Word64, 3) \
V(I64, 8, Word8, 0) \
V(I64, 16, Word16, 1) \
V(I64, 32, Word32, 2) \
V(F32, , Float32, 2) \
V(F64, , Float64, 3) \
V(S128, , Simd128, 4)
class StoreType {
public:
enum StoreTypeValue : uint8_t {
#define DEF_ENUM(type, suffix, ...) k##type##Store##suffix,
FOREACH_STORE_TYPE(DEF_ENUM)
#undef DEF_ENUM
};
// Allow implicit convertion of the enum value to this wrapper.
constexpr StoreType(StoreTypeValue val) // NOLINT(runtime/explicit)
: val_(val) {}
constexpr StoreTypeValue value() const { return val_; }
constexpr unsigned size_log_2() const { return kStoreSizeLog2[val_]; }
constexpr unsigned size() const { return 1 << size_log_2(); }
constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr ValueType mem_rep() const { return kMemRep[val_]; }
static StoreType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Store;
case kWasmI64:
return kI64Store;
case kWasmF32:
return kF32Store;
case kWasmF64:
return kF64Store;
default:
UNREACHABLE();
}
}
private:
const StoreTypeValue val_;
static constexpr uint8_t kStoreSizeLog2[] = {
#define STORE_SIZE(_, __, ___, size) size,
FOREACH_STORE_TYPE(STORE_SIZE)
#undef STORE_SIZE
};
static constexpr ValueType kValueType[] = {
#define VALUE_TYPE(type, ...) kWasm##type,
FOREACH_STORE_TYPE(VALUE_TYPE)
#undef VALUE_TYPE
};
static constexpr MachineRepresentation kMemRep[] = {
#define MEMREP(_, __, memrep, ___) MachineRepresentation::k##memrep,
FOREACH_STORE_TYPE(MEMREP)
#undef MEMREP
};
};
// A collection of ValueType-related static methods.
class V8_EXPORT_PRIVATE ValueTypes {
public:
static byte MemSize(MachineType type) {
return MemSize(type.representation());
}
static byte MemSize(ValueType type) { return 1 << ElementSizeLog2Of(type); }
static ValueTypeCode ValueTypeCodeFor(ValueType type) {
switch (type) {
case kWasmI32:
return kLocalI32;
case kWasmI64:
return kLocalI64;
case kWasmF32:
return kLocalF32;
case kWasmF64:
return kLocalF64;
case kWasmS128:
return kLocalS128;
case kWasmAnyRef:
return kLocalAnyRef;
case kWasmStmt:
return kLocalVoid;
default:
UNREACHABLE();
}
}
static MachineType MachineTypeFor(ValueType type) {
switch (type) {
case kWasmI32:
return MachineType::Int32();
case kWasmI64:
return MachineType::Int64();
case kWasmF32:
return MachineType::Float32();
case kWasmF64:
return MachineType::Float64();
case kWasmAnyRef:
return MachineType::TaggedPointer();
case kWasmS128:
return MachineType::Simd128();
case kWasmStmt:
return MachineType::None();
default:
UNREACHABLE();
}
}
static ValueType ValueTypeFor(MachineType type) {
switch (type.representation()) {
case MachineRepresentation::kWord8:
case MachineRepresentation::kWord16:
case MachineRepresentation::kWord32:
return kWasmI32;
case MachineRepresentation::kWord64:
return kWasmI64;
case MachineRepresentation::kFloat32:
return kWasmF32;
case MachineRepresentation::kFloat64:
return kWasmF64;
case MachineRepresentation::kTaggedPointer:
return kWasmAnyRef;
case MachineRepresentation::kSimd128:
return kWasmS128;
default:
UNREACHABLE();
}
}
static char ShortNameOf(ValueType type) {
switch (type) {
case kWasmI32:
return 'i';
case kWasmI64:
return 'l';
case kWasmF32:
return 'f';
case kWasmF64:
return 'd';
case kWasmAnyRef:
return 'r';
case kWasmS128:
return 's';
case kWasmStmt:
return 'v';
case kWasmVar:
return '*';
default:
return '?';
}
}
static const char* TypeName(ValueType type) {
switch (type) {
case kWasmI32:
return "i32";
case kWasmI64:
return "i64";
case kWasmF32:
return "f32";
case kWasmF64:
return "f64";
case kWasmAnyRef:
return "ref";
case kWasmS128:
return "s128";
case kWasmStmt:
return "<stmt>";
case kWasmVar:
return "<var>";
default:
return "<unknown>";
}
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ValueTypes);
};
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_VALUE_TYPE_H_
......@@ -301,7 +301,7 @@ uint32_t WasmModuleBuilder::AddImport(Vector<const char> name,
uint32_t WasmModuleBuilder::AddGlobalImport(Vector<const char> name,
ValueType type) {
global_imports_.push_back({name, WasmOpcodes::ValueTypeCodeFor(type)});
global_imports_.push_back({name, ValueTypes::ValueTypeCodeFor(type)});
return static_cast<uint32_t>(global_imports_.size() - 1);
}
......@@ -346,11 +346,11 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
buffer.write_u8(kWasmFunctionTypeCode);
buffer.write_size(sig->parameter_count());
for (auto param : sig->parameters()) {
buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(param));
buffer.write_u8(ValueTypes::ValueTypeCodeFor(param));
}
buffer.write_size(sig->return_count());
for (auto ret : sig->returns()) {
buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(ret));
buffer.write_u8(ValueTypes::ValueTypeCodeFor(ret));
}
}
FixupSection(buffer, start);
......@@ -423,7 +423,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
buffer.write_size(globals_.size());
for (auto global : globals_) {
buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(global.type));
buffer.write_u8(ValueTypes::ValueTypeCodeFor(global.type));
buffer.write_u8(global.mutability ? 1 : 0);
switch (global.init.kind) {
case WasmInitExpr::kI32Const:
......
......@@ -363,12 +363,12 @@ bool WasmOpcodes::IsAnyRefOpcode(WasmOpcode opcode) {
std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
if (sig.return_count() == 0) os << "v";
for (auto ret : sig.returns()) {
os << WasmOpcodes::ShortNameOf(ret);
os << ValueTypes::ShortNameOf(ret);
}
os << "_";
if (sig.parameter_count() == 0) os << "v";
for (auto param : sig.parameters()) {
os << WasmOpcodes::ShortNameOf(param);
os << ValueTypes::ShortNameOf(param);
}
return os;
}
......
......@@ -6,8 +6,8 @@
#define V8_WASM_WASM_OPCODES_H_
#include "src/globals.h"
#include "src/machine-type.h"
#include "src/runtime/runtime.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-constants.h"
namespace v8 {
......@@ -18,18 +18,6 @@ class Signature;
namespace wasm {
// We reuse the internal machine type to represent WebAssembly types.
// A typedef improves readability without adding a whole new type system.
using ValueType = MachineRepresentation;
constexpr ValueType kWasmStmt = MachineRepresentation::kNone;
constexpr ValueType kWasmI32 = MachineRepresentation::kWord32;
constexpr ValueType kWasmI64 = MachineRepresentation::kWord64;
constexpr ValueType kWasmF32 = MachineRepresentation::kFloat32;
constexpr ValueType kWasmF64 = MachineRepresentation::kFloat64;
constexpr ValueType kWasmS128 = MachineRepresentation::kSimd128;
constexpr ValueType kWasmAnyRef = MachineRepresentation::kTaggedPointer;
constexpr ValueType kWasmVar = MachineRepresentation::kTagged;
using FunctionSig = Signature<ValueType>;
std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
bool IsJSCompatibleSignature(const FunctionSig* sig);
......@@ -582,148 +570,6 @@ enum TrapReason {
kTrapCount
#undef DECLARE_ENUM
};
// TODO(clemensh): Compute memtype and size from ValueType once we have c++14
// constexpr support.
#define FOREACH_LOAD_TYPE(V) \
V(I32, , Int32, 2) \
V(I32, 8S, Int8, 0) \
V(I32, 8U, Uint8, 0) \
V(I32, 16S, Int16, 1) \
V(I32, 16U, Uint16, 1) \
V(I64, , Int64, 3) \
V(I64, 8S, Int8, 0) \
V(I64, 8U, Uint8, 0) \
V(I64, 16S, Int16, 1) \
V(I64, 16U, Uint16, 1) \
V(I64, 32S, Int32, 2) \
V(I64, 32U, Uint32, 2) \
V(F32, , Float32, 2) \
V(F64, , Float64, 3) \
V(S128, , Simd128, 4)
class LoadType {
public:
enum LoadTypeValue : uint8_t {
#define DEF_ENUM(type, suffix, ...) k##type##Load##suffix,
FOREACH_LOAD_TYPE(DEF_ENUM)
#undef DEF_ENUM
};
// Allow implicit convertion of the enum value to this wrapper.
constexpr LoadType(LoadTypeValue val) // NOLINT(runtime/explicit)
: val_(val) {}
constexpr LoadTypeValue value() const { return val_; }
constexpr unsigned size_log_2() const { return kLoadSizeLog2[val_]; }
constexpr unsigned size() const { return 1 << size_log_2(); }
constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr MachineType mem_type() const { return kMemType[val_]; }
static LoadType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Load;
case kWasmI64:
return kI64Load;
case kWasmF32:
return kF32Load;
case kWasmF64:
return kF64Load;
default:
UNREACHABLE();
}
}
private:
const LoadTypeValue val_;
static constexpr uint8_t kLoadSizeLog2[] = {
#define LOAD_SIZE(_, __, ___, size) size,
FOREACH_LOAD_TYPE(LOAD_SIZE)
#undef LOAD_SIZE
};
static constexpr ValueType kValueType[] = {
#define VALUE_TYPE(type, ...) kWasm##type,
FOREACH_LOAD_TYPE(VALUE_TYPE)
#undef VALUE_TYPE
};
static constexpr MachineType kMemType[] = {
#define MEMTYPE(_, __, memtype, ___) MachineType::memtype(),
FOREACH_LOAD_TYPE(MEMTYPE)
#undef MEMTYPE
};
};
#define FOREACH_STORE_TYPE(V) \
V(I32, , Word32, 2) \
V(I32, 8, Word8, 0) \
V(I32, 16, Word16, 1) \
V(I64, , Word64, 3) \
V(I64, 8, Word8, 0) \
V(I64, 16, Word16, 1) \
V(I64, 32, Word32, 2) \
V(F32, , Float32, 2) \
V(F64, , Float64, 3) \
V(S128, , Simd128, 4)
class StoreType {
public:
enum StoreTypeValue : uint8_t {
#define DEF_ENUM(type, suffix, ...) k##type##Store##suffix,
FOREACH_STORE_TYPE(DEF_ENUM)
#undef DEF_ENUM
};
// Allow implicit convertion of the enum value to this wrapper.
constexpr StoreType(StoreTypeValue val) // NOLINT(runtime/explicit)
: val_(val) {}
constexpr StoreTypeValue value() const { return val_; }
constexpr unsigned size_log_2() const { return kStoreSizeLog2[val_]; }
constexpr unsigned size() const { return 1 << size_log_2(); }
constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr ValueType mem_rep() const { return kMemRep[val_]; }
static StoreType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Store;
case kWasmI64:
return kI64Store;
case kWasmF32:
return kF32Store;
case kWasmF64:
return kF64Store;
default:
UNREACHABLE();
}
}
private:
const StoreTypeValue val_;
static constexpr uint8_t kStoreSizeLog2[] = {
#define STORE_SIZE(_, __, ___, size) size,
FOREACH_STORE_TYPE(STORE_SIZE)
#undef STORE_SIZE
};
static constexpr ValueType kValueType[] = {
#define VALUE_TYPE(type, ...) kWasm##type,
FOREACH_STORE_TYPE(VALUE_TYPE)
#undef VALUE_TYPE
};
static constexpr MachineRepresentation kMemRep[] = {
#define MEMREP(_, __, memrep, ___) MachineRepresentation::k##memrep,
FOREACH_STORE_TYPE(MEMREP)
#undef MEMREP
};
};
// A collection of opcode-related static methods.
class V8_EXPORT_PRIVATE WasmOpcodes {
public:
......@@ -740,121 +586,6 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
static int TrapReasonToMessageId(TrapReason reason);
static const char* TrapReasonMessage(TrapReason reason);
static byte MemSize(MachineType type) {
return MemSize(type.representation());
}
static byte MemSize(ValueType type) { return 1 << ElementSizeLog2Of(type); }
static ValueTypeCode ValueTypeCodeFor(ValueType type) {
switch (type) {
case kWasmI32:
return kLocalI32;
case kWasmI64:
return kLocalI64;
case kWasmF32:
return kLocalF32;
case kWasmF64:
return kLocalF64;
case kWasmS128:
return kLocalS128;
case kWasmAnyRef:
return kLocalAnyRef;
case kWasmStmt:
return kLocalVoid;
default:
UNREACHABLE();
}
}
static MachineType MachineTypeFor(ValueType type) {
switch (type) {
case kWasmI32:
return MachineType::Int32();
case kWasmI64:
return MachineType::Int64();
case kWasmF32:
return MachineType::Float32();
case kWasmF64:
return MachineType::Float64();
case kWasmAnyRef:
return MachineType::TaggedPointer();
case kWasmS128:
return MachineType::Simd128();
case kWasmStmt:
return MachineType::None();
default:
UNREACHABLE();
}
}
static ValueType ValueTypeFor(MachineType type) {
switch (type.representation()) {
case MachineRepresentation::kWord8:
case MachineRepresentation::kWord16:
case MachineRepresentation::kWord32:
return kWasmI32;
case MachineRepresentation::kWord64:
return kWasmI64;
case MachineRepresentation::kFloat32:
return kWasmF32;
case MachineRepresentation::kFloat64:
return kWasmF64;
case MachineRepresentation::kTaggedPointer:
return kWasmAnyRef;
case MachineRepresentation::kSimd128:
return kWasmS128;
default:
UNREACHABLE();
}
}
static char ShortNameOf(ValueType type) {
switch (type) {
case kWasmI32:
return 'i';
case kWasmI64:
return 'l';
case kWasmF32:
return 'f';
case kWasmF64:
return 'd';
case kWasmAnyRef:
return 'r';
case kWasmS128:
return 's';
case kWasmStmt:
return 'v';
case kWasmVar:
return '*';
default:
return '?';
}
}
static const char* TypeName(ValueType type) {
switch (type) {
case kWasmI32:
return "i32";
case kWasmI64:
return "i64";
case kWasmF32:
return "f32";
case kWasmF64:
return "f64";
case kWasmAnyRef:
return "ref";
case kWasmS128:
return "s128";
case kWasmStmt:
return "<stmt>";
case kWasmVar:
return "<var>";
default:
return "<unknown>";
}
}
};
// Representation of an initializer expression.
......
......@@ -54,13 +54,12 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
if (fun->sig->parameter_count()) {
os << " (param";
for (auto param : fun->sig->parameters())
os << ' ' << WasmOpcodes::TypeName(param);
os << ' ' << ValueTypes::TypeName(param);
os << ')';
}
if (fun->sig->return_count()) {
os << " (result";
for (auto ret : fun->sig->returns())
os << ' ' << WasmOpcodes::TypeName(ret);
for (auto ret : fun->sig->returns()) os << ' ' << ValueTypes::TypeName(ret);
os << ')';
}
os << "\n";
......@@ -74,7 +73,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
if (!decls.type_list.empty()) {
os << "(local";
for (const ValueType &v : decls.type_list) {
os << ' ' << WasmOpcodes::TypeName(v);
os << ' ' << ValueTypes::TypeName(v);
}
os << ")\n";
++line_nr;
......@@ -106,7 +105,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
if (operand.type == kWasmVar) {
os << " (type " << operand.sig_index << ")";
} else if (operand.out_arity() > 0) {
os << " " << WasmOpcodes::TypeName(operand.out_type(0));
os << " " << ValueTypes::TypeName(operand.out_type(0));
}
control_depth++;
break;
......
......@@ -1412,7 +1412,7 @@ WASM_EXEC_TEST(StoreMem_offset_oob_i64) {
WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
WASM_ZERO);
byte memsize = WasmOpcodes::MemSize(machineTypes[m]);
byte memsize = ValueTypes::MemSize(machineTypes[m]);
uint32_t boundary = num_bytes - 8 - memsize;
CHECK_EQ(0, r.Call(boundary)); // in bounds.
CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
......@@ -1529,9 +1529,9 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Build the selector function.
// =========================================================================
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::ValueTypeFor(result));
b.AddReturn(ValueTypes::ValueTypeFor(result));
for (int i = 0; i < num_params; i++) {
b.AddParam(WasmOpcodes::ValueTypeFor(memtypes[i]));
b.AddParam(ValueTypes::ValueTypeFor(memtypes[i]));
}
WasmFunctionCompiler& t = r.NewFunction(b.Build());
BUILD(t, WASM_GET_LOCAL(which));
......@@ -1551,7 +1551,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in a local.
byte local_index = r.AllocateLocal(WasmOpcodes::ValueTypeFor(result));
byte local_index = r.AllocateLocal(ValueTypes::ValueTypeFor(result));
ADD_CODE(code, kExprSetLocal, local_index);
// Store the result in memory.
......@@ -1568,7 +1568,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
r.builder().RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
int size = ValueTypes::MemSize(result);
for (int i = 0; i < size; i++) {
int base = (which + 1) * kElemSize;
byte expected = r.builder().raw_mem_at<byte>(base + i);
......
......@@ -1531,7 +1531,7 @@ WASM_EXEC_TEST(LoadMem_offset_oob) {
constexpr byte offset = 8;
uint32_t boundary =
num_bytes - offset - WasmOpcodes::MemSize(machineTypes[m]);
num_bytes - offset - ValueTypes::MemSize(machineTypes[m]);
BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], offset, WASM_GET_LOCAL(0)),
WASM_DROP, WASM_ZERO);
......@@ -1674,7 +1674,7 @@ WASM_EXEC_TEST(StoreMem_offset_oob) {
WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
WASM_ZERO);
byte memsize = WasmOpcodes::MemSize(machineTypes[m]);
byte memsize = ValueTypes::MemSize(machineTypes[m]);
uint32_t boundary = num_bytes - 8 - memsize;
CHECK_EQ(0, r.Call(boundary)); // in bounds.
CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
......@@ -2345,9 +2345,9 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Build the selector function.
// =========================================================================
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::ValueTypeFor(result));
b.AddReturn(ValueTypes::ValueTypeFor(result));
for (int i = 0; i < num_params; ++i) {
b.AddParam(WasmOpcodes::ValueTypeFor(memtypes[i]));
b.AddParam(ValueTypes::ValueTypeFor(memtypes[i]));
}
WasmFunctionCompiler& t = r.NewFunction(b.Build());
BUILD(t, WASM_GET_LOCAL(which));
......@@ -2367,7 +2367,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in a local.
byte local_index = r.AllocateLocal(WasmOpcodes::ValueTypeFor(result));
byte local_index = r.AllocateLocal(ValueTypes::ValueTypeFor(result));
ADD_CODE(code, kExprSetLocal, local_index);
// Store the result in memory.
......@@ -2384,7 +2384,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
r.builder().RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
int size = ValueTypes::MemSize(result);
for (int i = 0; i < size; ++i) {
int base = (which + 1) * kElemSize;
byte expected = r.builder().raw_mem_at<byte>(base + i);
......@@ -2442,7 +2442,7 @@ WASM_EXEC_TEST(MultiReturnSub) {
template <typename T>
void RunMultiReturnSelect(WasmExecutionMode execution_mode, const T* inputs) {
EXPERIMENTAL_FLAG_SCOPE(mv);
ValueType type = WasmOpcodes::ValueTypeFor(MachineTypeForC<T>());
ValueType type = ValueTypes::ValueTypeFor(MachineTypeForC<T>());
ValueType storage[] = {type, type, type, type, type, type};
const size_t kNumReturns = 2;
const size_t kNumParams = arraysize(storage) - kNumReturns;
......@@ -3176,7 +3176,7 @@ void BinOpOnDifferentRegisters(WasmExecutionMode execution_mode, ValueType type,
for (int i = 0; i < num_locals; ++i) {
ADD_CODE(
init_locals_code,
WASM_SET_LOCAL(i, WASM_LOAD_MEM(WasmOpcodes::MachineTypeFor(type),
WASM_SET_LOCAL(i, WASM_LOAD_MEM(ValueTypes::MachineTypeFor(type),
WASM_I32V_2(sizeof(ctype) * i))));
}
for (int lhs = 0; lhs < num_locals; ++lhs) {
......@@ -3189,7 +3189,7 @@ void BinOpOnDifferentRegisters(WasmExecutionMode execution_mode, ValueType type,
std::vector<byte> code(init_locals_code);
ADD_CODE(code,
// Store the result of the binary operation at memory 0.
WASM_STORE_MEM(WasmOpcodes::MachineTypeFor(type), WASM_ZERO,
WASM_STORE_MEM(ValueTypes::MachineTypeFor(type), WASM_ZERO,
WASM_BINOP(opcode, WASM_GET_LOCAL(lhs),
WASM_GET_LOCAL(rhs))),
// Return 0.
......
......@@ -201,7 +201,7 @@ ModuleEnv TestingModuleBuilder::CreateModuleEnv() {
}
const WasmGlobal* TestingModuleBuilder::AddGlobal(ValueType type) {
byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type));
byte size = ValueTypes::MemSize(ValueTypes::MachineTypeFor(type));
global_offset = (global_offset + size - 1) & ~(size - 1); // align
test_module_.globals.push_back(
{type, true, WasmInitExpr(), global_offset, false, false});
......@@ -488,10 +488,10 @@ FunctionSig* WasmRunnerBase::CreateSig(MachineType return_type,
// Convert machine types to local types, and check that there are no
// MachineType::None()'s in the parameters.
int idx = 0;
if (return_count) sig_types[idx++] = WasmOpcodes::ValueTypeFor(return_type);
if (return_count) sig_types[idx++] = ValueTypes::ValueTypeFor(return_type);
for (MachineType param : param_types) {
CHECK_NE(MachineType::None(), param);
sig_types[idx++] = WasmOpcodes::ValueTypeFor(param);
sig_types[idx++] = ValueTypes::ValueTypeFor(param);
}
return new (&zone_) FunctionSig(return_count, param_count, sig_types);
}
......
......@@ -108,7 +108,7 @@ class TestingModuleBuilder {
template <typename T>
T* AddGlobal(
ValueType type = WasmOpcodes::ValueTypeFor(MachineTypeForC<T>())) {
ValueType type = ValueTypes::ValueTypeFor(MachineTypeForC<T>())) {
const WasmGlobal* global = AddGlobal(type);
return reinterpret_cast<T*>(globals_data_ + global->offset);
}
......
......@@ -75,9 +75,9 @@
#define WASM_BLOCK_F(...) kExprBlock, kLocalF32, __VA_ARGS__, kExprEnd
#define WASM_BLOCK_D(...) kExprBlock, kLocalF64, __VA_ARGS__, kExprEnd
#define WASM_BLOCK_T(t, ...) \
kExprBlock, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(t)), \
__VA_ARGS__, kExprEnd
#define WASM_BLOCK_T(t, ...) \
kExprBlock, static_cast<byte>(ValueTypes::ValueTypeCodeFor(t)), __VA_ARGS__, \
kExprEnd
#define WASM_BLOCK_X(index, ...) \
kExprBlock, static_cast<byte>(index), __VA_ARGS__, kExprEnd
......@@ -90,17 +90,17 @@
#define WASM_LOOP_F(...) kExprLoop, kLocalF32, __VA_ARGS__, kExprEnd
#define WASM_LOOP_D(...) kExprLoop, kLocalF64, __VA_ARGS__, kExprEnd
#define WASM_LOOP_T(t, ...) \
kExprLoop, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(t)), \
__VA_ARGS__, kExprEnd
#define WASM_LOOP_T(t, ...) \
kExprLoop, static_cast<byte>(ValueTypes::ValueTypeCodeFor(t)), __VA_ARGS__, \
kExprEnd
#define WASM_LOOP_X(index, ...) \
kExprLoop, static_cast<byte>(index), __VA_ARGS__, kExprEnd
#define WASM_IF(cond, ...) cond, kExprIf, kLocalVoid, __VA_ARGS__, kExprEnd
#define WASM_IF_T(t, cond, ...) \
cond, kExprIf, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(t)), \
#define WASM_IF_T(t, cond, ...) \
cond, kExprIf, static_cast<byte>(ValueTypes::ValueTypeCodeFor(t)), \
__VA_ARGS__, kExprEnd
#define WASM_IF_X(index, cond, ...) \
......@@ -118,8 +118,8 @@
#define WASM_IF_ELSE_D(cond, tstmt, fstmt) \
cond, kExprIf, kLocalF64, tstmt, kExprElse, fstmt, kExprEnd
#define WASM_IF_ELSE_T(t, cond, tstmt, fstmt) \
cond, kExprIf, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(t)), tstmt, \
#define WASM_IF_ELSE_T(t, cond, tstmt, fstmt) \
cond, kExprIf, static_cast<byte>(ValueTypes::ValueTypeCodeFor(t)), tstmt, \
kExprElse, fstmt, kExprEnd
#define WASM_IF_ELSE_X(index, cond, tstmt, fstmt) \
......
......@@ -112,7 +112,7 @@ class WasmGenerator {
: gen_(gen) {
gen->blocks_.push_back(br_type);
gen->builder_->EmitWithU8(block_type,
WasmOpcodes::ValueTypeCodeFor(result_type));
ValueTypes::ValueTypeCodeFor(result_type));
}
~BlockScope() {
......
......@@ -205,7 +205,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
ValueType type = decls.type_list[pos];
while (pos + count < locals && decls.type_list[pos + count] == type)
++count;
os << ".addLocals({" << WasmOpcodes::TypeName(type)
os << ".addLocals({" << ValueTypes::TypeName(type)
<< "_count: " << count << "})";
}
os << "\n";
......
......@@ -1387,7 +1387,7 @@ TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) {
MachineType mem_type = machineTypes[j];
byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)};
FunctionSig sig(1, 0, &local_type);
if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) {
if (local_type == ValueTypes::ValueTypeFor(mem_type)) {
EXPECT_VERIFIES_SC(&sig, code);
} else {
EXPECT_FAILURE_SC(&sig, code);
......@@ -1406,7 +1406,7 @@ TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) {
MachineType mem_type = machineTypes[j];
byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))};
FunctionSig sig(0, 1, &local_type);
if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) {
if (local_type == ValueTypes::ValueTypeFor(mem_type)) {
EXPECT_VERIFIES_SC(&sig, code);
} else {
EXPECT_FAILURE_SC(&sig, code);
......@@ -3027,8 +3027,8 @@ TEST_F(LocalDeclDecoderTest, OneLocal) {
EXPERIMENTAL_FLAG_SCOPE(anyref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueType type = kValueTypes[i];
const byte data[] = {
1, 1, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))};
const byte data[] = {1, 1,
static_cast<byte>(ValueTypes::ValueTypeCodeFor(type))};
BodyLocalDecls decls(zone());
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
EXPECT_TRUE(result);
......@@ -3043,8 +3043,8 @@ TEST_F(LocalDeclDecoderTest, FiveLocals) {
EXPERIMENTAL_FLAG_SCOPE(anyref);
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueType type = kValueTypes[i];
const byte data[] = {
1, 5, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))};
const byte data[] = {1, 5,
static_cast<byte>(ValueTypes::ValueTypeCodeFor(type))};
BodyLocalDecls decls(zone());
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
EXPECT_TRUE(result);
......
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