| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 // A simple interpreter for the Irregexp byte code. | 5 // A simple interpreter for the Irregexp byte code. |
| 6 | 6 |
| 7 #include "src/regexp/interpreter-irregexp.h" | 7 #include "src/regexp/interpreter-irregexp.h" |
| 8 | 8 |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/regexp/bytecodes-irregexp.h" | 10 #include "src/regexp/bytecodes-irregexp.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (current == backtrack_sp[-1]) { | 263 if (current == backtrack_sp[-1]) { |
| 264 backtrack_sp--; | 264 backtrack_sp--; |
| 265 backtrack_stack_space++; | 265 backtrack_stack_space++; |
| 266 pc = code_base + Load32Aligned(pc + 4); | 266 pc = code_base + Load32Aligned(pc + 4); |
| 267 } else { | 267 } else { |
| 268 pc += BC_CHECK_GREEDY_LENGTH; | 268 pc += BC_CHECK_GREEDY_LENGTH; |
| 269 } | 269 } |
| 270 break; | 270 break; |
| 271 BYTECODE(LOAD_CURRENT_CHAR) { | 271 BYTECODE(LOAD_CURRENT_CHAR) { |
| 272 int pos = current + (insn >> BYTECODE_SHIFT); | 272 int pos = current + (insn >> BYTECODE_SHIFT); |
| 273 if (pos >= subject.length() || pos < 0) { | 273 if (pos >= subject.length()) { |
| 274 pc = code_base + Load32Aligned(pc + 4); | 274 pc = code_base + Load32Aligned(pc + 4); |
| 275 } else { | 275 } else { |
| 276 current_char = subject[pos]; | 276 current_char = subject[pos]; |
| 277 pc += BC_LOAD_CURRENT_CHAR_LENGTH; | 277 pc += BC_LOAD_CURRENT_CHAR_LENGTH; |
| 278 } | 278 } |
| 279 break; | 279 break; |
| 280 } | 280 } |
| 281 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { | 281 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { |
| 282 int pos = current + (insn >> BYTECODE_SHIFT); | 282 int pos = current + (insn >> BYTECODE_SHIFT); |
| 283 current_char = subject[pos]; | 283 current_char = subject[pos]; |
| 284 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; | 284 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; |
| 285 break; | 285 break; |
| 286 } | 286 } |
| 287 BYTECODE(LOAD_2_CURRENT_CHARS) { | 287 BYTECODE(LOAD_2_CURRENT_CHARS) { |
| 288 int pos = current + (insn >> BYTECODE_SHIFT); | 288 int pos = current + (insn >> BYTECODE_SHIFT); |
| 289 if (pos + 2 > subject.length() || pos < 0) { | 289 if (pos + 2 > subject.length()) { |
| 290 pc = code_base + Load32Aligned(pc + 4); | 290 pc = code_base + Load32Aligned(pc + 4); |
| 291 } else { | 291 } else { |
| 292 Char next = subject[pos + 1]; | 292 Char next = subject[pos + 1]; |
| 293 current_char = | 293 current_char = |
| 294 (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); | 294 (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); |
| 295 pc += BC_LOAD_2_CURRENT_CHARS_LENGTH; | 295 pc += BC_LOAD_2_CURRENT_CHARS_LENGTH; |
| 296 } | 296 } |
| 297 break; | 297 break; |
| 298 } | 298 } |
| 299 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) { | 299 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) { |
| 300 int pos = current + (insn >> BYTECODE_SHIFT); | 300 int pos = current + (insn >> BYTECODE_SHIFT); |
| 301 Char next = subject[pos + 1]; | 301 Char next = subject[pos + 1]; |
| 302 current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); | 302 current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char)))); |
| 303 pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH; | 303 pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH; |
| 304 break; | 304 break; |
| 305 } | 305 } |
| 306 BYTECODE(LOAD_4_CURRENT_CHARS) { | 306 BYTECODE(LOAD_4_CURRENT_CHARS) { |
| 307 DCHECK(sizeof(Char) == 1); | 307 DCHECK(sizeof(Char) == 1); |
| 308 int pos = current + (insn >> BYTECODE_SHIFT); | 308 int pos = current + (insn >> BYTECODE_SHIFT); |
| 309 if (pos + 4 > subject.length() || pos < 0) { | 309 if (pos + 4 > subject.length()) { |
| 310 pc = code_base + Load32Aligned(pc + 4); | 310 pc = code_base + Load32Aligned(pc + 4); |
| 311 } else { | 311 } else { |
| 312 Char next1 = subject[pos + 1]; | 312 Char next1 = subject[pos + 1]; |
| 313 Char next2 = subject[pos + 2]; | 313 Char next2 = subject[pos + 2]; |
| 314 Char next3 = subject[pos + 3]; | 314 Char next3 = subject[pos + 3]; |
| 315 current_char = (subject[pos] | | 315 current_char = (subject[pos] | |
| 316 (next1 << 8) | | 316 (next1 << 8) | |
| 317 (next2 << 16) | | 317 (next2 << 16) | |
| 318 (next3 << 24)); | 318 (next3 << 24)); |
| 319 pc += BC_LOAD_4_CURRENT_CHARS_LENGTH; | 319 pc += BC_LOAD_4_CURRENT_CHARS_LENGTH; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 if (registers[insn >> BYTECODE_SHIFT] == | 490 if (registers[insn >> BYTECODE_SHIFT] == |
| 491 registers[Load32Aligned(pc + 4)]) { | 491 registers[Load32Aligned(pc + 4)]) { |
| 492 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; | 492 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; |
| 493 } else { | 493 } else { |
| 494 pc = code_base + Load32Aligned(pc + 8); | 494 pc = code_base + Load32Aligned(pc + 8); |
| 495 } | 495 } |
| 496 break; | 496 break; |
| 497 BYTECODE(CHECK_NOT_BACK_REF) { | 497 BYTECODE(CHECK_NOT_BACK_REF) { |
| 498 int from = registers[insn >> BYTECODE_SHIFT]; | 498 int from = registers[insn >> BYTECODE_SHIFT]; |
| 499 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | 499 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
| 500 if (from >= 0 && len > 0) { | 500 if (from < 0 || len <= 0) { |
| 501 if (current + len > subject.length() || | 501 pc += BC_CHECK_NOT_BACK_REF_LENGTH; |
| 502 CompareChars(&subject[from], &subject[current], len) != 0) { | 502 break; |
| 503 pc = code_base + Load32Aligned(pc + 4); | 503 } |
| 504 break; | 504 if (current + len > subject.length()) { |
| 505 pc = code_base + Load32Aligned(pc + 4); |
| 506 break; |
| 507 } else { |
| 508 int i; |
| 509 for (i = 0; i < len; i++) { |
| 510 if (subject[from + i] != subject[current + i]) { |
| 511 pc = code_base + Load32Aligned(pc + 4); |
| 512 break; |
| 513 } |
| 505 } | 514 } |
| 515 if (i < len) break; |
| 506 current += len; | 516 current += len; |
| 507 } | 517 } |
| 508 pc += BC_CHECK_NOT_BACK_REF_LENGTH; | 518 pc += BC_CHECK_NOT_BACK_REF_LENGTH; |
| 509 break; | 519 break; |
| 510 } | 520 } |
| 511 BYTECODE(CHECK_NOT_BACK_REF_BACKWARD) { | |
| 512 int from = registers[insn >> BYTECODE_SHIFT]; | |
| 513 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | |
| 514 if (from >= 0 && len > 0) { | |
| 515 if (current - len < 0 || | |
| 516 CompareChars(&subject[from], &subject[current - len], len) != 0) { | |
| 517 pc = code_base + Load32Aligned(pc + 4); | |
| 518 break; | |
| 519 } | |
| 520 current -= len; | |
| 521 } | |
| 522 pc += BC_CHECK_NOT_BACK_REF_BACKWARD_LENGTH; | |
| 523 break; | |
| 524 } | |
| 525 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE) { | 521 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE) { |
| 526 int from = registers[insn >> BYTECODE_SHIFT]; | 522 int from = registers[insn >> BYTECODE_SHIFT]; |
| 527 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | 523 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; |
| 528 if (from >= 0 && len > 0) { | 524 if (from < 0 || len <= 0) { |
| 529 if (current + len > subject.length() || | 525 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
| 530 !BackRefMatchesNoCase(isolate->interp_canonicalize_mapping(), | 526 break; |
| 531 from, current, len, subject)) { | 527 } |
| 528 if (current + len > subject.length()) { |
| 529 pc = code_base + Load32Aligned(pc + 4); |
| 530 break; |
| 531 } else { |
| 532 if (BackRefMatchesNoCase(isolate->interp_canonicalize_mapping(), |
| 533 from, current, len, subject)) { |
| 534 current += len; |
| 535 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; |
| 536 } else { |
| 532 pc = code_base + Load32Aligned(pc + 4); | 537 pc = code_base + Load32Aligned(pc + 4); |
| 533 break; | |
| 534 } | 538 } |
| 535 current += len; | |
| 536 } | 539 } |
| 537 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_LENGTH; | |
| 538 break; | |
| 539 } | |
| 540 BYTECODE(CHECK_NOT_BACK_REF_NO_CASE_BACKWARD) { | |
| 541 int from = registers[insn >> BYTECODE_SHIFT]; | |
| 542 int len = registers[(insn >> BYTECODE_SHIFT) + 1] - from; | |
| 543 if (from >= 0 && len > 0) { | |
| 544 if (current - len < 0 || | |
| 545 !BackRefMatchesNoCase(isolate->interp_canonicalize_mapping(), | |
| 546 from, current - len, len, subject)) { | |
| 547 pc = code_base + Load32Aligned(pc + 4); | |
| 548 break; | |
| 549 } | |
| 550 current -= len; | |
| 551 } | |
| 552 pc += BC_CHECK_NOT_BACK_REF_NO_CASE_BACKWARD_LENGTH; | |
| 553 break; | 540 break; |
| 554 } | 541 } |
| 555 BYTECODE(CHECK_AT_START) | 542 BYTECODE(CHECK_AT_START) |
| 556 if (current == 0) { | 543 if (current == 0) { |
| 557 pc = code_base + Load32Aligned(pc + 4); | 544 pc = code_base + Load32Aligned(pc + 4); |
| 558 } else { | 545 } else { |
| 559 pc += BC_CHECK_AT_START_LENGTH; | 546 pc += BC_CHECK_AT_START_LENGTH; |
| 560 } | 547 } |
| 561 break; | 548 break; |
| 562 BYTECODE(CHECK_NOT_AT_START) | 549 BYTECODE(CHECK_NOT_AT_START) |
| 563 if (current + (insn >> BYTECODE_SHIFT) == 0) { | 550 if (current == 0) { |
| 564 pc += BC_CHECK_NOT_AT_START_LENGTH; | 551 pc += BC_CHECK_NOT_AT_START_LENGTH; |
| 565 } else { | 552 } else { |
| 566 pc = code_base + Load32Aligned(pc + 4); | 553 pc = code_base + Load32Aligned(pc + 4); |
| 567 } | 554 } |
| 568 break; | 555 break; |
| 569 BYTECODE(SET_CURRENT_POSITION_FROM_END) { | 556 BYTECODE(SET_CURRENT_POSITION_FROM_END) { |
| 570 int by = static_cast<uint32_t>(insn) >> BYTECODE_SHIFT; | 557 int by = static_cast<uint32_t>(insn) >> BYTECODE_SHIFT; |
| 571 if (subject.length() - current > by) { | 558 if (subject.length() - current > by) { |
| 572 current = subject.length() - by; | 559 current = subject.length() - by; |
| 573 current_char = subject[current - 1]; | 560 current_char = subject[current - 1]; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 code_base, | 599 code_base, |
| 613 subject_vector, | 600 subject_vector, |
| 614 registers, | 601 registers, |
| 615 start_position, | 602 start_position, |
| 616 previous_char); | 603 previous_char); |
| 617 } | 604 } |
| 618 } | 605 } |
| 619 | 606 |
| 620 } // namespace internal | 607 } // namespace internal |
| 621 } // namespace v8 | 608 } // namespace v8 |
| OLD | NEW |