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

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

Issue 18096: Experimental: merge from bleeding_edge. Merge up to and including... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 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
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 CHECK_MIN_MAX("a[bc]d", 3, 3); 284 CHECK_MIN_MAX("a[bc]d", 3, 3);
285 CHECK_MIN_MAX("a|bc", 1, 2); 285 CHECK_MIN_MAX("a|bc", 1, 2);
286 CHECK_MIN_MAX("ab|c", 1, 2); 286 CHECK_MIN_MAX("ab|c", 1, 2);
287 CHECK_MIN_MAX("a||bc", 0, 2); 287 CHECK_MIN_MAX("a||bc", 0, 2);
288 CHECK_MIN_MAX("|", 0, 0); 288 CHECK_MIN_MAX("|", 0, 0);
289 CHECK_MIN_MAX("(?:ab)", 2, 2); 289 CHECK_MIN_MAX("(?:ab)", 2, 2);
290 CHECK_MIN_MAX("(?:ab|cde)", 2, 3); 290 CHECK_MIN_MAX("(?:ab|cde)", 2, 3);
291 CHECK_MIN_MAX("(?:ab)|cde", 2, 3); 291 CHECK_MIN_MAX("(?:ab)|cde", 2, 3);
292 CHECK_MIN_MAX("(ab)", 2, 2); 292 CHECK_MIN_MAX("(ab)", 2, 2);
293 CHECK_MIN_MAX("(ab|cde)", 2, 3); 293 CHECK_MIN_MAX("(ab|cde)", 2, 3);
294 CHECK_MIN_MAX("(ab)\\1", 4, 4); 294 CHECK_MIN_MAX("(ab)\\1", 2, 4);
295 CHECK_MIN_MAX("(ab|cde)\\1", 4, 6); 295 CHECK_MIN_MAX("(ab|cde)\\1", 2, 6);
296 CHECK_MIN_MAX("(?:ab)?", 0, 2); 296 CHECK_MIN_MAX("(?:ab)?", 0, 2);
297 CHECK_MIN_MAX("(?:ab)*", 0, RegExpTree::kInfinity); 297 CHECK_MIN_MAX("(?:ab)*", 0, RegExpTree::kInfinity);
298 CHECK_MIN_MAX("(?:ab)+", 2, RegExpTree::kInfinity); 298 CHECK_MIN_MAX("(?:ab)+", 2, RegExpTree::kInfinity);
299 CHECK_MIN_MAX("a?", 0, 1); 299 CHECK_MIN_MAX("a?", 0, 1);
300 CHECK_MIN_MAX("a*", 0, RegExpTree::kInfinity); 300 CHECK_MIN_MAX("a*", 0, RegExpTree::kInfinity);
301 CHECK_MIN_MAX("a+", 1, RegExpTree::kInfinity); 301 CHECK_MIN_MAX("a+", 1, RegExpTree::kInfinity);
302 CHECK_MIN_MAX("a??", 0, 1); 302 CHECK_MIN_MAX("a??", 0, 1);
303 CHECK_MIN_MAX("a*?", 0, RegExpTree::kInfinity); 303 CHECK_MIN_MAX("a*?", 0, RegExpTree::kInfinity);
304 CHECK_MIN_MAX("a+?", 1, RegExpTree::kInfinity); 304 CHECK_MIN_MAX("a+?", 1, RegExpTree::kInfinity);
305 CHECK_MIN_MAX("(?:a?)?", 0, 1); 305 CHECK_MIN_MAX("(?:a?)?", 0, 1);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 byte codes[1024]; 591 byte codes[1024];
592 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024)); 592 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024));
593 // ^f(o)o. 593 // ^f(o)o.
594 Label fail, fail2, start; 594 Label fail, fail2, start;
595 uc16 foo_chars[3]; 595 uc16 foo_chars[3];
596 foo_chars[0] = 'f'; 596 foo_chars[0] = 'f';
597 foo_chars[1] = 'o'; 597 foo_chars[1] = 'o';
598 foo_chars[2] = 'o'; 598 foo_chars[2] = 'o';
599 Vector<const uc16> foo(foo_chars, 3); 599 Vector<const uc16> foo(foo_chars, 3);
600 m.SetRegister(4, 42); 600 m.SetRegister(4, 42);
601 m.PushRegister(4); 601 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck);
602 m.AdvanceRegister(4, 42); 602 m.AdvanceRegister(4, 42);
603 m.GoTo(&start); 603 m.GoTo(&start);
604 m.Fail(); 604 m.Fail();
605 m.Bind(&start); 605 m.Bind(&start);
606 m.PushBacktrack(&fail2); 606 m.PushBacktrack(&fail2);
607 m.CheckCharacters(foo, 0, &fail, true); 607 m.CheckCharacters(foo, 0, &fail, true);
608 m.WriteCurrentPositionToRegister(0, 0); 608 m.WriteCurrentPositionToRegister(0, 0);
609 m.PushCurrentPosition(); 609 m.PushCurrentPosition();
610 m.AdvanceCurrentPosition(3); 610 m.AdvanceCurrentPosition(3);
611 m.WriteCurrentPositionToRegister(1, 0); 611 m.WriteCurrentPositionToRegister(1, 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 ~ContextInitializer() { 659 ~ContextInitializer() {
660 env_->Exit(); 660 env_->Exit();
661 env_.Dispose(); 661 env_.Dispose();
662 } 662 }
663 private: 663 private:
664 v8::Persistent<v8::Context> env_; 664 v8::Persistent<v8::Context> env_;
665 v8::HandleScope scope_; 665 v8::HandleScope scope_;
666 v8::internal::StackGuard stack_guard_; 666 v8::internal::StackGuard stack_guard_;
667 }; 667 };
668 668
669 // Helper functions for calling the Execute method.
670 template <typename T>
671 static RegExpMacroAssemblerIA32::Result ExecuteIA32(Code* code,
672 const T** input,
673 int start_offset,
674 int end_offset,
675 int* captures,
676 bool at_start) {
677 return RegExpMacroAssemblerIA32::Execute(
678 code,
679 reinterpret_cast<Address*>(
680 reinterpret_cast<void*>(const_cast<T**>(input))),
681 start_offset,
682 end_offset,
683 captures,
684 at_start);
685 }
686
687 template <typename T>
688 static RegExpMacroAssemblerIA32::Result ExecuteIA32(Code* code,
689 T** input,
690 int start_offset,
691 int end_offset,
692 int* captures,
693 bool at_start) {
694 return RegExpMacroAssemblerIA32::Execute(
695 code,
696 reinterpret_cast<Address*>(reinterpret_cast<void*>(input)),
697 start_offset,
698 end_offset,
699 captures,
700 at_start);
701 }
702
669 703
670 TEST(MacroAssemblerIA32Success) { 704 TEST(MacroAssemblerIA32Success) {
671 v8::V8::Initialize(); 705 v8::V8::Initialize();
672 ContextInitializer initializer; 706 ContextInitializer initializer;
673 707
674 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 708 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
675 709
676 m.Succeed(); 710 m.Succeed();
677 711
678 Handle<String> source = Factory::NewStringFromAscii(CStrVector("")); 712 Handle<String> source = Factory::NewStringFromAscii(CStrVector(""));
679 Handle<Object> code_object = m.GetCode(source); 713 Handle<Object> code_object = m.GetCode(source);
680 Handle<Code> code = Handle<Code>::cast(code_object); 714 Handle<Code> code = Handle<Code>::cast(code_object);
681 715
682 int captures[4] = {42, 37, 87, 117}; 716 int captures[4] = {42, 37, 87, 117};
683 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 717 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
684 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 718 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
685 Address start_adr = seq_input->GetCharsAddress(); 719 Address start_adr = seq_input->GetCharsAddress();
686 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 720 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
687 int end_offset = start_offset + seq_input->length(); 721 int end_offset = start_offset + seq_input->length();
688 722
689 RegExpMacroAssemblerIA32::Result result = 723 RegExpMacroAssemblerIA32::Result result =
690 RegExpMacroAssemblerIA32::Execute(*code, 724 ExecuteIA32(*code,
691 seq_input.location(), 725 seq_input.location(),
692 start_offset, 726 start_offset,
693 end_offset, 727 end_offset,
694 captures, 728 captures,
695 true); 729 true);
696 730
697 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 731 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
698 CHECK_EQ(-1, captures[0]); 732 CHECK_EQ(-1, captures[0]);
699 CHECK_EQ(-1, captures[1]); 733 CHECK_EQ(-1, captures[1]);
700 CHECK_EQ(-1, captures[2]); 734 CHECK_EQ(-1, captures[2]);
701 CHECK_EQ(-1, captures[3]); 735 CHECK_EQ(-1, captures[3]);
702 } 736 }
703 737
704 738
705 TEST(MacroAssemblerIA32Simple) { 739 TEST(MacroAssemblerIA32Simple) {
(...skipping 19 matching lines...) Expand all
725 Handle<Code> code = Handle<Code>::cast(code_object); 759 Handle<Code> code = Handle<Code>::cast(code_object);
726 760
727 int captures[4] = {42, 37, 87, 117}; 761 int captures[4] = {42, 37, 87, 117};
728 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 762 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
729 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 763 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
730 Address start_adr = seq_input->GetCharsAddress(); 764 Address start_adr = seq_input->GetCharsAddress();
731 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 765 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
732 int end_offset = start_offset + seq_input->length(); 766 int end_offset = start_offset + seq_input->length();
733 767
734 RegExpMacroAssemblerIA32::Result result = 768 RegExpMacroAssemblerIA32::Result result =
735 RegExpMacroAssemblerIA32::Execute(*code, 769 ExecuteIA32(*code,
736 seq_input.location(), 770 seq_input.location(),
737 start_offset, 771 start_offset,
738 end_offset, 772 end_offset,
739 captures, 773 captures,
740 true); 774 true);
741 775
742 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 776 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
743 CHECK_EQ(0, captures[0]); 777 CHECK_EQ(0, captures[0]);
744 CHECK_EQ(3, captures[1]); 778 CHECK_EQ(3, captures[1]);
745 CHECK_EQ(-1, captures[2]); 779 CHECK_EQ(-1, captures[2]);
746 CHECK_EQ(-1, captures[3]); 780 CHECK_EQ(-1, captures[3]);
747 781
748 input = Factory::NewStringFromAscii(CStrVector("barbarbar")); 782 input = Factory::NewStringFromAscii(CStrVector("barbarbar"));
749 seq_input = Handle<SeqAsciiString>::cast(input); 783 seq_input = Handle<SeqAsciiString>::cast(input);
750 start_adr = seq_input->GetCharsAddress(); 784 start_adr = seq_input->GetCharsAddress();
751 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 785 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
752 end_offset = start_offset + seq_input->length(); 786 end_offset = start_offset + seq_input->length();
753 787
754 result = RegExpMacroAssemblerIA32::Execute(*code, 788 result = ExecuteIA32(*code,
755 seq_input.location(), 789 seq_input.location(),
756 start_offset, 790 start_offset,
757 end_offset, 791 end_offset,
758 captures, 792 captures,
759 true); 793 true);
760 794
761 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result); 795 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
762 } 796 }
763 797
764 798
765 TEST(MacroAssemblerIA32SimpleUC16) { 799 TEST(MacroAssemblerIA32SimpleUC16) {
766 v8::V8::Initialize(); 800 v8::V8::Initialize();
767 ContextInitializer initializer; 801 ContextInitializer initializer;
768 802
769 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4); 803 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4);
(...skipping 17 matching lines...) Expand all
787 int captures[4] = {42, 37, 87, 117}; 821 int captures[4] = {42, 37, 87, 117};
788 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; 822 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'};
789 Handle<String> input = 823 Handle<String> input =
790 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); 824 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
791 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); 825 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
792 Address start_adr = seq_input->GetCharsAddress(); 826 Address start_adr = seq_input->GetCharsAddress();
793 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 827 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
794 int end_offset = start_offset + seq_input->length() * sizeof(uc16); 828 int end_offset = start_offset + seq_input->length() * sizeof(uc16);
795 829
796 RegExpMacroAssemblerIA32::Result result = 830 RegExpMacroAssemblerIA32::Result result =
797 RegExpMacroAssemblerIA32::Execute(*code, 831 ExecuteIA32(*code,
798 seq_input.location(), 832 seq_input.location(),
799 start_offset, 833 start_offset,
800 end_offset, 834 end_offset,
801 captures, 835 captures,
802 true); 836 true);
803 837
804 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 838 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
805 CHECK_EQ(0, captures[0]); 839 CHECK_EQ(0, captures[0]);
806 CHECK_EQ(3, captures[1]); 840 CHECK_EQ(3, captures[1]);
807 CHECK_EQ(-1, captures[2]); 841 CHECK_EQ(-1, captures[2]);
808 CHECK_EQ(-1, captures[3]); 842 CHECK_EQ(-1, captures[3]);
809 843
810 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'}; 844 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'};
811 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9)); 845 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9));
812 seq_input = Handle<SeqTwoByteString>::cast(input); 846 seq_input = Handle<SeqTwoByteString>::cast(input);
813 start_adr = seq_input->GetCharsAddress(); 847 start_adr = seq_input->GetCharsAddress();
814 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 848 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
815 end_offset = start_offset + seq_input->length() * sizeof(uc16); 849 end_offset = start_offset + seq_input->length() * sizeof(uc16);
816 850
817 result = RegExpMacroAssemblerIA32::Execute(*code, 851 result = ExecuteIA32(*code,
818 seq_input.location(), 852 seq_input.location(),
819 start_offset, 853 start_offset,
820 end_offset, 854 end_offset,
821 captures, 855 captures,
822 true); 856 true);
823 857
824 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result); 858 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
825 } 859 }
826 860
827 861
828 TEST(MacroAssemblerIA32Backtrack) { 862 TEST(MacroAssemblerIA32Backtrack) {
829 v8::V8::Initialize(); 863 v8::V8::Initialize();
830 ContextInitializer initializer; 864 ContextInitializer initializer;
831 865
832 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 866 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
(...skipping 13 matching lines...) Expand all
846 Handle<Object> code_object = m.GetCode(source); 880 Handle<Object> code_object = m.GetCode(source);
847 Handle<Code> code = Handle<Code>::cast(code_object); 881 Handle<Code> code = Handle<Code>::cast(code_object);
848 882
849 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 883 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
850 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 884 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
851 Address start_adr = seq_input->GetCharsAddress(); 885 Address start_adr = seq_input->GetCharsAddress();
852 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 886 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
853 int end_offset = start_offset + seq_input->length(); 887 int end_offset = start_offset + seq_input->length();
854 888
855 RegExpMacroAssemblerIA32::Result result = 889 RegExpMacroAssemblerIA32::Result result =
856 RegExpMacroAssemblerIA32::Execute(*code, 890 ExecuteIA32(*code,
857 seq_input.location(), 891 seq_input.location(),
858 start_offset, 892 start_offset,
859 end_offset, 893 end_offset,
860 NULL, 894 NULL,
861 true); 895 true);
862 896
863 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result); 897 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
864 } 898 }
865 899
866 900
867 TEST(MacroAssemblerIA32BackReferenceASCII) { 901 TEST(MacroAssemblerIA32BackReferenceASCII) {
868 v8::V8::Initialize(); 902 v8::V8::Initialize();
869 ContextInitializer initializer; 903 ContextInitializer initializer;
870 904
871 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3); 905 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3);
(...skipping 18 matching lines...) Expand all
890 Handle<Code> code = Handle<Code>::cast(code_object); 924 Handle<Code> code = Handle<Code>::cast(code_object);
891 925
892 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo")); 926 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo"));
893 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 927 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
894 Address start_adr = seq_input->GetCharsAddress(); 928 Address start_adr = seq_input->GetCharsAddress();
895 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 929 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
896 int end_offset = start_offset + seq_input->length(); 930 int end_offset = start_offset + seq_input->length();
897 931
898 int output[3]; 932 int output[3];
899 RegExpMacroAssemblerIA32::Result result = 933 RegExpMacroAssemblerIA32::Result result =
900 RegExpMacroAssemblerIA32::Execute(*code, 934 ExecuteIA32(*code,
901 seq_input.location(), 935 seq_input.location(),
902 start_offset, 936 start_offset,
903 end_offset, 937 end_offset,
904 output, 938 output,
905 true); 939 true);
906 940
907 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 941 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
908 CHECK_EQ(0, output[0]); 942 CHECK_EQ(0, output[0]);
909 CHECK_EQ(2, output[1]); 943 CHECK_EQ(2, output[1]);
910 CHECK_EQ(6, output[2]); 944 CHECK_EQ(6, output[2]);
911 } 945 }
912 946
913 947
914 TEST(MacroAssemblerIA32BackReferenceUC16) { 948 TEST(MacroAssemblerIA32BackReferenceUC16) {
915 v8::V8::Initialize(); 949 v8::V8::Initialize();
(...skipping 24 matching lines...) Expand all
940 Handle<String> input = 974 Handle<String> input =
941 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); 975 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
942 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); 976 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
943 Address start_adr = seq_input->GetCharsAddress(); 977 Address start_adr = seq_input->GetCharsAddress();
944 978
945 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 979 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
946 int end_offset = start_offset + seq_input->length() * sizeof(input_data[0]); 980 int end_offset = start_offset + seq_input->length() * sizeof(input_data[0]);
947 981
948 int output[3]; 982 int output[3];
949 RegExpMacroAssemblerIA32::Result result = 983 RegExpMacroAssemblerIA32::Result result =
950 RegExpMacroAssemblerIA32::Execute(*code, 984 ExecuteIA32(*code,
951 seq_input.location(), 985 seq_input.location(),
952 start_offset, 986 start_offset,
953 end_offset, 987 end_offset,
954 output, 988 output,
955 true); 989 true);
956 990
957 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 991 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
958 CHECK_EQ(0, output[0]); 992 CHECK_EQ(0, output[0]);
959 CHECK_EQ(2, output[1]); 993 CHECK_EQ(2, output[1]);
960 CHECK_EQ(6, output[2]); 994 CHECK_EQ(6, output[2]);
961 } 995 }
962 996
963 997
964 998
965 TEST(MacroAssemblerIA32AtStart) { 999 TEST(MacroAssemblerIA32AtStart) {
(...skipping 27 matching lines...) Expand all
993 Handle<Object> code_object = m.GetCode(source); 1027 Handle<Object> code_object = m.GetCode(source);
994 Handle<Code> code = Handle<Code>::cast(code_object); 1028 Handle<Code> code = Handle<Code>::cast(code_object);
995 1029
996 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar")); 1030 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar"));
997 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1031 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
998 Address start_adr = seq_input->GetCharsAddress(); 1032 Address start_adr = seq_input->GetCharsAddress();
999 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1033 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1000 int end_offset = start_offset + seq_input->length(); 1034 int end_offset = start_offset + seq_input->length();
1001 1035
1002 RegExpMacroAssemblerIA32::Result result = 1036 RegExpMacroAssemblerIA32::Result result =
1003 RegExpMacroAssemblerIA32::Execute(*code, 1037 ExecuteIA32(*code,
1004 seq_input.location(), 1038 seq_input.location(),
1005 start_offset, 1039 start_offset,
1006 end_offset, 1040 end_offset,
1007 NULL, 1041 NULL,
1008 true); 1042 true);
1009 1043
1010 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 1044 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1011 1045
1012 start_offset += 3; 1046 start_offset += 3;
1013 result = RegExpMacroAssemblerIA32::Execute(*code, 1047 result = ExecuteIA32(*code,
1014 seq_input.location(), 1048 seq_input.location(),
1015 start_offset, 1049 start_offset,
1016 end_offset, 1050 end_offset,
1017 NULL, 1051 NULL,
1018 false); 1052 false);
1019 1053
1020 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 1054 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1021 } 1055 }
1022 1056
1023 1057
1024
1025
1026 TEST(MacroAssemblerIA32BackRefNoCase) { 1058 TEST(MacroAssemblerIA32BackRefNoCase) {
1027 v8::V8::Initialize(); 1059 v8::V8::Initialize();
1028 ContextInitializer initializer; 1060 ContextInitializer initializer;
1029 1061
1030 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 1062 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
1031 1063
1032 Label fail, succ; 1064 Label fail, succ;
1033 1065
1034 m.WriteCurrentPositionToRegister(0, 0); 1066 m.WriteCurrentPositionToRegister(0, 0);
1035 m.WriteCurrentPositionToRegister(2, 0); 1067 m.WriteCurrentPositionToRegister(2, 0);
(...skipping 22 matching lines...) Expand all
1058 1090
1059 Handle<String> input = 1091 Handle<String> input =
1060 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); 1092 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab"));
1061 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1093 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1062 Address start_adr = seq_input->GetCharsAddress(); 1094 Address start_adr = seq_input->GetCharsAddress();
1063 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1095 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1064 int end_offset = start_offset + seq_input->length(); 1096 int end_offset = start_offset + seq_input->length();
1065 1097
1066 int output[4]; 1098 int output[4];
1067 RegExpMacroAssemblerIA32::Result result = 1099 RegExpMacroAssemblerIA32::Result result =
1068 RegExpMacroAssemblerIA32::Execute(*code, 1100 ExecuteIA32(*code,
1069 seq_input.location(), 1101 seq_input.location(),
1070 start_offset, 1102 start_offset,
1071 end_offset, 1103 end_offset,
1072 output, 1104 output,
1073 true); 1105 true);
1074 1106
1075 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 1107 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1076 CHECK_EQ(0, output[0]); 1108 CHECK_EQ(0, output[0]);
1077 CHECK_EQ(12, output[1]); 1109 CHECK_EQ(12, output[1]);
1078 CHECK_EQ(0, output[2]); 1110 CHECK_EQ(0, output[2]);
1079 CHECK_EQ(3, output[3]); 1111 CHECK_EQ(3, output[3]);
1080 } 1112 }
1081 1113
1082 1114
1083 1115
1084 TEST(MacroAssemblerIA32Registers) { 1116 TEST(MacroAssemblerIA32Registers) {
1085 v8::V8::Initialize(); 1117 v8::V8::Initialize();
1086 ContextInitializer initializer; 1118 ContextInitializer initializer;
1087 1119
1088 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); 1120 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5);
1089 1121
1090 uc16 foo_chars[3] = {'f', 'o', 'o'}; 1122 uc16 foo_chars[3] = {'f', 'o', 'o'};
1091 Vector<const uc16> foo(foo_chars, 3); 1123 Vector<const uc16> foo(foo_chars, 3);
1092 1124
1093 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; 1125 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt };
1094 Label fail; 1126 Label fail;
1095 Label backtrack; 1127 Label backtrack;
1096 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] 1128 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0]
1097 m.PushRegister(out1); 1129 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck);
1098 m.PushBacktrack(&backtrack); 1130 m.PushBacktrack(&backtrack);
1099 m.WriteStackPointerToRegister(sp); 1131 m.WriteStackPointerToRegister(sp);
1100 // Fill stack and registers 1132 // Fill stack and registers
1101 m.AdvanceCurrentPosition(2); 1133 m.AdvanceCurrentPosition(2);
1102 m.WriteCurrentPositionToRegister(out1, 0); 1134 m.WriteCurrentPositionToRegister(out1, 0);
1103 m.PushRegister(out1); 1135 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck);
1104 m.PushBacktrack(&fail); 1136 m.PushBacktrack(&fail);
1105 // Drop backtrack stack frames. 1137 // Drop backtrack stack frames.
1106 m.ReadStackPointerFromRegister(sp); 1138 m.ReadStackPointerFromRegister(sp);
1107 // And take the first backtrack (to &backtrack) 1139 // And take the first backtrack (to &backtrack)
1108 m.Backtrack(); 1140 m.Backtrack();
1109 1141
1110 m.PushCurrentPosition(); 1142 m.PushCurrentPosition();
1111 m.AdvanceCurrentPosition(2); 1143 m.AdvanceCurrentPosition(2);
1112 m.PopCurrentPosition(); 1144 m.PopCurrentPosition();
1113 1145
(...skipping 14 matching lines...) Expand all
1128 Label loop2; 1160 Label loop2;
1129 m.SetRegister(loop_cnt, 2); // loop counter 1161 m.SetRegister(loop_cnt, 2); // loop counter
1130 m.Bind(&loop2); 1162 m.Bind(&loop2);
1131 m.AdvanceRegister(loop_cnt, -1); 1163 m.AdvanceRegister(loop_cnt, -1);
1132 m.AdvanceCurrentPosition(1); 1164 m.AdvanceCurrentPosition(1);
1133 m.IfRegisterGE(loop_cnt, 0, &loop2); 1165 m.IfRegisterGE(loop_cnt, 0, &loop2);
1134 m.WriteCurrentPositionToRegister(out4, 0); // [0,3,6,9] 1166 m.WriteCurrentPositionToRegister(out4, 0); // [0,3,6,9]
1135 1167
1136 Label loop3; 1168 Label loop3;
1137 Label exit_loop3; 1169 Label exit_loop3;
1138 m.PushRegister(out4); 1170 m.PushRegister(out4, RegExpMacroAssembler::kNoStackLimitCheck);
1139 m.PushRegister(out4); 1171 m.PushRegister(out4, RegExpMacroAssembler::kNoStackLimitCheck);
1140 m.ReadCurrentPositionFromRegister(out3); 1172 m.ReadCurrentPositionFromRegister(out3);
1141 m.Bind(&loop3); 1173 m.Bind(&loop3);
1142 m.AdvanceCurrentPosition(1); 1174 m.AdvanceCurrentPosition(1);
1143 m.CheckGreedyLoop(&exit_loop3); 1175 m.CheckGreedyLoop(&exit_loop3);
1144 m.GoTo(&loop3); 1176 m.GoTo(&loop3);
1145 m.Bind(&exit_loop3); 1177 m.Bind(&exit_loop3);
1146 m.PopCurrentPosition(); 1178 m.PopCurrentPosition();
1147 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9] 1179 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9]
1148 1180
1149 m.Succeed(); 1181 m.Succeed();
1150 1182
1151 m.Bind(&fail); 1183 m.Bind(&fail);
1152 m.Fail(); 1184 m.Fail();
1153 1185
1154 Handle<String> source = 1186 Handle<String> source =
1155 Factory::NewStringFromAscii(CStrVector("<loop test>")); 1187 Factory::NewStringFromAscii(CStrVector("<loop test>"));
1156 Handle<Object> code_object = m.GetCode(source); 1188 Handle<Object> code_object = m.GetCode(source);
1157 Handle<Code> code = Handle<Code>::cast(code_object); 1189 Handle<Code> code = Handle<Code>::cast(code_object);
1158 1190
1159 // String long enough for test (content doesn't matter). 1191 // String long enough for test (content doesn't matter).
1160 Handle<String> input = 1192 Handle<String> input =
1161 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); 1193 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo"));
1162 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1194 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1163 Address start_adr = seq_input->GetCharsAddress(); 1195 Address start_adr = seq_input->GetCharsAddress();
1164 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1196 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1165 int end_offset = start_offset + seq_input->length(); 1197 int end_offset = start_offset + seq_input->length();
1166 1198
1167 int output[5]; 1199 int output[5];
1168 RegExpMacroAssemblerIA32::Result result = 1200 RegExpMacroAssemblerIA32::Result result =
1169 RegExpMacroAssemblerIA32::Execute(*code, 1201 ExecuteIA32(*code,
1170 seq_input.location(), 1202 seq_input.location(),
1171 start_offset, 1203 start_offset,
1172 end_offset, 1204 end_offset,
1173 output, 1205 output,
1174 true); 1206 true);
1175 1207
1176 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); 1208 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1177 CHECK_EQ(0, output[0]); 1209 CHECK_EQ(0, output[0]);
1178 CHECK_EQ(3, output[1]); 1210 CHECK_EQ(3, output[1]);
1179 CHECK_EQ(6, output[2]); 1211 CHECK_EQ(6, output[2]);
1180 CHECK_EQ(9, output[3]); 1212 CHECK_EQ(9, output[3]);
1181 CHECK_EQ(9, output[4]); 1213 CHECK_EQ(9, output[4]);
1182 } 1214 }
1183 1215
1184 1216
(...skipping 15 matching lines...) Expand all
1200 1232
1201 // String long enough for test (content doesn't matter). 1233 // String long enough for test (content doesn't matter).
1202 Handle<String> input = 1234 Handle<String> input =
1203 Factory::NewStringFromAscii(CStrVector("dummy")); 1235 Factory::NewStringFromAscii(CStrVector("dummy"));
1204 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1236 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1205 Address start_adr = seq_input->GetCharsAddress(); 1237 Address start_adr = seq_input->GetCharsAddress();
1206 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1238 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1207 int end_offset = start_offset + seq_input->length(); 1239 int end_offset = start_offset + seq_input->length();
1208 1240
1209 RegExpMacroAssemblerIA32::Result result = 1241 RegExpMacroAssemblerIA32::Result result =
1210 RegExpMacroAssemblerIA32::Execute(*code, 1242 ExecuteIA32(*code,
1211 seq_input.location(), 1243 seq_input.location(),
1212 start_offset, 1244 start_offset,
1213 end_offset, 1245 end_offset,
1214 NULL, 1246 NULL,
1215 true); 1247 true);
1216 1248
1217 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result); 1249 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result);
1218 CHECK(Top::has_pending_exception()); 1250 CHECK(Top::has_pending_exception());
1219 Top::clear_pending_exception(); 1251 Top::clear_pending_exception();
1220 } 1252 }
1221 1253
1222 1254
1255 TEST(MacroAssemblerIA32LotsOfRegisters) {
1256 v8::V8::Initialize();
1257 ContextInitializer initializer;
1258
1259 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 2);
1260
1261 // At least 2048, to ensure the allocated space for registers
1262 // span one full page.
1263 const int large_number = 8000;
1264 m.WriteCurrentPositionToRegister(large_number, 42);
1265 m.WriteCurrentPositionToRegister(0, 0);
1266 m.WriteCurrentPositionToRegister(1, 1);
1267 Label done;
1268 m.CheckNotBackReference(0, &done); // Performs a system-stack push.
1269 m.Bind(&done);
1270 m.PushRegister(large_number, RegExpMacroAssembler::kNoStackLimitCheck);
1271 m.PopRegister(1);
1272 m.Succeed();
1273
1274 Handle<String> source =
1275 Factory::NewStringFromAscii(CStrVector("<huge register space test>"));
1276 Handle<Object> code_object = m.GetCode(source);
1277 Handle<Code> code = Handle<Code>::cast(code_object);
1278
1279 // String long enough for test (content doesn't matter).
1280 Handle<String> input =
1281 Factory::NewStringFromAscii(CStrVector("sample text"));
1282 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1283 Address start_adr = seq_input->GetCharsAddress();
1284 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1285 int end_offset = start_offset + seq_input->length();
1286
1287 int captures[2];
1288 RegExpMacroAssemblerIA32::Result result =
1289 ExecuteIA32(*code,
1290 seq_input.location(),
1291 start_offset,
1292 end_offset,
1293 captures,
1294 true);
1295
1296 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1297 CHECK_EQ(0, captures[0]);
1298 CHECK_EQ(42, captures[1]);
1299
1300 Top::clear_pending_exception();
1301 }
1302
1303
1304
1223 #endif // !defined ARM 1305 #endif // !defined ARM
1224 1306
1225 TEST(AddInverseToTable) { 1307 TEST(AddInverseToTable) {
1226 static const int kLimit = 1000; 1308 static const int kLimit = 1000;
1227 static const int kRangeCount = 16; 1309 static const int kRangeCount = 16;
1228 for (int t = 0; t < 10; t++) { 1310 for (int t = 0; t < 10; t++) {
1229 ZoneScope zone_scope(DELETE_ON_EXIT); 1311 ZoneScope zone_scope(DELETE_ON_EXIT);
1230 ZoneList<CharacterRange>* ranges = 1312 ZoneList<CharacterRange>* ranges =
1231 new ZoneList<CharacterRange>(kRangeCount); 1313 new ZoneList<CharacterRange>(kRangeCount);
1232 for (int i = 0; i < kRangeCount; i++) { 1314 for (int i = 0; i < kRangeCount; i++) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 } else { 1541 } else {
1460 CHECK(!InClass(i, included)); 1542 CHECK(!InClass(i, included));
1461 CHECK(!InClass(i, excluded)); 1543 CHECK(!InClass(i, excluded));
1462 } 1544 }
1463 } 1545 }
1464 } 1546 }
1465 1547
1466 1548
1467 TEST(Graph) { 1549 TEST(Graph) {
1468 V8::Initialize(NULL); 1550 V8::Initialize(NULL);
1469 Execute("\\b\\w+\\b", false, true, true); 1551 Execute("(?:(?:x(.))?\1)+$", false, true, true);
1470 } 1552 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698