Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: src/wasm/module-decoder.cc

Issue 2174123002: [wasm] Add support for multiple indirect function tables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix GC issue Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index ffa24a41b826872a6630708ad945dfd787c53a9f..ad2124ed98a776beb53395ca8c71601c1e57bb10 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -257,38 +257,19 @@ class ModuleDecoder : public Decoder {
}
break;
}
- case WasmSection::Code::FunctionTablePad: {
- if (!FLAG_wasm_jit_prototype) {
- error("FunctionTablePad section without jiting enabled");
- }
- // An indirect function table requires functions first.
- module->indirect_table_size = consume_u32v("indirect entry count");
- if (module->indirect_table_size > 0 &&
- module->indirect_table_size < module->function_table.size()) {
- error("more predefined indirect entries than table can hold");
- }
- break;
- }
case WasmSection::Code::FunctionTable: {
// An indirect function table requires functions first.
CheckForFunctions(module, section);
- uint32_t function_table_count = consume_u32v("function table count");
- module->function_table.reserve(SafeReserve(function_table_count));
+ // Assume only one table for now.
+ static const uint32_t kSupportedTableCount = 1;
+ module->function_tables.reserve(SafeReserve(kSupportedTableCount));
// Decode function table.
- for (uint32_t i = 0; i < function_table_count; ++i) {
+ for (uint32_t i = 0; i < kSupportedTableCount; ++i) {
if (failed()) break;
TRACE("DecodeFunctionTable[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
- uint16_t index = consume_u32v();
- if (index >= module->functions.size()) {
- error(pc_ - 2, "invalid function index");
- break;
- }
- module->function_table.push_back(index);
- }
- if (module->indirect_table_size > 0 &&
- module->indirect_table_size < module->function_table.size()) {
- error("more predefined indirect entries than table can hold");
+ module->function_tables.push_back({0, 0, std::vector<uint16_t>()});
+ DecodeFunctionTableInModule(module, &module->function_tables[i]);
}
break;
}
@@ -520,6 +501,27 @@ class ModuleDecoder : public Decoder {
consume_bytes(segment->source_size);
}
+ // Decodes a single function table inside a module starting at {pc_}.
+ void DecodeFunctionTableInModule(WasmModule* module,
+ WasmIndirectFunctionTable* table) {
+ table->size = consume_u32v("function table entry count");
+ table->max_size = FLAG_wasm_jit_prototype ? consume_u32v() : table->size;
+
+ if ((!FLAG_wasm_jit_prototype && table->max_size != table->size) ||
+ (FLAG_wasm_jit_prototype && table->max_size < table->size)) {
+ error("invalid table maximum size");
+ }
+
+ for (uint32_t i = 0; i < table->size; ++i) {
+ uint16_t index = consume_u32v();
+ if (index >= module->functions.size()) {
+ error(pc_ - sizeof(index), "invalid function index");
+ break;
+ }
+ table->values.push_back(index);
+ }
+ }
+
// Calculate individual global offsets and total size of globals table.
void CalculateGlobalsOffsets(WasmModule* module) {
uint32_t offset = 0;
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698