ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | // A simple interpreter for the Irregexp byte code. |
| 29 | |
| 30 | |
| 31 | #include "v8.h" |
| 32 | #include "unicode.h" |
| 33 | #include "utils.h" |
| 34 | #include "ast.h" |
| 35 | #include "bytecodes-irregexp.h" |
| 36 | #include "interpreter-irregexp.h" |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 37 | #include "jsregexp.h" |
| 38 | #include "regexp-macro-assembler.h" |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 39 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 42 | |
| 43 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 44 | typedef unibrow::Mapping<unibrow::Ecma262Canonicalize> Canonicalize; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 45 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 46 | static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize, |
| 47 | int from, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 48 | int current, |
| 49 | int len, |
| 50 | Vector<const uc16> subject) { |
| 51 | for (int i = 0; i < len; i++) { |
| 52 | unibrow::uchar old_char = subject[from++]; |
| 53 | unibrow::uchar new_char = subject[current++]; |
| 54 | if (old_char == new_char) continue; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 55 | unibrow::uchar old_string[1] = { old_char }; |
| 56 | unibrow::uchar new_string[1] = { new_char }; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 57 | interp_canonicalize->get(old_char, '\0', old_string); |
| 58 | interp_canonicalize->get(new_char, '\0', new_string); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 59 | if (old_string[0] != new_string[0]) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 67 | static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize, |
| 68 | int from, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 69 | int current, |
| 70 | int len, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 71 | Vector<const uint8_t> subject) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 72 | for (int i = 0; i < len; i++) { |
| 73 | unsigned int old_char = subject[from++]; |
| 74 | unsigned int new_char = subject[current++]; |
| 75 | if (old_char == new_char) continue; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 76 | // Convert both characters to lower case. |
| 77 | old_char |= 0x20; |
| 78 | new_char |= 0x20; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 79 | if (old_char != new_char) return false; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 80 | // Not letters in the ASCII range and Latin-1 range. |
| 81 | if (!(old_char - 'a' <= 'z' - 'a') && |
| 82 | !(old_char - 224 <= 254 - 224 && old_char != 247)) { |
| 83 | return false; |
| 84 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 90 | #ifdef DEBUG |
| 91 | static void TraceInterpreter(const byte* code_base, |
| 92 | const byte* pc, |
| 93 | int stack_depth, |
| 94 | int current_position, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 95 | uint32_t current_char, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 96 | int bytecode_length, |
| 97 | const char* bytecode_name) { |
| 98 | if (FLAG_trace_regexp_bytecodes) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 99 | bool printable = (current_char < 127 && current_char >= 32); |
| 100 | const char* format = |
| 101 | printable ? |
| 102 | "pc = %02x, sp = %d, curpos = %d, curchar = %08x (%c), bc = %s" : |
| 103 | "pc = %02x, sp = %d, curpos = %d, curchar = %08x .%c., bc = %s"; |
| 104 | PrintF(format, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 105 | pc - code_base, |
| 106 | stack_depth, |
| 107 | current_position, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 108 | current_char, |
| 109 | printable ? current_char : '.', |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 110 | bytecode_name); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 111 | for (int i = 0; i < bytecode_length; i++) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 112 | printf(", %02x", pc[i]); |
| 113 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 114 | printf(" "); |
| 115 | for (int i = 1; i < bytecode_length; i++) { |
| 116 | unsigned char b = pc[i]; |
| 117 | if (b < 127 && b >= 32) { |
| 118 | printf("%c", b); |
| 119 | } else { |
| 120 | printf("."); |
| 121 | } |
| 122 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 123 | printf("\n"); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 128 | #define BYTECODE(name) \ |
| 129 | case BC_##name: \ |
| 130 | TraceInterpreter(code_base, \ |
| 131 | pc, \ |
| 132 | static_cast<int>(backtrack_sp - backtrack_stack_base), \ |
| 133 | current, \ |
| 134 | current_char, \ |
| 135 | BC_##name##_LENGTH, \ |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 136 | #name); |
| 137 | #else |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 138 | #define BYTECODE(name) \ |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 139 | case BC_##name: |
| 140 | #endif |
| 141 | |
| 142 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 143 | static int32_t Load32Aligned(const byte* pc) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 144 | ASSERT((reinterpret_cast<intptr_t>(pc) & 3) == 0); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 145 | return *reinterpret_cast<const int32_t *>(pc); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static int32_t Load16Aligned(const byte* pc) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 150 | ASSERT((reinterpret_cast<intptr_t>(pc) & 1) == 0); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 151 | return *reinterpret_cast<const uint16_t *>(pc); |
| 152 | } |
| 153 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 154 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 155 | // A simple abstraction over the backtracking stack used by the interpreter. |
| 156 | // This backtracking stack does not grow automatically, but it ensures that the |
| 157 | // the memory held by the stack is released or remembered in a cache if the |
| 158 | // matching terminates. |
| 159 | class BacktrackStack { |
| 160 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 161 | explicit BacktrackStack(Isolate* isolate) : isolate_(isolate) { |
| 162 | if (isolate->irregexp_interpreter_backtrack_stack_cache() != NULL) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 163 | // If the cache is not empty reuse the previously allocated stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 164 | data_ = isolate->irregexp_interpreter_backtrack_stack_cache(); |
| 165 | isolate->set_irregexp_interpreter_backtrack_stack_cache(NULL); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 166 | } else { |
| 167 | // Cache was empty. Allocate a new backtrack stack. |
| 168 | data_ = NewArray<int>(kBacktrackStackSize); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | ~BacktrackStack() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 173 | if (isolate_->irregexp_interpreter_backtrack_stack_cache() == NULL) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 174 | // The cache is empty. Keep this backtrack stack around. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 175 | isolate_->set_irregexp_interpreter_backtrack_stack_cache(data_); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 176 | } else { |
| 177 | // A backtrack stack was already cached, just release this one. |
| 178 | DeleteArray(data_); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | int* data() const { return data_; } |
| 183 | |
| 184 | int max_size() const { return kBacktrackStackSize; } |
| 185 | |
| 186 | private: |
| 187 | static const int kBacktrackStackSize = 10000; |
| 188 | |
| 189 | int* data_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 190 | Isolate* isolate_; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 191 | |
| 192 | DISALLOW_COPY_AND_ASSIGN(BacktrackStack); |
| 193 | }; |
| 194 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 195 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 196 | template <typename Char> |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 197 | static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, |
| 198 | const byte* code_base, |
| 199 | Vector<const Char> subject, |
| 200 | int* registers, |
| 201 | int current, |
| 202 | uint32_t current_char) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 203 | const byte* pc = code_base; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 204 | // BacktrackStack ensures that the memory allocated for the backtracking stack |
| 205 | // is returned to the system or cached if there is no stack being cached at |
| 206 | // the moment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 207 | BacktrackStack backtrack_stack(isolate); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 208 | int* backtrack_stack_base = backtrack_stack.data(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 209 | int* backtrack_sp = backtrack_stack_base; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 210 | int backtrack_stack_space = backtrack_stack.max_size(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 211 | #ifdef DEBUG |
| 212 | if (FLAG_trace_regexp_bytecodes) { |
| 213 | PrintF("\n\nStart bytecode interpreter\n\n"); |
| 214 | } |
| 215 | #endif |
| 216 | while (true) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 217 | int32_t insn = Load32Aligned(pc); |
| 218 | switch (insn & BYTECODE_MASK) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 219 | BYTECODE(BREAK) |
| 220 | UNREACHABLE(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 221 | return RegExpImpl::RE_FAILURE; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 222 | BYTECODE(PUSH_CP) |
| 223 | if (--backtrack_stack_space < 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 224 | return RegExpImpl::RE_EXCEPTION; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 225 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 226 | *backtrack_sp++ = current; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 227 | pc += BC_PUSH_CP_LENGTH; |
| 228 | break; |
| 229 | BYTECODE(PUSH_BT) |
| 230 | if (--backtrack_stack_space < 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 231 | return RegExpImpl::RE_EXCEPTION; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 232 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 233 | *backtrack_sp++ = Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 234 | pc += BC_PUSH_BT_LENGTH; |
| 235 | break; |
| 236 | BYTECODE(PUSH_REGISTER) |
| 237 | if (--backtrack_stack_space < 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 238 | return RegExpImpl::RE_EXCEPTION; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 239 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 240 | *backtrack_sp++ = registers[insn >> BYTECODE_SHIFT]; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 241 | pc += BC_PUSH_REGISTER_LENGTH; |
| 242 | break; |
| 243 | BYTECODE(SET_REGISTER) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 244 | registers[insn >> BYTECODE_SHIFT] = Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 245 | pc += BC_SET_REGISTER_LENGTH; |
| 246 | break; |
| 247 | BYTECODE(ADVANCE_REGISTER) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 248 | registers[insn >> BYTECODE_SHIFT] += Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 249 | pc += BC_ADVANCE_REGISTER_LENGTH; |
| 250 | break; |
| 251 | BYTECODE(SET_REGISTER_TO_CP) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 252 | registers[insn >> BYTECODE_SHIFT] = current + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 253 | pc += BC_SET_REGISTER_TO_CP_LENGTH; |
| 254 | break; |
| 255 | BYTECODE(SET_CP_TO_REGISTER) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 256 | current = registers[insn >> BYTECODE_SHIFT]; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 257 | pc += BC_SET_CP_TO_REGISTER_LENGTH; |
| 258 | break; |
| 259 | BYTECODE(SET_REGISTER_TO_SP) |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 260 | registers[insn >> BYTECODE_SHIFT] = |
| 261 | static_cast<int>(backtrack_sp - backtrack_stack_base); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 262 | pc += BC_SET_REGISTER_TO_SP_LENGTH; |
| 263 | break; |
| 264 | BYTECODE(SET_SP_TO_REGISTER) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 265 | backtrack_sp = backtrack_stack_base + registers[insn >> BYTECODE_SHIFT]; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 266 | backtrack_stack_space = backtrack_stack.max_size() - |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 267 | static_cast<int>(backtrack_sp - backtrack_stack_base); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 268 | pc += BC_SET_SP_TO_REGISTER_LENGTH; |
| 269 | break; |
| 270 | BYTECODE(POP_CP) |
| 271 | backtrack_stack_space++; |
| 272 | --backtrack_sp; |
| 273 | current = *backtrack_sp; |
| 274 | pc += BC_POP_CP_LENGTH; |
| 275 | break; |
| 276 | BYTECODE(POP_BT) |
| 277 | backtrack_stack_space++; |
| 278 | --backtrack_sp; |
| 279 | pc = code_base + *backtrack_sp; |
| 280 | break; |
| 281 | BYTECODE(POP_REGISTER) |
| 282 | backtrack_stack_space++; |
| 283 | --backtrack_sp; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 284 | registers[insn >> BYTECODE_SHIFT] = *backtrack_sp; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 285 | pc += BC_POP_REGISTER_LENGTH; |
| 286 | break; |
| 287 | BYTECODE(FAIL) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 288 | return RegExpImpl::RE_FAILURE; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 289 | BYTECODE(SUCCEED) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 290 | return RegExpImpl::RE_SUCCESS; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 291 | BYTECODE(ADVANCE_CP) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 292 | current += insn >> BYTECODE_SHIFT; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 293 | pc += BC_ADVANCE_CP_LENGTH; |
| 294 | break; |
| 295 | BYTECODE(GOTO) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 296 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 297 | break; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 298 | BYTECODE(ADVANCE_CP_AND_GOTO) |
| 299 | current += insn >> BYTECODE_SHIFT; |
| 300 | pc = code_base + Load32Aligned(pc + 4); |
| 301 | break; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 302 | BYTECODE(CHECK_GREEDY) |
| 303 | if (current == backtrack_sp[-1]) { |
| 304 | backtrack_sp--; |
| 305 | backtrack_stack_space++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 306 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 307 | } else { |
| 308 | pc += BC_CHECK_GREEDY_LENGTH; |
| 309 | } |
| 310 | break; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 311 | BYTECODE(LOAD_CURRENT_CHAR) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 312 | int pos = current + (insn >> BYTECODE_SHIFT); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 313 | if (pos >= subject.length()) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 314 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 315 | } else { |
| 316 | current_char = subject[pos]; |
| 317 | pc += BC_LOAD_CURRENT_CHAR_LENGTH; |
| 318 | } |
| 319 | break; |
| 320 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 321 | BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 322 | int pos = current + (insn >> BYTECODE_SHIFT); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 323 | current_char = subject[pos]; |
| 324 | pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; |
| 325 | break; |
| 326 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 327 | BYTECODE(LOAD_2_CURRENT_CHARS) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 328 | int pos = current + (insn >> BYTECODE_SHIFT); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 329 | if (pos + 2 > subject.length()) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 330 | pc = code_base + Load32Aligned(pc + 4); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 331 | } else { |
| 332 | Char next = subject[pos + 1]; |
| 333 | current_char = |
| 334 | (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); |
| 335 | pc += BC_LOAD_2_CURRENT_CHARS_LENGTH; |
| 336 | } |
| 337 | break; |
| 338 | } |
| 339 | BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 340 | int pos = current + (insn >> BYTECODE_SHIFT); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 341 | Char next = subject[pos + 1]; |
| 342 | current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); |
| 343 | pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH; |
| 344 | break; |
| 345 | } |
| 346 | BYTECODE(LOAD_4_CURRENT_CHARS) { |
| 347 | ASSERT(sizeof(Char) == 1); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 348 | int pos = current + (insn >> BYTECODE_SHIFT); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 349 | if (pos + 4 > subject.length()) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 350 | pc = code_base + Load32Aligned(pc + 4); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 351 | } else { |
| 352 | Char next1 = subject[pos + 1]; |
| 353 | Char next2 = subject[pos + 2]; |
| 354 | Char next3 = subject[pos + 3]; |
| 355 | current_char = (subject[pos] | |
| 356 | (next1 << 8) | |
| 357 | (next2 << 16) | |
| 358 | (next3 << 24)); |
| 359 | pc += BC_LOAD_4_CURRENT_CHARS_LENGTH; |
| 360 | } |
| 361 | break; |
| 362 | } |
| 363 | BYTECODE(LOAD_4_CURRENT_CHARS_UNCHECKED) { |
| 364 | ASSERT(sizeof(Char) == 1); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 365 | int pos = current + (insn >> BYTECODE_SHIFT); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 366 | Char next1 = subject[pos + 1]; |
| 367 | Char next2 = subject[pos + 2]; |
| 368 | Char next3 = subject[pos + 3]; |
| 369 | current_char = (subject[pos] | |
| 370 | (next1 << 8) | |
| 371 | (next2 << 16) | |
| 372 | (next3 << 24)); |
| 373 | pc += BC_LOAD_4_CURRENT_CHARS_UNCHECKED_LENGTH; |
| 374 | break; |
| 375 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 376 | BYTECODE(CHECK_4_CHARS) { |
| 377 | uint32_t c = Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 378 | if (c == current_char) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 379 | pc = code_base + Load32Aligned(pc + 8); |
| 380 | } else { |
| 381 | pc += BC_CHECK_4_CHARS_LENGTH; |
| 382 | } |
| 383 | break; |
| 384 | } |
| 385 | BYTECODE(CHECK_CHAR) { |
| 386 | uint32_t c = (insn >> BYTECODE_SHIFT); |
| 387 | if (c == current_char) { |
| 388 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 389 | } else { |
| 390 | pc += BC_CHECK_CHAR_LENGTH; |
| 391 | } |
| 392 | break; |
| 393 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 394 | BYTECODE(CHECK_NOT_4_CHARS) { |
| 395 | uint32_t c = Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 396 | if (c != current_char) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 397 | pc = code_base + Load32Aligned(pc + 8); |
| 398 | } else { |
| 399 | pc += BC_CHECK_NOT_4_CHARS_LENGTH; |
| 400 | } |
| 401 | break; |
| 402 | } |
| 403 | BYTECODE(CHECK_NOT_CHAR) { |
| 404 | uint32_t c = (insn >> BYTECODE_SHIFT); |
| 405 | if (c != current_char) { |
| 406 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 407 | } else { |
| 408 | pc += BC_CHECK_NOT_CHAR_LENGTH; |
| 409 | } |
| 410 | break; |
| 411 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 412 | BYTECODE(AND_CHECK_4_CHARS) { |
| 413 | uint32_t c = Load32Aligned(pc + 4); |
| 414 | if (c == (current_char & Load32Aligned(pc + 8))) { |
| 415 | pc = code_base + Load32Aligned(pc + 12); |
| 416 | } else { |
| 417 | pc += BC_AND_CHECK_4_CHARS_LENGTH; |
| 418 | } |
| 419 | break; |
| 420 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 421 | BYTECODE(AND_CHECK_CHAR) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 422 | uint32_t c = (insn >> BYTECODE_SHIFT); |
| 423 | if (c == (current_char & Load32Aligned(pc + 4))) { |
| 424 | pc = code_base + Load32Aligned(pc + 8); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 425 | } else { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 426 | pc += BC_AND_CHECK_CHAR_LENGTH; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 427 | } |
| 428 | break; |
| 429 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 430 | BYTECODE(AND_CHECK_NOT_4_CHARS) { |
| 431 | uint32_t c = Load32Aligned(pc + 4); |
| 432 | if (c != (current_char & Load32Aligned(pc + 8))) { |
| 433 | pc = code_base + Load32Aligned(pc + 12); |
| 434 | } else { |
| 435 | pc += BC_AND_CHECK_NOT_4_CHARS_LENGTH; |
| 436 | } |
| 437 | break; |
| 438 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 439 | BYTECODE(AND_CHECK_NOT_CHAR) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 440 | uint32_t c = (insn >> BYTECODE_SHIFT); |
| 441 | if (c != (current_char & Load32Aligned(pc + 4))) { |
| 442 | pc = code_base + Load32Aligned(pc + 8); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 443 | } else { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 444 | pc += BC_AND_CHECK_NOT_CHAR_LENGTH; |
| 445 | } |
| 446 | break; |
| 447 | } |
| 448 | BYTECODE(MINUS_AND_CHECK_NOT_CHAR) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 449 | uint32_t c = (insn >> BYTECODE_SHIFT); |
| 450 | uint32_t minus = Load16Aligned(pc + 4); |
| 451 | uint32_t mask = Load16Aligned(pc + 6); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 452 | if (c != ((current_char - minus) & mask)) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 453 | pc = code_base + Load32Aligned(pc + 8); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 454 | } else { |
| 455 | pc += BC_MINUS_AND_CHECK_NOT_CHAR_LENGTH; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 456 | } |
| 457 | break; |
| 458 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 459 | BYTECODE(CHECK_CHAR_IN_RANGE) { |
| 460 | uint32_t from = Load16Aligned(pc + 4); |
| 461 | uint32_t to = Load16Aligned(pc + 6); |
| 462 | if (from <= current_char && current_char <= to) { |
| 463 | pc = code_base + Load32Aligned(pc + 8); |
| 464 | } else { |
| 465 | pc += BC_CHECK_CHAR_IN_RANGE_LENGTH; |
| 466 | } |
| 467 | break; |
| 468 | } |
| 469 | BYTECODE(CHECK_CHAR_NOT_IN_RANGE) { |
| 470 | uint32_t from = Load16Aligned(pc + 4); |
| 471 | uint32_t to = Load16Aligned(pc + 6); |
| 472 | if (from > current_char || current_char > to) { |
| 473 | pc = code_base + Load32Aligned(pc + 8); |
| 474 | } else { |
| 475 | pc += BC_CHECK_CHAR_NOT_IN_RANGE_LENGTH; |
| 476 | } |
| 477 | break; |
| 478 | } |
| 479 | BYTECODE(CHECK_BIT_IN_TABLE) { |
| 480 | int mask = RegExpMacroAssembler::kTableMask; |
| 481 | byte b = pc[8 + ((current_char & mask) >> kBitsPerByteLog2)]; |
| 482 | int bit = (current_char & (kBitsPerByte - 1)); |
| 483 | if ((b & (1 << bit)) != 0) { |
| 484 | pc = code_base + Load32Aligned(pc + 4); |
| 485 | } else { |
| 486 | pc += BC_CHECK_BIT_IN_TABLE_LENGTH; |
| 487 | } |
| 488 | break; |
| 489 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 490 | BYTECODE(CHECK_LT) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 491 | uint32_t limit = (insn >> BYTECODE_SHIFT); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 492 | if (current_char < limit) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 493 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 494 | } else { |
| 495 | pc += BC_CHECK_LT_LENGTH; |
| 496 | } |
| 497 | break; |
| 498 | } |
| 499 | BYTECODE(CHECK_GT) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 500 | uint32_t limit = (insn >> BYTECODE_SHIFT); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 501 | if (current_char > limit) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 502 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 503 | } else { |
| 504 | pc += BC_CHECK_GT_LENGTH; |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | BYTECODE(CHECK_REGISTER_LT) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 509 | if (registers[insn >> BYTECODE_SHIFT] < Load32Aligned(pc + 4)) { |
| 510 | pc = code_base + Load32Aligned(pc + 8); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 511 | } else { |
| 512 | pc += BC_CHECK_REGISTER_LT_LENGTH; |
| 513 | } |
| 514 | break; |
| 515 | BYTECODE(CHECK_REGISTER_GE) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 516 | if (registers[insn >> BYTECODE_SHIFT] >= Load32Aligned(pc + 4)) { |
| 517 | pc = code_base + Load32Aligned(pc + 8); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 518 | } else { |
| 519 | pc += BC_CHECK_REGISTER_GE_LENGTH; |
| 520 | } |
| 521 | break; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 522 | BYTECODE(CHECK_REGISTER_EQ_POS) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 523 | if (registers[insn >> BYTECODE_SHIFT] == current) { |
| 524 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 525 | } else { |
| 526 | pc += BC_CHECK_REGISTER_EQ_POS_LENGTH; |
| 527 | } |
| 528 | break; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 529 | BYTECODE(CHECK_NOT_REGS_EQUAL) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 530 | if (registers[insn >> BYTECODE_SHIFT] == |
| 531 | registers[Load32Aligned(pc + 4)]) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 532 | pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; |
| 533 | } else { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 534 | pc = code_base + Load32Aligned(pc + 8); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 535 | } |
| 536 | break; |
| 537 | BYTECODE(CHECK_NOT_BACK_REF) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 538 | int from = registers[insn >> BYTECODE_SHIFT]; |
| 539 | int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 540 | if (from < 0 || len <= 0) { |
| 541 | pc += BC_CHECK_NOT_BACK_REF_LENGTH; |
| 542 | break; |
| 543 | } |
| 544 | if (current + len > subject.length()) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 545 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 546 | break; |
| 547 | } else { |
| 548 | int i; |
| 549 | for (i = 0; i < len; i++) { |
| 550 | if (subject[from + i] != subject[current + i]) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 551 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 552 | break; |
| 553 | } |
| 554 | } |
| 555 | if (i < len) break; |
| 556 | current += len; |
| 557 | } |
| 558 | pc += BC_CHECK_NOT_BACK_REF_LENGTH; |
| 559 | break; |
| 560 | } |
| 561 | BYTECODE(CHECK_NOT_BACK_REF_NO_CASE) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 562 | int from = registers[insn >> BYTECODE_SHIFT]; |
| 563 | int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 564 | if (from < 0 || len <= 0) { |
| 565 | pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
| 566 | break; |
| 567 | } |
| 568 | if (current + len > subject.length()) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 569 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 570 | break; |
| 571 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 572 | if (BackRefMatchesNoCase(isolate->interp_canonicalize_mapping(), |
| 573 | from, current, len, subject)) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 574 | current += len; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 575 | pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
| 576 | } else { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 577 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | break; |
| 581 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 582 | BYTECODE(CHECK_AT_START) |
| 583 | if (current == 0) { |
| 584 | pc = code_base + Load32Aligned(pc + 4); |
| 585 | } else { |
| 586 | pc += BC_CHECK_AT_START_LENGTH; |
| 587 | } |
| 588 | break; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 589 | BYTECODE(CHECK_NOT_AT_START) |
| 590 | if (current == 0) { |
| 591 | pc += BC_CHECK_NOT_AT_START_LENGTH; |
| 592 | } else { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 593 | pc = code_base + Load32Aligned(pc + 4); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 594 | } |
| 595 | break; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 596 | BYTECODE(SET_CURRENT_POSITION_FROM_END) { |
| 597 | int by = static_cast<uint32_t>(insn) >> BYTECODE_SHIFT; |
| 598 | if (subject.length() - current > by) { |
| 599 | current = subject.length() - by; |
| 600 | current_char = subject[current - 1]; |
| 601 | } |
| 602 | pc += BC_SET_CURRENT_POSITION_FROM_END_LENGTH; |
| 603 | break; |
| 604 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 605 | default: |
| 606 | UNREACHABLE(); |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 613 | RegExpImpl::IrregexpResult IrregexpInterpreter::Match( |
| 614 | Isolate* isolate, |
| 615 | Handle<ByteArray> code_array, |
| 616 | Handle<String> subject, |
| 617 | int* registers, |
| 618 | int start_position) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 619 | ASSERT(subject->IsFlat()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 620 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 621 | DisallowHeapAllocation no_gc; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 622 | const byte* code_base = code_array->GetDataStartAddress(); |
| 623 | uc16 previous_char = '\n'; |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 624 | String::FlatContent subject_content = subject->GetFlatContent(); |
| 625 | if (subject_content.IsAscii()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 626 | Vector<const uint8_t> subject_vector = subject_content.ToOneByteVector(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 627 | if (start_position != 0) previous_char = subject_vector[start_position - 1]; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 628 | return RawMatch(isolate, |
| 629 | code_base, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 630 | subject_vector, |
| 631 | registers, |
| 632 | start_position, |
| 633 | previous_char); |
| 634 | } else { |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 635 | ASSERT(subject_content.IsTwoByte()); |
| 636 | Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 637 | if (start_position != 0) previous_char = subject_vector[start_position - 1]; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 638 | return RawMatch(isolate, |
| 639 | code_base, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 640 | subject_vector, |
| 641 | registers, |
| 642 | start_position, |
| 643 | previous_char); |
| 644 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | } } // namespace v8::internal |