OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // A simple interpreter for the Irregexp byte code. | 5 // A simple interpreter for the Irregexp byte code. |
6 | 6 |
7 #include "vm/regexp_interpreter.h" | 7 #include "vm/regexp_interpreter.h" |
8 | 8 |
9 #include "vm/regexp_bytecodes.h" | 9 #include "vm/regexp_bytecodes.h" |
10 #include "vm/regexp_assembler.h" | 10 #include "vm/regexp_assembler.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/unicode.h" | 12 #include "vm/unicode.h" |
13 #include "vm/unibrow.h" | 13 #include "vm/unibrow.h" |
14 #include "vm/unibrow-inl.h" | 14 #include "vm/unibrow-inl.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 DEFINE_FLAG(bool, trace_regexp_bytecodes, false, "trace_regexp_bytecodes"); | 18 DEFINE_FLAG(bool, trace_regexp_bytecodes, false, "trace_regexp_bytecodes"); |
19 | 19 |
20 typedef unibrow::Mapping<unibrow::Ecma262Canonicalize> Canonicalize; | 20 typedef unibrow::Mapping<unibrow::Ecma262Canonicalize> Canonicalize; |
21 | 21 |
22 template<typename Char> | 22 template <typename Char> |
23 static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize, | 23 static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize, |
24 intptr_t from, | 24 intptr_t from, |
25 intptr_t current, | 25 intptr_t current, |
26 intptr_t len, | 26 intptr_t len, |
27 const String& subject); | 27 const String& subject); |
28 | 28 |
29 template <> | 29 template <> |
30 bool BackRefMatchesNoCase<uint16_t>(Canonicalize* interp_canonicalize, | 30 bool BackRefMatchesNoCase<uint16_t>(Canonicalize* interp_canonicalize, |
31 intptr_t from, | 31 intptr_t from, |
32 intptr_t current, | 32 intptr_t current, |
33 intptr_t len, | 33 intptr_t len, |
34 const String& subject) { | 34 const String& subject) { |
35 for (int i = 0; i < len; i++) { | 35 for (int i = 0; i < len; i++) { |
36 int32_t old_char = subject.CharAt(from++); | 36 int32_t old_char = subject.CharAt(from++); |
37 int32_t new_char = subject.CharAt(current++); | 37 int32_t new_char = subject.CharAt(current++); |
38 if (old_char == new_char) continue; | 38 if (old_char == new_char) continue; |
39 int32_t old_string[1] = { old_char }; | 39 int32_t old_string[1] = {old_char}; |
40 int32_t new_string[1] = { new_char }; | 40 int32_t new_string[1] = {new_char}; |
41 interp_canonicalize->get(old_char, '\0', old_string); | 41 interp_canonicalize->get(old_char, '\0', old_string); |
42 interp_canonicalize->get(new_char, '\0', new_string); | 42 interp_canonicalize->get(new_char, '\0', new_string); |
43 if (old_string[0] != new_string[0]) { | 43 if (old_string[0] != new_string[0]) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 } | 46 } |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 template <> | 50 template <> |
(...skipping 24 matching lines...) Expand all Loading... |
75 static void TraceInterpreter(const uint8_t* code_base, | 75 static void TraceInterpreter(const uint8_t* code_base, |
76 const uint8_t* pc, | 76 const uint8_t* pc, |
77 int stack_depth, | 77 int stack_depth, |
78 int current_position, | 78 int current_position, |
79 uint32_t current_char, | 79 uint32_t current_char, |
80 int bytecode_length, | 80 int bytecode_length, |
81 const char* bytecode_name) { | 81 const char* bytecode_name) { |
82 if (FLAG_trace_regexp_bytecodes) { | 82 if (FLAG_trace_regexp_bytecodes) { |
83 bool printable = (current_char < 127 && current_char >= 32); | 83 bool printable = (current_char < 127 && current_char >= 32); |
84 const char* format = | 84 const char* format = |
85 printable ? | 85 printable |
86 "pc = %02x, sp = %d, curpos = %d, curchar = %08x (%c), bc = %s" : | 86 ? "pc = %02x, sp = %d, curpos = %d, curchar = %08x (%c), bc = %s" |
87 "pc = %02x, sp = %d, curpos = %d, curchar = %08x .%c., bc = %s"; | 87 : "pc = %02x, sp = %d, curpos = %d, curchar = %08x .%c., bc = %s"; |
88 OS::Print(format, | 88 OS::Print(format, pc - code_base, stack_depth, current_position, |
89 pc - code_base, | 89 current_char, printable ? current_char : '.', bytecode_name); |
90 stack_depth, | |
91 current_position, | |
92 current_char, | |
93 printable ? current_char : '.', | |
94 bytecode_name); | |
95 for (int i = 0; i < bytecode_length; i++) { | 90 for (int i = 0; i < bytecode_length; i++) { |
96 OS::Print(", %02x", pc[i]); | 91 OS::Print(", %02x", pc[i]); |
97 } | 92 } |
98 OS::Print(" "); | 93 OS::Print(" "); |
99 for (int i = 1; i < bytecode_length; i++) { | 94 for (int i = 1; i < bytecode_length; i++) { |
100 unsigned char b = pc[i]; | 95 unsigned char b = pc[i]; |
101 if (b < 127 && b >= 32) { | 96 if (b < 127 && b >= 32) { |
102 OS::Print("%c", b); | 97 OS::Print("%c", b); |
103 } else { | 98 } else { |
104 OS::Print("."); | 99 OS::Print("."); |
105 } | 100 } |
106 } | 101 } |
107 OS::Print("\n"); | 102 OS::Print("\n"); |
108 } | 103 } |
109 } | 104 } |
110 | 105 |
111 | 106 |
112 #define BYTECODE(name) \ | 107 #define BYTECODE(name) \ |
113 case BC_##name: \ | 108 case BC_##name: \ |
114 TraceInterpreter(code_base, \ | 109 TraceInterpreter(code_base, pc, \ |
115 pc, \ | 110 static_cast<int>(backtrack_sp - backtrack_stack_base), \ |
116 static_cast<int>(backtrack_sp - backtrack_stack_base), \ | 111 current, current_char, BC_##name##_LENGTH, #name); |
117 current, \ | |
118 current_char, \ | |
119 BC_##name##_LENGTH, \ | |
120 #name); | |
121 #else | 112 #else |
122 #define BYTECODE(name) \ | 113 #define BYTECODE(name) case BC_##name: |
123 case BC_##name: | |
124 #endif | 114 #endif |
125 | 115 |
126 | 116 |
127 static int32_t Load32Aligned(const uint8_t* pc) { | 117 static int32_t Load32Aligned(const uint8_t* pc) { |
128 ASSERT((reinterpret_cast<intptr_t>(pc) & 3) == 0); | 118 ASSERT((reinterpret_cast<intptr_t>(pc) & 3) == 0); |
129 return *reinterpret_cast<const int32_t *>(pc); | 119 return *reinterpret_cast<const int32_t*>(pc); |
130 } | 120 } |
131 | 121 |
132 | 122 |
133 static int32_t Load16Aligned(const uint8_t* pc) { | 123 static int32_t Load16Aligned(const uint8_t* pc) { |
134 ASSERT((reinterpret_cast<intptr_t>(pc) & 1) == 0); | 124 ASSERT((reinterpret_cast<intptr_t>(pc) & 1) == 0); |
135 return *reinterpret_cast<const uint16_t *>(pc); | 125 return *reinterpret_cast<const uint16_t*>(pc); |
136 } | 126 } |
137 | 127 |
138 | 128 |
139 // A simple abstraction over the backtracking stack used by the interpreter. | 129 // A simple abstraction over the backtracking stack used by the interpreter. |
140 // This backtracking stack does not grow automatically, but it ensures that the | 130 // This backtracking stack does not grow automatically, but it ensures that the |
141 // the memory held by the stack is released or remembered in a cache if the | 131 // the memory held by the stack is released or remembered in a cache if the |
142 // matching terminates. | 132 // matching terminates. |
143 class BacktrackStack { | 133 class BacktrackStack { |
144 public: | 134 public: |
145 explicit BacktrackStack(Zone* zone) { | 135 explicit BacktrackStack(Zone* zone) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 173 |
184 #ifdef DEBUG | 174 #ifdef DEBUG |
185 if (FLAG_trace_regexp_bytecodes) { | 175 if (FLAG_trace_regexp_bytecodes) { |
186 OS::Print("Start irregexp bytecode interpreter\n"); | 176 OS::Print("Start irregexp bytecode interpreter\n"); |
187 } | 177 } |
188 #endif | 178 #endif |
189 while (true) { | 179 while (true) { |
190 int32_t insn = Load32Aligned(pc); | 180 int32_t insn = Load32Aligned(pc); |
191 switch (insn & BYTECODE_MASK) { | 181 switch (insn & BYTECODE_MASK) { |
192 BYTECODE(BREAK) | 182 BYTECODE(BREAK) |
193 UNREACHABLE(); | 183 UNREACHABLE(); |
194 return IrregexpInterpreter::RE_FAILURE; | 184 return IrregexpInterpreter::RE_FAILURE; |
195 BYTECODE(PUSH_CP) | 185 BYTECODE(PUSH_CP) |
196 if (--backtrack_stack_space < 0) { | 186 if (--backtrack_stack_space < 0) { |
197 return IrregexpInterpreter::RE_EXCEPTION; | 187 return IrregexpInterpreter::RE_EXCEPTION; |
198 } | 188 } |
199 *backtrack_sp++ = current; | 189 *backtrack_sp++ = current; |
200 pc += BC_PUSH_CP_LENGTH; | 190 pc += BC_PUSH_CP_LENGTH; |
201 break; | 191 break; |
202 BYTECODE(PUSH_BT) | 192 BYTECODE(PUSH_BT) |
203 if (--backtrack_stack_space < 0) { | 193 if (--backtrack_stack_space < 0) { |
204 return IrregexpInterpreter::RE_EXCEPTION; | 194 return IrregexpInterpreter::RE_EXCEPTION; |
205 } | 195 } |
206 *backtrack_sp++ = Load32Aligned(pc + 4); | 196 *backtrack_sp++ = Load32Aligned(pc + 4); |
207 pc += BC_PUSH_BT_LENGTH; | 197 pc += BC_PUSH_BT_LENGTH; |
208 break; | 198 break; |
209 BYTECODE(PUSH_REGISTER) | 199 BYTECODE(PUSH_REGISTER) |
210 if (--backtrack_stack_space < 0) { | 200 if (--backtrack_stack_space < 0) { |
211 return IrregexpInterpreter::RE_EXCEPTION; | 201 return IrregexpInterpreter::RE_EXCEPTION; |
212 } | 202 } |
213 *backtrack_sp++ = registers[insn >> BYTECODE_SHIFT]; | 203 *backtrack_sp++ = registers[insn >> BYTECODE_SHIFT]; |
214 pc += BC_PUSH_REGISTER_LENGTH; | 204 pc += BC_PUSH_REGISTER_LENGTH; |
215 break; | 205 break; |
216 BYTECODE(SET_REGISTER) | 206 BYTECODE(SET_REGISTER) |
217 registers[insn >> BYTECODE_SHIFT] = Load32Aligned(pc + 4); | 207 registers[insn >> BYTECODE_SHIFT] = Load32Aligned(pc + 4); |
218 pc += BC_SET_REGISTER_LENGTH; | 208 pc += BC_SET_REGISTER_LENGTH; |
219 break; | 209 break; |
220 BYTECODE(ADVANCE_REGISTER) | 210 BYTECODE(ADVANCE_REGISTER) |
221 registers[insn >> BYTECODE_SHIFT] += Load32Aligned(pc + 4); | 211 registers[insn >> BYTECODE_SHIFT] += Load32Aligned(pc + 4); |
222 pc += BC_ADVANCE_REGISTER_LENGTH; | 212 pc += BC_ADVANCE_REGISTER_LENGTH; |
223 break; | 213 break; |
224 BYTECODE(SET_REGISTER_TO_CP) | 214 BYTECODE(SET_REGISTER_TO_CP) |
225 registers[insn >> BYTECODE_SHIFT] = current + Load32Aligned(pc + 4); | 215 registers[insn >> BYTECODE_SHIFT] = current + Load32Aligned(pc + 4); |
226 pc += BC_SET_REGISTER_TO_CP_LENGTH; | 216 pc += BC_SET_REGISTER_TO_CP_LENGTH; |
227 break; | 217 break; |
228 BYTECODE(SET_CP_TO_REGISTER) | 218 BYTECODE(SET_CP_TO_REGISTER) |
229 current = registers[insn >> BYTECODE_SHIFT]; | 219 current = registers[insn >> BYTECODE_SHIFT]; |
230 pc += BC_SET_CP_TO_REGISTER_LENGTH; | 220 pc += BC_SET_CP_TO_REGISTER_LENGTH; |
231 break; | 221 break; |
232 BYTECODE(SET_REGISTER_TO_SP) | 222 BYTECODE(SET_REGISTER_TO_SP) |
233 registers[insn >> BYTECODE_SHIFT] = | 223 registers[insn >> BYTECODE_SHIFT] = |
234 static_cast<int>(backtrack_sp - backtrack_stack_base); | 224 static_cast<int>(backtrack_sp - backtrack_stack_base); |
235 pc += BC_SET_REGISTER_TO_SP_LENGTH; | 225 pc += BC_SET_REGISTER_TO_SP_LENGTH; |
236 break; | 226 break; |
237 BYTECODE(SET_SP_TO_REGISTER) | 227 BYTECODE(SET_SP_TO_REGISTER) |
238 backtrack_sp = backtrack_stack_base + registers[insn >> BYTECODE_SHIFT]; | 228 backtrack_sp = backtrack_stack_base + registers[insn >> BYTECODE_SHIFT]; |
239 backtrack_stack_space = backtrack_stack.max_size() - | 229 backtrack_stack_space = |
240 static_cast<int>(backtrack_sp - backtrack_stack_base); | 230 backtrack_stack.max_size() - |
241 pc += BC_SET_SP_TO_REGISTER_LENGTH; | 231 static_cast<int>(backtrack_sp - backtrack_stack_base); |
242 break; | 232 pc += BC_SET_SP_TO_REGISTER_LENGTH; |
| 233 break; |
243 BYTECODE(POP_CP) | 234 BYTECODE(POP_CP) |
| 235 backtrack_stack_space++; |
| 236 --backtrack_sp; |
| 237 current = *backtrack_sp; |
| 238 pc += BC_POP_CP_LENGTH; |
| 239 break; |
| 240 BYTECODE(POP_BT) |
| 241 backtrack_stack_space++; |
| 242 --backtrack_sp; |
| 243 pc = code_base + *backtrack_sp; |
| 244 break; |
| 245 BYTECODE(POP_REGISTER) |
| 246 backtrack_stack_space++; |
| 247 --backtrack_sp; |
| 248 registers[insn >> BYTECODE_SHIFT] = *backtrack_sp; |
| 249 pc += BC_POP_REGISTER_LENGTH; |
| 250 break; |
| 251 BYTECODE(FAIL) |
| 252 return IrregexpInterpreter::RE_FAILURE; |
| 253 BYTECODE(SUCCEED) |
| 254 return IrregexpInterpreter::RE_SUCCESS; |
| 255 BYTECODE(ADVANCE_CP) |
| 256 current += insn >> BYTECODE_SHIFT; |
| 257 pc += BC_ADVANCE_CP_LENGTH; |
| 258 break; |
| 259 BYTECODE(GOTO) |
| 260 pc = code_base + Load32Aligned(pc + 4); |
| 261 break; |
| 262 BYTECODE(ADVANCE_CP_AND_GOTO) |
| 263 current += insn >> BYTECODE_SHIFT; |
| 264 pc = code_base + Load32Aligned(pc + 4); |
| 265 break; |
| 266 BYTECODE(CHECK_GREEDY) |
| 267 if (current == backtrack_sp[-1]) { |
| 268 backtrack_sp--; |
244 backtrack_stack_space++; | 269 backtrack_stack_space++; |
245 --backtrack_sp; | |
246 current = *backtrack_sp; | |
247 pc += BC_POP_CP_LENGTH; | |
248 break; | |
249 BYTECODE(POP_BT) | |
250 backtrack_stack_space++; | |
251 --backtrack_sp; | |
252 pc = code_base + *backtrack_sp; | |
253 break; | |
254 BYTECODE(POP_REGISTER) | |
255 backtrack_stack_space++; | |
256 --backtrack_sp; | |
257 registers[insn >> BYTECODE_SHIFT] = *backtrack_sp; | |
258 pc += BC_POP_REGISTER_LENGTH; | |
259 break; | |
260 BYTECODE(FAIL) | |
261 return IrregexpInterpreter::RE_FAILURE; | |
262 BYTECODE(SUCCEED) | |
263 return IrregexpInterpreter::RE_SUCCESS; | |
264 BYTECODE(ADVANCE_CP) | |
265 current += insn >> BYTECODE_SHIFT; | |
266 pc += BC_ADVANCE_CP_LENGTH; | |
267 break; | |
268 BYTECODE(GOTO) | |
269 pc = code_base + Load32Aligned(pc + 4); | 270 pc = code_base + Load32Aligned(pc + 4); |
270 break; | 271 } else { |
271 BYTECODE(ADVANCE_CP_AND_GOTO) | 272 pc += BC_CHECK_GREEDY_LENGTH; |
272 current += insn >> BYTECODE_SHIFT; | 273 } |
273 pc = code_base + Load32Aligned(pc + 4); | 274 break; |
274 break; | |
275 BYTECODE(CHECK_GREEDY) | |
276 if (current == backtrack_sp[-1]) { | |
277 backtrack_sp--; | |
278 backtrack_stack_space++; | |
279 pc = code_base + Load32Aligned(pc + 4); | |
280 } else { | |
281 pc += BC_CHECK_GREEDY_LENGTH; | |
282 } | |
283 break; | |
284 BYTECODE(LOAD_CURRENT_CHAR) { | 275 BYTECODE(LOAD_CURRENT_CHAR) { |
285 int pos = current + (insn >> BYTECODE_SHIFT); | 276 int pos = current + (insn >> BYTECODE_SHIFT); |
286 if (pos >= subject_length) { | 277 if (pos >= subject_length) { |
287 pc = code_base + Load32Aligned(pc + 4); | 278 pc = code_base + Load32Aligned(pc + 4); |
288 } else { | 279 } else { |
289 current_char = subject.CharAt(pos); | 280 current_char = subject.CharAt(pos); |
290 pc += BC_LOAD_CURRENT_CHAR_LENGTH; | 281 pc += BC_LOAD_CURRENT_CHAR_LENGTH; |
291 } | 282 } |
292 break; | 283 break; |
293 } | 284 } |
294 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { | 285 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { |
295 int pos = current + (insn >> BYTECODE_SHIFT); | 286 int pos = current + (insn >> BYTECODE_SHIFT); |
296 current_char = subject.CharAt(pos); | 287 current_char = subject.CharAt(pos); |
297 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; | 288 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; |
298 break; | 289 break; |
299 } | 290 } |
300 BYTECODE(LOAD_2_CURRENT_CHARS) { | 291 BYTECODE(LOAD_2_CURRENT_CHARS) { |
301 int pos = current + (insn >> BYTECODE_SHIFT); | 292 int pos = current + (insn >> BYTECODE_SHIFT); |
302 if (pos + 2 > subject_length) { | 293 if (pos + 2 > subject_length) { |
303 pc = code_base + Load32Aligned(pc + 4); | 294 pc = code_base + Load32Aligned(pc + 4); |
304 } else { | 295 } else { |
305 Char next = subject.CharAt(pos + 1); | 296 Char next = subject.CharAt(pos + 1); |
306 current_char = subject.CharAt(pos) | | 297 current_char = |
307 (next << (kBitsPerByte * sizeof(Char))); | 298 subject.CharAt(pos) | (next << (kBitsPerByte * sizeof(Char))); |
308 pc += BC_LOAD_2_CURRENT_CHARS_LENGTH; | 299 pc += BC_LOAD_2_CURRENT_CHARS_LENGTH; |
309 } | 300 } |
310 break; | 301 break; |
311 } | 302 } |
312 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) { | 303 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) { |
313 int pos = current + (insn >> BYTECODE_SHIFT); | 304 int pos = current + (insn >> BYTECODE_SHIFT); |
314 Char next = subject.CharAt(pos + 1); | 305 Char next = subject.CharAt(pos + 1); |
315 current_char = subject.CharAt(pos) | | 306 current_char = |
316 (next << (kBitsPerByte * sizeof(Char))); | 307 subject.CharAt(pos) | (next << (kBitsPerByte * sizeof(Char))); |
317 pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH; | 308 pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH; |
318 break; | 309 break; |
319 } | 310 } |
320 BYTECODE(LOAD_4_CURRENT_CHARS) { | 311 BYTECODE(LOAD_4_CURRENT_CHARS) { |
321 ASSERT(sizeof(Char) == 1); | 312 ASSERT(sizeof(Char) == 1); |
322 int pos = current + (insn >> BYTECODE_SHIFT); | 313 int pos = current + (insn >> BYTECODE_SHIFT); |
323 if (pos + 4 > subject_length) { | 314 if (pos + 4 > subject_length) { |
324 pc = code_base + Load32Aligned(pc + 4); | 315 pc = code_base + Load32Aligned(pc + 4); |
325 } else { | 316 } else { |
326 Char next1 = subject.CharAt(pos + 1); | 317 Char next1 = subject.CharAt(pos + 1); |
327 Char next2 = subject.CharAt(pos + 2); | 318 Char next2 = subject.CharAt(pos + 2); |
328 Char next3 = subject.CharAt(pos + 3); | 319 Char next3 = subject.CharAt(pos + 3); |
329 current_char = (subject.CharAt(pos) | | 320 current_char = (subject.CharAt(pos) | (next1 << 8) | (next2 << 16) | |
330 (next1 << 8) | | |
331 (next2 << 16) | | |
332 (next3 << 24)); | 321 (next3 << 24)); |
333 pc += BC_LOAD_4_CURRENT_CHARS_LENGTH; | 322 pc += BC_LOAD_4_CURRENT_CHARS_LENGTH; |
334 } | 323 } |
335 break; | 324 break; |
336 } | 325 } |
337 BYTECODE(LOAD_4_CURRENT_CHARS_UNCHECKED) { | 326 BYTECODE(LOAD_4_CURRENT_CHARS_UNCHECKED) { |
338 ASSERT(sizeof(Char) == 1); | 327 ASSERT(sizeof(Char) == 1); |
339 int pos = current + (insn >> BYTECODE_SHIFT); | 328 int pos = current + (insn >> BYTECODE_SHIFT); |
340 Char next1 = subject.CharAt(pos + 1); | 329 Char next1 = subject.CharAt(pos + 1); |
341 Char next2 = subject.CharAt(pos + 2); | 330 Char next2 = subject.CharAt(pos + 2); |
342 Char next3 = subject.CharAt(pos + 3); | 331 Char next3 = subject.CharAt(pos + 3); |
343 current_char = (subject.CharAt(pos) | | 332 current_char = (subject.CharAt(pos) | (next1 << 8) | (next2 << 16) | |
344 (next1 << 8) | | |
345 (next2 << 16) | | |
346 (next3 << 24)); | 333 (next3 << 24)); |
347 pc += BC_LOAD_4_CURRENT_CHARS_UNCHECKED_LENGTH; | 334 pc += BC_LOAD_4_CURRENT_CHARS_UNCHECKED_LENGTH; |
348 break; | 335 break; |
349 } | 336 } |
350 BYTECODE(CHECK_4_CHARS) { | 337 BYTECODE(CHECK_4_CHARS) { |
351 uint32_t c = Load32Aligned(pc + 4); | 338 uint32_t c = Load32Aligned(pc + 4); |
352 if (c == current_char) { | 339 if (c == current_char) { |
353 pc = code_base + Load32Aligned(pc + 8); | 340 pc = code_base + Load32Aligned(pc + 8); |
354 } else { | 341 } else { |
355 pc += BC_CHECK_4_CHARS_LENGTH; | 342 pc += BC_CHECK_4_CHARS_LENGTH; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 BYTECODE(CHECK_GT) { | 460 BYTECODE(CHECK_GT) { |
474 uint32_t limit = (insn >> BYTECODE_SHIFT); | 461 uint32_t limit = (insn >> BYTECODE_SHIFT); |
475 if (current_char > limit) { | 462 if (current_char > limit) { |
476 pc = code_base + Load32Aligned(pc + 4); | 463 pc = code_base + Load32Aligned(pc + 4); |
477 } else { | 464 } else { |
478 pc += BC_CHECK_GT_LENGTH; | 465 pc += BC_CHECK_GT_LENGTH; |
479 } | 466 } |
480 break; | 467 break; |
481 } | 468 } |
482 BYTECODE(CHECK_REGISTER_LT) | 469 BYTECODE(CHECK_REGISTER_LT) |
483 if (registers[insn >> BYTECODE_SHIFT] < Load32Aligned(pc + 4)) { | 470 if (registers[insn >> BYTECODE_SHIFT] < Load32Aligned(pc + 4)) { |
484 pc = code_base + Load32Aligned(pc + 8); | 471 pc = code_base + Load32Aligned(pc + 8); |
485 } else { | 472 } else { |
486 pc += BC_CHECK_REGISTER_LT_LENGTH; | 473 pc += BC_CHECK_REGISTER_LT_LENGTH; |
487 } | 474 } |
488 break; | 475 break; |
489 BYTECODE(CHECK_REGISTER_GE) | 476 BYTECODE(CHECK_REGISTER_GE) |
490 if (registers[insn >> BYTECODE_SHIFT] >= Load32Aligned(pc + 4)) { | 477 if (registers[insn >> BYTECODE_SHIFT] >= Load32Aligned(pc + 4)) { |
491 pc = code_base + Load32Aligned(pc + 8); | 478 pc = code_base + Load32Aligned(pc + 8); |
492 } else { | 479 } else { |
493 pc += BC_CHECK_REGISTER_GE_LENGTH; | 480 pc += BC_CHECK_REGISTER_GE_LENGTH; |
494 } | 481 } |
495 break; | 482 break; |
496 BYTECODE(CHECK_REGISTER_EQ_POS) | 483 BYTECODE(CHECK_REGISTER_EQ_POS) |
497 if (registers[insn >> BYTECODE_SHIFT] == current) { | 484 if (registers[insn >> BYTECODE_SHIFT] == current) { |
498 pc = code_base + Load32Aligned(pc + 4); | 485 pc = code_base + Load32Aligned(pc + 4); |
499 } else { | 486 } else { |
500 pc += BC_CHECK_REGISTER_EQ_POS_LENGTH; | 487 pc += BC_CHECK_REGISTER_EQ_POS_LENGTH; |
501 } | 488 } |
502 break; | 489 break; |
503 BYTECODE(CHECK_NOT_REGS_EQUAL) | 490 BYTECODE(CHECK_NOT_REGS_EQUAL) |
504 if (registers[insn >> BYTECODE_SHIFT] == | 491 if (registers[insn >> BYTECODE_SHIFT] == |
505 registers[Load32Aligned(pc + 4)]) { | 492 registers[Load32Aligned(pc + 4)]) { |
506 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; | 493 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; |
507 } else { | 494 } else { |
508 pc = code_base + Load32Aligned(pc + 8); | 495 pc = code_base + Load32Aligned(pc + 8); |
509 } | 496 } |
510 break; | 497 break; |
511 BYTECODE(CHECK_NOT_BACK_REF) { | 498 BYTECODE(CHECK_NOT_BACK_REF) { |
512 int from = registers[insn >> BYTECODE_SHIFT]; | 499 int from = registers[insn >> BYTECODE_SHIFT]; |
513 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | 500 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
514 if (from < 0 || len <= 0) { | 501 if (from < 0 || len <= 0) { |
515 pc += BC_CHECK_NOT_BACK_REF_LENGTH; | 502 pc += BC_CHECK_NOT_BACK_REF_LENGTH; |
516 break; | 503 break; |
517 } | 504 } |
518 if (current + len > subject_length) { | 505 if (current + len > subject_length) { |
519 pc = code_base + Load32Aligned(pc + 4); | 506 pc = code_base + Load32Aligned(pc + 4); |
520 break; | 507 break; |
(...skipping 15 matching lines...) Expand all Loading... |
536 int from = registers[insn >> BYTECODE_SHIFT]; | 523 int from = registers[insn >> BYTECODE_SHIFT]; |
537 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | 524 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
538 if (from < 0 || len <= 0) { | 525 if (from < 0 || len <= 0) { |
539 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; | 526 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
540 break; | 527 break; |
541 } | 528 } |
542 if (current + len > subject_length) { | 529 if (current + len > subject_length) { |
543 pc = code_base + Load32Aligned(pc + 4); | 530 pc = code_base + Load32Aligned(pc + 4); |
544 break; | 531 break; |
545 } else { | 532 } else { |
546 if (BackRefMatchesNoCase<Char>(&canonicalize, | 533 if (BackRefMatchesNoCase<Char>(&canonicalize, from, current, len, |
547 from, current, len, subject)) { | 534 subject)) { |
548 current += len; | 535 current += len; |
549 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; | 536 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
550 } else { | 537 } else { |
551 pc = code_base + Load32Aligned(pc + 4); | 538 pc = code_base + Load32Aligned(pc + 4); |
552 } | 539 } |
553 } | 540 } |
554 break; | 541 break; |
555 } | 542 } |
556 BYTECODE(CHECK_AT_START) | 543 BYTECODE(CHECK_AT_START) |
557 if (current == 0) { | 544 if (current == 0) { |
558 pc = code_base + Load32Aligned(pc + 4); | 545 pc = code_base + Load32Aligned(pc + 4); |
559 } else { | 546 } else { |
560 pc += BC_CHECK_AT_START_LENGTH; | 547 pc += BC_CHECK_AT_START_LENGTH; |
561 } | 548 } |
562 break; | 549 break; |
563 BYTECODE(CHECK_NOT_AT_START) | 550 BYTECODE(CHECK_NOT_AT_START) |
564 if (current == 0) { | 551 if (current == 0) { |
565 pc += BC_CHECK_NOT_AT_START_LENGTH; | 552 pc += BC_CHECK_NOT_AT_START_LENGTH; |
566 } else { | 553 } else { |
567 pc = code_base + Load32Aligned(pc + 4); | 554 pc = code_base + Load32Aligned(pc + 4); |
568 } | 555 } |
569 break; | 556 break; |
570 BYTECODE(SET_CURRENT_POSITION_FROM_END) { | 557 BYTECODE(SET_CURRENT_POSITION_FROM_END) { |
571 int by = static_cast<uint32_t>(insn) >> BYTECODE_SHIFT; | 558 int by = static_cast<uint32_t>(insn) >> BYTECODE_SHIFT; |
572 if (subject_length - current > by) { | 559 if (subject_length - current > by) { |
573 current = subject_length - by; | 560 current = subject_length - by; |
574 current_char = subject.CharAt(current - 1); | 561 current_char = subject.CharAt(current - 1); |
575 } | 562 } |
576 pc += BC_SET_CURRENT_POSITION_FROM_END_LENGTH; | 563 pc += BC_SET_CURRENT_POSITION_FROM_END_LENGTH; |
577 break; | 564 break; |
578 } | 565 } |
579 default: | 566 default: |
(...skipping 12 matching lines...) Expand all Loading... |
592 Zone* zone) { | 579 Zone* zone) { |
593 NoSafepointScope no_safepoint; | 580 NoSafepointScope no_safepoint; |
594 const uint8_t* code_base = reinterpret_cast<uint8_t*>(bytecode.DataAddr(0)); | 581 const uint8_t* code_base = reinterpret_cast<uint8_t*>(bytecode.DataAddr(0)); |
595 | 582 |
596 uint16_t previous_char = '\n'; | 583 uint16_t previous_char = '\n'; |
597 if (start_position != 0) { | 584 if (start_position != 0) { |
598 previous_char = subject.CharAt(start_position - 1); | 585 previous_char = subject.CharAt(start_position - 1); |
599 } | 586 } |
600 | 587 |
601 if (subject.IsOneByteString() || subject.IsExternalOneByteString()) { | 588 if (subject.IsOneByteString() || subject.IsExternalOneByteString()) { |
602 return RawMatch<uint8_t>(code_base, | 589 return RawMatch<uint8_t>(code_base, subject, registers, start_position, |
603 subject, | 590 previous_char, zone); |
604 registers, | |
605 start_position, | |
606 previous_char, | |
607 zone); | |
608 } else if (subject.IsTwoByteString() || subject.IsExternalTwoByteString()) { | 591 } else if (subject.IsTwoByteString() || subject.IsExternalTwoByteString()) { |
609 return RawMatch<uint16_t>(code_base, | 592 return RawMatch<uint16_t>(code_base, subject, registers, start_position, |
610 subject, | 593 previous_char, zone); |
611 registers, | |
612 start_position, | |
613 previous_char, | |
614 zone); | |
615 } else { | 594 } else { |
616 UNREACHABLE(); | 595 UNREACHABLE(); |
617 return IrregexpInterpreter::RE_FAILURE; | 596 return IrregexpInterpreter::RE_FAILURE; |
618 } | 597 } |
619 } | 598 } |
620 | 599 |
621 } // namespace dart | 600 } // namespace dart |
OLD | NEW |