OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/signature.h" | 5 #include "src/signature.h" |
6 | 6 |
7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
8 #include "src/flags.h" | 8 #include "src/flags.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 c->merge.vals.array[i] = {pc_, nullptr, sig_->GetReturn(i)}; | 652 c->merge.vals.array[i] = {pc_, nullptr, sig_->GetReturn(i)}; |
653 } | 653 } |
654 } | 654 } |
655 } | 655 } |
656 | 656 |
657 while (pc_ < end_) { // decoding loop. | 657 while (pc_ < end_) { // decoding loop. |
658 unsigned len = 1; | 658 unsigned len = 1; |
659 WasmOpcode opcode = static_cast<WasmOpcode>(*pc_); | 659 WasmOpcode opcode = static_cast<WasmOpcode>(*pc_); |
660 if (!WasmOpcodes::IsPrefixOpcode(opcode)) { | 660 if (!WasmOpcodes::IsPrefixOpcode(opcode)) { |
661 TRACE(" @%-8d #%02x:%-20s|", startrel(pc_), opcode, | 661 TRACE(" @%-8d #%02x:%-20s|", startrel(pc_), opcode, |
662 WasmOpcodes::ShortOpcodeName(opcode)); | 662 WasmOpcodes::OpcodeName(opcode)); |
663 } | 663 } |
664 | 664 |
665 FunctionSig* sig = WasmOpcodes::Signature(opcode); | 665 FunctionSig* sig = WasmOpcodes::Signature(opcode); |
666 if (sig) { | 666 if (sig) { |
667 BuildSimpleOperator(opcode, sig); | 667 BuildSimpleOperator(opcode, sig); |
668 } else { | 668 } else { |
669 // Complex bytecode. | 669 // Complex bytecode. |
670 switch (opcode) { | 670 switch (opcode) { |
671 case kExprNop: | 671 case kExprNop: |
672 break; | 672 break; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 | 845 |
846 if (control_.size() == 1) { | 846 if (control_.size() == 1) { |
847 // If at the last (implicit) control, check we are at end. | 847 // If at the last (implicit) control, check we are at end. |
848 if (pc_ + 1 != end_) { | 848 if (pc_ + 1 != end_) { |
849 error(pc_, pc_ + 1, "trailing code after function end"); | 849 error(pc_, pc_ + 1, "trailing code after function end"); |
850 break; | 850 break; |
851 } | 851 } |
852 last_end_found_ = true; | 852 last_end_found_ = true; |
853 if (ssa_env_->go()) { | 853 if (ssa_env_->go()) { |
854 // The result of the block is the return value. | 854 // The result of the block is the return value. |
855 TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "ImplicitReturn"); | 855 TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "(implicit) return"); |
856 DoReturn(); | 856 DoReturn(); |
857 TRACE("\n"); | 857 TRACE("\n"); |
858 } | 858 } |
859 } | 859 } |
860 PopControl(); | 860 PopControl(); |
861 break; | 861 break; |
862 } | 862 } |
863 case kExprSelect: { | 863 case kExprSelect: { |
864 Value cond = Pop(2, kWasmI32); | 864 Value cond = Pop(2, kWasmI32); |
865 Value fval = Pop(); | 865 Value fval = Pop(); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 } | 1157 } |
1158 len = 1 + operand.length; | 1158 len = 1 + operand.length; |
1159 break; | 1159 break; |
1160 } | 1160 } |
1161 case kSimdPrefix: { | 1161 case kSimdPrefix: { |
1162 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); | 1162 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); |
1163 len++; | 1163 len++; |
1164 byte simd_index = checked_read_u8(pc_, 1, "simd index"); | 1164 byte simd_index = checked_read_u8(pc_, 1, "simd index"); |
1165 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); | 1165 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); |
1166 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, | 1166 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, |
1167 simd_index, WasmOpcodes::ShortOpcodeName(opcode)); | 1167 simd_index, WasmOpcodes::OpcodeName(opcode)); |
1168 len += DecodeSimdOpcode(opcode); | 1168 len += DecodeSimdOpcode(opcode); |
1169 break; | 1169 break; |
1170 } | 1170 } |
1171 case kAtomicPrefix: { | 1171 case kAtomicPrefix: { |
1172 if (module_ == nullptr || module_->origin != kAsmJsOrigin) { | 1172 if (module_ == nullptr || module_->origin != kAsmJsOrigin) { |
1173 error("Atomics are allowed only in AsmJs modules"); | 1173 error("Atomics are allowed only in AsmJs modules"); |
1174 break; | 1174 break; |
1175 } | 1175 } |
1176 if (!FLAG_wasm_atomics_prototype) { | 1176 if (!FLAG_wasm_atomics_prototype) { |
1177 error("Invalid opcode (enable with --wasm_atomics_prototype)"); | 1177 error("Invalid opcode (enable with --wasm_atomics_prototype)"); |
(...skipping 26 matching lines...) Expand all Loading... |
1204 #if DEBUG | 1204 #if DEBUG |
1205 if (FLAG_trace_wasm_decoder) { | 1205 if (FLAG_trace_wasm_decoder) { |
1206 for (size_t i = 0; i < stack_.size(); ++i) { | 1206 for (size_t i = 0; i < stack_.size(); ++i) { |
1207 Value& val = stack_[i]; | 1207 Value& val = stack_[i]; |
1208 WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc); | 1208 WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc); |
1209 if (WasmOpcodes::IsPrefixOpcode(opcode)) { | 1209 if (WasmOpcodes::IsPrefixOpcode(opcode)) { |
1210 opcode = static_cast<WasmOpcode>(opcode << 8 | *(val.pc + 1)); | 1210 opcode = static_cast<WasmOpcode>(opcode << 8 | *(val.pc + 1)); |
1211 } | 1211 } |
1212 PrintF(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type), | 1212 PrintF(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type), |
1213 static_cast<int>(val.pc - start_), | 1213 static_cast<int>(val.pc - start_), |
1214 WasmOpcodes::ShortOpcodeName(opcode)); | 1214 WasmOpcodes::OpcodeName(opcode)); |
1215 switch (opcode) { | 1215 switch (opcode) { |
1216 case kExprI32Const: { | 1216 case kExprI32Const: { |
1217 ImmI32Operand operand(this, val.pc); | 1217 ImmI32Operand operand(this, val.pc); |
1218 PrintF("[%d]", operand.value); | 1218 PrintF("[%d]", operand.value); |
1219 break; | 1219 break; |
1220 } | 1220 } |
1221 case kExprGetLocal: { | 1221 case kExprGetLocal: { |
1222 LocalIndexOperand operand(this, val.pc); | 1222 LocalIndexOperand operand(this, val.pc); |
1223 PrintF("[%u]", operand.index); | 1223 PrintF("[%u]", operand.index); |
1224 break; | 1224 break; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 | 1416 |
1417 void PushReturns(FunctionSig* sig, TFNode** rets) { | 1417 void PushReturns(FunctionSig* sig, TFNode** rets) { |
1418 for (size_t i = 0; i < sig->return_count(); i++) { | 1418 for (size_t i = 0; i < sig->return_count(); i++) { |
1419 // When verifying only, then {rets} will be null, so push null. | 1419 // When verifying only, then {rets} will be null, so push null. |
1420 Push(sig->GetReturn(i), rets ? rets[i] : nullptr); | 1420 Push(sig->GetReturn(i), rets ? rets[i] : nullptr); |
1421 } | 1421 } |
1422 } | 1422 } |
1423 | 1423 |
1424 const char* SafeOpcodeNameAt(const byte* pc) { | 1424 const char* SafeOpcodeNameAt(const byte* pc) { |
1425 if (pc >= end_) return "<end>"; | 1425 if (pc >= end_) return "<end>"; |
1426 return WasmOpcodes::ShortOpcodeName(static_cast<WasmOpcode>(*pc)); | 1426 return WasmOpcodes::OpcodeName(static_cast<WasmOpcode>(*pc)); |
1427 } | 1427 } |
1428 | 1428 |
1429 Value Pop(int index, ValueType expected) { | 1429 Value Pop(int index, ValueType expected) { |
1430 Value val = Pop(); | 1430 Value val = Pop(); |
1431 if (val.type != expected) { | 1431 if (val.type != expected) { |
1432 if (val.type != kWasmEnd) { | 1432 if (val.type != kWasmEnd) { |
1433 error(pc_, val.pc, "%s[%d] expected type %s, found %s of type %s", | 1433 error(pc_, val.pc, "%s[%d] expected type %s, found %s of type %s", |
1434 SafeOpcodeNameAt(pc_), index, WasmOpcodes::TypeName(expected), | 1434 SafeOpcodeNameAt(pc_), index, WasmOpcodes::TypeName(expected), |
1435 SafeOpcodeNameAt(val.pc), WasmOpcodes::TypeName(val.type)); | 1435 SafeOpcodeNameAt(val.pc), WasmOpcodes::TypeName(val.type)); |
1436 } | 1436 } |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 2012 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
2013 const byte* start, const byte* end) { | 2013 const byte* start, const byte* end) { |
2014 Decoder decoder(start, end); | 2014 Decoder decoder(start, end); |
2015 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, | 2015 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, |
2016 static_cast<int>(num_locals), zone); | 2016 static_cast<int>(num_locals), zone); |
2017 } | 2017 } |
2018 | 2018 |
2019 } // namespace wasm | 2019 } // namespace wasm |
2020 } // namespace internal | 2020 } // namespace internal |
2021 } // namespace v8 | 2021 } // namespace v8 |
OLD | NEW |