Commit ca4c236f authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Rename WasmTableInit to WasmElemSegment

This matches the terminology that is used throughout the spec.

R=clemensh@chromium.org

Change-Id: I62445e750415e6048b805110c7306f3bdbf9da60
Reviewed-on: https://chromium-review.googlesource.com/c/1408988
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58774}
parent 514033ab
......@@ -1059,7 +1059,7 @@ class WasmDecoder : public Decoder {
inline bool Validate(TableInitImmediate<validate>& imm) {
if (!Validate(pc_ + 1, imm.table)) return false;
if (!VALIDATE(module_ != nullptr &&
imm.elem_segment_index < module_->table_inits.size())) {
imm.elem_segment_index < module_->elem_segments.size())) {
errorf(pc_ + 2, "invalid element segment index: %u",
imm.elem_segment_index);
return false;
......@@ -1069,7 +1069,7 @@ class WasmDecoder : public Decoder {
inline bool Validate(TableDropImmediate<validate>& imm) {
if (!VALIDATE(module_ != nullptr &&
imm.index < module_->table_inits.size())) {
imm.index < module_->elem_segments.size())) {
errorf(pc_ + 2, "invalid element segment index: %u", imm.index);
return false;
}
......
......@@ -1265,12 +1265,12 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//--------------------------------------------------------------------------
// Check that indirect function table segments are within bounds.
//--------------------------------------------------------------------------
for (const WasmTableInit& table_init : module_->table_inits) {
if (!table_init.active) continue;
DCHECK(table_init.table_index < table_instances_.size());
uint32_t base = EvalUint32InitExpr(table_init.offset);
size_t table_size = table_instances_[table_init.table_index].table_size;
if (!in_bounds(base, table_init.entries.size(), table_size)) {
for (const WasmElemSegment& elem_segment : module_->elem_segments) {
if (!elem_segment.active) continue;
DCHECK(elem_segment.table_index < table_instances_.size());
uint32_t base = EvalUint32InitExpr(elem_segment.offset);
size_t table_size = table_instances_[elem_segment.table_index].table_size;
if (!in_bounds(base, elem_segment.entries.size(), table_size)) {
thrower_->LinkError("table initializer is out of bounds");
return {};
}
......@@ -2277,17 +2277,17 @@ void InstanceBuilder::InitializeTables(Handle<WasmInstanceObject> instance) {
void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
NativeModule* native_module = module_object_->native_module();
for (auto& table_init : module_->table_inits) {
for (auto& elem_segment : module_->elem_segments) {
// Passive segments are not copied during instantiation.
if (!table_init.active) continue;
if (!elem_segment.active) continue;
uint32_t base = EvalUint32InitExpr(table_init.offset);
uint32_t num_entries = static_cast<uint32_t>(table_init.entries.size());
uint32_t index = table_init.table_index;
uint32_t base = EvalUint32InitExpr(elem_segment.offset);
uint32_t num_entries = static_cast<uint32_t>(elem_segment.entries.size());
uint32_t index = elem_segment.table_index;
TableInstance& table_instance = table_instances_[index];
DCHECK(in_bounds(base, num_entries, table_instance.table_size));
for (uint32_t i = 0; i < num_entries; ++i) {
uint32_t func_index = table_init.entries[i];
uint32_t func_index = elem_segment.entries[i];
const WasmFunction* function = &module_->functions[func_index];
int table_index = static_cast<int>(i + base);
......
......@@ -801,12 +801,12 @@ class ModuleDecoderImpl : public Decoder {
uint32_t num_elem =
consume_count("number of elements", kV8MaxWasmTableEntries);
if (is_active) {
module_->table_inits.emplace_back(table_index, offset);
module_->elem_segments.emplace_back(table_index, offset);
} else {
module_->table_inits.emplace_back();
module_->elem_segments.emplace_back();
}
WasmTableInit* init = &module_->table_inits.back();
WasmElemSegment* init = &module_->elem_segments.back();
for (uint32_t j = 0; j < num_elem; j++) {
WasmFunction* func = nullptr;
uint32_t index = consume_func_index(module_.get(), &func);
......
......@@ -321,7 +321,7 @@ size_t EstimateStoredSize(const WasmModule* module) {
VectorSize(module->functions) + VectorSize(module->data_segments) +
VectorSize(module->tables) + VectorSize(module->import_table) +
VectorSize(module->export_table) + VectorSize(module->exceptions) +
VectorSize(module->table_inits);
VectorSize(module->elem_segments);
}
} // namespace wasm
} // namespace internal
......
......@@ -109,16 +109,16 @@ struct WasmTable {
bool exported = false; // true if exported.
};
// Static representation of how to initialize a table.
struct WasmTableInit {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmTableInit);
// Static representation of wasm element segment (table initializer).
struct WasmElemSegment {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmElemSegment);
// Construct an active segment.
WasmTableInit(uint32_t table_index, WasmInitExpr offset)
WasmElemSegment(uint32_t table_index, WasmInitExpr offset)
: table_index(table_index), offset(offset), active(true) {}
// Construct a passive segment, which has no table index or offset.
WasmTableInit() : table_index(0), active(false) {}
WasmElemSegment() : table_index(0), active(false) {}
uint32_t table_index;
WasmInitExpr offset;
......@@ -181,7 +181,7 @@ struct V8_EXPORT_PRIVATE WasmModule {
std::vector<WasmImport> import_table;
std::vector<WasmExport> export_table;
std::vector<WasmException> exceptions;
std::vector<WasmTableInit> table_inits;
std::vector<WasmElemSegment> elem_segments;
SignatureMap signature_map; // canonicalizing map for signature indexes.
ModuleOrigin origin = kWasmOrigin; // origin of the module
......
......@@ -180,19 +180,19 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
os << "undefined);\n";
}
}
for (const WasmTableInit& table_init : module->table_inits) {
for (const WasmElemSegment& elem_segment : module->elem_segments) {
os << " builder.addElementSegment(";
switch (table_init.offset.kind) {
switch (elem_segment.offset.kind) {
case WasmInitExpr::kGlobalIndex:
os << table_init.offset.val.global_index << ", true";
os << elem_segment.offset.val.global_index << ", true";
break;
case WasmInitExpr::kI32Const:
os << table_init.offset.val.i32_const << ", false";
os << elem_segment.offset.val.i32_const << ", false";
break;
default:
UNREACHABLE();
}
os << ", " << PrintCollection(table_init.entries) << ");\n";
os << ", " << PrintCollection(elem_segment.entries) << ");\n";
}
for (const WasmFunction& func : module->functions) {
......
......@@ -264,8 +264,8 @@ class TestModuleBuilder {
void InitializeTable() { mod.tables.emplace_back(); }
byte AddPassiveElementSegment() {
mod.table_inits.emplace_back();
return static_cast<byte>(mod.table_inits.size() - 1);
mod.elem_segments.emplace_back();
return static_cast<byte>(mod.elem_segments.size() - 1);
}
// Set the number of data segments as declared by the DataCount section.
......
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