OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_REGEXP_ASSEMBLER_H_ | 5 #ifndef RUNTIME_VM_REGEXP_ASSEMBLER_H_ |
6 #define RUNTIME_VM_REGEXP_ASSEMBLER_H_ | 6 #define RUNTIME_VM_REGEXP_ASSEMBLER_H_ |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 JoinEntryInstr* block() const { return block_; } | 24 JoinEntryInstr* block() const { return block_; } |
25 | 25 |
26 bool IsBound() const { return is_bound_; } | 26 bool IsBound() const { return is_bound_; } |
27 void SetBound(intptr_t block_id) { | 27 void SetBound(intptr_t block_id) { |
28 ASSERT(!is_bound_); | 28 ASSERT(!is_bound_); |
29 block_->set_block_id(block_id); | 29 block_->set_block_id(block_id); |
30 is_bound_ = true; | 30 is_bound_ = true; |
31 } | 31 } |
32 | 32 |
33 bool IsLinked() const { return !is_bound_ && is_linked_; } | 33 bool IsLinked() const { return !is_bound_ && is_linked_; } |
34 void SetLinked() { | 34 void SetLinked() { is_linked_ = true; } |
35 is_linked_ = true; | |
36 } | |
37 | 35 |
38 intptr_t Position() const { | 36 intptr_t Position() const { |
39 ASSERT(IsBound()); | 37 ASSERT(IsBound()); |
40 return block_->block_id(); | 38 return block_->block_id(); |
41 } | 39 } |
42 | 40 |
43 private: | 41 private: |
44 JoinEntryInstr* block_; | 42 JoinEntryInstr* block_; |
45 | 43 |
46 bool is_bound_; | 44 bool is_bound_; |
47 bool is_linked_; | 45 bool is_linked_; |
48 | 46 |
49 // Used by the bytecode assembler. | 47 // Used by the bytecode assembler. |
50 public: | 48 public: |
51 ~BlockLabel() { | 49 ~BlockLabel() { ASSERT(!is_linked()); } |
52 ASSERT(!is_linked()); | |
53 } | |
54 | 50 |
55 intptr_t pos() const { | 51 intptr_t pos() const { return pos_; } |
56 return pos_; | |
57 } | |
58 bool is_bound() const { return IsBound(); } | 52 bool is_bound() const { return IsBound(); } |
59 bool is_linked() const { return IsLinked(); } | 53 bool is_linked() const { return IsLinked(); } |
60 | 54 |
61 void Unuse() { | 55 void Unuse() { |
62 pos_ = 0; | 56 pos_ = 0; |
63 is_bound_ = false; | 57 is_bound_ = false; |
64 is_linked_ = false; | 58 is_linked_ = false; |
65 } | 59 } |
66 | 60 |
67 void bind_to(intptr_t pos) { | 61 void bind_to(intptr_t pos) { |
(...skipping 26 matching lines...) Expand all Loading... |
94 static const intptr_t kTableSize = 1 << kTableSizeBits; | 88 static const intptr_t kTableSize = 1 << kTableSizeBits; |
95 static const intptr_t kTableMask = kTableSize - 1; | 89 static const intptr_t kTableMask = kTableSize - 1; |
96 | 90 |
97 enum { | 91 enum { |
98 kParamRegExpIndex = 0, | 92 kParamRegExpIndex = 0, |
99 kParamStringIndex, | 93 kParamStringIndex, |
100 kParamStartOffsetIndex, | 94 kParamStartOffsetIndex, |
101 kParamCount | 95 kParamCount |
102 }; | 96 }; |
103 | 97 |
104 enum IrregexpImplementation { | 98 enum IrregexpImplementation { kBytecodeImplementation, kIRImplementation }; |
105 kBytecodeImplementation, | |
106 kIRImplementation | |
107 }; | |
108 | 99 |
109 explicit RegExpMacroAssembler(Zone* zone); | 100 explicit RegExpMacroAssembler(Zone* zone); |
110 virtual ~RegExpMacroAssembler(); | 101 virtual ~RegExpMacroAssembler(); |
111 // The maximal number of pushes between stack checks. Users must supply | 102 // The maximal number of pushes between stack checks. Users must supply |
112 // kCheckStackLimit flag to push operations (instead of kNoStackLimitCheck) | 103 // kCheckStackLimit flag to push operations (instead of kNoStackLimitCheck) |
113 // at least once for every stack_limit() pushes that are executed. | 104 // at least once for every stack_limit() pushes that are executed. |
114 virtual intptr_t stack_limit_slack() = 0; | 105 virtual intptr_t stack_limit_slack() = 0; |
115 virtual bool CanReadUnaligned() = 0; | 106 virtual bool CanReadUnaligned() = 0; |
116 virtual void AdvanceCurrentPosition(intptr_t by) = 0; // Signed cp change. | 107 virtual void AdvanceCurrentPosition(intptr_t by) = 0; // Signed cp change. |
117 virtual void AdvanceRegister(intptr_t reg, intptr_t by) = 0; // r[reg] += by. | 108 virtual void AdvanceRegister(intptr_t reg, intptr_t by) = 0; // r[reg] += by. |
118 // Continues execution from the position pushed on the top of the backtrack | 109 // Continues execution from the position pushed on the top of the backtrack |
119 // stack by an earlier PushBacktrack(BlockLabel*). | 110 // stack by an earlier PushBacktrack(BlockLabel*). |
120 virtual void Backtrack() = 0; | 111 virtual void Backtrack() = 0; |
121 virtual void BindBlock(BlockLabel* label) = 0; | 112 virtual void BindBlock(BlockLabel* label) = 0; |
122 virtual void CheckAtStart(BlockLabel* on_at_start) = 0; | 113 virtual void CheckAtStart(BlockLabel* on_at_start) = 0; |
123 // Dispatch after looking the current character up in a 2-bits-per-entry | 114 // Dispatch after looking the current character up in a 2-bits-per-entry |
124 // map. The destinations vector has up to 4 labels. | 115 // map. The destinations vector has up to 4 labels. |
125 virtual void CheckCharacter(unsigned c, BlockLabel* on_equal) = 0; | 116 virtual void CheckCharacter(unsigned c, BlockLabel* on_equal) = 0; |
126 // Bitwise and the current character with the given constant and then | 117 // Bitwise and the current character with the given constant and then |
127 // check for a match with c. | 118 // check for a match with c. |
128 virtual void CheckCharacterAfterAnd(unsigned c, | 119 virtual void CheckCharacterAfterAnd(unsigned c, |
129 unsigned and_with, | 120 unsigned and_with, |
130 BlockLabel* on_equal) = 0; | 121 BlockLabel* on_equal) = 0; |
131 virtual void CheckCharacterGT(uint16_t limit, BlockLabel* on_greater) = 0; | 122 virtual void CheckCharacterGT(uint16_t limit, BlockLabel* on_greater) = 0; |
132 virtual void CheckCharacterLT(uint16_t limit, BlockLabel* on_less) = 0; | 123 virtual void CheckCharacterLT(uint16_t limit, BlockLabel* on_less) = 0; |
133 virtual void CheckGreedyLoop(BlockLabel* on_tos_equals_current_position) = 0; | 124 virtual void CheckGreedyLoop(BlockLabel* on_tos_equals_current_position) = 0; |
134 virtual void CheckNotAtStart(BlockLabel* on_not_at_start) = 0; | 125 virtual void CheckNotAtStart(BlockLabel* on_not_at_start) = 0; |
135 virtual void CheckNotBackReference( | 126 virtual void CheckNotBackReference(intptr_t start_reg, |
136 intptr_t start_reg, BlockLabel* on_no_match) = 0; | 127 BlockLabel* on_no_match) = 0; |
137 virtual void CheckNotBackReferenceIgnoreCase(intptr_t start_reg, | 128 virtual void CheckNotBackReferenceIgnoreCase(intptr_t start_reg, |
138 BlockLabel* on_no_match) = 0; | 129 BlockLabel* on_no_match) = 0; |
139 // Check the current character for a match with a literal character. If we | 130 // Check the current character for a match with a literal character. If we |
140 // fail to match then goto the on_failure label. End of input always | 131 // fail to match then goto the on_failure label. End of input always |
141 // matches. If the label is NULL then we should pop a backtrack address off | 132 // matches. If the label is NULL then we should pop a backtrack address off |
142 // the stack and go to that. | 133 // the stack and go to that. |
143 virtual void CheckNotCharacter(unsigned c, BlockLabel* on_not_equal) = 0; | 134 virtual void CheckNotCharacter(unsigned c, BlockLabel* on_not_equal) = 0; |
144 virtual void CheckNotCharacterAfterAnd(unsigned c, | 135 virtual void CheckNotCharacterAfterAnd(unsigned c, |
145 unsigned and_with, | 136 unsigned and_with, |
146 BlockLabel* on_not_equal) = 0; | 137 BlockLabel* on_not_equal) = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
171 // character. Returns false if the type of special character class does | 162 // character. Returns false if the type of special character class does |
172 // not have custom support. | 163 // not have custom support. |
173 // May clobber the current loaded character. | 164 // May clobber the current loaded character. |
174 virtual bool CheckSpecialCharacterClass(uint16_t type, | 165 virtual bool CheckSpecialCharacterClass(uint16_t type, |
175 BlockLabel* on_no_match) { | 166 BlockLabel* on_no_match) { |
176 return false; | 167 return false; |
177 } | 168 } |
178 virtual void Fail() = 0; | 169 virtual void Fail() = 0; |
179 // Check whether a register is >= a given constant and go to a label if it | 170 // Check whether a register is >= a given constant and go to a label if it |
180 // is. Backtracks instead if the label is NULL. | 171 // is. Backtracks instead if the label is NULL. |
181 virtual void IfRegisterGE( | 172 virtual void IfRegisterGE(intptr_t reg, |
182 intptr_t reg, intptr_t comparand, BlockLabel* if_ge) = 0; | 173 intptr_t comparand, |
| 174 BlockLabel* if_ge) = 0; |
183 // Check whether a register is < a given constant and go to a label if it is. | 175 // Check whether a register is < a given constant and go to a label if it is. |
184 // Backtracks instead if the label is NULL. | 176 // Backtracks instead if the label is NULL. |
185 virtual void IfRegisterLT( | 177 virtual void IfRegisterLT(intptr_t reg, |
186 intptr_t reg, intptr_t comparand, BlockLabel* if_lt) = 0; | 178 intptr_t comparand, |
| 179 BlockLabel* if_lt) = 0; |
187 // Check whether a register is == to the current position and go to a | 180 // Check whether a register is == to the current position and go to a |
188 // label if it is. | 181 // label if it is. |
189 virtual void IfRegisterEqPos(intptr_t reg, BlockLabel* if_eq) = 0; | 182 virtual void IfRegisterEqPos(intptr_t reg, BlockLabel* if_eq) = 0; |
190 virtual IrregexpImplementation Implementation() = 0; | 183 virtual IrregexpImplementation Implementation() = 0; |
191 // The assembler is closed, iff there is no current instruction assigned. | 184 // The assembler is closed, iff there is no current instruction assigned. |
192 virtual bool IsClosed() const = 0; | 185 virtual bool IsClosed() const = 0; |
193 // Jump to the target label without setting it as the current instruction. | 186 // Jump to the target label without setting it as the current instruction. |
194 virtual void GoTo(BlockLabel* to) = 0; | 187 virtual void GoTo(BlockLabel* to) = 0; |
195 virtual void LoadCurrentCharacter(intptr_t cp_offset, | 188 virtual void LoadCurrentCharacter(intptr_t cp_offset, |
196 BlockLabel* on_end_of_input, | 189 BlockLabel* on_end_of_input, |
197 bool check_bounds = true, | 190 bool check_bounds = true, |
198 intptr_t characters = 1) = 0; | 191 intptr_t characters = 1) = 0; |
199 virtual void PopCurrentPosition() = 0; | 192 virtual void PopCurrentPosition() = 0; |
200 virtual void PopRegister(intptr_t register_index) = 0; | 193 virtual void PopRegister(intptr_t register_index) = 0; |
201 // Prints string within the generated code. Used for debugging. | 194 // Prints string within the generated code. Used for debugging. |
202 virtual void Print(const char* str) = 0; | 195 virtual void Print(const char* str) = 0; |
203 // Prints all emitted blocks. | 196 // Prints all emitted blocks. |
204 virtual void PrintBlocks() = 0; | 197 virtual void PrintBlocks() = 0; |
205 // Pushes the label on the backtrack stack, so that a following Backtrack | 198 // Pushes the label on the backtrack stack, so that a following Backtrack |
206 // will go to this label. Always checks the backtrack stack limit. | 199 // will go to this label. Always checks the backtrack stack limit. |
207 virtual void PushBacktrack(BlockLabel* label) = 0; | 200 virtual void PushBacktrack(BlockLabel* label) = 0; |
208 virtual void PushCurrentPosition() = 0; | 201 virtual void PushCurrentPosition() = 0; |
209 virtual void PushRegister(intptr_t register_index) = 0; | 202 virtual void PushRegister(intptr_t register_index) = 0; |
210 virtual void ReadCurrentPositionFromRegister(intptr_t reg) = 0; | 203 virtual void ReadCurrentPositionFromRegister(intptr_t reg) = 0; |
211 virtual void ReadStackPointerFromRegister(intptr_t reg) = 0; | 204 virtual void ReadStackPointerFromRegister(intptr_t reg) = 0; |
212 virtual void SetCurrentPositionFromEnd(intptr_t by) = 0; | 205 virtual void SetCurrentPositionFromEnd(intptr_t by) = 0; |
213 virtual void SetRegister(intptr_t register_index, intptr_t to) = 0; | 206 virtual void SetRegister(intptr_t register_index, intptr_t to) = 0; |
214 // Return whether the matching (with a global regexp) will be restarted. | 207 // Return whether the matching (with a global regexp) will be restarted. |
215 virtual bool Succeed() = 0; | 208 virtual bool Succeed() = 0; |
216 virtual void WriteCurrentPositionToRegister( | 209 virtual void WriteCurrentPositionToRegister(intptr_t reg, |
217 intptr_t reg, intptr_t cp_offset) = 0; | 210 intptr_t cp_offset) = 0; |
218 virtual void ClearRegisters(intptr_t reg_from, intptr_t reg_to) = 0; | 211 virtual void ClearRegisters(intptr_t reg_from, intptr_t reg_to) = 0; |
219 virtual void WriteStackPointerToRegister(intptr_t reg) = 0; | 212 virtual void WriteStackPointerToRegister(intptr_t reg) = 0; |
220 | 213 |
221 // Controls the generation of large inlined constants in the code. | 214 // Controls the generation of large inlined constants in the code. |
222 void set_slow_safe(bool ssc) { slow_safe_compiler_ = ssc; } | 215 void set_slow_safe(bool ssc) { slow_safe_compiler_ = ssc; } |
223 bool slow_safe() { return slow_safe_compiler_; } | 216 bool slow_safe() { return slow_safe_compiler_; } |
224 | 217 |
225 enum GlobalMode { NOT_GLOBAL, GLOBAL, GLOBAL_NO_ZERO_LENGTH_CHECK }; | 218 enum GlobalMode { NOT_GLOBAL, GLOBAL, GLOBAL_NO_ZERO_LENGTH_CHECK }; |
226 // Set whether the regular expression has the global flag. Exiting due to | 219 // Set whether the regular expression has the global flag. Exiting due to |
227 // a failure in a global regexp may still mean success overall. | 220 // a failure in a global regexp may still mean success overall. |
228 inline void set_global_mode(GlobalMode mode) { global_mode_ = mode; } | 221 inline void set_global_mode(GlobalMode mode) { global_mode_ = mode; } |
229 inline bool global() { return global_mode_ != NOT_GLOBAL; } | 222 inline bool global() { return global_mode_ != NOT_GLOBAL; } |
230 inline bool global_with_zero_length_check() { | 223 inline bool global_with_zero_length_check() { return global_mode_ == GLOBAL; } |
231 return global_mode_ == GLOBAL; | |
232 } | |
233 | 224 |
234 Zone* zone() const { return zone_; } | 225 Zone* zone() const { return zone_; } |
235 | 226 |
236 private: | 227 private: |
237 bool slow_safe_compiler_; | 228 bool slow_safe_compiler_; |
238 bool global_mode_; | 229 bool global_mode_; |
239 Zone* zone_; | 230 Zone* zone_; |
240 }; | 231 }; |
241 | 232 |
242 } // namespace dart | 233 } // namespace dart |
243 | 234 |
244 #endif // RUNTIME_VM_REGEXP_ASSEMBLER_H_ | 235 #endif // RUNTIME_VM_REGEXP_ASSEMBLER_H_ |
OLD | NEW |