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

Side by Side Diff: src/wasm/function-body-decoder.cc

Issue 2613193002: [wasm] Decoder had 2 representations for "end". (Closed)
Patch Set: Created 3 years, 11 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/decoder.h ('k') | src/wasm/module-decoder.cc » ('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 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // Initialize {local_type_vec} from signature. 590 // Initialize {local_type_vec} from signature.
591 if (sig_) { 591 if (sig_) {
592 local_type_vec_.reserve(sig_->parameter_count()); 592 local_type_vec_.reserve(sig_->parameter_count());
593 for (size_t i = 0; i < sig_->parameter_count(); ++i) { 593 for (size_t i = 0; i < sig_->parameter_count(); ++i) {
594 local_type_vec_.push_back(sig_->GetParam(i)); 594 local_type_vec_.push_back(sig_->GetParam(i));
595 } 595 }
596 } 596 }
597 // Decode local declarations, if any. 597 // Decode local declarations, if any.
598 uint32_t entries = consume_u32v("local decls count"); 598 uint32_t entries = consume_u32v("local decls count");
599 TRACE("local decls count: %u\n", entries); 599 TRACE("local decls count: %u\n", entries);
600 while (entries-- > 0 && pc_ < limit_) { 600 while (entries-- > 0 && pc_ < end_) {
601 uint32_t count = consume_u32v("local count"); 601 uint32_t count = consume_u32v("local count");
602 if ((count + local_type_vec_.size()) > kMaxNumWasmLocals) { 602 if ((count + local_type_vec_.size()) > kMaxNumWasmLocals) {
603 error(pc_ - 1, "local count too large"); 603 error(pc_ - 1, "local count too large");
604 return; 604 return;
605 } 605 }
606 byte code = consume_u8("local type"); 606 byte code = consume_u8("local type");
607 ValueType type; 607 ValueType type;
608 switch (code) { 608 switch (code) {
609 case kLocalI32: 609 case kLocalI32:
610 type = kWasmI32; 610 type = kWasmI32;
(...skipping 16 matching lines...) Expand all
627 } 627 }
628 local_type_vec_.insert(local_type_vec_.end(), count, type); 628 local_type_vec_.insert(local_type_vec_.end(), count, type);
629 } 629 }
630 total_locals_ = local_type_vec_.size(); 630 total_locals_ = local_type_vec_.size();
631 } 631 }
632 632
633 // Decodes the body of a function. 633 // Decodes the body of a function.
634 void DecodeFunctionBody() { 634 void DecodeFunctionBody() {
635 TRACE("wasm-decode %p...%p (module+%d, %d bytes) %s\n", 635 TRACE("wasm-decode %p...%p (module+%d, %d bytes) %s\n",
636 reinterpret_cast<const void*>(start_), 636 reinterpret_cast<const void*>(start_),
637 reinterpret_cast<const void*>(limit_), baserel(pc_), 637 reinterpret_cast<const void*>(end_), baserel(pc_),
638 static_cast<int>(limit_ - start_), builder_ ? "graph building" : ""); 638 static_cast<int>(end_ - start_), builder_ ? "graph building" : "");
639 639
640 { 640 {
641 // Set up initial function block. 641 // Set up initial function block.
642 SsaEnv* break_env = ssa_env_; 642 SsaEnv* break_env = ssa_env_;
643 SetEnv("initial env", Steal(break_env)); 643 SetEnv("initial env", Steal(break_env));
644 PushBlock(break_env); 644 PushBlock(break_env);
645 Control* c = &control_.back(); 645 Control* c = &control_.back();
646 c->merge.arity = static_cast<uint32_t>(sig_->return_count()); 646 c->merge.arity = static_cast<uint32_t>(sig_->return_count());
647 647
648 if (c->merge.arity == 1) { 648 if (c->merge.arity == 1) {
649 c->merge.vals.first = {pc_, nullptr, sig_->GetReturn(0)}; 649 c->merge.vals.first = {pc_, nullptr, sig_->GetReturn(0)};
650 } else if (c->merge.arity > 1) { 650 } else if (c->merge.arity > 1) {
651 c->merge.vals.array = zone_->NewArray<Value>(c->merge.arity); 651 c->merge.vals.array = zone_->NewArray<Value>(c->merge.arity);
652 for (unsigned i = 0; i < c->merge.arity; i++) { 652 for (unsigned i = 0; i < c->merge.arity; i++) {
653 c->merge.vals.array[i] = {pc_, nullptr, sig_->GetReturn(i)}; 653 c->merge.vals.array[i] = {pc_, nullptr, sig_->GetReturn(i)};
654 } 654 }
655 } 655 }
656 } 656 }
657 657
658 if (pc_ >= limit_) return; // Nothing to do. 658 if (pc_ >= end_) return; // Nothing to do.
659 659
660 while (true) { // decoding loop. 660 while (true) { // decoding loop.
661 unsigned len = 1; 661 unsigned len = 1;
662 WasmOpcode opcode = static_cast<WasmOpcode>(*pc_); 662 WasmOpcode opcode = static_cast<WasmOpcode>(*pc_);
663 if (!WasmOpcodes::IsPrefixOpcode(opcode)) { 663 if (!WasmOpcodes::IsPrefixOpcode(opcode)) {
664 TRACE(" @%-8d #%02x:%-20s|", startrel(pc_), opcode, 664 TRACE(" @%-8d #%02x:%-20s|", startrel(pc_), opcode,
665 WasmOpcodes::ShortOpcodeName(opcode)); 665 WasmOpcodes::ShortOpcodeName(opcode));
666 } 666 }
667 667
668 FunctionSig* sig = WasmOpcodes::Signature(opcode); 668 FunctionSig* sig = WasmOpcodes::Signature(opcode);
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 break; 1239 break;
1240 } 1240 }
1241 default: 1241 default:
1242 break; 1242 break;
1243 } 1243 }
1244 } 1244 }
1245 PrintF("\n"); 1245 PrintF("\n");
1246 } 1246 }
1247 #endif 1247 #endif
1248 pc_ += len; 1248 pc_ += len;
1249 if (pc_ >= limit_) { 1249 if (pc_ >= end_) {
1250 // End of code reached or exceeded. 1250 // End of code reached or exceeded.
1251 if (pc_ > limit_ && ok()) error("Beyond end of code"); 1251 if (pc_ > end_ && ok()) error("Beyond end of code");
1252 return; 1252 return;
1253 } 1253 }
1254 } // end decode loop 1254 } // end decode loop
1255 } 1255 }
1256 1256
1257 void EndControl() { ssa_env_->Kill(SsaEnv::kControlEnd); } 1257 void EndControl() { ssa_env_->Kill(SsaEnv::kControlEnd); }
1258 1258
1259 void SetBlockType(Control* c, BlockTypeOperand& operand) { 1259 void SetBlockType(Control* c, BlockTypeOperand& operand) {
1260 c->merge.arity = operand.arity; 1260 c->merge.arity = operand.arity;
1261 if (c->merge.arity == 1) { 1261 if (c->merge.arity == 1) {
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 result->locals = nullptr; 1816 result->locals = nullptr;
1817 return result; 1817 return result;
1818 } 1818 }
1819 1819
1820 int EnvironmentCount() { 1820 int EnvironmentCount() {
1821 if (builder_) return static_cast<int>(local_type_vec_.size()); 1821 if (builder_) return static_cast<int>(local_type_vec_.size());
1822 return 0; // if we aren't building a graph, don't bother with SSA renaming. 1822 return 0; // if we aren't building a graph, don't bother with SSA renaming.
1823 } 1823 }
1824 1824
1825 virtual void onFirstError() { 1825 virtual void onFirstError() {
1826 limit_ = start_; // Terminate decoding loop. 1826 end_ = start_; // Terminate decoding loop.
1827 builder_ = nullptr; // Don't build any more nodes. 1827 builder_ = nullptr; // Don't build any more nodes.
1828 TRACE(" !%s\n", error_msg_.get()); 1828 TRACE(" !%s\n", error_msg_.get());
1829 } 1829 }
1830 BitVector* AnalyzeLoopAssignment(const byte* pc) { 1830 BitVector* AnalyzeLoopAssignment(const byte* pc) {
1831 if (pc >= limit_) return nullptr; 1831 if (pc >= end_) return nullptr;
1832 if (*pc != kExprLoop) return nullptr; 1832 if (*pc != kExprLoop) return nullptr;
1833 1833
1834 BitVector* assigned = 1834 BitVector* assigned =
1835 new (zone_) BitVector(static_cast<int>(local_type_vec_.size()), zone_); 1835 new (zone_) BitVector(static_cast<int>(local_type_vec_.size()), zone_);
1836 int depth = 0; 1836 int depth = 0;
1837 // Iteratively process all AST nodes nested inside the loop. 1837 // Iteratively process all AST nodes nested inside the loop.
1838 while (pc < limit_ && ok()) { 1838 while (pc < end_ && ok()) {
1839 WasmOpcode opcode = static_cast<WasmOpcode>(*pc); 1839 WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
1840 unsigned length = 1; 1840 unsigned length = 1;
1841 switch (opcode) { 1841 switch (opcode) {
1842 case kExprLoop: 1842 case kExprLoop:
1843 case kExprIf: 1843 case kExprIf:
1844 case kExprBlock: 1844 case kExprBlock:
1845 case kExprTry: 1845 case kExprTry:
1846 length = OpcodeLength(pc); 1846 length = OpcodeLength(pc);
1847 depth++; 1847 depth++;
1848 break; 1848 break;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 2071 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
2072 const byte* start, const byte* end) { 2072 const byte* start, const byte* end) {
2073 FunctionBody body = {nullptr, nullptr, start, end}; 2073 FunctionBody body = {nullptr, nullptr, start, end};
2074 WasmFullDecoder decoder(zone, body); 2074 WasmFullDecoder decoder(zone, body);
2075 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); 2075 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
2076 } 2076 }
2077 2077
2078 } // namespace wasm 2078 } // namespace wasm
2079 } // namespace internal 2079 } // namespace internal
2080 } // namespace v8 2080 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698