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

Side by Side Diff: runtime/vm/regexp_assembler.h

Issue 678193004: Copy irregexp related code from V8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 1 month 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 | « runtime/vm/regexp.cc ('k') | runtime/vm/regexp_assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef VM_REGEXP_ASSEMBLER_H_
6 #define VM_REGEXP_ASSEMBLER_H_
7
8 // SNIP
9
10 namespace dart {
11
12 // SNIP
13
14 class RegExpMacroAssembler {
15 public:
16 // The implementation must be able to handle at least:
17 static const int kMaxRegister = (1 << 16) - 1;
18 static const int kMaxCPOffset = (1 << 15) - 1;
19 static const int kMinCPOffset = -(1 << 15);
20
21 static const int kTableSizeBits = 7;
22 static const int kTableSize = 1 << kTableSizeBits;
23 static const int kTableMask = kTableSize - 1;
24
25 enum IrregexpImplementation {
26 kIA32Implementation,
27 kARMImplementation,
28 kARM64Implementation,
29 kMIPSImplementation,
30 kX64Implementation,
31 kX87Implementation,
32 kBytecodeImplementation
33 };
34
35 enum StackCheckFlag {
36 kNoStackLimitCheck = false,
37 kCheckStackLimit = true
38 };
39
40 explicit RegExpMacroAssembler(Zone* zone);
41 virtual ~RegExpMacroAssembler();
42 // The maximal number of pushes between stack checks. Users must supply
43 // kCheckStackLimit flag to push operations (instead of kNoStackLimitCheck)
44 // at least once for every stack_limit() pushes that are executed.
45 virtual int stack_limit_slack() = 0;
46 virtual bool CanReadUnaligned() = 0;
47 virtual void AdvanceCurrentPosition(int by) = 0; // Signed cp change.
48 virtual void AdvanceRegister(int reg, int by) = 0; // r[reg] += by.
49 // Continues execution from the position pushed on the top of the backtrack
50 // stack by an earlier PushBacktrack(Label*).
51 virtual void Backtrack() = 0;
52 virtual void Bind(Label* label) = 0;
53 virtual void CheckAtStart(Label* on_at_start) = 0;
54 // Dispatch after looking the current character up in a 2-bits-per-entry
55 // map. The destinations vector has up to 4 labels.
56 virtual void CheckCharacter(unsigned c, Label* on_equal) = 0;
57 // Bitwise and the current character with the given constant and then
58 // check for a match with c.
59 virtual void CheckCharacterAfterAnd(unsigned c,
60 unsigned and_with,
61 Label* on_equal) = 0;
62 virtual void CheckCharacterGT(uc16 limit, Label* on_greater) = 0;
63 virtual void CheckCharacterLT(uc16 limit, Label* on_less) = 0;
64 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position) = 0;
65 virtual void CheckNotAtStart(Label* on_not_at_start) = 0;
66 virtual void CheckNotBackReference(int start_reg, Label* on_no_match) = 0;
67 virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
68 Label* on_no_match) = 0;
69 // Check the current character for a match with a literal character. If we
70 // fail to match then goto the on_failure label. End of input always
71 // matches. If the label is NULL then we should pop a backtrack address off
72 // the stack and go to that.
73 virtual void CheckNotCharacter(unsigned c, Label* on_not_equal) = 0;
74 virtual void CheckNotCharacterAfterAnd(unsigned c,
75 unsigned and_with,
76 Label* on_not_equal) = 0;
77 // Subtract a constant from the current character, then and with the given
78 // constant and then check for a match with c.
79 virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
80 uc16 minus,
81 uc16 and_with,
82 Label* on_not_equal) = 0;
83 virtual void CheckCharacterInRange(uc16 from,
84 uc16 to, // Both inclusive.
85 Label* on_in_range) = 0;
86 virtual void CheckCharacterNotInRange(uc16 from,
87 uc16 to, // Both inclusive.
88 Label* on_not_in_range) = 0;
89
90 // The current character (modulus the kTableSize) is looked up in the byte
91 // array, and if the found byte is non-zero, we jump to the on_bit_set label.
92 virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set) = 0;
93
94 // Checks whether the given offset from the current position is before
95 // the end of the string. May overwrite the current character.
96 virtual void CheckPosition(int cp_offset, Label* on_outside_input) {
97 LoadCurrentCharacter(cp_offset, on_outside_input, true);
98 }
99 // Check whether a standard/default character class matches the current
100 // character. Returns false if the type of special character class does
101 // not have custom support.
102 // May clobber the current loaded character.
103 virtual bool CheckSpecialCharacterClass(uc16 type,
104 Label* on_no_match) {
105 return false;
106 }
107 virtual void Fail() = 0;
108 virtual Handle<HeapObject> GetCode(Handle<String> source) = 0;
109 virtual void GoTo(Label* label) = 0;
110 // Check whether a register is >= a given constant and go to a label if it
111 // is. Backtracks instead if the label is NULL.
112 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge) = 0;
113 // Check whether a register is < a given constant and go to a label if it is.
114 // Backtracks instead if the label is NULL.
115 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt) = 0;
116 // Check whether a register is == to the current position and go to a
117 // label if it is.
118 virtual void IfRegisterEqPos(int reg, Label* if_eq) = 0;
119 virtual IrregexpImplementation Implementation() = 0;
120 virtual void LoadCurrentCharacter(int cp_offset,
121 Label* on_end_of_input,
122 bool check_bounds = true,
123 int characters = 1) = 0;
124 virtual void PopCurrentPosition() = 0;
125 virtual void PopRegister(int register_index) = 0;
126 // Pushes the label on the backtrack stack, so that a following Backtrack
127 // will go to this label. Always checks the backtrack stack limit.
128 virtual void PushBacktrack(Label* label) = 0;
129 virtual void PushCurrentPosition() = 0;
130 virtual void PushRegister(int register_index,
131 StackCheckFlag check_stack_limit) = 0;
132 virtual void ReadCurrentPositionFromRegister(int reg) = 0;
133 virtual void ReadStackPointerFromRegister(int reg) = 0;
134 virtual void SetCurrentPositionFromEnd(int by) = 0;
135 virtual void SetRegister(int register_index, int to) = 0;
136 // Return whether the matching (with a global regexp) will be restarted.
137 virtual bool Succeed() = 0;
138 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset) = 0;
139 virtual void ClearRegisters(int reg_from, int reg_to) = 0;
140 virtual void WriteStackPointerToRegister(int reg) = 0;
141
142 // Controls the generation of large inlined constants in the code.
143 void set_slow_safe(bool ssc) { slow_safe_compiler_ = ssc; }
144 bool slow_safe() { return slow_safe_compiler_; }
145
146 enum GlobalMode { NOT_GLOBAL, GLOBAL, GLOBAL_NO_ZERO_LENGTH_CHECK };
147 // Set whether the regular expression has the global flag. Exiting due to
148 // a failure in a global regexp may still mean success overall.
149 inline void set_global_mode(GlobalMode mode) { global_mode_ = mode; }
150 inline bool global() { return global_mode_ != NOT_GLOBAL; }
151 inline bool global_with_zero_length_check() {
152 return global_mode_ == GLOBAL;
153 }
154
155 Zone* zone() const { return zone_; }
156
157 private:
158 bool slow_safe_compiler_;
159 bool global_mode_;
160 Zone* zone_;
161 };
162
163 // SNIP
164
165 } // namespace dart
166
167 #endif // VM_REGEXP_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « runtime/vm/regexp.cc ('k') | runtime/vm/regexp_assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698