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

Side by Side Diff: test/cctest/test-regexp.cc

Issue 12900: Irregexp:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years 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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 355 }
356 356
357 357
358 static RegExpNode* Compile(const char* input, bool multiline) { 358 static RegExpNode* Compile(const char* input, bool multiline) {
359 V8::Initialize(NULL); 359 V8::Initialize(NULL);
360 FlatStringReader reader(CStrVector(input)); 360 FlatStringReader reader(CStrVector(input));
361 RegExpParseResult result; 361 RegExpParseResult result;
362 if (!v8::internal::ParseRegExp(&reader, multiline, &result)) 362 if (!v8::internal::ParseRegExp(&reader, multiline, &result))
363 return NULL; 363 return NULL;
364 RegExpNode* node = NULL; 364 RegExpNode* node = NULL;
365 RegExpEngine::Compile(&result, &node, false, multiline); 365 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input));
366 RegExpEngine::Compile(&result, &node, false, multiline, pattern);
366 return node; 367 return node;
367 } 368 }
368 369
369 370
370 static void Execute(const char* input, 371 static void Execute(const char* input,
371 bool multiline, 372 bool multiline,
372 bool dot_output = false) { 373 bool dot_output = false) {
373 v8::HandleScope scope; 374 v8::HandleScope scope;
374 ZoneScope zone_scope(DELETE_ON_EXIT); 375 ZoneScope zone_scope(DELETE_ON_EXIT);
375 RegExpNode* node = Compile(input, multiline); 376 RegExpNode* node = Compile(input, multiline);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 foo_chars[1] = 'o'; 514 foo_chars[1] = 'o';
514 foo_chars[2] = 'o'; 515 foo_chars[2] = 'o';
515 Vector<const uc16> foo(foo_chars, 3); 516 Vector<const uc16> foo(foo_chars, 3);
516 m.SetRegister(4, 42); 517 m.SetRegister(4, 42);
517 m.PushRegister(4); 518 m.PushRegister(4);
518 m.AdvanceRegister(4, 42); 519 m.AdvanceRegister(4, 42);
519 m.GoTo(&start); 520 m.GoTo(&start);
520 m.Fail(); 521 m.Fail();
521 m.Bind(&start); 522 m.Bind(&start);
522 m.PushBacktrack(&fail2); 523 m.PushBacktrack(&fail2);
523 m.CheckCharacters(foo, 0, &fail); 524 m.CheckCharacters(foo, 0, &fail, true);
524 m.WriteCurrentPositionToRegister(0); 525 m.WriteCurrentPositionToRegister(0, 0);
525 m.PushCurrentPosition(); 526 m.PushCurrentPosition();
526 m.AdvanceCurrentPosition(3); 527 m.AdvanceCurrentPosition(3);
527 m.WriteCurrentPositionToRegister(1); 528 m.WriteCurrentPositionToRegister(1, 0);
528 m.PopCurrentPosition(); 529 m.PopCurrentPosition();
529 m.AdvanceCurrentPosition(1); 530 m.AdvanceCurrentPosition(1);
530 m.WriteCurrentPositionToRegister(2); 531 m.WriteCurrentPositionToRegister(2, 0);
531 m.AdvanceCurrentPosition(1); 532 m.AdvanceCurrentPosition(1);
532 m.WriteCurrentPositionToRegister(3); 533 m.WriteCurrentPositionToRegister(3, 0);
533 m.Succeed(); 534 m.Succeed();
534 535
535 m.Bind(&fail); 536 m.Bind(&fail);
536 m.Backtrack(); 537 m.Backtrack();
537 m.Succeed(); 538 m.Succeed();
538 539
539 m.Bind(&fail2); 540 m.Bind(&fail2);
540 m.PopRegister(0); 541 m.PopRegister(0);
541 m.Fail(); 542 m.Fail();
542 543
543 v8::HandleScope scope; 544 v8::HandleScope scope;
544 545
545 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode()); 546 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^f(o)o"));
547 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode(source));
546 int captures[5]; 548 int captures[5];
547 549
548 Handle<String> f1 = 550 Handle<String> f1 =
549 Factory::NewStringFromAscii(CStrVector("foobar")); 551 Factory::NewStringFromAscii(CStrVector("foobar"));
550 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); 552 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1);
551 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0)); 553 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0));
552 CHECK_EQ(0, captures[0]); 554 CHECK_EQ(0, captures[0]);
553 CHECK_EQ(3, captures[1]); 555 CHECK_EQ(3, captures[1]);
554 CHECK_EQ(1, captures[2]); 556 CHECK_EQ(1, captures[2]);
555 CHECK_EQ(2, captures[3]); 557 CHECK_EQ(2, captures[3]);
(...skipping 13 matching lines...) Expand all
569 V8::Initialize(NULL); 571 V8::Initialize(NULL);
570 572
571 // regexp-macro-assembler-ia32 needs a handle scope to allocate 573 // regexp-macro-assembler-ia32 needs a handle scope to allocate
572 // byte-arrays for constants. 574 // byte-arrays for constants.
573 v8::HandleScope scope; 575 v8::HandleScope scope;
574 576
575 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 577 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
576 578
577 m.Succeed(); 579 m.Succeed();
578 580
579 Handle<Object> code_object = m.GetCode(); 581 Handle<String> source = Factory::NewStringFromAscii(CStrVector(""));
582 Handle<Object> code_object = m.GetCode(source);
580 Handle<Code> code = Handle<Code>::cast(code_object); 583 Handle<Code> code = Handle<Code>::cast(code_object);
581 584
582 int captures[4] = {42, 37, 87, 117}; 585 int captures[4] = {42, 37, 87, 117};
583 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 586 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
584 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 587 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
585 Address start_adr = seq_input->GetCharsAddress(); 588 Address start_adr = seq_input->GetCharsAddress();
586 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 589 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
587 int end_offset = start_offset + seq_input->length(); 590 int end_offset = start_offset + seq_input->length();
588 591
589 bool success = RegExpMacroAssemblerIA32::Execute(*code, 592 bool success = RegExpMacroAssemblerIA32::Execute(*code,
(...skipping 17 matching lines...) Expand all
607 // regexp-macro-assembler-ia32 needs a handle scope to allocate 610 // regexp-macro-assembler-ia32 needs a handle scope to allocate
608 // byte-arrays for constants. 611 // byte-arrays for constants.
609 v8::HandleScope scope; 612 v8::HandleScope scope;
610 613
611 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 614 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
612 615
613 uc16 foo_chars[3] = {'f', 'o', 'o'}; 616 uc16 foo_chars[3] = {'f', 'o', 'o'};
614 Vector<const uc16> foo(foo_chars, 3); 617 Vector<const uc16> foo(foo_chars, 3);
615 618
616 Label fail; 619 Label fail;
617 m.CheckCharacters(foo, 0, &fail); 620 m.CheckCharacters(foo, 0, &fail, true);
618 m.WriteCurrentPositionToRegister(0); 621 m.WriteCurrentPositionToRegister(0, 0);
619 m.AdvanceCurrentPosition(3); 622 m.AdvanceCurrentPosition(3);
620 m.WriteCurrentPositionToRegister(1); 623 m.WriteCurrentPositionToRegister(1, 0);
621 m.Succeed(); 624 m.Succeed();
622 m.Bind(&fail); 625 m.Bind(&fail);
623 m.Fail(); 626 m.Fail();
624 627
625 Handle<Object> code_object = m.GetCode(); 628 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
629 Handle<Object> code_object = m.GetCode(source);
626 Handle<Code> code = Handle<Code>::cast(code_object); 630 Handle<Code> code = Handle<Code>::cast(code_object);
627 631
628 int captures[4] = {42, 37, 87, 117}; 632 int captures[4] = {42, 37, 87, 117};
629 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 633 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
630 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 634 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
631 Address start_adr = seq_input->GetCharsAddress(); 635 Address start_adr = seq_input->GetCharsAddress();
632 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 636 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
633 int end_offset = start_offset + seq_input->length(); 637 int end_offset = start_offset + seq_input->length();
634 638
635 bool success = RegExpMacroAssemblerIA32::Execute(*code, 639 bool success = RegExpMacroAssemblerIA32::Execute(*code,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // regexp-macro-assembler-ia32 needs a handle scope to allocate 672 // regexp-macro-assembler-ia32 needs a handle scope to allocate
669 // byte-arrays for constants. 673 // byte-arrays for constants.
670 v8::HandleScope scope; 674 v8::HandleScope scope;
671 675
672 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4); 676 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4);
673 677
674 uc16 foo_chars[3] = {'f', 'o', 'o'}; 678 uc16 foo_chars[3] = {'f', 'o', 'o'};
675 Vector<const uc16> foo(foo_chars, 3); 679 Vector<const uc16> foo(foo_chars, 3);
676 680
677 Label fail; 681 Label fail;
678 m.CheckCharacters(foo, 0, &fail); 682 m.CheckCharacters(foo, 0, &fail, true);
679 m.WriteCurrentPositionToRegister(0); 683 m.WriteCurrentPositionToRegister(0, 0);
680 m.AdvanceCurrentPosition(3); 684 m.AdvanceCurrentPosition(3);
681 m.WriteCurrentPositionToRegister(1); 685 m.WriteCurrentPositionToRegister(1, 0);
682 m.Succeed(); 686 m.Succeed();
683 m.Bind(&fail); 687 m.Bind(&fail);
684 m.Fail(); 688 m.Fail();
685 689
686 Handle<Object> code_object = m.GetCode(); 690 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
691 Handle<Object> code_object = m.GetCode(source);
687 Handle<Code> code = Handle<Code>::cast(code_object); 692 Handle<Code> code = Handle<Code>::cast(code_object);
688 693
689 int captures[4] = {42, 37, 87, 117}; 694 int captures[4] = {42, 37, 87, 117};
690 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; 695 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'};
691 Handle<String> input = 696 Handle<String> input =
692 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); 697 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
693 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); 698 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
694 Address start_adr = seq_input->GetCharsAddress(); 699 Address start_adr = seq_input->GetCharsAddress();
695 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 700 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
696 int end_offset = start_offset + seq_input->length() * sizeof(uc16); 701 int end_offset = start_offset + seq_input->length() * sizeof(uc16);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 733
729 TEST(MacroAssemblerIA32Backtrack) { 734 TEST(MacroAssemblerIA32Backtrack) {
730 V8::Initialize(NULL); 735 V8::Initialize(NULL);
731 736
732 // regexp-macro-assembler-ia32 needs a handle scope to allocate 737 // regexp-macro-assembler-ia32 needs a handle scope to allocate
733 // byte-arrays for constants. 738 // byte-arrays for constants.
734 v8::HandleScope scope; 739 v8::HandleScope scope;
735 740
736 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 741 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
737 742
738 uc16 foo_chars[3] = {'f', 'o', 'o'};
739 Vector<const uc16> foo(foo_chars, 3);
740
741 Label fail; 743 Label fail;
742 Label backtrack; 744 Label backtrack;
743 m.LoadCurrentCharacter(10, &fail); 745 m.LoadCurrentCharacter(10, &fail);
744 m.Succeed(); 746 m.Succeed();
745 m.Bind(&fail); 747 m.Bind(&fail);
746 m.PushBacktrack(&backtrack); 748 m.PushBacktrack(&backtrack);
747 m.LoadCurrentCharacter(10, NULL); 749 m.LoadCurrentCharacter(10, NULL);
748 m.Succeed(); 750 m.Succeed();
749 m.Bind(&backtrack); 751 m.Bind(&backtrack);
750 m.Fail(); 752 m.Fail();
751 753
752 Handle<Object> code_object = m.GetCode(); 754 Handle<String> source = Factory::NewStringFromAscii(CStrVector(".........."));
755 Handle<Object> code_object = m.GetCode(source);
753 Handle<Code> code = Handle<Code>::cast(code_object); 756 Handle<Code> code = Handle<Code>::cast(code_object);
754 757
755 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 758 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
756 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 759 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
757 Address start_adr = seq_input->GetCharsAddress(); 760 Address start_adr = seq_input->GetCharsAddress();
758 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 761 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
759 int end_offset = start_offset + seq_input->length(); 762 int end_offset = start_offset + seq_input->length();
760 763
761 bool success = RegExpMacroAssemblerIA32::Execute(*code, 764 bool success = RegExpMacroAssemblerIA32::Execute(*code,
762 seq_input.location(), 765 seq_input.location(),
763 start_offset, 766 start_offset,
764 end_offset, 767 end_offset,
765 NULL, 768 NULL,
766 true); 769 true);
767 770
768 CHECK(!success); 771 CHECK(!success);
769 } 772 }
770 773
771 774
772 TEST(MacroAssemblerIA32BackReference) { 775 TEST(MacroAssemblerIA32BackReference) {
773 V8::Initialize(NULL); 776 V8::Initialize(NULL);
774 777
775 // regexp-macro-assembler-ia32 needs a handle scope to allocate 778 // regexp-macro-assembler-ia32 needs a handle scope to allocate
776 // byte-arrays for constants. 779 // byte-arrays for constants.
777 v8::HandleScope scope; 780 v8::HandleScope scope;
778 781
779 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3); 782 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3);
780 783
781 m.WriteCurrentPositionToRegister(0); 784 m.WriteCurrentPositionToRegister(0, 0);
782 m.AdvanceCurrentPosition(2); 785 m.AdvanceCurrentPosition(2);
783 m.WriteCurrentPositionToRegister(1); 786 m.WriteCurrentPositionToRegister(1, 0);
784 Label nomatch; 787 Label nomatch;
785 m.CheckNotBackReference(0, &nomatch); 788 m.CheckNotBackReference(0, &nomatch);
786 m.Fail(); 789 m.Fail();
787 m.Bind(&nomatch); 790 m.Bind(&nomatch);
788 m.AdvanceCurrentPosition(2); 791 m.AdvanceCurrentPosition(2);
789 Label missing_match; 792 Label missing_match;
790 m.CheckNotBackReference(0, &missing_match); 793 m.CheckNotBackReference(0, &missing_match);
791 m.WriteCurrentPositionToRegister(2); 794 m.WriteCurrentPositionToRegister(2, 0);
792 m.Succeed(); 795 m.Succeed();
793 m.Bind(&missing_match); 796 m.Bind(&missing_match);
794 m.Fail(); 797 m.Fail();
795 798
796 Handle<Object> code_object = m.GetCode(); 799 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1"));
800 Handle<Object> code_object = m.GetCode(source);
797 Handle<Code> code = Handle<Code>::cast(code_object); 801 Handle<Code> code = Handle<Code>::cast(code_object);
798 802
799 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo")); 803 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo"));
800 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 804 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
801 Address start_adr = seq_input->GetCharsAddress(); 805 Address start_adr = seq_input->GetCharsAddress();
802 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 806 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
803 int end_offset = start_offset + seq_input->length(); 807 int end_offset = start_offset + seq_input->length();
804 808
805 int output[3]; 809 int output[3];
806 bool success = RegExpMacroAssemblerIA32::Execute(*code, 810 bool success = RegExpMacroAssemblerIA32::Execute(*code,
(...skipping 12 matching lines...) Expand all
819 823
820 TEST(MacroAssemblerIA32AtStart) { 824 TEST(MacroAssemblerIA32AtStart) {
821 V8::Initialize(NULL); 825 V8::Initialize(NULL);
822 826
823 // regexp-macro-assembler-ia32 needs a handle scope to allocate 827 // regexp-macro-assembler-ia32 needs a handle scope to allocate
824 // byte-arrays for constants. 828 // byte-arrays for constants.
825 v8::HandleScope scope; 829 v8::HandleScope scope;
826 830
827 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 831 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
828 832
829 uc16 foo_chars[3] = {'f', 'o', 'o'};
830 Vector<const uc16> foo(foo_chars, 3);
831
832 Label not_at_start, newline, fail; 833 Label not_at_start, newline, fail;
833 m.CheckNotAtStart(&not_at_start); 834 m.CheckNotAtStart(&not_at_start);
834 // Check that prevchar = '\n' and current = 'f'. 835 // Check that prevchar = '\n' and current = 'f'.
835 m.CheckCharacter('\n', &newline); 836 m.CheckCharacter('\n', &newline);
836 m.Bind(&fail); 837 m.Bind(&fail);
837 m.Fail(); 838 m.Fail();
838 m.Bind(&newline); 839 m.Bind(&newline);
839 m.LoadCurrentCharacter(0, &fail); 840 m.LoadCurrentCharacter(0, &fail);
840 m.CheckNotCharacter('f', &fail); 841 m.CheckNotCharacter('f', &fail);
841 m.Succeed(); 842 m.Succeed();
842 843
843 m.Bind(&not_at_start); 844 m.Bind(&not_at_start);
844 // Check that prevchar = 'o' and current = 'b'. 845 // Check that prevchar = 'o' and current = 'b'.
845 Label prevo; 846 Label prevo;
846 m.CheckCharacter('o', &prevo); 847 m.CheckCharacter('o', &prevo);
847 m.Fail(); 848 m.Fail();
848 m.Bind(&prevo); 849 m.Bind(&prevo);
849 m.LoadCurrentCharacter(0, &fail); 850 m.LoadCurrentCharacter(0, &fail);
850 m.CheckNotCharacter('b', &fail); 851 m.CheckNotCharacter('b', &fail);
851 m.Succeed(); 852 m.Succeed();
852 853
853 Handle<Object> code_object = m.GetCode(); 854 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)"));
855 Handle<Object> code_object = m.GetCode(source);
854 Handle<Code> code = Handle<Code>::cast(code_object); 856 Handle<Code> code = Handle<Code>::cast(code_object);
855 857
856 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar")); 858 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar"));
857 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 859 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
858 Address start_adr = seq_input->GetCharsAddress(); 860 Address start_adr = seq_input->GetCharsAddress();
859 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 861 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
860 int end_offset = start_offset + seq_input->length(); 862 int end_offset = start_offset + seq_input->length();
861 863
862 bool success = RegExpMacroAssemblerIA32::Execute(*code, 864 bool success = RegExpMacroAssemblerIA32::Execute(*code,
863 seq_input.location(), 865 seq_input.location(),
(...skipping 22 matching lines...) Expand all
886 V8::Initialize(NULL); 888 V8::Initialize(NULL);
887 889
888 // regexp-macro-assembler-ia32 needs a handle scope to allocate 890 // regexp-macro-assembler-ia32 needs a handle scope to allocate
889 // byte-arrays for constants. 891 // byte-arrays for constants.
890 v8::HandleScope scope; 892 v8::HandleScope scope;
891 893
892 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 894 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
893 895
894 Label fail, succ; 896 Label fail, succ;
895 897
896 m.WriteCurrentPositionToRegister(0); 898 m.WriteCurrentPositionToRegister(0, 0);
897 m.WriteCurrentPositionToRegister(2); 899 m.WriteCurrentPositionToRegister(2, 0);
898 m.AdvanceCurrentPosition(3); 900 m.AdvanceCurrentPosition(3);
899 m.WriteCurrentPositionToRegister(3); 901 m.WriteCurrentPositionToRegister(3, 0);
900 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". 902 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC".
901 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". 903 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC".
902 Label expected_fail; 904 Label expected_fail;
903 m.CheckNotBackReferenceIgnoreCase(2, &expected_fail); 905 m.CheckNotBackReferenceIgnoreCase(2, &expected_fail);
904 m.Bind(&fail); 906 m.Bind(&fail);
905 m.Fail(); 907 m.Fail();
906 908
907 m.Bind(&expected_fail); 909 m.Bind(&expected_fail);
908 m.AdvanceCurrentPosition(3); // Skip "xYz" 910 m.AdvanceCurrentPosition(3); // Skip "xYz"
909 m.CheckNotBackReferenceIgnoreCase(2, &succ); 911 m.CheckNotBackReferenceIgnoreCase(2, &succ);
910 m.Fail(); 912 m.Fail();
911 913
912 m.Bind(&succ); 914 m.Bind(&succ);
913 m.WriteCurrentPositionToRegister(1); 915 m.WriteCurrentPositionToRegister(1, 0);
914 m.Succeed(); 916 m.Succeed();
915 917
916 Handle<Object> code_object = m.GetCode(); 918 Handle<String> source =
919 Factory::NewStringFromAscii(CStrVector("^(abc)\1\1(?!\1)...(?!\1)"));
920 Handle<Object> code_object = m.GetCode(source);
917 Handle<Code> code = Handle<Code>::cast(code_object); 921 Handle<Code> code = Handle<Code>::cast(code_object);
918 922
919 Handle<String> input = 923 Handle<String> input =
920 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); 924 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab"));
921 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 925 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
922 Address start_adr = seq_input->GetCharsAddress(); 926 Address start_adr = seq_input->GetCharsAddress();
923 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 927 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
924 int end_offset = start_offset + seq_input->length(); 928 int end_offset = start_offset + seq_input->length();
925 929
926 int output[4]; 930 int output[4];
(...skipping 21 matching lines...) Expand all
948 v8::HandleScope scope; 952 v8::HandleScope scope;
949 953
950 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); 954 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5);
951 955
952 uc16 foo_chars[3] = {'f', 'o', 'o'}; 956 uc16 foo_chars[3] = {'f', 'o', 'o'};
953 Vector<const uc16> foo(foo_chars, 3); 957 Vector<const uc16> foo(foo_chars, 3);
954 958
955 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; 959 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt };
956 Label fail; 960 Label fail;
957 Label backtrack; 961 Label backtrack;
958 m.WriteCurrentPositionToRegister(out1); // Output: [0] 962 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0]
959 m.PushRegister(out1); 963 m.PushRegister(out1);
960 m.PushBacktrack(&backtrack); 964 m.PushBacktrack(&backtrack);
961 m.WriteStackPointerToRegister(sp); 965 m.WriteStackPointerToRegister(sp);
962 // Fill stack and registers 966 // Fill stack and registers
963 m.AdvanceCurrentPosition(2); 967 m.AdvanceCurrentPosition(2);
964 m.WriteCurrentPositionToRegister(out1); 968 m.WriteCurrentPositionToRegister(out1, 0);
965 m.PushRegister(out1); 969 m.PushRegister(out1);
966 m.PushBacktrack(&fail); 970 m.PushBacktrack(&fail);
967 // Drop backtrack stack frames. 971 // Drop backtrack stack frames.
968 m.ReadStackPointerFromRegister(sp); 972 m.ReadStackPointerFromRegister(sp);
969 // And take the first backtrack (to &backtrack) 973 // And take the first backtrack (to &backtrack)
970 m.Backtrack(); 974 m.Backtrack();
971 975
972 m.PushCurrentPosition(); 976 m.PushCurrentPosition();
973 m.AdvanceCurrentPosition(2); 977 m.AdvanceCurrentPosition(2);
974 m.PopCurrentPosition(); 978 m.PopCurrentPosition();
975 979
976 m.Bind(&backtrack); 980 m.Bind(&backtrack);
977 m.PopRegister(out1); 981 m.PopRegister(out1);
978 m.ReadCurrentPositionFromRegister(out1); 982 m.ReadCurrentPositionFromRegister(out1);
979 m.AdvanceCurrentPosition(3); 983 m.AdvanceCurrentPosition(3);
980 m.WriteCurrentPositionToRegister(out2); // [0,3] 984 m.WriteCurrentPositionToRegister(out2, 0); // [0,3]
981 985
982 Label loop; 986 Label loop;
983 m.SetRegister(loop_cnt, 0); // loop counter 987 m.SetRegister(loop_cnt, 0); // loop counter
984 m.Bind(&loop); 988 m.Bind(&loop);
985 m.AdvanceRegister(loop_cnt, 1); 989 m.AdvanceRegister(loop_cnt, 1);
986 m.AdvanceCurrentPosition(1); 990 m.AdvanceCurrentPosition(1);
987 m.IfRegisterLT(loop_cnt, 3, &loop); 991 m.IfRegisterLT(loop_cnt, 3, &loop);
988 m.WriteCurrentPositionToRegister(out3); // [0,3,6] 992 m.WriteCurrentPositionToRegister(out3, 0); // [0,3,6]
989 993
990 Label loop2; 994 Label loop2;
991 m.SetRegister(loop_cnt, 2); // loop counter 995 m.SetRegister(loop_cnt, 2); // loop counter
992 m.Bind(&loop2); 996 m.Bind(&loop2);
993 m.AdvanceRegister(loop_cnt, -1); 997 m.AdvanceRegister(loop_cnt, -1);
994 m.AdvanceCurrentPosition(1); 998 m.AdvanceCurrentPosition(1);
995 m.IfRegisterGE(loop_cnt, 0, &loop2); 999 m.IfRegisterGE(loop_cnt, 0, &loop2);
996 m.WriteCurrentPositionToRegister(out4); // [0,3,6,9] 1000 m.WriteCurrentPositionToRegister(out4, 0); // [0,3,6,9]
997 1001
998 Label loop3; 1002 Label loop3;
999 Label exit_loop3; 1003 Label exit_loop3;
1004 m.PushRegister(out4);
1005 m.PushRegister(out4);
1000 m.ReadCurrentPositionFromRegister(out3); 1006 m.ReadCurrentPositionFromRegister(out3);
1001 m.Bind(&loop3); 1007 m.Bind(&loop3);
1002 m.AdvanceCurrentPosition(1); 1008 m.AdvanceCurrentPosition(1);
1003 m.CheckCurrentPosition(out4, &exit_loop3); 1009 m.CheckGreedyLoop(&exit_loop3);
1004 m.GoTo(&loop3); 1010 m.GoTo(&loop3);
1005 m.Bind(&exit_loop3); 1011 m.Bind(&exit_loop3);
1006 m.WriteCurrentPositionToRegister(out5); // [0,3,6,9,9] 1012 m.PopCurrentPosition();
1013 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9]
1007 1014
1008 m.Succeed(); 1015 m.Succeed();
1009 1016
1010 m.Bind(&fail); 1017 m.Bind(&fail);
1011 m.Fail(); 1018 m.Fail();
1012 1019
1013 Handle<Object> code_object = m.GetCode(); 1020 Handle<String> source =
1021 Factory::NewStringFromAscii(CStrVector("<loop test>"));
1022 Handle<Object> code_object = m.GetCode(source);
1014 Handle<Code> code = Handle<Code>::cast(code_object); 1023 Handle<Code> code = Handle<Code>::cast(code_object);
1015 1024
1016 // String long enough for test (content doesn't matter). 1025 // String long enough for test (content doesn't matter).
1017 Handle<String> input = 1026 Handle<String> input =
1018 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); 1027 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo"));
1019 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1028 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1020 Address start_adr = seq_input->GetCharsAddress(); 1029 Address start_adr = seq_input->GetCharsAddress();
1021 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1030 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1022 int end_offset = start_offset + seq_input->length(); 1031 int end_offset = start_offset + seq_input->length();
1023 1032
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } else { 1293 } else {
1285 CHECK(!InClass(i, included)); 1294 CHECK(!InClass(i, included));
1286 CHECK(!InClass(i, excluded)); 1295 CHECK(!InClass(i, excluded));
1287 } 1296 }
1288 } 1297 }
1289 } 1298 }
1290 1299
1291 1300
1292 TEST(Graph) { 1301 TEST(Graph) {
1293 V8::Initialize(NULL); 1302 V8::Initialize(NULL);
1294 Execute("\\b\\w", false, true); 1303 Execute("(?=[d#.])", false, true);
1295 } 1304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698