Chromium Code Reviews| Index: src/wasm/module-decoder.cc |
| diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc |
| index 326c2e26ab541515db785537f4173f0ad1b6ef21..15067febba05f16b7f23251673feb273d3bff55c 100644 |
| --- a/src/wasm/module-decoder.cc |
| +++ b/src/wasm/module-decoder.cc |
| @@ -257,38 +257,20 @@ 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. |
| + uint32_t table_count = 1; |
|
Mircea Trofin
2016/07/26 03:37:27
static const uint32_t kSupportedTableCount = 1
ddchen
2016/07/26 05:44:44
Done.
|
| + module->function_tables.reserve(SafeReserve(table_count)); |
| // Decode function table. |
| - for (uint32_t i = 0; i < function_table_count; ++i) { |
| + for (uint32_t i = 0; i < table_count; ++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.back()); |
|
Mircea Trofin
2016/07/26 03:37:26
should it be module->function_tables[i], for consi
ddchen
2016/07/26 05:44:44
Done.
|
| } |
| break; |
| } |
| @@ -520,6 +502,26 @@ class ModuleDecoder : public Decoder { |
| consume_bytes(segment->source_size); |
| } |
| + // Decodes a single function table inside a module starting at {pc_}. |
| + void DecodeFunctionTableInModule(WasmModule* module, WasmTable* 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++) { |
|
Mircea Trofin
2016/07/26 03:37:26
++i
ddchen
2016/07/26 05:44:44
Done.
|
| + uint16_t index = consume_u32v(); |
| + if (index >= module->functions.size()) { |
| + error(pc_ - 2, "invalid function index"); |
|
Mircea Trofin
2016/07/26 03:37:26
what's "2"? (sizeof(uint16_t) ?)
ddchen
2016/07/26 05:44:44
Done.
|
| + break; |
| + } |
| + table->values.push_back(index); |
| + } |
| + } |
| + |
| // Calculate individual global offsets and total size of globals table. |
| void CalculateGlobalsOffsets(WasmModule* module) { |
| uint32_t offset = 0; |