| 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 21 matching lines...) Expand all Loading... |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #define CHECK_PROTOTYPE_OPCODE(flag) \ | 34 #define CHECK_PROTOTYPE_OPCODE(flag) \ |
| 35 if (module_ != nullptr && module_->origin == kAsmJsOrigin) { \ | 35 if (module_ != nullptr && module_->origin == kAsmJsOrigin) { \ |
| 36 error("Opcode not supported for asmjs modules"); \ | 36 error("Opcode not supported for asmjs modules"); \ |
| 37 } \ | 37 } \ |
| 38 if (!FLAG_##flag) { \ | 38 if (!FLAG_##flag) { \ |
| 39 error("Invalid opcode (enable with --" #flag ")"); \ | 39 error("Invalid opcode (enable with --" #flag ")"); \ |
| 40 break; \ | 40 break; \ |
| 41 } | 41 } |
| 42 // TODO(titzer): this is only for intermediate migration. |
| 43 #define IMPLICIT_FUNCTION_END 1 |
| 42 | 44 |
| 43 // An SsaEnv environment carries the current local variable renaming | 45 // An SsaEnv environment carries the current local variable renaming |
| 44 // as well as the current effect and control dependency in the TF graph. | 46 // as well as the current effect and control dependency in the TF graph. |
| 45 // It maintains a control state that tracks whether the environment | 47 // It maintains a control state that tracks whether the environment |
| 46 // is reachable, has reached a control end, or has been merged. | 48 // is reachable, has reached a control end, or has been merged. |
| 47 struct SsaEnv { | 49 struct SsaEnv { |
| 48 enum State { kControlEnd, kUnreachable, kReached, kMerged }; | 50 enum State { kControlEnd, kUnreachable, kReached, kMerged }; |
| 49 | 51 |
| 50 State state; | 52 State state; |
| 51 TFNode* control; | 53 TFNode* control; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return false; | 486 return false; |
| 485 } | 487 } |
| 486 | 488 |
| 487 DCHECK_EQ(0, local_types_->size()); | 489 DCHECK_EQ(0, local_types_->size()); |
| 488 WasmDecoder::DecodeLocals(this, sig_, local_types_); | 490 WasmDecoder::DecodeLocals(this, sig_, local_types_); |
| 489 InitSsaEnv(); | 491 InitSsaEnv(); |
| 490 DecodeFunctionBody(); | 492 DecodeFunctionBody(); |
| 491 | 493 |
| 492 if (failed()) return TraceFailed(); | 494 if (failed()) return TraceFailed(); |
| 493 | 495 |
| 494 if (!control_.empty()) { | 496 #if IMPLICIT_FUNCTION_END |
| 495 // Generate a better error message whether the unterminated control | 497 // With implicit end support (old style), the function block |
| 496 // structure is the function body block or an innner structure. | 498 // remains on the stack. Other control blocks are an error. |
| 497 if (control_.size() > 1) { | 499 if (control_.size() > 1) { |
| 498 error(pc_, control_.back().pc, "unterminated control structure"); | 500 error(pc_, control_.back().pc, "unterminated control structure"); |
| 499 } else { | |
| 500 error("function body must end with \"end\" opcode."); | |
| 501 } | |
| 502 return TraceFailed(); | 501 return TraceFailed(); |
| 503 } | 502 } |
| 504 | 503 |
| 504 // Assume an implicit end to the function body block. |
| 505 if (control_.size() == 1) { |
| 506 Control* c = &control_.back(); |
| 507 if (ssa_env_->go()) { |
| 508 FallThruTo(c); |
| 509 } |
| 510 |
| 511 if (c->end_env->go()) { |
| 512 // Push the end values onto the stack. |
| 513 stack_.resize(c->stack_depth); |
| 514 if (c->merge.arity == 1) { |
| 515 stack_.push_back(c->merge.vals.first); |
| 516 } else { |
| 517 for (unsigned i = 0; i < c->merge.arity; i++) { |
| 518 stack_.push_back(c->merge.vals.array[i]); |
| 519 } |
| 520 } |
| 521 |
| 522 TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "ImplicitReturn"); |
| 523 SetEnv("function:end", c->end_env); |
| 524 DoReturn(); |
| 525 TRACE("\n"); |
| 526 } |
| 527 } |
| 528 #else |
| 529 if (!control_.empty()) { |
| 530 error(pc_, control_.back().pc, "unterminated control structure"); |
| 531 return TraceFailed(); |
| 532 } |
| 533 |
| 505 if (!last_end_found_) { | 534 if (!last_end_found_) { |
| 506 error("function body must end with \"end\" opcode."); | 535 error("function body must end with \"end\" opcode."); |
| 507 return false; | 536 return false; |
| 508 } | 537 } |
| 538 #endif |
| 509 | 539 |
| 510 if (FLAG_trace_wasm_decode_time) { | 540 if (FLAG_trace_wasm_decode_time) { |
| 511 double ms = decode_timer.Elapsed().InMillisecondsF(); | 541 double ms = decode_timer.Elapsed().InMillisecondsF(); |
| 512 PrintF("wasm-decode %s (%0.3f ms)\n\n", ok() ? "ok" : "failed", ms); | 542 PrintF("wasm-decode %s (%0.3f ms)\n\n", ok() ? "ok" : "failed", ms); |
| 513 } else { | 543 } else { |
| 514 TRACE("wasm-decode %s\n\n", ok() ? "ok" : "failed"); | 544 TRACE("wasm-decode %s\n\n", ok() ? "ok" : "failed"); |
| 515 } | 545 } |
| 516 | 546 |
| 517 return true; | 547 return true; |
| 518 } | 548 } |
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 2056 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
| 2027 const byte* start, const byte* end) { | 2057 const byte* start, const byte* end) { |
| 2028 Decoder decoder(start, end); | 2058 Decoder decoder(start, end); |
| 2029 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, | 2059 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, |
| 2030 static_cast<int>(num_locals), zone); | 2060 static_cast<int>(num_locals), zone); |
| 2031 } | 2061 } |
| 2032 | 2062 |
| 2033 } // namespace wasm | 2063 } // namespace wasm |
| 2034 } // namespace internal | 2064 } // namespace internal |
| 2035 } // namespace v8 | 2065 } // namespace v8 |
| OLD | NEW |