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

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 loop bug, cleanups, style 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
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 WasmTable* table = &module_->function_tables[table_index];
921 if (entry_index >= table->values.size()) return nullptr;
922 uint32_t index = table->values[entry_index];
921 if (index >= interpreter_code_.size()) return nullptr; 923 if (index >= interpreter_code_.size()) return nullptr;
922 return GetCode(index); 924 return GetCode(index);
923 } 925 }
924 926
925 InterpreterCode* Preprocess(InterpreterCode* code) { 927 InterpreterCode* Preprocess(InterpreterCode* code) {
926 if (code->targets == nullptr && code->start) { 928 if (code->targets == nullptr && code->start) {
927 // Compute the control targets map and the local declarations. 929 // Compute the control targets map and the local declarations.
928 CHECK(DecodeLocalDecls(code->locals, code->start, code->end)); 930 CHECK(DecodeLocalDecls(code->locals, code->start, code->end));
929 code->targets = 931 code->targets =
930 new (zone_) ControlTransfers(zone_, code->locals.decls_encoded_size, 932 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); 1378 InterpreterCode* target = codemap()->GetCode(operand.index);
1377 DoCall(target, &pc, pc + 1 + operand.length, &limit); 1379 DoCall(target, &pc, pc + 1 + operand.length, &limit);
1378 code = target; 1380 code = target;
1379 decoder.Reset(code->start, code->end); 1381 decoder.Reset(code->start, code->end);
1380 continue; 1382 continue;
1381 } 1383 }
1382 case kExprCallIndirect: { 1384 case kExprCallIndirect: {
1383 CallIndirectOperand operand(&decoder, code->at(pc)); 1385 CallIndirectOperand operand(&decoder, code->at(pc));
1384 size_t index = stack_.size() - operand.arity - 1; 1386 size_t index = stack_.size() - operand.arity - 1;
1385 DCHECK_LT(index, stack_.size()); 1387 DCHECK_LT(index, stack_.size());
1386 uint32_t table_index = stack_[index].to<uint32_t>(); 1388 uint32_t entry_index = stack_[index].to<uint32_t>();
1387 if (table_index >= module()->function_table.size()) { 1389 // Assume only one table for now.
1390 DCHECK_EQ(module()->function_tables.size(), 1);
1391 InterpreterCode* target = codemap()->GetIndirectCode(0, entry_index);
1392 if (!target) {
Mircea Trofin 2016/07/26 03:37:27 target == nullptr
ddchen 2016/07/26 05:44:44 Done.
1388 return DoTrap(kTrapFuncInvalid, pc); 1393 return DoTrap(kTrapFuncInvalid, pc);
1389 } 1394 } 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); 1395 return DoTrap(kTrapFuncSigMismatch, pc);
1395 } 1396 }
1396 1397
1397 DoCall(target, &pc, pc + 1 + operand.length, &limit); 1398 DoCall(target, &pc, pc + 1 + operand.length, &limit);
1398 code = target; 1399 code = target;
1399 decoder.Reset(code->start, code->end); 1400 decoder.Reset(code->start, code->end);
1400 continue; 1401 continue;
1401 } 1402 }
1402 case kExprCallImport: { 1403 case kExprCallImport: {
1403 UNIMPLEMENTED(); 1404 UNIMPLEMENTED();
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 1809
1809 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1810 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1810 Zone* zone, const byte* start, const byte* end) { 1811 Zone* zone, const byte* start, const byte* end) {
1811 ControlTransfers targets(zone, 0, start, end); 1812 ControlTransfers targets(zone, 0, start, end);
1812 return targets.map_; 1813 return targets.map_;
1813 } 1814 }
1814 1815
1815 } // namespace wasm 1816 } // namespace wasm
1816 } // namespace internal 1817 } // namespace internal
1817 } // namespace v8 1818 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698