Commit 01e59c4b authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Refactoring in preparation of generalizing WasmInitExpr

Motivation: With rtt.sub now allowed in constant expressions, we have
to generalize WasmInitExpr to be able to handle expressions with
operands. This CL prepares the ground for this change and adds no
functionality.

Changes:
- ValueType::heap_representation and HeapType::representation now
  return HeapType::Representation.
- Add ValueType::is_rtt().
- WasmInitExpr:
  - Make kind private. Rename val -> operator, make it private. Add
    accessors.
  - Rename kGlobalIndex -> kGlobalGet.
  - Squash global_index and function_index into index.
  - Add heap_type Immediate. Use it for RefNullConst. TypeOf in
    module-decoder.cc can now fully determine the type of a
    WasmInitExpr.
  - Add class constructors/static method constructors for each Operator
    kind.
  - Delete copy constructor. WasmInitExpr will use std::unique_ptr for
    its operands.
- consume_init_expr now uses a stack.
- A few minor improvements.

Bug: v8:7748
Change-Id: I3ba3ee7ac2d6bc58e887790c37110ceb80658985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2284483
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68759}
parent 607452dc
......@@ -250,10 +250,10 @@ void AsmJsParser::AddGlobalImport(Vector<const char> name, AsmType* type,
void AsmJsParser::DeclareGlobal(VarInfo* info, bool mutable_variable,
AsmType* type, ValueType vtype,
const WasmInitExpr& init) {
WasmInitExpr init) {
info->kind = VarKind::kGlobal;
info->type = type;
info->index = module_builder_->AddGlobal(vtype, true, init);
info->index = module_builder_->AddGlobal(vtype, true, std::move(init));
info->mutable_variable = mutable_variable;
}
......
......@@ -313,8 +313,7 @@ class AsmJsParser {
VarInfo* GetVarInfo(AsmJsScanner::token_t token);
uint32_t VarIndex(VarInfo* info);
void DeclareGlobal(VarInfo* info, bool mutable_variable, AsmType* type,
ValueType vtype,
const WasmInitExpr& init = WasmInitExpr());
ValueType vtype, WasmInitExpr init = WasmInitExpr());
void DeclareStdlibFunc(VarInfo* info, VarKind kind, AsmType* type);
void AddGlobalImport(Vector<const char> name, AsmType* type, ValueType vtype,
bool mutable_variable, VarInfo* info);
......
......@@ -3809,7 +3809,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
CALL_INTERFACE_IF_REACHABLE(DoReturn, return_values);
}
inline Value* Push(ValueType type) {
V8_INLINE Value* Push(ValueType type) {
DCHECK_NE(kWasmStmt, type);
stack_.emplace_back(this->pc_, type);
return &stack_.back();
......
This diff is collapsed.
......@@ -37,12 +37,12 @@ byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) {
uint32_t EvalUint32InitExpr(Handle<WasmInstanceObject> instance,
const WasmInitExpr& expr) {
switch (expr.kind) {
switch (expr.kind()) {
case WasmInitExpr::kI32Const:
return expr.val.i32_const;
case WasmInitExpr::kGlobalIndex: {
return expr.immediate().i32_const;
case WasmInitExpr::kGlobalGet: {
uint32_t offset =
instance->module()->globals[expr.val.global_index].offset;
instance->module()->globals[expr.immediate().index].offset;
auto raw_addr = reinterpret_cast<Address>(
instance->untagged_globals_buffer().backing_store()) +
offset;
......@@ -1404,27 +1404,27 @@ T* InstanceBuilder::GetRawGlobalPtr(const WasmGlobal& global) {
// Process initialization of globals.
void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) {
for (auto global : module_->globals) {
for (const WasmGlobal& global : module_->globals) {
if (global.mutability && global.imported) {
continue;
}
switch (global.init.kind) {
switch (global.init.kind()) {
case WasmInitExpr::kI32Const:
WriteLittleEndianValue<int32_t>(GetRawGlobalPtr<int32_t>(global),
global.init.val.i32_const);
global.init.immediate().i32_const);
break;
case WasmInitExpr::kI64Const:
WriteLittleEndianValue<int64_t>(GetRawGlobalPtr<int64_t>(global),
global.init.val.i64_const);
global.init.immediate().i64_const);
break;
case WasmInitExpr::kF32Const:
WriteLittleEndianValue<float>(GetRawGlobalPtr<float>(global),
global.init.val.f32_const);
global.init.immediate().f32_const);
break;
case WasmInitExpr::kF64Const:
WriteLittleEndianValue<double>(GetRawGlobalPtr<double>(global),
global.init.val.f64_const);
global.init.immediate().f64_const);
break;
case WasmInitExpr::kRefNullConst:
DCHECK(enabled_.has_reftypes() || enabled_.has_eh());
......@@ -1437,15 +1437,15 @@ void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) {
case WasmInitExpr::kRefFuncConst: {
DCHECK(enabled_.has_reftypes());
auto function = WasmInstanceObject::GetOrCreateWasmExternalFunction(
isolate_, instance, global.init.val.function_index);
isolate_, instance, global.init.immediate().index);
tagged_globals_->set(global.offset, *function);
break;
}
case WasmInitExpr::kGlobalIndex: {
case WasmInitExpr::kGlobalGet: {
// Initialize with another global.
uint32_t new_offset = global.offset;
uint32_t old_offset =
module_->globals[global.init.val.global_index].offset;
module_->globals[global.init.immediate().index].offset;
TRACE("init [globals+%u] = [globals+%d]\n", global.offset, old_offset);
if (global.type.is_reference_type()) {
DCHECK(enabled_.has_reftypes() || enabled_.has_eh());
......
......@@ -51,7 +51,7 @@ class HeapType {
kEq, // shorthand: q
kExn, // shorthand: x
kI31, // shorthand: j
// This code is used to represent failures in the parsing of heap types and
// This value is used to represent failures in the parsing of heap types and
// does not correspond to a wasm heap type.
kBottom
};
......@@ -90,7 +90,7 @@ class HeapType {
return representation_ != other.representation_;
}
constexpr uint32_t representation() const { return representation_; }
constexpr Representation representation() const { return representation_; }
constexpr uint32_t ref_index() const {
CONSTEXPR_DCHECK(is_index());
return representation_;
......@@ -183,7 +183,8 @@ class ValueType {
constexpr bool has_index() const {
return is_reference_type() && heap_type().is_index();
}
constexpr bool has_depth() const { return kind() == kRtt; }
constexpr bool is_rtt() const { return kind() == kRtt; }
constexpr bool has_depth() const { return is_rtt(); }
constexpr ValueType() : bit_field_(KindField::encode(kStmt)) {}
static constexpr ValueType Primitive(Kind kind) {
......@@ -219,9 +220,10 @@ class ValueType {
}
constexpr Kind kind() const { return KindField::decode(bit_field_); }
constexpr uint32_t heap_representation() const {
constexpr HeapType::Representation heap_representation() const {
CONSTEXPR_DCHECK(is_reference_type());
return HeapTypeField::decode(bit_field_);
return static_cast<HeapType::Representation>(
HeapTypeField::decode(bit_field_));
}
constexpr HeapType heap_type() const {
return HeapType(heap_representation());
......
......@@ -144,7 +144,7 @@ class DebugEvaluatorProxy {
void GetGlobal(uint32_t global, uint32_t result_offset) {
DCHECK(frame_->is_wasm());
WasmGlobal global_variable =
const WasmGlobal& global_variable =
WasmFrame::cast(frame_)->native_module()->module()->globals.at(global);
Handle<WasmInstanceObject> instance(
......
......@@ -376,9 +376,9 @@ void WasmModuleBuilder::AddExport(Vector<const char> name,
}
uint32_t WasmModuleBuilder::AddExportedGlobal(ValueType type, bool mutability,
const WasmInitExpr& init,
WasmInitExpr init,
Vector<const char> name) {
uint32_t index = AddGlobal(type, mutability, init);
uint32_t index = AddGlobal(type, mutability, std::move(init));
AddExport(name, kExternalGlobal, index);
return index;
}
......@@ -395,8 +395,8 @@ void WasmModuleBuilder::ExportImportedFunction(Vector<const char> name,
}
uint32_t WasmModuleBuilder::AddGlobal(ValueType type, bool mutability,
const WasmInitExpr& init) {
globals_.push_back({type, mutability, init});
WasmInitExpr init) {
globals_.push_back({type, mutability, std::move(init)});
return static_cast<uint32_t>(globals_.size() - 1);
}
......@@ -542,34 +542,35 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer* buffer) const {
for (const WasmGlobal& global : globals_) {
WriteValueType(buffer, global.type);
buffer->write_u8(global.mutability ? 1 : 0);
switch (global.init.kind) {
switch (global.init.kind()) {
case WasmInitExpr::kI32Const:
DCHECK_EQ(kWasmI32, global.type);
buffer->write_u8(kExprI32Const);
buffer->write_i32v(global.init.val.i32_const);
buffer->write_i32v(global.init.immediate().i32_const);
break;
case WasmInitExpr::kI64Const:
DCHECK_EQ(kWasmI64, global.type);
buffer->write_u8(kExprI64Const);
buffer->write_i64v(global.init.val.i64_const);
buffer->write_i64v(global.init.immediate().i64_const);
break;
case WasmInitExpr::kF32Const:
DCHECK_EQ(kWasmF32, global.type);
buffer->write_u8(kExprF32Const);
buffer->write_f32(global.init.val.f32_const);
buffer->write_f32(global.init.immediate().f32_const);
break;
case WasmInitExpr::kF64Const:
DCHECK_EQ(kWasmF64, global.type);
buffer->write_u8(kExprF64Const);
buffer->write_f64(global.init.val.f64_const);
buffer->write_f64(global.init.immediate().f64_const);
break;
case WasmInitExpr::kGlobalIndex:
case WasmInitExpr::kGlobalGet:
buffer->write_u8(kExprGlobalGet);
buffer->write_u32v(global.init.val.global_index);
buffer->write_u32v(global.init.immediate().index);
break;
case WasmInitExpr::kRefNullConst:
buffer->write_u8(kExprRefNull);
buffer->write_i32v(global.type.heap_type().code());
buffer->write_i32v(
HeapType(global.init.immediate().heap_type).code());
break;
case WasmInitExpr::kRefFuncConst:
UNIMPLEMENTED();
......@@ -607,6 +608,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer* buffer) const {
case ValueType::kRtt:
UNREACHABLE();
}
break;
}
}
buffer->write_u8(kExprEnd);
......
......@@ -238,7 +238,7 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
Vector<const char> module = {});
WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
uint32_t AddGlobal(ValueType type, bool mutability = true,
const WasmInitExpr& init = WasmInitExpr());
WasmInitExpr init = WasmInitExpr());
uint32_t AddGlobalImport(Vector<const char> name, ValueType type,
bool mutability, Vector<const char> module = {});
void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
......@@ -259,8 +259,8 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
void AddExport(Vector<const char> name, WasmFunctionBuilder* builder) {
AddExport(name, kExternalFunction, builder->func_index());
}
uint32_t AddExportedGlobal(ValueType type, bool mutability,
const WasmInitExpr& init, Vector<const char> name);
uint32_t AddExportedGlobal(ValueType type, bool mutability, WasmInitExpr init,
Vector<const char> name);
void ExportImportedFunction(Vector<const char> name, int import_index);
void SetMinMemorySize(uint32_t value);
void SetMaxMemorySize(uint32_t value);
......@@ -314,6 +314,8 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
};
struct WasmGlobal {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmGlobal);
ValueType type;
bool mutability;
WasmInitExpr init;
......
......@@ -91,7 +91,7 @@ struct WasmException {
struct WasmDataSegment {
// Construct an active segment.
explicit WasmDataSegment(WasmInitExpr dest_addr)
: dest_addr(dest_addr), active(true) {}
: dest_addr(std::move(dest_addr)), active(true) {}
// Construct a passive segment, which has no dest_addr.
WasmDataSegment() : active(false) {}
......@@ -120,7 +120,7 @@ struct WasmElemSegment {
WasmElemSegment(uint32_t table_index, WasmInitExpr offset)
: type(ValueType::Ref(HeapType::kFunc, kNullable)),
table_index(table_index),
offset(offset),
offset(std::move(offset)),
status(kStatusActive) {}
// Construct a passive or declarative segment, which has no table index or
......
......@@ -747,47 +747,71 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
};
// Representation of an initializer expression.
struct WasmInitExpr {
enum WasmInitKind {
class WasmInitExpr {
public:
enum Operator {
kNone,
kGlobalIndex,
kGlobalGet,
kI32Const,
kI64Const,
kF32Const,
kF64Const,
kRefNullConst,
kRefFuncConst,
} kind;
kRefFuncConst
};
union {
union Immediate {
int32_t i32_const;
int64_t i64_const;
float f32_const;
double f64_const;
uint32_t global_index;
uint32_t function_index;
} val;
WasmInitExpr() : kind(kNone) {}
explicit WasmInitExpr(int32_t v) : kind(kI32Const) { val.i32_const = v; }
explicit WasmInitExpr(int64_t v) : kind(kI64Const) { val.i64_const = v; }
explicit WasmInitExpr(float v) : kind(kF32Const) { val.f32_const = v; }
explicit WasmInitExpr(double v) : kind(kF64Const) { val.f64_const = v; }
explicit WasmInitExpr(WasmInitKind kind) : kind(kind) {
DCHECK_EQ(kind, kRefNullConst);
uint32_t index;
HeapType::Representation heap_type;
};
WasmInitExpr() : kind_(kNone) { immediate_.i32_const = 0; }
explicit WasmInitExpr(int32_t v) : kind_(kI32Const) {
immediate_.i32_const = v;
}
explicit WasmInitExpr(int64_t v) : kind_(kI64Const) {
immediate_.i64_const = v;
}
explicit WasmInitExpr(float v) : kind_(kF32Const) {
immediate_.f32_const = v;
}
explicit WasmInitExpr(double v) : kind_(kF64Const) {
immediate_.f64_const = v;
}
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmInitExpr);
static WasmInitExpr GlobalGet(uint32_t index) {
WasmInitExpr expr;
expr.kind_ = kGlobalGet;
expr.immediate_.index = index;
return expr;
}
static WasmInitExpr RefFuncConst(uint32_t index) {
WasmInitExpr expr;
expr.kind_ = kRefFuncConst;
expr.immediate_.index = index;
return expr;
}
WasmInitExpr(WasmInitKind kind, uint32_t index) : kind(kind) {
if (kind == kGlobalIndex) {
val.global_index = index;
} else if (kind == kRefFuncConst) {
val.function_index = index;
} else {
// For the other types, the other initializers should be used.
UNREACHABLE();
}
static WasmInitExpr RefNullConst(HeapType::Representation heap_type) {
WasmInitExpr expr;
expr.kind_ = kRefNullConst;
expr.immediate_.heap_type = heap_type;
return expr;
}
Immediate immediate() const { return immediate_; }
Operator kind() const { return kind_; }
private:
Immediate immediate_;
Operator kind_;
};
} // namespace wasm
......
......@@ -44,7 +44,7 @@ class WasmGCTester {
}
uint32_t AddGlobal(ValueType type, bool mutability, WasmInitExpr init) {
return builder_.AddGlobal(type, mutability, init);
return builder_.AddGlobal(type, mutability, std::move(init));
}
uint32_t DefineFunction(FunctionSig* sig,
......@@ -220,8 +220,10 @@ TEST(WasmRefAsNonNull) {
ValueType kOptRefType = optref(type_index);
FunctionSig sig_q_v(1, 0, kRefTypes);
uint32_t global_index = tester.AddGlobal(
kOptRefType, true, WasmInitExpr(WasmInitExpr::kRefNullConst));
uint32_t global_index =
tester.AddGlobal(kOptRefType, true,
WasmInitExpr::RefNullConst(
static_cast<HeapType::Representation>(type_index)));
uint32_t field_index = 0;
const uint32_t kFunc = tester.DefineFunction(
tester.sigs.i_v(), {},
......
......@@ -315,8 +315,7 @@ ZoneBuffer GetModuleWithInvalidSection(Zone* zone) {
TestSignatures sigs;
WasmModuleBuilder builder(zone);
// Add an invalid global to the module. The decoder will fail there.
builder.AddGlobal(kWasmStmt, true,
WasmInitExpr(WasmInitExpr::kGlobalIndex, 12));
builder.AddGlobal(kWasmStmt, true, WasmInitExpr::GlobalGet(12));
{
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
uint8_t code[] = {kExprLocalGet, 0, kExprEnd};
......
......@@ -204,12 +204,12 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
for (const WasmElemSegment& elem_segment : module->elem_segments) {
os << "builder.addElementSegment(";
os << elem_segment.table_index << ", ";
switch (elem_segment.offset.kind) {
case WasmInitExpr::kGlobalIndex:
os << elem_segment.offset.val.global_index << ", true";
switch (elem_segment.offset.kind()) {
case WasmInitExpr::kGlobalGet:
os << elem_segment.offset.immediate().index << ", true";
break;
case WasmInitExpr::kI32Const:
os << elem_segment.offset.val.i32_const << ", false";
os << elem_segment.offset.immediate().i32_const << ", false";
break;
default:
UNREACHABLE();
......
......@@ -261,8 +261,8 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) {
EXPECT_EQ(kWasmI32, global->type);
EXPECT_EQ(0u, global->offset);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind);
EXPECT_EQ(13, global->init.val.i32_const);
EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind());
EXPECT_EQ(13, global->init.immediate().i32_const);
}
EXPECT_OFF_END_FAILURE(data, 1);
......@@ -307,13 +307,13 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
const WasmGlobal* global = &result.value()->globals[0];
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind);
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind());
global = &result.value()->globals[1];
EXPECT_EQ(kWasmFuncRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind);
EXPECT_EQ(uint32_t{1}, global->init.val.function_index);
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind());
EXPECT_EQ(uint32_t{1}, global->init.immediate().index);
}
}
......@@ -355,13 +355,13 @@ TEST_F(WasmModuleVerifyTest, FuncRefGlobal) {
const WasmGlobal* global = &result.value()->globals[0];
EXPECT_EQ(kWasmFuncRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind);
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind());
global = &result.value()->globals[1];
EXPECT_EQ(kWasmFuncRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind);
EXPECT_EQ(uint32_t{1}, global->init.val.function_index);
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind());
EXPECT_EQ(uint32_t{1}, global->init.immediate().index);
}
}
......@@ -410,7 +410,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kGlobalIndex, global->init.kind);
EXPECT_EQ(WasmInitExpr::kGlobalGet, global->init.kind());
}
}
......@@ -444,7 +444,7 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
EXPECT_EQ(WasmInitExpr::kGlobalIndex, global->init.kind);
EXPECT_EQ(WasmInitExpr::kGlobalGet, global->init.kind());
}
}
......@@ -582,14 +582,14 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
EXPECT_EQ(kWasmF32, g0->type);
EXPECT_EQ(0u, g0->offset);
EXPECT_FALSE(g0->mutability);
EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind);
EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind());
const WasmGlobal* g1 = &result.value()->globals[1];
EXPECT_EQ(kWasmF64, g1->type);
EXPECT_EQ(8u, g1->offset);
EXPECT_TRUE(g1->mutability);
EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind);
EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind());
}
EXPECT_OFF_END_FAILURE(data, 1);
......@@ -826,9 +826,9 @@ TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
WasmInitExpr expr = result.value()->data_segments.back().dest_addr;
EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind);
EXPECT_EQ(1u, expr.val.global_index);
WasmInitExpr expr = std::move(result.value()->data_segments.back()).dest_addr;
EXPECT_EQ(WasmInitExpr::kGlobalGet, expr.kind());
EXPECT_EQ(1u, expr.immediate().index);
}
TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
......@@ -885,8 +885,8 @@ TEST_F(WasmModuleVerifyTest, OneDataSegment) {
const WasmDataSegment* segment = &result.value()->data_segments.back();
EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind);
EXPECT_EQ(0x9BBAA, segment->dest_addr.val.i32_const);
EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind());
EXPECT_EQ(0x9BBAA, segment->dest_addr.immediate().i32_const);
EXPECT_EQ(kDataSegmentSourceOffset, segment->source.offset());
EXPECT_EQ(3u, segment->source.length());
}
......@@ -922,13 +922,13 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
const WasmDataSegment* s0 = &result.value()->data_segments[0];
const WasmDataSegment* s1 = &result.value()->data_segments[1];
EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind);
EXPECT_EQ(0x7FFEE, s0->dest_addr.val.i32_const);
EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind());
EXPECT_EQ(0x7FFEE, s0->dest_addr.immediate().i32_const);
EXPECT_EQ(kDataSegment0SourceOffset, s0->source.offset());
EXPECT_EQ(4u, s0->source.length());
EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind);
EXPECT_EQ(0x6DDCC, s1->dest_addr.val.i32_const);
EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind());
EXPECT_EQ(0x6DDCC, s1->dest_addr.immediate().i32_const);
EXPECT_EQ(kDataSegment1SourceOffset, s1->source.offset());
EXPECT_EQ(10u, s1->source.length());
}
......@@ -2259,15 +2259,15 @@ class WasmInitExprDecodeTest : public TestWithZone {
{ \
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind); \
EXPECT_EQ(value, expr.val.type##_const); \
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind()); \
EXPECT_EQ(value, expr.immediate().type##_const); \
}
#define EXPECT_INIT_EXPR_FAIL(...) \
{ \
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
EXPECT_EQ(WasmInitExpr::kNone, expr.kind); \
EXPECT_EQ(WasmInitExpr::kNone, expr.kind()); \
}
TEST_F(WasmInitExprDecodeTest, InitExpr_i32) {
......@@ -2302,7 +2302,7 @@ TEST_F(WasmInitExprDecodeTest, InitExpr_ExternRef) {
WASM_FEATURE_SCOPE(reftypes);
static const byte data[] = {kExprRefNull, kLocalExternRef, kExprEnd};
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data));
EXPECT_EQ(WasmInitExpr::kRefNullConst, expr.kind);
EXPECT_EQ(WasmInitExpr::kRefNullConst, expr.kind());
}
TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) {
......
......@@ -34,9 +34,9 @@ TEST_F(WasmCapiTest, HostRef) {
FunctionSig r_i_sig(1, 1, ri_reps);
uint32_t func_index = builder()->AddImport(CStrVector("f"), &r_r_sig);
const bool kMutable = true;
const WasmInitExpr global_init(WasmInitExpr::kRefNullConst);
uint32_t global_index = builder()->AddExportedGlobal(
kWasmExternRef, kMutable, global_init, CStrVector("global"));
kWasmExternRef, kMutable, WasmInitExpr::RefNullConst(HeapType::kExtern),
CStrVector("global"));
uint32_t table_index = builder()->AddTable(kWasmExternRef, 10);
builder()->AddExport(CStrVector("table"), kExternalTable, table_index);
byte global_set_code[] = {WASM_SET_GLOBAL(global_index, WASM_GET_LOCAL(0))};
......
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