OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_JSREGEXP_H_ | 5 #ifndef V8_JSREGEXP_H_ |
6 #define V8_JSREGEXP_H_ | 6 #define V8_JSREGEXP_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
10 | 10 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 bool cannot_match_; | 563 bool cannot_match_; |
564 }; | 564 }; |
565 | 565 |
566 | 566 |
567 extern int kUninitializedRegExpNodePlaceHolder; | 567 extern int kUninitializedRegExpNodePlaceHolder; |
568 | 568 |
569 | 569 |
570 class RegExpNode: public ZoneObject { | 570 class RegExpNode: public ZoneObject { |
571 public: | 571 public: |
572 explicit RegExpNode(Zone* zone) | 572 explicit RegExpNode(Zone* zone) |
573 : replacement_(NULL), trace_count_(0), zone_(zone) { | 573 : replacement_(NULL), on_work_list_(false), trace_count_(0), zone_(zone) { |
574 bm_info_[0] = bm_info_[1] = NULL; | 574 bm_info_[0] = bm_info_[1] = NULL; |
575 } | 575 } |
576 virtual ~RegExpNode(); | 576 virtual ~RegExpNode(); |
577 virtual void Accept(NodeVisitor* visitor) = 0; | 577 virtual void Accept(NodeVisitor* visitor) = 0; |
578 // Generates a goto to this node or actually generates the code at this point. | 578 // Generates a goto to this node or actually generates the code at this point. |
579 virtual void Emit(RegExpCompiler* compiler, Trace* trace) = 0; | 579 virtual void Emit(RegExpCompiler* compiler, Trace* trace) = 0; |
580 // How many characters must this node consume at a minimum in order to | 580 // How many characters must this node consume at a minimum in order to |
581 // succeed. If we have found at least 'still_to_find' characters that | 581 // succeed. If we have found at least 'still_to_find' characters that |
582 // must be consumed there is no need to ask any following nodes whether | 582 // must be consumed there is no need to ask any following nodes whether |
583 // they are sure to eat any more characters. The not_at_start argument is | 583 // they are sure to eat any more characters. The not_at_start argument is |
(...skipping 27 matching lines...) Expand all Loading... |
611 RegExpCompiler* compiler) { | 611 RegExpCompiler* compiler) { |
612 return NULL; | 612 return NULL; |
613 } | 613 } |
614 | 614 |
615 // Collects information on the possible code units (mod 128) that can match if | 615 // Collects information on the possible code units (mod 128) that can match if |
616 // we look forward. This is used for a Boyer-Moore-like string searching | 616 // we look forward. This is used for a Boyer-Moore-like string searching |
617 // implementation. TODO(erikcorry): This should share more code with | 617 // implementation. TODO(erikcorry): This should share more code with |
618 // EatsAtLeast, GetQuickCheckDetails. The budget argument is used to limit | 618 // EatsAtLeast, GetQuickCheckDetails. The budget argument is used to limit |
619 // the number of nodes we are willing to look at in order to create this data. | 619 // the number of nodes we are willing to look at in order to create this data. |
620 static const int kRecursionBudget = 200; | 620 static const int kRecursionBudget = 200; |
| 621 bool KeepRecursing(RegExpCompiler* compiler); |
621 virtual void FillInBMInfo(int offset, | 622 virtual void FillInBMInfo(int offset, |
622 int budget, | 623 int budget, |
623 BoyerMooreLookahead* bm, | 624 BoyerMooreLookahead* bm, |
624 bool not_at_start) { | 625 bool not_at_start) { |
625 UNREACHABLE(); | 626 UNREACHABLE(); |
626 } | 627 } |
627 | 628 |
628 // If we know that the input is one-byte then there are some nodes that can | 629 // If we know that the input is one-byte then there are some nodes that can |
629 // never match. This method returns a node that can be substituted for | 630 // never match. This method returns a node that can be substituted for |
630 // itself, or NULL if the node can never match. | 631 // itself, or NULL if the node can never match. |
(...skipping 20 matching lines...) Expand all Loading... |
651 } | 652 } |
652 | 653 |
653 Label* label() { return &label_; } | 654 Label* label() { return &label_; } |
654 // If non-generic code is generated for a node (i.e. the node is not at the | 655 // If non-generic code is generated for a node (i.e. the node is not at the |
655 // start of the trace) then it cannot be reused. This variable sets a limit | 656 // start of the trace) then it cannot be reused. This variable sets a limit |
656 // on how often we allow that to happen before we insist on starting a new | 657 // on how often we allow that to happen before we insist on starting a new |
657 // trace and generating generic code for a node that can be reused by flushing | 658 // trace and generating generic code for a node that can be reused by flushing |
658 // the deferred actions in the current trace and generating a goto. | 659 // the deferred actions in the current trace and generating a goto. |
659 static const int kMaxCopiesCodeGenerated = 10; | 660 static const int kMaxCopiesCodeGenerated = 10; |
660 | 661 |
| 662 bool on_work_list() { return on_work_list_; } |
| 663 void set_on_work_list(bool value) { on_work_list_ = value; } |
| 664 |
661 NodeInfo* info() { return &info_; } | 665 NodeInfo* info() { return &info_; } |
662 | 666 |
663 BoyerMooreLookahead* bm_info(bool not_at_start) { | 667 BoyerMooreLookahead* bm_info(bool not_at_start) { |
664 return bm_info_[not_at_start ? 1 : 0]; | 668 return bm_info_[not_at_start ? 1 : 0]; |
665 } | 669 } |
666 | 670 |
667 Zone* zone() const { return zone_; } | 671 Zone* zone() const { return zone_; } |
668 | 672 |
669 protected: | 673 protected: |
670 enum LimitResult { DONE, CONTINUE }; | 674 enum LimitResult { DONE, CONTINUE }; |
671 RegExpNode* replacement_; | 675 RegExpNode* replacement_; |
672 | 676 |
673 LimitResult LimitVersions(RegExpCompiler* compiler, Trace* trace); | 677 LimitResult LimitVersions(RegExpCompiler* compiler, Trace* trace); |
674 | 678 |
675 void set_bm_info(bool not_at_start, BoyerMooreLookahead* bm) { | 679 void set_bm_info(bool not_at_start, BoyerMooreLookahead* bm) { |
676 bm_info_[not_at_start ? 1 : 0] = bm; | 680 bm_info_[not_at_start ? 1 : 0] = bm; |
677 } | 681 } |
678 | 682 |
679 private: | 683 private: |
680 static const int kFirstCharBudget = 10; | 684 static const int kFirstCharBudget = 10; |
681 Label label_; | 685 Label label_; |
| 686 bool on_work_list_; |
682 NodeInfo info_; | 687 NodeInfo info_; |
683 // This variable keeps track of how many times code has been generated for | 688 // This variable keeps track of how many times code has been generated for |
684 // this node (in different traces). We don't keep track of where the | 689 // this node (in different traces). We don't keep track of where the |
685 // generated code is located unless the code is generated at the start of | 690 // generated code is located unless the code is generated at the start of |
686 // a trace, in which case it is generic and can be reused by flushing the | 691 // a trace, in which case it is generic and can be reused by flushing the |
687 // deferred operations in the current trace and generating a goto. | 692 // deferred operations in the current trace and generating a goto. |
688 int trace_count_; | 693 int trace_count_; |
689 BoyerMooreLookahead* bm_info_[2]; | 694 BoyerMooreLookahead* bm_info_[2]; |
690 | 695 |
691 Zone* zone_; | 696 Zone* zone_; |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 | 1675 |
1671 static bool TooMuchRegExpCode(Handle<String> pattern); | 1676 static bool TooMuchRegExpCode(Handle<String> pattern); |
1672 | 1677 |
1673 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 1678 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |
1674 }; | 1679 }; |
1675 | 1680 |
1676 | 1681 |
1677 } } // namespace v8::internal | 1682 } } // namespace v8::internal |
1678 | 1683 |
1679 #endif // V8_JSREGEXP_H_ | 1684 #endif // V8_JSREGEXP_H_ |
OLD | NEW |