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

Side by Side Diff: src/wasm/wasm-interpreter.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, 4 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 unified diff | Download patch
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-interpreter.h" 5 #include "src/wasm/wasm-interpreter.h"
6 #include "src/wasm/ast-decoder.h" 6 #include "src/wasm/ast-decoder.h"
7 #include "src/wasm/decoder.h" 7 #include "src/wasm/decoder.h"
8 #include "src/wasm/wasm-external-refs.h" 8 #include "src/wasm/wasm-external-refs.h"
9 #include "src/wasm/wasm-module.h" 9 #include "src/wasm/wasm-module.h"
10 10
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 return code; 908 return code;
909 } 909 }
910 return nullptr; 910 return nullptr;
911 } 911 }
912 912
913 InterpreterCode* GetCode(uint32_t function_index) { 913 InterpreterCode* GetCode(uint32_t function_index) {
914 CHECK_LT(function_index, interpreter_code_.size()); 914 CHECK_LT(function_index, interpreter_code_.size());
915 return Preprocess(&interpreter_code_[function_index]); 915 return Preprocess(&interpreter_code_[function_index]);
916 } 916 }
917 917
918 InterpreterCode* GetIndirectCode(uint32_t indirect_index) { 918 InterpreterCode* GetIndirectCode(uint32_t table_index, uint32_t entry_index) {
919 if (indirect_index >= module_->function_table.size()) return nullptr; 919 if (table_index >= module_->function_tables.size()) return nullptr;
920 uint32_t index = module_->function_table[indirect_index]; 920 const WasmIndirectFunctionTable* table =
921 &module_->function_tables[table_index];
922 if (entry_index >= table->values.size()) return nullptr;
923 uint32_t index = table->values[entry_index];
921 if (index >= interpreter_code_.size()) return nullptr; 924 if (index >= interpreter_code_.size()) return nullptr;
922 return GetCode(index); 925 return GetCode(index);
923 } 926 }
924 927
925 InterpreterCode* Preprocess(InterpreterCode* code) { 928 InterpreterCode* Preprocess(InterpreterCode* code) {
926 if (code->targets == nullptr && code->start) { 929 if (code->targets == nullptr && code->start) {
927 // Compute the control targets map and the local declarations. 930 // Compute the control targets map and the local declarations.
928 CHECK(DecodeLocalDecls(code->locals, code->start, code->end)); 931 CHECK(DecodeLocalDecls(code->locals, code->start, code->end));
929 code->targets = 932 code->targets =
930 new (zone_) ControlTransfers(zone_, code->locals.decls_encoded_size, 933 new (zone_) ControlTransfers(zone_, code->locals.decls_encoded_size,
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 InterpreterCode* target = codemap()->GetCode(operand.index); 1379 InterpreterCode* target = codemap()->GetCode(operand.index);
1377 DoCall(target, &pc, pc + 1 + operand.length, &limit); 1380 DoCall(target, &pc, pc + 1 + operand.length, &limit);
1378 code = target; 1381 code = target;
1379 decoder.Reset(code->start, code->end); 1382 decoder.Reset(code->start, code->end);
1380 continue; 1383 continue;
1381 } 1384 }
1382 case kExprCallIndirect: { 1385 case kExprCallIndirect: {
1383 CallIndirectOperand operand(&decoder, code->at(pc)); 1386 CallIndirectOperand operand(&decoder, code->at(pc));
1384 size_t index = stack_.size() - operand.arity - 1; 1387 size_t index = stack_.size() - operand.arity - 1;
1385 DCHECK_LT(index, stack_.size()); 1388 DCHECK_LT(index, stack_.size());
1386 uint32_t table_index = stack_[index].to<uint32_t>(); 1389 uint32_t entry_index = stack_[index].to<uint32_t>();
1387 if (table_index >= module()->function_table.size()) { 1390 // Assume only one table for now.
1391 DCHECK_LE(module()->function_tables.size(), 1u);
1392 InterpreterCode* target = codemap()->GetIndirectCode(0, entry_index);
1393 if (target == nullptr) {
1388 return DoTrap(kTrapFuncInvalid, pc); 1394 return DoTrap(kTrapFuncInvalid, pc);
1389 } 1395 } else if (target->function->sig_index != operand.index) {
1390 uint16_t function_index = module()->function_table[table_index];
1391 InterpreterCode* target = codemap()->GetCode(function_index);
1392 DCHECK(target);
1393 if (target->function->sig_index != operand.index) {
1394 return DoTrap(kTrapFuncSigMismatch, pc); 1396 return DoTrap(kTrapFuncSigMismatch, pc);
1395 } 1397 }
1396 1398
1397 DoCall(target, &pc, pc + 1 + operand.length, &limit); 1399 DoCall(target, &pc, pc + 1 + operand.length, &limit);
1398 code = target; 1400 code = target;
1399 decoder.Reset(code->start, code->end); 1401 decoder.Reset(code->start, code->end);
1400 continue; 1402 continue;
1401 } 1403 }
1402 case kExprCallImport: { 1404 case kExprCallImport: {
1403 UNIMPLEMENTED(); 1405 UNIMPLEMENTED();
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 1810
1809 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1811 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1810 Zone* zone, const byte* start, const byte* end) { 1812 Zone* zone, const byte* start, const byte* end) {
1811 ControlTransfers targets(zone, 0, start, end); 1813 ControlTransfers targets(zone, 0, start, end);
1812 return targets.map_; 1814 return targets.map_;
1813 } 1815 }
1814 1816
1815 } // namespace wasm 1817 } // namespace wasm
1816 } // namespace internal 1818 } // namespace internal
1817 } // namespace v8 1819 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698