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

[wasm] Remove special memory type for (internal) globals and use local type instead.

R=ahaas@chromium.org,rossberg@chromium.org,bradnelson@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2165633006
Cr-Commit-Position: refs/heads/master@{#37945}
parent 1b004d3f
......@@ -1698,8 +1698,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
ZoneHashMap::Entry* entry =
global_variables_.Lookup(v, ComputePointerHash(v));
if (entry == nullptr) {
uint32_t index =
builder_->AddGlobal(WasmOpcodes::MachineTypeFor(type), 0);
uint32_t index = builder_->AddGlobal(type, 0);
IndexContainer* container = new (zone()) IndexContainer();
container->index = index;
entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v),
......
......@@ -2887,7 +2887,8 @@ Node* WasmGraphBuilder::ChangeToRuntimeCall(Node* node,
}
Node* WasmGraphBuilder::LoadGlobal(uint32_t index) {
MachineType mem_type = module_->GetGlobalType(index);
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index));
Node* addr = jsgraph()->RelocatableIntPtrConstant(
reinterpret_cast<uintptr_t>(module_->instance->globals_start +
module_->module->globals[index].offset),
......@@ -2900,7 +2901,8 @@ Node* WasmGraphBuilder::LoadGlobal(uint32_t index) {
}
Node* WasmGraphBuilder::StoreGlobal(uint32_t index, Node* val) {
MachineType mem_type = module_->GetGlobalType(index);
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index));
Node* addr = jsgraph()->RelocatableIntPtrConstant(
reinterpret_cast<uintptr_t>(module_->instance->globals_start +
module_->module->globals[index].offset),
......
......@@ -114,8 +114,7 @@ class WasmDecoder : public Decoder {
inline bool Validate(const byte* pc, GlobalIndexOperand& operand) {
ModuleEnv* m = module_;
if (m && m->module && operand.index < m->module->globals.size()) {
operand.machine_type = m->module->globals[operand.index].type;
operand.type = WasmOpcodes::LocalTypeFor(operand.machine_type);
operand.type = m->module->globals[operand.index].type;
return true;
}
error(pc, pc + 1, "invalid global index");
......
......@@ -79,13 +79,11 @@ struct ImmF64Operand {
struct GlobalIndexOperand {
uint32_t index;
LocalType type;
MachineType machine_type;
unsigned length;
inline GlobalIndexOperand(Decoder* decoder, const byte* pc) {
index = decoder->checked_read_u32v(pc, 1, &length, "global index");
type = kAstStmt;
machine_type = MachineType::None();
}
};
......
......@@ -247,7 +247,7 @@ void WasmModuleBuilder::MarkStartFunction(uint32_t index) {
start_function_index_ = index;
}
uint32_t WasmModuleBuilder::AddGlobal(MachineType type, bool exported) {
uint32_t WasmModuleBuilder::AddGlobal(LocalType type, bool exported) {
globals_.push_back(std::make_pair(type, exported));
return static_cast<uint32_t>(globals_.size() - 1);
}
......@@ -286,7 +286,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
for (auto global : globals_) {
buffer.write_u32v(0); // Length of the global name.
buffer.write_u8(WasmOpcodes::MemTypeCodeFor(global.first));
buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(global.first));
buffer.write_u8(global.second);
}
FixupSection(buffer, start);
......
......@@ -170,7 +170,7 @@ class WasmModuleBuilder : public ZoneObject {
// Building methods.
uint32_t AddFunction();
uint32_t AddGlobal(MachineType type, bool exported);
uint32_t AddGlobal(LocalType type, bool exported);
WasmFunctionBuilder* FunctionAt(size_t index);
void AddDataSegment(WasmDataSegmentEncoder* data);
uint32_t AddSignature(FunctionSig* sig);
......@@ -195,7 +195,7 @@ class WasmModuleBuilder : public ZoneObject {
ZoneVector<WasmFunctionBuilder*> functions_;
ZoneVector<WasmDataSegmentEncoder*> data_segments_;
ZoneVector<uint32_t> indirect_functions_;
ZoneVector<std::pair<MachineType, bool>> globals_;
ZoneVector<std::pair<LocalType, bool>> globals_;
SignatureMap signature_map_;
int start_function_index_;
};
......
......@@ -233,7 +233,8 @@ class ModuleDecoder : public Decoder {
if (failed()) break;
TRACE("DecodeGlobal[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
module->globals.push_back({0, 0, MachineType::Int32(), 0, false});
// Add an uninitialized global and pass a pointer to it.
module->globals.push_back({0, 0, kAstStmt, 0, false});
WasmGlobal* global = &module->globals.back();
DecodeGlobalInModule(global);
}
......@@ -481,7 +482,7 @@ class ModuleDecoder : public Decoder {
global->name_offset = consume_string(&global->name_length, false);
DCHECK(unibrow::Utf8::Validate(start_ + global->name_offset,
global->name_length));
global->type = mem_type();
global->type = consume_local_type();
global->offset = 0;
global->exported = consume_u8("exported") != 0;
}
......@@ -527,7 +528,8 @@ class ModuleDecoder : public Decoder {
return;
}
for (WasmGlobal& global : module->globals) {
byte size = WasmOpcodes::MemSize(global.type);
byte size =
WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(global.type));
offset = (offset + size - 1) & ~(size - 1); // align
global.offset = offset;
offset += size;
......@@ -635,39 +637,6 @@ class ModuleDecoder : public Decoder {
}
}
// Reads a single 8-bit integer, interpreting it as a memory type.
MachineType mem_type() {
byte val = consume_u8("memory type");
MemTypeCode t = static_cast<MemTypeCode>(val);
switch (t) {
case kMemI8:
return MachineType::Int8();
case kMemU8:
return MachineType::Uint8();
case kMemI16:
return MachineType::Int16();
case kMemU16:
return MachineType::Uint16();
case kMemI32:
return MachineType::Int32();
case kMemU32:
return MachineType::Uint32();
case kMemI64:
return MachineType::Int64();
case kMemU64:
return MachineType::Uint64();
case kMemF32:
return MachineType::Float32();
case kMemF64:
return MachineType::Float64();
case kMemS128:
return MachineType::Simd128();
default:
error(pc_ - 1, "invalid memory type");
return MachineType::None();
}
}
// Parses a type entry, which is currently limited to functions only.
FunctionSig* consume_sig() {
const byte* pos = pc_;
......
......@@ -1407,31 +1407,15 @@ class ThreadImpl : public WasmInterpreter::Thread {
GlobalIndexOperand operand(&decoder, code->at(pc));
const WasmGlobal* global = &module()->globals[operand.index];
byte* ptr = instance()->globals_start + global->offset;
MachineType type = global->type;
LocalType type = global->type;
WasmVal val;
if (type == MachineType::Int8()) {
val =
WasmVal(static_cast<int32_t>(*reinterpret_cast<int8_t*>(ptr)));
} else if (type == MachineType::Uint8()) {
val =
WasmVal(static_cast<int32_t>(*reinterpret_cast<uint8_t*>(ptr)));
} else if (type == MachineType::Int16()) {
val =
WasmVal(static_cast<int32_t>(*reinterpret_cast<int16_t*>(ptr)));
} else if (type == MachineType::Uint16()) {
val = WasmVal(
static_cast<int32_t>(*reinterpret_cast<uint16_t*>(ptr)));
} else if (type == MachineType::Int32()) {
if (type == kAstI32) {
val = WasmVal(*reinterpret_cast<int32_t*>(ptr));
} else if (type == MachineType::Uint32()) {
val = WasmVal(*reinterpret_cast<uint32_t*>(ptr));
} else if (type == MachineType::Int64()) {
} else if (type == kAstI64) {
val = WasmVal(*reinterpret_cast<int64_t*>(ptr));
} else if (type == MachineType::Uint64()) {
val = WasmVal(*reinterpret_cast<uint64_t*>(ptr));
} else if (type == MachineType::Float32()) {
} else if (type == kAstF32) {
val = WasmVal(*reinterpret_cast<float*>(ptr));
} else if (type == MachineType::Float64()) {
} else if (type == kAstF64) {
val = WasmVal(*reinterpret_cast<double*>(ptr));
} else {
UNREACHABLE();
......@@ -1444,31 +1428,15 @@ class ThreadImpl : public WasmInterpreter::Thread {
GlobalIndexOperand operand(&decoder, code->at(pc));
const WasmGlobal* global = &module()->globals[operand.index];
byte* ptr = instance()->globals_start + global->offset;
MachineType type = global->type;
LocalType type = global->type;
WasmVal val = Pop();
if (type == MachineType::Int8()) {
*reinterpret_cast<int8_t*>(ptr) =
static_cast<int8_t>(val.to<int32_t>());
} else if (type == MachineType::Uint8()) {
*reinterpret_cast<uint8_t*>(ptr) =
static_cast<uint8_t>(val.to<uint32_t>());
} else if (type == MachineType::Int16()) {
*reinterpret_cast<int16_t*>(ptr) =
static_cast<int16_t>(val.to<int32_t>());
} else if (type == MachineType::Uint16()) {
*reinterpret_cast<uint16_t*>(ptr) =
static_cast<uint16_t>(val.to<uint32_t>());
} else if (type == MachineType::Int32()) {
if (type == kAstI32) {
*reinterpret_cast<int32_t*>(ptr) = val.to<int32_t>();
} else if (type == MachineType::Uint32()) {
*reinterpret_cast<uint32_t*>(ptr) = val.to<uint32_t>();
} else if (type == MachineType::Int64()) {
} else if (type == kAstI64) {
*reinterpret_cast<int64_t*>(ptr) = val.to<int64_t>();
} else if (type == MachineType::Uint64()) {
*reinterpret_cast<uint64_t*>(ptr) = val.to<uint64_t>();
} else if (type == MachineType::Float32()) {
} else if (type == kAstF32) {
*reinterpret_cast<float*>(ptr) = val.to<float>();
} else if (type == MachineType::Float64()) {
} else if (type == kAstF64) {
*reinterpret_cast<double*>(ptr) = val.to<double>();
} else {
UNREACHABLE();
......
......@@ -138,7 +138,7 @@ struct WasmExport {
struct WasmGlobal {
uint32_t name_offset; // offset in the module bytes of the name, if any.
uint32_t name_length; // length in bytes of the global name.
MachineType type; // type of the global.
LocalType type; // type of the global.
uint32_t offset; // offset from beginning of globals area.
bool exported; // true if this global is exported.
};
......@@ -293,7 +293,7 @@ struct ModuleEnv {
bool IsValidImport(uint32_t index) {
return module && index < module->import_table.size();
}
MachineType GetGlobalType(uint32_t index) {
LocalType GetGlobalType(uint32_t index) {
DCHECK(IsValidGlobal(index));
return module->globals[index].type;
}
......
......@@ -22,21 +22,6 @@ enum LocalTypeCode {
kLocalS128 = 5
};
// Binary encoding of memory types.
enum MemTypeCode {
kMemI8 = 0,
kMemU8 = 1,
kMemI16 = 2,
kMemU16 = 3,
kMemI32 = 4,
kMemU32 = 5,
kMemI64 = 6,
kMemU64 = 7,
kMemF32 = 8,
kMemF64 = 9,
kMemS128 = 10
};
// We reuse the internal machine type to represent WebAssembly AST types.
// A typedef improves readability without adding a whole new type system.
typedef MachineRepresentation LocalType;
......@@ -531,35 +516,6 @@ class WasmOpcodes {
}
}
static MemTypeCode MemTypeCodeFor(MachineType type) {
if (type == MachineType::Int8()) {
return kMemI8;
} else if (type == MachineType::Uint8()) {
return kMemU8;
} else if (type == MachineType::Int16()) {
return kMemI16;
} else if (type == MachineType::Uint16()) {
return kMemU16;
} else if (type == MachineType::Int32()) {
return kMemI32;
} else if (type == MachineType::Uint32()) {
return kMemU32;
} else if (type == MachineType::Int64()) {
return kMemI64;
} else if (type == MachineType::Uint64()) {
return kMemU64;
} else if (type == MachineType::Float32()) {
return kMemF32;
} else if (type == MachineType::Float64()) {
return kMemF64;
} else if (type == MachineType::Simd128()) {
return kMemS128;
} else {
UNREACHABLE();
return kMemI32;
}
}
static MachineType MachineTypeFor(LocalType type) {
switch (type) {
case kAstI32:
......
......@@ -1368,7 +1368,7 @@ WASM_EXEC_TEST(I64Global) {
REQUIRE(I64And);
REQUIRE(DepthFirst);
TestingModule module(execution_mode);
int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
int64_t* global = module.AddGlobal<int64_t>(kAstI64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
BUILD(r, B2(WASM_STORE_GLOBAL(
......
......@@ -156,8 +156,8 @@ TEST(Run_WasmModule_Global) {
TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
uint32_t global1 = builder->AddGlobal(MachineType::Int32(), 0);
uint32_t global2 = builder->AddGlobal(MachineType::Int32(), 0);
uint32_t global1 = builder->AddGlobal(kAstI32, 0);
uint32_t global2 = builder->AddGlobal(kAstI32, 0);
uint16_t f1_index = builder->AddFunction();
WasmFunctionBuilder* f = builder->FunctionAt(f1_index);
f->SetSignature(sigs.i_v());
......
......@@ -13,23 +13,20 @@
using namespace v8::internal;
using namespace v8::internal::compiler;
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int8_t, Int8, WASM_I32_ADD) \
TEST_BODY(uint8_t, Uint8, WASM_I32_ADD) \
TEST_BODY(int16_t, Int16, WASM_I32_ADD) \
TEST_BODY(uint16_t, Uint16, WASM_I32_ADD) \
TEST_BODY(int32_t, Int32, WASM_I32_ADD) \
TEST_BODY(uint32_t, Uint32, WASM_I32_ADD) \
TEST_BODY(float, Float32, WASM_F32_ADD) \
TEST_BODY(double, Float64, WASM_F64_ADD)
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, I32, WASM_I32_ADD) \
TEST_BODY(int64_t, I64, WASM_I64_ADD) \
TEST_BODY(float, F32, WASM_F32_ADD) \
TEST_BODY(double, F64, WASM_F64_ADD)
#define LOAD_STORE_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
TestingModule module(kExecuteCompiled); \
module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
\
WasmRunner<C_TYPE> r(&module, MachineType::MACHINE_TYPE()); \
WasmRunner<C_TYPE> r(&module, \
WasmOpcodes::MachineTypeFor(kAst##MACHINE_TYPE)); \
\
/* global = global + p0 */ \
BUILD(r, \
......
......@@ -1858,7 +1858,7 @@ WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
WASM_EXEC_TEST(Int32Global) {
TestingModule module(execution_mode);
int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32());
int32_t* global = module.AddGlobal<int32_t>(kAstI32);
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
BUILD(r, WASM_STORE_GLOBAL(
......@@ -1875,9 +1875,9 @@ WASM_EXEC_TEST(Int32Global) {
WASM_EXEC_TEST(Int32Globals_DontAlias) {
const int kNumGlobals = 3;
TestingModule module(execution_mode);
int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()),
module.AddGlobal<int32_t>(MachineType::Int32()),
module.AddGlobal<int32_t>(MachineType::Int32())};
int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32),
module.AddGlobal<int32_t>(kAstI32),
module.AddGlobal<int32_t>(kAstI32)};
for (int g = 0; g < kNumGlobals; ++g) {
// global = global + p0
......@@ -1902,7 +1902,7 @@ WASM_EXEC_TEST(Int32Globals_DontAlias) {
WASM_EXEC_TEST(Float32Global) {
TestingModule module(execution_mode);
float* global = module.AddGlobal<float>(MachineType::Float32());
float* global = module.AddGlobal<float>(kAstF32);
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
BUILD(r, B2(WASM_STORE_GLOBAL(
......@@ -1920,7 +1920,7 @@ WASM_EXEC_TEST(Float32Global) {
WASM_EXEC_TEST(Float64Global) {
TestingModule module(execution_mode);
double* global = module.AddGlobal<double>(MachineType::Float64());
double* global = module.AddGlobal<double>(kAstF64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
BUILD(r, B2(WASM_STORE_GLOBAL(
......@@ -1938,32 +1938,24 @@ WASM_EXEC_TEST(Float64Global) {
WASM_EXEC_TEST(MixedGlobals) {
TestingModule module(execution_mode);
int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32());
int32_t* unused = module.AddGlobal<int32_t>(kAstI32);
byte* memory = module.AddMemory(32);
int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8());
uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8());
int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16());
uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16());
int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32());
uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32());
float* var_float = module.AddGlobal<float>(MachineType::Float32());
double* var_double = module.AddGlobal<double>(MachineType::Float64());
int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32);
uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32);
float* var_float = module.AddGlobal<float>(kAstF32);
double* var_double = module.AddGlobal<double>(kAstF64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(
r,
WASM_BLOCK(
WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int8(), WASM_ZERO)),
WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint8(), WASM_ZERO)),
WASM_STORE_GLOBAL(3, WASM_LOAD_MEM(MachineType::Int16(), WASM_ZERO)),
WASM_STORE_GLOBAL(4, WASM_LOAD_MEM(MachineType::Uint16(), WASM_ZERO)),
WASM_STORE_GLOBAL(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
WASM_STORE_GLOBAL(6, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
WASM_STORE_GLOBAL(7,
WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
WASM_STORE_GLOBAL(3,
WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)),
WASM_STORE_GLOBAL(8,
WASM_STORE_GLOBAL(4,
WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)),
WASM_ZERO));
......@@ -1977,10 +1969,6 @@ WASM_EXEC_TEST(MixedGlobals) {
memory[7] = 0x99;
r.Call(1);
CHECK(static_cast<int8_t>(0xaa) == *var_int8);
CHECK(static_cast<uint8_t>(0xaa) == *var_uint8);
CHECK(static_cast<int16_t>(0xccaa) == *var_int16);
CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16);
CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32);
CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32);
CHECK(bit_cast<float>(0xee55ccaa) == *var_float);
......
......@@ -112,8 +112,8 @@ class TestingModule : public ModuleEnv {
}
template <typename T>
T* AddGlobal(MachineType mem_type) {
const WasmGlobal* global = AddGlobal(mem_type);
T* AddGlobal(LocalType type) {
const WasmGlobal* global = AddGlobal(type);
return reinterpret_cast<T*>(instance->globals_start + global->offset);
}
......@@ -257,10 +257,10 @@ class TestingModule : public ModuleEnv {
V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
WasmInterpreter* interpreter_;
const WasmGlobal* AddGlobal(MachineType mem_type) {
byte size = WasmOpcodes::MemSize(mem_type);
const WasmGlobal* AddGlobal(LocalType type) {
byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type));
global_offset = (global_offset + size - 1) & ~(size - 1); // align
module_.globals.push_back({0, 0, mem_type, global_offset, false});
module_.globals.push_back({0, 0, type, global_offset, false});
global_offset += size;
// limit number of globals.
CHECK_LT(global_offset, kMaxGlobalsSize);
......
......@@ -1154,8 +1154,8 @@ class TestModuleEnv : public ModuleEnv {
instance = nullptr;
module = &mod;
}
byte AddGlobal(MachineType mem_type) {
mod.globals.push_back({0, 0, mem_type, 0, false});
byte AddGlobal(LocalType type) {
mod.globals.push_back({0, 0, type, 0, false});
CHECK(mod.globals.size() <= 127);
return static_cast<byte>(mod.globals.size() - 1);
}
......@@ -1345,26 +1345,10 @@ TEST_F(AstDecoderTest, Int32Globals) {
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(MachineType::Int8());
module_env.AddGlobal(MachineType::Uint8());
module_env.AddGlobal(MachineType::Int16());
module_env.AddGlobal(MachineType::Uint16());
module_env.AddGlobal(MachineType::Int32());
module_env.AddGlobal(MachineType::Uint32());
module_env.AddGlobal(kAstI32);
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(2));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(3));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(4));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(5));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0)));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0)));
}
TEST_F(AstDecoderTest, Int32Globals_fail) {
......@@ -1372,10 +1356,10 @@ TEST_F(AstDecoderTest, Int32Globals_fail) {
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(MachineType::Int64());
module_env.AddGlobal(MachineType::Uint64());
module_env.AddGlobal(MachineType::Float32());
module_env.AddGlobal(MachineType::Float64());
module_env.AddGlobal(kAstI64);
module_env.AddGlobal(kAstI64);
module_env.AddGlobal(kAstF32);
module_env.AddGlobal(kAstF64);
EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(0));
EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(1));
......@@ -1393,8 +1377,8 @@ TEST_F(AstDecoderTest, Int64Globals) {
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(MachineType::Int64());
module_env.AddGlobal(MachineType::Uint64());
module_env.AddGlobal(kAstI64);
module_env.AddGlobal(kAstI64);
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1));
......@@ -1408,7 +1392,7 @@ TEST_F(AstDecoderTest, Float32Globals) {
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(MachineType::Float32());
module_env.AddGlobal(kAstF32);
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
......@@ -1419,7 +1403,7 @@ TEST_F(AstDecoderTest, Float64Globals) {
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(MachineType::Float64());
module_env.AddGlobal(kAstF64);
EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
......@@ -1428,13 +1412,13 @@ TEST_F(AstDecoderTest, Float64Globals) {
TEST_F(AstDecoderTest, AllLoadGlobalCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
LocalType global_type = kLocalTypes[j];
FunctionSig sig(1, 0, &local_type);
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(mem_type);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
module_env.AddGlobal(global_type);
if (local_type == global_type) {
EXPECT_VERIFIES_INLINE(&sig, WASM_LOAD_GLOBAL(0));
} else {
EXPECT_FAILURE_INLINE(&sig, WASM_LOAD_GLOBAL(0));
......@@ -1446,13 +1430,13 @@ TEST_F(AstDecoderTest, AllLoadGlobalCombinations) {
TEST_F(AstDecoderTest, AllStoreGlobalCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
LocalType global_type = kLocalTypes[j];
FunctionSig sig(0, 1, &local_type);
TestModuleEnv module_env;
module = &module_env;
module_env.AddGlobal(mem_type);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
module_env.AddGlobal(global_type);
if (local_type == global_type) {
EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
} else {
EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
......
......@@ -177,9 +177,9 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) {
SECTION(GLOBALS, 5), // --
1,
NAME_LENGTH(1),
'g', // name
kMemI32, // memory type
0, // exported
'g', // name
kLocalI32, // local type
0, // exported
};
{
......@@ -193,7 +193,7 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) {
const WasmGlobal* global = &result.val->globals.back();
EXPECT_EQ(1, global->name_length);
EXPECT_EQ(MachineType::Int32(), global->type);
EXPECT_EQ(kAstI32, global->type);
EXPECT_EQ(0, global->offset);
EXPECT_FALSE(global->exported);
......@@ -244,9 +244,9 @@ static void AppendUint32v(std::vector<byte>& buffer, uint32_t val) {
TEST_F(WasmModuleVerifyTest, NGlobals) {
static const byte data[] = {
NO_NAME, // name length
kMemI32, // memory type
0, // exported
NO_NAME, // name length
kLocalF32, // memory type
0, // exported
};
for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) {
......@@ -295,12 +295,12 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
static const byte data[] = {
SECTION(GLOBALS, 7),
2,
NO_NAME, // #0: name length
kMemF32, // memory type
0, // exported
NO_NAME, // #1: name length
kMemF64, // memory type
1, // exported
NO_NAME, // #0: name length
kLocalF32, // type
0, // exported
NO_NAME, // #1: name length
kLocalF64, // type
1, // exported
};
{
......@@ -315,12 +315,12 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
const WasmGlobal* g1 = &result.val->globals[1];
EXPECT_EQ(0, g0->name_length);
EXPECT_EQ(MachineType::Float32(), g0->type);
EXPECT_EQ(kAstF32, g0->type);
EXPECT_EQ(0, g0->offset);
EXPECT_FALSE(g0->exported);
EXPECT_EQ(0, g1->name_length);
EXPECT_EQ(MachineType::Float64(), g1->type);
EXPECT_EQ(kAstF64, g1->type);
EXPECT_EQ(8, g1->offset);
EXPECT_TRUE(g1->exported);
......@@ -857,9 +857,9 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
0, // one byte section
SECTION(GLOBALS, 4),
1,
0, // name length
kMemI32, // memory type
0, // exported
0, // name length
kLocalI32, // memory type
0, // exported
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_OK(result);
......@@ -871,7 +871,7 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
const WasmGlobal* global = &result.val->globals.back();
EXPECT_EQ(0, global->name_length);
EXPECT_EQ(MachineType::Int32(), global->type);
EXPECT_EQ(kAstI32, global->type);
EXPECT_EQ(0, global->offset);
EXPECT_FALSE(global->exported);
......
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