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

Side by Side Diff: src/interpreter-irregexp.cc

Issue 9854020: RegExp: Add support for table-based character class (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 8 months 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // A simple interpreter for the Irregexp byte code. 28 // A simple interpreter for the Irregexp byte code.
29 29
30 30
31 #include "v8.h" 31 #include "v8.h"
32 #include "unicode.h" 32 #include "unicode.h"
33 #include "utils.h" 33 #include "utils.h"
34 #include "ast.h" 34 #include "ast.h"
35 #include "bytecodes-irregexp.h" 35 #include "bytecodes-irregexp.h"
36 #include "interpreter-irregexp.h"
36 #include "jsregexp.h" 37 #include "jsregexp.h"
37 #include "interpreter-irregexp.h" 38 #include "regexp-macro-assembler.h"
38 39
39 namespace v8 { 40 namespace v8 {
40 namespace internal { 41 namespace internal {
41 42
42 43
43 typedef unibrow::Mapping<unibrow::Ecma262Canonicalize> Canonicalize; 44 typedef unibrow::Mapping<unibrow::Ecma262Canonicalize> Canonicalize;
44 45
45 static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize, 46 static bool BackRefMatchesNoCase(Canonicalize* interp_canonicalize,
46 int from, 47 int from,
47 int current, 48 int current,
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 uint32_t c = (insn >> BYTECODE_SHIFT); 443 uint32_t c = (insn >> BYTECODE_SHIFT);
443 uint32_t minus = Load16Aligned(pc + 4); 444 uint32_t minus = Load16Aligned(pc + 4);
444 uint32_t mask = Load16Aligned(pc + 6); 445 uint32_t mask = Load16Aligned(pc + 6);
445 if (c != ((current_char - minus) & mask)) { 446 if (c != ((current_char - minus) & mask)) {
446 pc = code_base + Load32Aligned(pc + 8); 447 pc = code_base + Load32Aligned(pc + 8);
447 } else { 448 } else {
448 pc += BC_MINUS_AND_CHECK_NOT_CHAR_LENGTH; 449 pc += BC_MINUS_AND_CHECK_NOT_CHAR_LENGTH;
449 } 450 }
450 break; 451 break;
451 } 452 }
453 BYTECODE(CHECK_CHAR_IN_RANGE) {
454 uint32_t from = Load16Aligned(pc + 4);
455 uint32_t to = Load16Aligned(pc + 6);
456 if (from <= current_char && current_char <= to) {
457 pc = code_base + Load32Aligned(pc + 8);
458 } else {
459 pc += BC_CHECK_CHAR_IN_RANGE_LENGTH;
460 }
461 break;
462 }
463 BYTECODE(CHECK_CHAR_NOT_IN_RANGE) {
464 uint32_t from = Load16Aligned(pc + 4);
465 uint32_t to = Load16Aligned(pc + 6);
466 if (from > current_char || current_char > to) {
467 pc = code_base + Load32Aligned(pc + 8);
468 } else {
469 pc += BC_CHECK_CHAR_NOT_IN_RANGE_LENGTH;
470 }
471 break;
472 }
473 BYTECODE(CHECK_BIT_IN_TABLE) {
474 int mask = RegExpMacroAssembler::kTableMask;
475 byte b = pc[8 + ((current_char & mask) >> kBitsPerByteLog2)];
476 int bit = (current_char & (kBitsPerByte - 1));
477 if ((b & (1 << bit)) != 0) {
478 pc = code_base + Load32Aligned(pc + 4);
479 } else {
480 pc += BC_CHECK_BIT_IN_TABLE_LENGTH;
481 }
482 break;
483 }
452 BYTECODE(CHECK_LT) { 484 BYTECODE(CHECK_LT) {
453 uint32_t limit = (insn >> BYTECODE_SHIFT); 485 uint32_t limit = (insn >> BYTECODE_SHIFT);
454 if (current_char < limit) { 486 if (current_char < limit) {
455 pc = code_base + Load32Aligned(pc + 4); 487 pc = code_base + Load32Aligned(pc + 4);
456 } else { 488 } else {
457 pc += BC_CHECK_LT_LENGTH; 489 pc += BC_CHECK_LT_LENGTH;
458 } 490 }
459 break; 491 break;
460 } 492 }
461 BYTECODE(CHECK_GT) { 493 BYTECODE(CHECK_GT) {
(...skipping 19 matching lines...) Expand all
481 pc += BC_CHECK_REGISTER_GE_LENGTH; 513 pc += BC_CHECK_REGISTER_GE_LENGTH;
482 } 514 }
483 break; 515 break;
484 BYTECODE(CHECK_REGISTER_EQ_POS) 516 BYTECODE(CHECK_REGISTER_EQ_POS)
485 if (registers[insn >> BYTECODE_SHIFT] == current) { 517 if (registers[insn >> BYTECODE_SHIFT] == current) {
486 pc = code_base + Load32Aligned(pc + 4); 518 pc = code_base + Load32Aligned(pc + 4);
487 } else { 519 } else {
488 pc += BC_CHECK_REGISTER_EQ_POS_LENGTH; 520 pc += BC_CHECK_REGISTER_EQ_POS_LENGTH;
489 } 521 }
490 break; 522 break;
491 BYTECODE(LOOKUP_MAP1) {
492 // Look up character in a bitmap. If we find a 0, then jump to the
493 // location at pc + 8. Otherwise fall through!
494 int index = current_char - (insn >> BYTECODE_SHIFT);
495 byte map = code_base[Load32Aligned(pc + 4) + (index >> 3)];
496 map = ((map >> (index & 7)) & 1);
497 if (map == 0) {
498 pc = code_base + Load32Aligned(pc + 8);
499 } else {
500 pc += BC_LOOKUP_MAP1_LENGTH;
501 }
502 break;
503 }
504 BYTECODE(LOOKUP_MAP2) {
505 // Look up character in a half-nibble map. If we find 00, then jump to
506 // the location at pc + 8. If we find 01 then jump to location at
507 // pc + 11, etc.
508 int index = (current_char - (insn >> BYTECODE_SHIFT)) << 1;
509 byte map = code_base[Load32Aligned(pc + 3) + (index >> 3)];
510 map = ((map >> (index & 7)) & 3);
511 if (map < 2) {
512 if (map == 0) {
513 pc = code_base + Load32Aligned(pc + 8);
514 } else {
515 pc = code_base + Load32Aligned(pc + 12);
516 }
517 } else {
518 if (map == 2) {
519 pc = code_base + Load32Aligned(pc + 16);
520 } else {
521 pc = code_base + Load32Aligned(pc + 20);
522 }
523 }
524 break;
525 }
526 BYTECODE(LOOKUP_MAP8) {
527 // Look up character in a byte map. Use the byte as an index into a
528 // table that follows this instruction immediately.
529 int index = current_char - (insn >> BYTECODE_SHIFT);
530 byte map = code_base[Load32Aligned(pc + 4) + index];
531 const byte* new_pc = code_base + Load32Aligned(pc + 8) + (map << 2);
532 pc = code_base + Load32Aligned(new_pc);
533 break;
534 }
535 BYTECODE(LOOKUP_HI_MAP8) {
536 // Look up high byte of this character in a byte map. Use the byte as
537 // an index into a table that follows this instruction immediately.
538 int index = (current_char >> 8) - (insn >> BYTECODE_SHIFT);
539 byte map = code_base[Load32Aligned(pc + 4) + index];
540 const byte* new_pc = code_base + Load32Aligned(pc + 8) + (map << 2);
541 pc = code_base + Load32Aligned(new_pc);
542 break;
543 }
544 BYTECODE(CHECK_NOT_REGS_EQUAL) 523 BYTECODE(CHECK_NOT_REGS_EQUAL)
545 if (registers[insn >> BYTECODE_SHIFT] == 524 if (registers[insn >> BYTECODE_SHIFT] ==
546 registers[Load32Aligned(pc + 4)]) { 525 registers[Load32Aligned(pc + 4)]) {
547 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH; 526 pc += BC_CHECK_NOT_REGS_EQUAL_LENGTH;
548 } else { 527 } else {
549 pc = code_base + Load32Aligned(pc + 8); 528 pc = code_base + Load32Aligned(pc + 8);
550 } 529 }
551 break; 530 break;
552 BYTECODE(CHECK_NOT_BACK_REF) { 531 BYTECODE(CHECK_NOT_BACK_REF) {
553 int from = registers[insn >> BYTECODE_SHIFT]; 532 int from = registers[insn >> BYTECODE_SHIFT];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return RawMatch(isolate, 632 return RawMatch(isolate,
654 code_base, 633 code_base,
655 subject_vector, 634 subject_vector,
656 registers, 635 registers,
657 start_position, 636 start_position,
658 previous_char); 637 previous_char);
659 } 638 }
660 } 639 }
661 640
662 } } // namespace v8::internal 641 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/regexp-macro-assembler-ia32.cc ('k') | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698