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

Side by Side Diff: src/lithium.h

Issue 6993023: Fix a bug in Lithium environment iteration. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added x64 and ARM files. Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/lithium-allocator.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 }; 511 };
512 512
513 513
514 // Iterates over the non-null, non-constant operands in an environment. 514 // Iterates over the non-null, non-constant operands in an environment.
515 class ShallowIterator BASE_EMBEDDED { 515 class ShallowIterator BASE_EMBEDDED {
516 public: 516 public:
517 explicit ShallowIterator(LEnvironment* env) 517 explicit ShallowIterator(LEnvironment* env)
518 : env_(env), 518 : env_(env),
519 limit_(env != NULL ? env->values()->length() : 0), 519 limit_(env != NULL ? env->values()->length() : 0),
520 current_(0) { 520 current_(0) {
521 current_ = AdvanceToNext(0); 521 SkipUninteresting();
522 } 522 }
523 523
524 inline bool HasNext() { 524 bool Done() { return current_ >= limit_; }
525 return env_ != NULL && current_ < limit_;
526 }
527 525
528 inline LOperand* Next() { 526 LOperand* Current() {
529 ASSERT(HasNext()); 527 ASSERT(!Done());
530 return env_->values()->at(current_); 528 return env_->values()->at(current_);
531 } 529 }
532 530
533 inline void Advance() { 531 void Advance() {
534 current_ = AdvanceToNext(current_ + 1); 532 ASSERT(!Done());
533 ++current_;
534 SkipUninteresting();
535 } 535 }
536 536
537 inline LEnvironment* env() { return env_; } 537 LEnvironment* env() { return env_; }
538 538
539 private: 539 private:
540 inline bool ShouldSkip(LOperand* op) { 540 bool ShouldSkip(LOperand* op) {
541 return op == NULL || op->IsConstantOperand() || op->IsArgument(); 541 return op == NULL || op->IsConstantOperand() || op->IsArgument();
542 } 542 }
543 543
544 inline int AdvanceToNext(int start) { 544 // Skip until something interesting, beginning with and including current_.
545 while (start < limit_ && ShouldSkip(env_->values()->at(start))) { 545 void SkipUninteresting() {
546 start++; 546 while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) {
547 ++current_;
547 } 548 }
548 return start;
549 } 549 }
550 550
551 LEnvironment* env_; 551 LEnvironment* env_;
552 int limit_; 552 int limit_;
553 int current_; 553 int current_;
554 }; 554 };
555 555
556 556
557 // Iterator for non-null, non-constant operands incl. outer environments. 557 // Iterator for non-null, non-constant operands incl. outer environments.
558 class DeepIterator BASE_EMBEDDED { 558 class DeepIterator BASE_EMBEDDED {
559 public: 559 public:
560 explicit DeepIterator(LEnvironment* env) 560 explicit DeepIterator(LEnvironment* env)
561 : current_iterator_(env) { } 561 : current_iterator_(env) {
562 562 SkipUninteresting();
563 inline bool HasNext() {
564 if (current_iterator_.HasNext()) return true;
565 if (current_iterator_.env() == NULL) return false;
566 AdvanceToOuter();
567 return current_iterator_.HasNext();
568 } 563 }
569 564
570 inline LOperand* Next() { 565 bool Done() { return current_iterator_.Done(); }
571 ASSERT(current_iterator_.HasNext()); 566
572 return current_iterator_.Next(); 567 LOperand* Current() {
568 ASSERT(!current_iterator_.Done());
569 return current_iterator_.Current();
573 } 570 }
574 571
575 inline void Advance() { 572 void Advance() {
576 if (current_iterator_.HasNext()) { 573 current_iterator_.Advance();
577 current_iterator_.Advance(); 574 SkipUninteresting();
578 } else { 575 }
579 AdvanceToOuter(); 576
577 private:
578 void SkipUninteresting() {
579 while (current_iterator_.env() != NULL && current_iterator_.Done()) {
580 current_iterator_ = ShallowIterator(current_iterator_.env()->outer());
580 } 581 }
581 } 582 }
582 583
583 private:
584 inline void AdvanceToOuter() {
585 current_iterator_ = ShallowIterator(current_iterator_.env()->outer());
586 }
587
588 ShallowIterator current_iterator_; 584 ShallowIterator current_iterator_;
589 }; 585 };
590 586
591 587
592 int ExternalArrayTypeToShiftSize(ExternalArrayType type); 588 int ExternalArrayTypeToShiftSize(ExternalArrayType type);
593 589
594 590
595 } } // namespace v8::internal 591 } } // namespace v8::internal
596 592
597 #endif // V8_LITHIUM_H_ 593 #endif // V8_LITHIUM_H_
OLDNEW
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/lithium-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698