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

Side by Side Diff: src/wasm/wasm-interpreter.cc

Issue 2594993002: [wasm] Rename wasm::LocalType to wasm::ValueType and kAst* to kWasm* (Closed)
Patch Set: Fix inspector tests Created 4 years 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/wasm-interpreter.h ('k') | src/wasm/wasm-macro-gen.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 6
7 #include "src/utils.h" 7 #include "src/utils.h"
8 #include "src/wasm/decoder.h" 8 #include "src/wasm/decoder.h"
9 #include "src/wasm/function-body-decoder.h" 9 #include "src/wasm/function-body-decoder.h"
10 #include "src/wasm/wasm-external-refs.h" 10 #include "src/wasm/wasm-external-refs.h"
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 static_cast<uint32_t>(code->function->sig->return_count())}); 1115 static_cast<uint32_t>(code->function->sig->return_count())});
1116 frames_.back().ret_pc = InitLocals(code); 1116 frames_.back().ret_pc = InitLocals(code);
1117 TRACE(" => push func#%u @%zu\n", code->function->func_index, 1117 TRACE(" => push func#%u @%zu\n", code->function->func_index,
1118 frames_.back().ret_pc); 1118 frames_.back().ret_pc);
1119 } 1119 }
1120 1120
1121 pc_t InitLocals(InterpreterCode* code) { 1121 pc_t InitLocals(InterpreterCode* code) {
1122 for (auto p : code->locals.local_types) { 1122 for (auto p : code->locals.local_types) {
1123 WasmVal val; 1123 WasmVal val;
1124 switch (p.first) { 1124 switch (p.first) {
1125 case kAstI32: 1125 case kWasmI32:
1126 val = WasmVal(static_cast<int32_t>(0)); 1126 val = WasmVal(static_cast<int32_t>(0));
1127 break; 1127 break;
1128 case kAstI64: 1128 case kWasmI64:
1129 val = WasmVal(static_cast<int64_t>(0)); 1129 val = WasmVal(static_cast<int64_t>(0));
1130 break; 1130 break;
1131 case kAstF32: 1131 case kWasmF32:
1132 val = WasmVal(static_cast<float>(0)); 1132 val = WasmVal(static_cast<float>(0));
1133 break; 1133 break;
1134 case kAstF64: 1134 case kWasmF64:
1135 val = WasmVal(static_cast<double>(0)); 1135 val = WasmVal(static_cast<double>(0));
1136 break; 1136 break;
1137 default: 1137 default:
1138 UNREACHABLE(); 1138 UNREACHABLE();
1139 break; 1139 break;
1140 } 1140 }
1141 stack_.insert(stack_.end(), p.second, val); 1141 stack_.insert(stack_.end(), p.second, val);
1142 } 1142 }
1143 return code->locals.decls_encoded_size; 1143 return code->locals.decls_encoded_size;
1144 } 1144 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1441
1442 DoCall(target, &pc, pc + 1 + operand.length, &limit); 1442 DoCall(target, &pc, pc + 1 + operand.length, &limit);
1443 code = target; 1443 code = target;
1444 decoder.Reset(code->start, code->end); 1444 decoder.Reset(code->start, code->end);
1445 continue; 1445 continue;
1446 } 1446 }
1447 case kExprGetGlobal: { 1447 case kExprGetGlobal: {
1448 GlobalIndexOperand operand(&decoder, code->at(pc)); 1448 GlobalIndexOperand operand(&decoder, code->at(pc));
1449 const WasmGlobal* global = &module()->globals[operand.index]; 1449 const WasmGlobal* global = &module()->globals[operand.index];
1450 byte* ptr = instance()->globals_start + global->offset; 1450 byte* ptr = instance()->globals_start + global->offset;
1451 LocalType type = global->type; 1451 ValueType type = global->type;
1452 WasmVal val; 1452 WasmVal val;
1453 if (type == kAstI32) { 1453 if (type == kWasmI32) {
1454 val = WasmVal(*reinterpret_cast<int32_t*>(ptr)); 1454 val = WasmVal(*reinterpret_cast<int32_t*>(ptr));
1455 } else if (type == kAstI64) { 1455 } else if (type == kWasmI64) {
1456 val = WasmVal(*reinterpret_cast<int64_t*>(ptr)); 1456 val = WasmVal(*reinterpret_cast<int64_t*>(ptr));
1457 } else if (type == kAstF32) { 1457 } else if (type == kWasmF32) {
1458 val = WasmVal(*reinterpret_cast<float*>(ptr)); 1458 val = WasmVal(*reinterpret_cast<float*>(ptr));
1459 } else if (type == kAstF64) { 1459 } else if (type == kWasmF64) {
1460 val = WasmVal(*reinterpret_cast<double*>(ptr)); 1460 val = WasmVal(*reinterpret_cast<double*>(ptr));
1461 } else { 1461 } else {
1462 UNREACHABLE(); 1462 UNREACHABLE();
1463 } 1463 }
1464 Push(pc, val); 1464 Push(pc, val);
1465 len = 1 + operand.length; 1465 len = 1 + operand.length;
1466 break; 1466 break;
1467 } 1467 }
1468 case kExprSetGlobal: { 1468 case kExprSetGlobal: {
1469 GlobalIndexOperand operand(&decoder, code->at(pc)); 1469 GlobalIndexOperand operand(&decoder, code->at(pc));
1470 const WasmGlobal* global = &module()->globals[operand.index]; 1470 const WasmGlobal* global = &module()->globals[operand.index];
1471 byte* ptr = instance()->globals_start + global->offset; 1471 byte* ptr = instance()->globals_start + global->offset;
1472 LocalType type = global->type; 1472 ValueType type = global->type;
1473 WasmVal val = Pop(); 1473 WasmVal val = Pop();
1474 if (type == kAstI32) { 1474 if (type == kWasmI32) {
1475 *reinterpret_cast<int32_t*>(ptr) = val.to<int32_t>(); 1475 *reinterpret_cast<int32_t*>(ptr) = val.to<int32_t>();
1476 } else if (type == kAstI64) { 1476 } else if (type == kWasmI64) {
1477 *reinterpret_cast<int64_t*>(ptr) = val.to<int64_t>(); 1477 *reinterpret_cast<int64_t*>(ptr) = val.to<int64_t>();
1478 } else if (type == kAstF32) { 1478 } else if (type == kWasmF32) {
1479 *reinterpret_cast<float*>(ptr) = val.to<float>(); 1479 *reinterpret_cast<float*>(ptr) = val.to<float>();
1480 } else if (type == kAstF64) { 1480 } else if (type == kWasmF64) {
1481 *reinterpret_cast<double*>(ptr) = val.to<double>(); 1481 *reinterpret_cast<double*>(ptr) = val.to<double>();
1482 } else { 1482 } else {
1483 UNREACHABLE(); 1483 UNREACHABLE();
1484 } 1484 }
1485 len = 1 + operand.length; 1485 len = 1 + operand.length;
1486 break; 1486 break;
1487 } 1487 }
1488 1488
1489 #define LOAD_CASE(name, ctype, mtype) \ 1489 #define LOAD_CASE(name, ctype, mtype) \
1490 case kExpr##name: { \ 1490 case kExpr##name: { \
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 } 1695 }
1696 1696
1697 WasmVal PopArity(size_t arity) { 1697 WasmVal PopArity(size_t arity) {
1698 if (arity == 0) return WasmVal(); 1698 if (arity == 0) return WasmVal();
1699 CHECK_EQ(1, arity); 1699 CHECK_EQ(1, arity);
1700 return Pop(); 1700 return Pop();
1701 } 1701 }
1702 1702
1703 void Push(pc_t pc, WasmVal val) { 1703 void Push(pc_t pc, WasmVal val) {
1704 // TODO(titzer): store PC as well? 1704 // TODO(titzer): store PC as well?
1705 if (val.type != kAstStmt) stack_.push_back(val); 1705 if (val.type != kWasmStmt) stack_.push_back(val);
1706 } 1706 }
1707 1707
1708 void TraceStack(const char* phase, pc_t pc) { 1708 void TraceStack(const char* phase, pc_t pc) {
1709 if (FLAG_trace_wasm_interpreter) { 1709 if (FLAG_trace_wasm_interpreter) {
1710 PrintF("%s @%zu", phase, pc); 1710 PrintF("%s @%zu", phase, pc);
1711 UNIMPLEMENTED(); 1711 UNIMPLEMENTED();
1712 PrintF("\n"); 1712 PrintF("\n");
1713 } 1713 }
1714 } 1714 }
1715 1715
1716 void TraceValueStack() { 1716 void TraceValueStack() {
1717 Frame* top = frames_.size() > 0 ? &frames_.back() : nullptr; 1717 Frame* top = frames_.size() > 0 ? &frames_.back() : nullptr;
1718 sp_t sp = top ? top->sp : 0; 1718 sp_t sp = top ? top->sp : 0;
1719 sp_t plimit = top ? top->plimit() : 0; 1719 sp_t plimit = top ? top->plimit() : 0;
1720 sp_t llimit = top ? top->llimit() : 0; 1720 sp_t llimit = top ? top->llimit() : 0;
1721 if (FLAG_trace_wasm_interpreter) { 1721 if (FLAG_trace_wasm_interpreter) {
1722 for (size_t i = sp; i < stack_.size(); ++i) { 1722 for (size_t i = sp; i < stack_.size(); ++i) {
1723 if (i < plimit) 1723 if (i < plimit)
1724 PrintF(" p%zu:", i); 1724 PrintF(" p%zu:", i);
1725 else if (i < llimit) 1725 else if (i < llimit)
1726 PrintF(" l%zu:", i); 1726 PrintF(" l%zu:", i);
1727 else 1727 else
1728 PrintF(" s%zu:", i); 1728 PrintF(" s%zu:", i);
1729 WasmVal val = stack_[i]; 1729 WasmVal val = stack_[i];
1730 switch (val.type) { 1730 switch (val.type) {
1731 case kAstI32: 1731 case kWasmI32:
1732 PrintF("i32:%d", val.to<int32_t>()); 1732 PrintF("i32:%d", val.to<int32_t>());
1733 break; 1733 break;
1734 case kAstI64: 1734 case kWasmI64:
1735 PrintF("i64:%" PRId64 "", val.to<int64_t>()); 1735 PrintF("i64:%" PRId64 "", val.to<int64_t>());
1736 break; 1736 break;
1737 case kAstF32: 1737 case kWasmF32:
1738 PrintF("f32:%f", val.to<float>()); 1738 PrintF("f32:%f", val.to<float>());
1739 break; 1739 break;
1740 case kAstF64: 1740 case kWasmF64:
1741 PrintF("f64:%lf", val.to<double>()); 1741 PrintF("f64:%lf", val.to<double>());
1742 break; 1742 break;
1743 case kAstStmt: 1743 case kWasmStmt:
1744 PrintF("void"); 1744 PrintF("void");
1745 break; 1745 break;
1746 default: 1746 default:
1747 UNREACHABLE(); 1747 UNREACHABLE();
1748 break; 1748 break;
1749 } 1749 }
1750 } 1750 }
1751 } 1751 }
1752 } 1752 }
1753 }; 1753 };
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 1837
1838 WasmInterpreter::Thread* WasmInterpreter::GetThread(int id) { 1838 WasmInterpreter::Thread* WasmInterpreter::GetThread(int id) {
1839 CHECK_EQ(0, id); // only one thread for now. 1839 CHECK_EQ(0, id); // only one thread for now.
1840 return internals_->threads_[id]; 1840 return internals_->threads_[id];
1841 } 1841 }
1842 1842
1843 WasmVal WasmInterpreter::GetLocalVal(const WasmFrame* frame, int index) { 1843 WasmVal WasmInterpreter::GetLocalVal(const WasmFrame* frame, int index) {
1844 CHECK_GE(index, 0); 1844 CHECK_GE(index, 0);
1845 UNIMPLEMENTED(); 1845 UNIMPLEMENTED();
1846 WasmVal none; 1846 WasmVal none;
1847 none.type = kAstStmt; 1847 none.type = kWasmStmt;
1848 return none; 1848 return none;
1849 } 1849 }
1850 1850
1851 WasmVal WasmInterpreter::GetExprVal(const WasmFrame* frame, int pc) { 1851 WasmVal WasmInterpreter::GetExprVal(const WasmFrame* frame, int pc) {
1852 UNIMPLEMENTED(); 1852 UNIMPLEMENTED();
1853 WasmVal none; 1853 WasmVal none;
1854 none.type = kAstStmt; 1854 none.type = kWasmStmt;
1855 return none; 1855 return none;
1856 } 1856 }
1857 1857
1858 void WasmInterpreter::SetLocalVal(WasmFrame* frame, int index, WasmVal val) { 1858 void WasmInterpreter::SetLocalVal(WasmFrame* frame, int index, WasmVal val) {
1859 UNIMPLEMENTED(); 1859 UNIMPLEMENTED();
1860 } 1860 }
1861 1861
1862 void WasmInterpreter::SetExprVal(WasmFrame* frame, int pc, WasmVal val) { 1862 void WasmInterpreter::SetExprVal(WasmFrame* frame, int pc, WasmVal val) {
1863 UNIMPLEMENTED(); 1863 UNIMPLEMENTED();
1864 } 1864 }
(...skipping 23 matching lines...) Expand all
1888 1888
1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1890 Zone* zone, const byte* start, const byte* end) { 1890 Zone* zone, const byte* start, const byte* end) {
1891 ControlTransfers targets(zone, nullptr, start, end); 1891 ControlTransfers targets(zone, nullptr, start, end);
1892 return targets.map_; 1892 return targets.map_;
1893 } 1893 }
1894 1894
1895 } // namespace wasm 1895 } // namespace wasm
1896 } // namespace internal 1896 } // namespace internal
1897 } // namespace v8 1897 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-interpreter.h ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698