Chromium Code Reviews| Index: src/compiler/wasm-compiler.cc |
| diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
| index 300547a31add6284d64c51dacbd9f7761351b962..1855af530f29ba9e9abcc5e34a30b7437ddf257c 100644 |
| --- a/src/compiler/wasm-compiler.cc |
| +++ b/src/compiler/wasm-compiler.cc |
| @@ -276,7 +276,7 @@ WasmGraphBuilder::WasmGraphBuilder( |
| module_(nullptr), |
| mem_buffer_(nullptr), |
| mem_size_(nullptr), |
| - function_table_(nullptr), |
| + function_tables_(zone), |
| control_(nullptr), |
| effect_(nullptr), |
| cur_buffer_(def_buffer_), |
| @@ -2057,11 +2057,14 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, |
| // Compute the code object by loading it from the function table. |
| Node* key = args[0]; |
| + // Assume only one table for now. |
| + DCHECK_EQ(module_->instance->function_tables.size(), 1); |
| // Bounds check the index. |
| - int table_size = static_cast<int>(module_->FunctionTableSize()); |
| + int table_size = |
| + module_->IsValidTable(0) ? module_->GetTable(0)->max_size : 0; |
| if (table_size > 0) { |
| // Bounds check against the table size. |
| - Node* size = Int32Constant(static_cast<int>(table_size)); |
| + Node* size = Int32Constant(table_size); |
| Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); |
| trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); |
| } else { |
| @@ -2069,7 +2072,7 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, |
| trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, Int32Constant(0), position); |
| return trap_->GetTrapValue(module_->GetSignature(index)); |
| } |
| - Node* table = FunctionTable(); |
| + Node* table = FunctionTable(0); |
| // Load signature from the table and check. |
| // The table is a FixedArray; signatures are encoded as SMIs. |
| @@ -2129,10 +2132,13 @@ Node* WasmGraphBuilder::JITSingleFunction(Node* const base, Node* const length, |
| // Bounds check the index. |
| { |
| - int table_size = static_cast<int>(module_->FunctionTableSize()); |
| + // Assume only one table for now. |
| + DCHECK_EQ(module_->instance->function_tables.size(), 1); |
| + int table_size = |
| + module_->IsValidTable(0) ? module_->GetTable(0)->max_size : 0; |
| if (table_size > 0) { |
| // Bounds check against the table size. |
| - Node* size = Int32Constant(static_cast<int>(table_size)); |
| + Node* size = Int32Constant(table_size); |
| Node* in_bounds = |
| graph()->NewNode(machine->Uint32LessThan(), index, size); |
| trap_->AddTrapIfFalse(wasm::kTrapInvalidIndex, in_bounds, position); |
| @@ -2162,7 +2168,7 @@ Node* WasmGraphBuilder::JITSingleFunction(Node* const base, Node* const length, |
| inputs[1] = BuildChangeUint32ToSmi(base); |
| inputs[2] = BuildChangeUint32ToSmi(length); |
| inputs[3] = BuildChangeUint32ToSmi(index); |
| - inputs[4] = FunctionTable(); |
| + inputs[4] = FunctionTable(0); |
| inputs[5] = Uint32Constant(sig_index); |
| inputs[6] = BuildChangeUint32ToSmi(Uint32Constant(return_count)); |
| @@ -2804,13 +2810,17 @@ Node* WasmGraphBuilder::DefaultS128Value() { |
| zero, zero); |
| } |
| -Node* WasmGraphBuilder::FunctionTable() { |
| +Node* WasmGraphBuilder::FunctionTable(uint32_t index) { |
| DCHECK(module_ && module_->instance && |
| - !module_->instance->function_table.is_null()); |
| - if (!function_table_) { |
| - function_table_ = HeapConstant(module_->instance->function_table); |
| + index < module_->instance->function_tables.size()); |
| + if (index >= function_tables_.size()) { |
|
Mircea Trofin
2016/07/26 03:37:26
I think it'd be a bit more readable if you either:
ddchen
2016/07/26 05:44:43
I'll take the former approach; the module isn't av
|
| + for (size_t i = function_tables_.size(); i <= index; i++) { |
|
Mircea Trofin
2016/07/26 03:37:26
++i
ddchen
2016/07/26 05:44:44
Done.
|
| + DCHECK(!module_->instance->function_tables[i].is_null()); |
| + function_tables_.push_back( |
| + HeapConstant(module_->instance->function_tables[i])); |
| + } |
| } |
| - return function_table_; |
| + return function_tables_[index]; |
| } |
| Node* WasmGraphBuilder::ChangeToRuntimeCall(Node* node, |