Commit 07b115f8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [cleanup] Introduce WireBytesRef struct

In many places in WasmModule and contained structs we store references
into the wire bytes as pairs of offset and length.
This CL introduces a WireBytesRef struct which encapsulates these two
connected fields. This makes it easier to pass them and assign them as
one unit.

R=ahaas@chromium.org, mtrofin@chromium.org
BUG=v8:6474

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I4f2a40d848a51dc6f6f599f9253c3c6ed6e51627
Reviewed-on: https://chromium-review.googlesource.com/530687
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45859}
parent 291f8dcf
......@@ -9559,10 +9559,10 @@ std::pair<int, int> debug::WasmScript::GetFunctionRange(
DCHECK_GT(compiled_module->module()->functions.size(), function_index);
i::wasm::WasmFunction& func =
compiled_module->module()->functions[function_index];
DCHECK_GE(i::kMaxInt, func.code_start_offset);
DCHECK_GE(i::kMaxInt, func.code_end_offset);
return std::make_pair(static_cast<int>(func.code_start_offset),
static_cast<int>(func.code_end_offset));
DCHECK_GE(i::kMaxInt, func.code.offset());
DCHECK_GE(i::kMaxInt, func.code.end_offset());
return std::make_pair(static_cast<int>(func.code.offset()),
static_cast<int>(func.code.end_offset()));
}
debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
......
......@@ -3914,8 +3914,8 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate,
isolate, &module_env->module_env,
wasm::FunctionBody{
function->sig, module_env->wire_bytes.start(),
module_env->wire_bytes.start() + function->code_start_offset,
module_env->wire_bytes.start() + function->code_end_offset},
module_env->wire_bytes.start() + function->code.offset(),
module_env->wire_bytes.start() + function->code.end_offset()},
module_env->wire_bytes.GetNameOrNull(function), function->func_index,
is_sync) {}
......
......@@ -286,8 +286,8 @@ void ModuleCompiler::ValidateSequentially(ModuleBytesEnv* module_env,
if (func.imported) continue;
const byte* base = module_env->wire_bytes.start();
FunctionBody body{func.sig, base, base + func.code_start_offset,
base + func.code_end_offset};
FunctionBody body{func.sig, base, base + func.code.offset(),
base + func.code.end_offset()};
DecodeResult result = VerifyWasmCode(isolate_->allocator(),
module_env->module_env.module, body);
if (result.failed()) {
......@@ -399,7 +399,6 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
return script;
}
// Ensure that the code object in <code_table> at offset <func_index> has
// Ensure that the code object in <code_table> at offset <func_index> has
// deoptimization data attached. This is needed for lazy compile stubs which are
// called from JS_TO_WASM functions or via exported function tables. The deopt
......@@ -932,7 +931,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
memory_.is_null()
? 0
: static_cast<uint32_t>(memory_->byte_length()->Number());
if (!in_bounds(base, seg.source_size, mem_size)) {
if (!in_bounds(base, seg.source.length(), mem_size)) {
thrower_->LinkError("data segment is out of bounds");
return {};
}
......@@ -1205,7 +1204,7 @@ void InstanceBuilder::LoadDataSegments(Address mem_addr, size_t mem_size) {
Handle<SeqOneByteString> module_bytes(compiled_module_->module_bytes(),
isolate_);
for (const WasmDataSegment& segment : module_->data_segments) {
uint32_t source_size = segment.source_size;
uint32_t source_size = segment.source.length();
// Segments of size == 0 are just nops.
if (source_size == 0) continue;
uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr);
......@@ -1213,7 +1212,7 @@ void InstanceBuilder::LoadDataSegments(Address mem_addr, size_t mem_size) {
in_bounds(dest_offset, source_size, static_cast<uint32_t>(mem_size)));
byte* dest = mem_addr + dest_offset;
const byte* src = reinterpret_cast<const byte*>(
module_bytes->GetCharsAddress() + segment.source_offset);
module_bytes->GetCharsAddress() + segment.source.offset());
memcpy(dest, src, source_size);
}
}
......@@ -1256,15 +1255,13 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
Handle<String> module_name;
MaybeHandle<String> maybe_module_name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, import.module_name_offset,
import.module_name_length);
isolate_, compiled_module_, import.module_name);
if (!maybe_module_name.ToHandle(&module_name)) return -1;
Handle<String> import_name;
MaybeHandle<String> maybe_import_name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, import.field_name_offset,
import.field_name_length);
isolate_, compiled_module_, import.field_name);
if (!maybe_import_name.ToHandle(&import_name)) return -1;
MaybeHandle<Object> result =
......@@ -1555,10 +1552,9 @@ void InstanceBuilder::ProcessExports(
// Process each export in the export table.
int export_index = 0; // Index into {weak_exported_functions}.
for (WasmExport& exp : module_->export_table) {
Handle<String> name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, exp.name_offset, exp.name_length)
.ToHandleChecked();
Handle<String> name = WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, exp.name)
.ToHandleChecked();
Handle<JSObject> export_to;
if (module_->is_asm_js() && exp.kind == kExternalFunction &&
String::Equals(name, single_function_name)) {
......@@ -1582,8 +1578,7 @@ void InstanceBuilder::ProcessExports(
if (module_->is_asm_js()) {
// For modules arising from asm.js, honor the names section.
func_name = WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, function.name_offset,
function.name_length)
isolate_, compiled_module_, function.name)
.ToHandleChecked();
}
js_function = WasmExportedFunction::New(
......@@ -1805,8 +1800,7 @@ void InstanceBuilder::LoadTableSegments(Handle<FixedArray> code_table,
if (module_->is_asm_js()) {
// For modules arising from asm.js, honor the names section.
func_name = WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, function->name_offset,
function->name_length)
isolate_, compiled_module_, function->name)
.ToHandleChecked();
}
Handle<WasmExportedFunction> js_function =
......
This diff is collapsed.
......@@ -80,12 +80,9 @@ V8_EXPORT_PRIVATE WasmInitExpr DecodeWasmInitExprForTesting(const byte* start,
const byte* end);
struct CustomSectionOffset {
uint32_t section_start;
uint32_t name_offset;
uint32_t name_length;
uint32_t payload_offset;
uint32_t payload_length;
uint32_t section_length;
WireBytesRef section;
WireBytesRef name;
WireBytesRef payload;
};
V8_EXPORT_PRIVATE std::vector<CustomSectionOffset> DecodeCustomSections(
......
......@@ -47,7 +47,7 @@ class PatchDirectCallsHelper {
WasmCompiledModule* comp_mod = instance->compiled_module();
int func_index = Smi::cast(deopt_data->get(1))->value();
func_bytes = comp_mod->module_bytes()->GetChars() +
comp_mod->module()->functions[func_index].code_start_offset;
comp_mod->module()->functions[func_index].code.offset();
}
SourcePositionTableIterator source_pos_it;
......
......@@ -955,12 +955,11 @@ class CodeMap {
interpreter_code_.reserve(module->functions.size());
for (const WasmFunction& function : module->functions) {
if (function.imported) {
DCHECK_EQ(function.code_start_offset, function.code_end_offset);
DCHECK(!function.code.is_set());
AddFunction(&function, nullptr, nullptr);
} else {
const byte* code_start = module_start + function.code_start_offset;
const byte* code_end = module_start + function.code_end_offset;
AddFunction(&function, code_start, code_end);
AddFunction(&function, module_start + function.code.offset(),
module_start + function.code.end_offset());
}
}
}
......@@ -2560,7 +2559,7 @@ ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
// Create some dummy structures, to avoid special-casing the implementation
// just for testing.
FunctionSig sig(0, 0, nullptr);
WasmFunction function{&sig, 0, 0, 0, 0, 0, 0, false, false};
WasmFunction function{&sig, 0, 0, {0, 0}, {0, 0}, false, false};
InterpreterCode code{
&function, BodyLocalDecls(zone), start, end, nullptr, nullptr, nullptr};
......
......@@ -331,7 +331,7 @@ void wasm::UnpackAndRegisterProtectedInstructions(
std::ostream& wasm::operator<<(std::ostream& os, const WasmFunctionName& name) {
os << "#" << name.function_->func_index;
if (name.function_->name_offset > 0) {
if (name.function_->name.is_set()) {
if (name.name_.start()) {
os << ":";
os.write(name.name_.start(), name.name_.length());
......@@ -589,13 +589,11 @@ Handle<JSArray> wasm::GetImports(Isolate* isolate,
MaybeHandle<String> import_module =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate, compiled_module, import.module_name_offset,
import.module_name_length);
isolate, compiled_module, import.module_name);
MaybeHandle<String> import_name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate, compiled_module, import.field_name_offset,
import.field_name_length);
isolate, compiled_module, import.field_name);
JSObject::AddProperty(entry, module_string, import_module.ToHandleChecked(),
NONE);
......@@ -660,7 +658,7 @@ Handle<JSArray> wasm::GetExports(Isolate* isolate,
MaybeHandle<String> export_name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate, compiled_module, exp.name_offset, exp.name_length);
isolate, compiled_module, exp.name);
JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(),
NONE);
......@@ -694,10 +692,10 @@ Handle<JSArray> wasm::GetCustomSections(Isolate* isolate,
std::vector<Handle<Object>> matching_sections;
// Gather matching sections.
for (auto section : custom_sections) {
for (auto& section : custom_sections) {
MaybeHandle<String> section_name =
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate, compiled_module, section.name_offset, section.name_length);
isolate, compiled_module, section.name);
if (!name->Equals(*section_name.ToHandleChecked())) continue;
......@@ -705,7 +703,7 @@ Handle<JSArray> wasm::GetCustomSections(Isolate* isolate,
void* allocation_base = nullptr; // Set by TryAllocateBackingStore
size_t allocation_length = 0; // Set by TryAllocateBackingStore
const bool enable_guard_regions = false;
void* memory = TryAllocateBackingStore(isolate, section.payload_length,
void* memory = TryAllocateBackingStore(isolate, section.payload.length(),
enable_guard_regions,
allocation_base, allocation_length);
......@@ -715,13 +713,14 @@ Handle<JSArray> wasm::GetCustomSections(Isolate* isolate,
const bool is_external = false;
JSArrayBuffer::Setup(buffer, isolate, is_external, allocation_base,
allocation_length, memory,
static_cast<int>(section.payload_length));
static_cast<int>(section.payload.length()));
DisallowHeapAllocation no_gc; // for raw access to string bytes.
Handle<SeqOneByteString> module_bytes(compiled_module->module_bytes(),
isolate);
const byte* start =
reinterpret_cast<const byte*>(module_bytes->GetCharsAddress());
memcpy(memory, start + section.payload_offset, section.payload_length);
memcpy(memory, start + section.payload.offset(),
section.payload.length());
section_data = buffer;
} else {
thrower->RangeError("out of memory allocating custom section data");
......@@ -982,8 +981,8 @@ void LazyCompilationOrchestrator::CompileFunction(
uint8_t* module_start = compiled_module->module_bytes()->GetChars();
const WasmFunction* func = &module_env.module->functions[func_index];
wasm::FunctionBody body{func->sig, module_start,
module_start + func->code_start_offset,
module_start + func->code_end_offset};
module_start + func->code.offset(),
module_start + func->code.end_offset()};
// TODO(wasm): Refactor this to only get the name if it is really needed for
// tracing / debugging.
std::string func_name;
......@@ -1071,9 +1070,8 @@ Handle<Code> LazyCompilationOrchestrator::CompileLazy(
int caller_func_index =
Smi::cast(caller->deoptimization_data()->get(1))->value();
const byte* func_bytes =
module_bytes->GetChars() + compiled_module->module()
->functions[caller_func_index]
.code_start_offset;
module_bytes->GetChars() +
compiled_module->module()->functions[caller_func_index].code.offset();
for (RelocIterator it(*caller, RelocInfo::kCodeTargetMask); !it.done();
it.next()) {
Code* callee =
......
......@@ -15,7 +15,6 @@
#include "src/parsing/preparse-data.h"
#include "src/wasm/signature-map.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-opcodes.h"
namespace v8 {
......@@ -25,6 +24,7 @@ class WasmCompiledModule;
class WasmDebugInfo;
class WasmModuleObject;
class WasmInstanceObject;
class WasmTableObject;
class WasmMemoryObject;
namespace compiler {
......@@ -70,15 +70,34 @@ struct WasmInitExpr {
}
};
// Reference to a string in the wire bytes.
class WireBytesRef {
public:
WireBytesRef() : WireBytesRef(0, 0) {}
WireBytesRef(uint32_t offset, uint32_t length)
: offset_(offset), length_(length) {
DCHECK_IMPLIES(offset_ == 0, length_ == 0);
DCHECK_LE(offset_, offset_ + length_); // no uint32_t overflow.
}
uint32_t offset() const { return offset_; }
uint32_t length() const { return length_; }
uint32_t end_offset() const { return offset_ + length_; }
bool is_empty() const { return length_ == 0; }
bool is_set() const { return offset_ != 0; }
private:
uint32_t offset_;
uint32_t length_;
};
// Static representation of a wasm function.
struct WasmFunction {
FunctionSig* sig; // signature of the function.
uint32_t func_index; // index into the function table.
uint32_t sig_index; // index into the signature table.
uint32_t name_offset; // offset in the module bytes of the name, if any.
uint32_t name_length; // length in bytes of the name.
uint32_t code_start_offset; // offset in the module bytes of code start.
uint32_t code_end_offset; // offset in the module bytes of code end.
WireBytesRef name; // function name, if any.
WireBytesRef code; // code of this function.
bool imported;
bool exported;
};
......@@ -96,8 +115,7 @@ struct WasmGlobal {
// Static representation of a wasm data segment.
struct WasmDataSegment {
WasmInitExpr dest_addr; // destination memory address of the data.
uint32_t source_offset; // start offset in the module bytes.
uint32_t source_size; // end offset in the module bytes.
WireBytesRef source; // start offset in the module bytes.
};
// Static representation of a wasm indirect call table.
......@@ -121,18 +139,15 @@ struct WasmTableInit {
// Static representation of a wasm import.
struct WasmImport {
uint32_t module_name_length; // length in bytes of the module name.
uint32_t module_name_offset; // offset in module bytes of the module name.
uint32_t field_name_length; // length in bytes of the import name.
uint32_t field_name_offset; // offset in module bytes of the import name.
WasmExternalKind kind; // kind of the import.
uint32_t index; // index into the respective space.
WireBytesRef module_name; // module name.
WireBytesRef field_name; // import name.
WasmExternalKind kind; // kind of the import.
uint32_t index; // index into the respective space.
};
// Static representation of a wasm export.
struct WasmExport {
uint32_t name_length; // length in bytes of the exported name.
uint32_t name_offset; // offset in module bytes of the name to export.
WireBytesRef name; // exported name.
WasmExternalKind kind; // kind of the export.
uint32_t index; // index into the respective space.
};
......@@ -169,8 +184,7 @@ struct V8_EXPORT_PRIVATE WasmModule {
uint32_t num_imported_functions = 0; // number of imported functions.
uint32_t num_declared_functions = 0; // number of declared functions.
uint32_t num_exported_functions = 0; // number of exported functions.
uint32_t name_offset = 0; // offset in the module bytes of the name, if any.
uint32_t name_length = 0; // length in bytes of the name.
WireBytesRef name = {0, 0}; // module name, if any.
// TODO(wasm): Add url here, for spec'ed location information.
std::vector<FunctionSig*> signatures; // signatures in this module.
std::vector<WasmFunction> functions; // functions in this module.
......@@ -255,31 +269,29 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes {
}
// Get a string stored in the module bytes representing a name.
WasmName GetName(uint32_t offset, uint32_t length) const {
if (length == 0) return {"<?>", 3}; // no name.
CHECK(BoundsCheck(offset, length));
DCHECK_GE(length, 0);
WasmName GetName(WireBytesRef ref) const {
if (ref.is_empty()) return {"<?>", 3}; // no name.
CHECK(BoundsCheck(ref.offset(), ref.length()));
return Vector<const char>::cast(
module_bytes_.SubVector(offset, offset + length));
module_bytes_.SubVector(ref.offset(), ref.end_offset()));
}
// Get a string stored in the module bytes representing a function name.
WasmName GetName(const WasmFunction* function) const {
return GetName(function->name_offset, function->name_length);
return GetName(function->name);
}
// Get a string stored in the module bytes representing a name.
WasmName GetNameOrNull(uint32_t offset, uint32_t length) const {
if (offset == 0 && length == 0) return {NULL, 0}; // no name.
CHECK(BoundsCheck(offset, length));
DCHECK_GE(length, 0);
WasmName GetNameOrNull(WireBytesRef ref) const {
if (!ref.is_set()) return {NULL, 0}; // no name.
CHECK(BoundsCheck(ref.offset(), ref.length()));
return Vector<const char>::cast(
module_bytes_.SubVector(offset, offset + length));
module_bytes_.SubVector(ref.offset(), ref.end_offset()));
}
// Get a string stored in the module bytes representing a function name.
WasmName GetNameOrNull(const WasmFunction* function) const {
return GetNameOrNull(function->name_offset, function->name_length);
return GetNameOrNull(function->name);
}
// Checks the given offset range is contained within the module bytes.
......@@ -289,8 +301,8 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes {
}
Vector<const byte> GetFunctionBytes(const WasmFunction* function) const {
return module_bytes_.SubVector(function->code_start_offset,
function->code_end_offset);
return module_bytes_.SubVector(function->code.offset(),
function->code.end_offset());
}
const byte* start() const { return module_bytes_.start(); }
......
This diff is collapsed.
......@@ -11,13 +11,12 @@
#include "src/objects/script.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
namespace v8 {
namespace internal {
namespace wasm {
class InterpretedFrame;
struct WasmModule;
struct WasmInstance;
class WasmInterpreter;
}
......@@ -499,7 +498,7 @@ class WasmCompiledModule : public FixedArray {
// string.
static MaybeHandle<String> ExtractUtf8StringFromModuleBytes(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
uint32_t offset, uint32_t size);
wasm::WireBytesRef ref);
// Get a list of all possible breakpoints within a given range of this module.
bool GetPossibleBreakpoints(const debug::Location& start,
......
......@@ -140,7 +140,7 @@ Handle<JSObject> MakeFakeBreakpoint(Isolate* isolate, int position) {
void SetBreakpoint(WasmRunnerBase& runner, int function_index, int byte_offset,
int expected_set_byte_offset = -1) {
int func_offset =
runner.module().module->functions[function_index].code_start_offset;
runner.module().module->functions[function_index].code.offset();
int code_offset = func_offset + byte_offset;
if (expected_set_byte_offset == -1) expected_set_byte_offset = byte_offset;
Handle<WasmInstanceObject> instance = runner.module().instance_object();
......
......@@ -194,11 +194,11 @@ class TestingModule : public ModuleEnv {
module_.functions.reserve(kMaxFunctions);
}
uint32_t index = static_cast<uint32_t>(module->functions.size());
module_.functions.push_back({sig, index, 0, 0, 0, 0, 0, false, false});
module_.functions.push_back({sig, index, 0, {0, 0}, {0, 0}, false, false});
if (name) {
Vector<const byte> name_vec = Vector<const byte>::cast(CStrVector(name));
module_.functions.back().name_offset = AddBytes(name_vec);
module_.functions.back().name_length = name_vec.length();
module_.functions.back().name = {
AddBytes(name_vec), static_cast<uint32_t>(name_vec.length())};
}
instance->function_code.push_back(code);
if (interpreter_) {
......@@ -537,9 +537,9 @@ class WasmFunctionCompiler : private GraphAndBuilders {
CHECK_GE(kMaxInt, end - start);
int len = static_cast<int>(end - start);
function_->code_start_offset =
testing_module_->AddBytes(Vector<const byte>(start, len));
function_->code_end_offset = function_->code_start_offset + len;
function_->code = {
testing_module_->AddBytes(Vector<const byte>(start, len)),
static_cast<uint32_t>(len)};
if (interpreter_) {
// Add the code to the interpreter.
......
......@@ -210,10 +210,8 @@ class TestModuleEnv : public ModuleEnv {
mod.functions.push_back({sig, // sig
0, // func_index
0, // sig_index
0, // name_offset
0, // name_length
0, // code_start_offset
0, // code_end_offset
{0, 0}, // name
{0, 0}, // code
false, // import
false}); // export
CHECK(mod.functions.size() <= 127);
......
......@@ -525,8 +525,8 @@ TEST_F(WasmModuleVerifyTest, OneDataSegment) {
EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind);
EXPECT_EQ(0x9bbaa, segment->dest_addr.val.i32_const);
EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
EXPECT_EQ(3u, segment->source_size);
EXPECT_EQ(kDataSegmentSourceOffset, segment->source.offset());
EXPECT_EQ(3u, segment->source.length());
}
EXPECT_OFF_END_FAILURE(data, 14, sizeof(data));
......@@ -578,13 +578,13 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind);
EXPECT_EQ(0x7ffee, s0->dest_addr.val.i32_const);
EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset);
EXPECT_EQ(4u, s0->source_size);
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(kDataSegment1SourceOffset, s1->source_offset);
EXPECT_EQ(10u, s1->source_size);
EXPECT_EQ(kDataSegment1SourceOffset, s1->source.offset());
EXPECT_EQ(10u, s1->source.length());
}
EXPECT_OFF_END_FAILURE(data, 14, sizeof(data));
......@@ -932,10 +932,10 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
WasmFunction* function = result.val.get();
EXPECT_EQ(0u, function->sig->parameter_count());
EXPECT_EQ(0u, function->sig->return_count());
EXPECT_EQ(0u, function->name_offset);
EXPECT_EQ(0u, function->name.offset());
EXPECT_EQ(static_cast<uint32_t>(SIZEOF_SIG_ENTRY_v_v),
function->code_start_offset);
EXPECT_EQ(sizeof(data), function->code_end_offset);
function->code.offset());
EXPECT_EQ(sizeof(data), function->code.end_offset());
// TODO(titzer): verify encoding of local declarations
}
}
......@@ -1525,7 +1525,7 @@ TEST_F(WasmModuleVerifyTest, Section_Name_No_UTF8) {
class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
public:
void CheckSections(const byte* module_start, const byte* module_end,
CustomSectionOffset expected[], size_t num_expected) {
const CustomSectionOffset* expected, size_t num_expected) {
// Add the WASM magic and version number automatically.
size_t size = static_cast<size_t>(module_end - module_start);
byte header[] = {WASM_MODULE_HEADER};
......@@ -1539,18 +1539,22 @@ class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
CHECK_EQ(num_expected, custom_sections.size());
for (size_t i = 0; i < num_expected; i++) {
EXPECT_EQ(expected[i].section_start, custom_sections[i].section_start);
EXPECT_EQ(expected[i].name_offset, custom_sections[i].name_offset);
EXPECT_EQ(expected[i].name_length, custom_sections[i].name_length);
EXPECT_EQ(expected[i].payload_offset, custom_sections[i].payload_offset);
EXPECT_EQ(expected[i].payload_length, custom_sections[i].payload_length);
EXPECT_EQ(expected[i].section_length, custom_sections[i].section_length);
EXPECT_EQ(expected[i].section.offset(),
custom_sections[i].section.offset());
EXPECT_EQ(expected[i].section.length(),
custom_sections[i].section.length());
EXPECT_EQ(expected[i].name.offset(), custom_sections[i].name.offset());
EXPECT_EQ(expected[i].name.length(), custom_sections[i].name.length());
EXPECT_EQ(expected[i].payload.offset(),
custom_sections[i].payload.offset());
EXPECT_EQ(expected[i].payload.length(),
custom_sections[i].payload.length());
}
}
};
TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
static const byte data[] = {
static constexpr byte data[] = {
U32_LE(kWasmMagic), // --
U32_LE(kWasmVersion), // --
SECTION(Unknown, 4), 1, 'X', 17, 18, // --
......@@ -1558,11 +1562,11 @@ TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
};
static CustomSectionOffset expected[] = {
// sec_start, nm_offset, nm_length, py_offset, py_length, sec_length
{10, 11, 1, 12, 2, 4}, // --
{16, 17, 3, 20, 5, 9}, // --
{27, 28, 5, 33, 2, 8}, // --
static const CustomSectionOffset expected[] = {
// section, name, payload
{{10, 4}, {11, 1}, {12, 2}}, // --
{{16, 9}, {17, 3}, {20, 5}}, // --
{{27, 8}, {28, 5}, {33, 2}}, // --
};
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
......@@ -1590,10 +1594,10 @@ TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
8, // --
};
static CustomSectionOffset expected[] = {
// sec_start, nm_offset, nm_length, py_offset, py_length, sec_length
{19, 20, 1, 21, 2, 4}, // --
{29, 30, 5, 35, 2, 8}, // --
static const CustomSectionOffset expected[] = {
// section, name, payload
{{19, 4}, {20, 1}, {21, 2}}, // --
{{29, 8}, {30, 5}, {35, 2}}, // --
};
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
......
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