| OLD | NEW |
| 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, RegExpMacroAssembler::kCheckStackLimit); |
| 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(RegExpMacroAssembler::kCheckStackLimit); |
| 610 m.AdvanceCurrentPosition(3); | 610 m.AdvanceCurrentPosition(3); |
| 611 m.WriteCurrentPositionToRegister(1, 0); | 611 m.WriteCurrentPositionToRegister(1, 0); |
| 612 m.PopCurrentPosition(); | 612 m.PopCurrentPosition(); |
| 613 m.AdvanceCurrentPosition(1); | 613 m.AdvanceCurrentPosition(1); |
| 614 m.WriteCurrentPositionToRegister(2, 0); | 614 m.WriteCurrentPositionToRegister(2, 0); |
| 615 m.AdvanceCurrentPosition(1); | 615 m.AdvanceCurrentPosition(1); |
| 616 m.WriteCurrentPositionToRegister(3, 0); | 616 m.WriteCurrentPositionToRegister(3, 0); |
| 617 m.Succeed(); | 617 m.Succeed(); |
| 618 | 618 |
| 619 m.Bind(&fail); | 619 m.Bind(&fail); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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); |
| 833 | 867 |
| 834 Label fail; | 868 Label fail; |
| 835 Label backtrack; | 869 Label backtrack; |
| 836 m.LoadCurrentCharacter(10, &fail); | 870 m.LoadCurrentCharacter(10, &fail); |
| 837 m.Succeed(); | 871 m.Succeed(); |
| 838 m.Bind(&fail); | 872 m.Bind(&fail); |
| 839 m.PushBacktrack(&backtrack); | 873 m.PushBacktrack(&backtrack, RegExpMacroAssembler::kNoStackLimitCheck); |
| 840 m.LoadCurrentCharacter(10, NULL); | 874 m.LoadCurrentCharacter(10, NULL); |
| 841 m.Succeed(); | 875 m.Succeed(); |
| 842 m.Bind(&backtrack); | 876 m.Bind(&backtrack); |
| 843 m.Fail(); | 877 m.Fail(); |
| 844 | 878 |
| 845 Handle<String> source = Factory::NewStringFromAscii(CStrVector("..........")); | 879 Handle<String> source = Factory::NewStringFromAscii(CStrVector("..........")); |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 | 1058 |
| 1025 | 1059 |
| 1026 TEST(MacroAssemblerIA32BackRefNoCase) { | 1060 TEST(MacroAssemblerIA32BackRefNoCase) { |
| 1027 v8::V8::Initialize(); | 1061 v8::V8::Initialize(); |
| 1028 ContextInitializer initializer; | 1062 ContextInitializer initializer; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1058 | 1092 |
| 1059 Handle<String> input = | 1093 Handle<String> input = |
| 1060 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); | 1094 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); |
| 1061 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1095 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
| 1062 Address start_adr = seq_input->GetCharsAddress(); | 1096 Address start_adr = seq_input->GetCharsAddress(); |
| 1063 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); | 1097 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); |
| 1064 int end_offset = start_offset + seq_input->length(); | 1098 int end_offset = start_offset + seq_input->length(); |
| 1065 | 1099 |
| 1066 int output[4]; | 1100 int output[4]; |
| 1067 RegExpMacroAssemblerIA32::Result result = | 1101 RegExpMacroAssemblerIA32::Result result = |
| 1068 RegExpMacroAssemblerIA32::Execute(*code, | 1102 ExecuteIA32(*code, |
| 1069 seq_input.location(), | 1103 seq_input.location(), |
| 1070 start_offset, | 1104 start_offset, |
| 1071 end_offset, | 1105 end_offset, |
| 1072 output, | 1106 output, |
| 1073 true); | 1107 true); |
| 1074 | 1108 |
| 1075 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); | 1109 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); |
| 1076 CHECK_EQ(0, output[0]); | 1110 CHECK_EQ(0, output[0]); |
| 1077 CHECK_EQ(12, output[1]); | 1111 CHECK_EQ(12, output[1]); |
| 1078 CHECK_EQ(0, output[2]); | 1112 CHECK_EQ(0, output[2]); |
| 1079 CHECK_EQ(3, output[3]); | 1113 CHECK_EQ(3, output[3]); |
| 1080 } | 1114 } |
| 1081 | 1115 |
| 1082 | 1116 |
| 1083 | 1117 |
| 1084 TEST(MacroAssemblerIA32Registers) { | 1118 TEST(MacroAssemblerIA32Registers) { |
| 1085 v8::V8::Initialize(); | 1119 v8::V8::Initialize(); |
| 1086 ContextInitializer initializer; | 1120 ContextInitializer initializer; |
| 1087 | 1121 |
| 1088 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); | 1122 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); |
| 1089 | 1123 |
| 1090 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 1124 uc16 foo_chars[3] = {'f', 'o', 'o'}; |
| 1091 Vector<const uc16> foo(foo_chars, 3); | 1125 Vector<const uc16> foo(foo_chars, 3); |
| 1092 | 1126 |
| 1093 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; | 1127 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; |
| 1094 Label fail; | 1128 Label fail; |
| 1095 Label backtrack; | 1129 Label backtrack; |
| 1096 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] | 1130 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] |
| 1097 m.PushRegister(out1); | 1131 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1098 m.PushBacktrack(&backtrack); | 1132 m.PushBacktrack(&backtrack, RegExpMacroAssembler::kCheckStackLimit); |
| 1099 m.WriteStackPointerToRegister(sp); | 1133 m.WriteStackPointerToRegister(sp); |
| 1100 // Fill stack and registers | 1134 // Fill stack and registers |
| 1101 m.AdvanceCurrentPosition(2); | 1135 m.AdvanceCurrentPosition(2); |
| 1102 m.WriteCurrentPositionToRegister(out1, 0); | 1136 m.WriteCurrentPositionToRegister(out1, 0); |
| 1103 m.PushRegister(out1); | 1137 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1104 m.PushBacktrack(&fail); | 1138 m.PushBacktrack(&fail, RegExpMacroAssembler::kCheckStackLimit); |
| 1105 // Drop backtrack stack frames. | 1139 // Drop backtrack stack frames. |
| 1106 m.ReadStackPointerFromRegister(sp); | 1140 m.ReadStackPointerFromRegister(sp); |
| 1107 // And take the first backtrack (to &backtrack) | 1141 // And take the first backtrack (to &backtrack) |
| 1108 m.Backtrack(); | 1142 m.Backtrack(); |
| 1109 | 1143 |
| 1110 m.PushCurrentPosition(); | 1144 m.PushCurrentPosition(RegExpMacroAssembler::kNoStackLimitCheck); |
| 1111 m.AdvanceCurrentPosition(2); | 1145 m.AdvanceCurrentPosition(2); |
| 1112 m.PopCurrentPosition(); | 1146 m.PopCurrentPosition(); |
| 1113 | 1147 |
| 1114 m.Bind(&backtrack); | 1148 m.Bind(&backtrack); |
| 1115 m.PopRegister(out1); | 1149 m.PopRegister(out1); |
| 1116 m.ReadCurrentPositionFromRegister(out1); | 1150 m.ReadCurrentPositionFromRegister(out1); |
| 1117 m.AdvanceCurrentPosition(3); | 1151 m.AdvanceCurrentPosition(3); |
| 1118 m.WriteCurrentPositionToRegister(out2, 0); // [0,3] | 1152 m.WriteCurrentPositionToRegister(out2, 0); // [0,3] |
| 1119 | 1153 |
| 1120 Label loop; | 1154 Label loop; |
| 1121 m.SetRegister(loop_cnt, 0); // loop counter | 1155 m.SetRegister(loop_cnt, 0); // loop counter |
| 1122 m.Bind(&loop); | 1156 m.Bind(&loop); |
| 1123 m.AdvanceRegister(loop_cnt, 1); | 1157 m.AdvanceRegister(loop_cnt, 1); |
| 1124 m.AdvanceCurrentPosition(1); | 1158 m.AdvanceCurrentPosition(1); |
| 1125 m.IfRegisterLT(loop_cnt, 3, &loop); | 1159 m.IfRegisterLT(loop_cnt, 3, &loop); |
| 1126 m.WriteCurrentPositionToRegister(out3, 0); // [0,3,6] | 1160 m.WriteCurrentPositionToRegister(out3, 0); // [0,3,6] |
| 1127 | 1161 |
| 1128 Label loop2; | 1162 Label loop2; |
| 1129 m.SetRegister(loop_cnt, 2); // loop counter | 1163 m.SetRegister(loop_cnt, 2); // loop counter |
| 1130 m.Bind(&loop2); | 1164 m.Bind(&loop2); |
| 1131 m.AdvanceRegister(loop_cnt, -1); | 1165 m.AdvanceRegister(loop_cnt, -1); |
| 1132 m.AdvanceCurrentPosition(1); | 1166 m.AdvanceCurrentPosition(1); |
| 1133 m.IfRegisterGE(loop_cnt, 0, &loop2); | 1167 m.IfRegisterGE(loop_cnt, 0, &loop2); |
| 1134 m.WriteCurrentPositionToRegister(out4, 0); // [0,3,6,9] | 1168 m.WriteCurrentPositionToRegister(out4, 0); // [0,3,6,9] |
| 1135 | 1169 |
| 1136 Label loop3; | 1170 Label loop3; |
| 1137 Label exit_loop3; | 1171 Label exit_loop3; |
| 1138 m.PushRegister(out4); | 1172 m.PushRegister(out4, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1139 m.PushRegister(out4); | 1173 m.PushRegister(out4, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1140 m.ReadCurrentPositionFromRegister(out3); | 1174 m.ReadCurrentPositionFromRegister(out3); |
| 1141 m.Bind(&loop3); | 1175 m.Bind(&loop3); |
| 1142 m.AdvanceCurrentPosition(1); | 1176 m.AdvanceCurrentPosition(1); |
| 1143 m.CheckGreedyLoop(&exit_loop3); | 1177 m.CheckGreedyLoop(&exit_loop3); |
| 1144 m.GoTo(&loop3); | 1178 m.GoTo(&loop3); |
| 1145 m.Bind(&exit_loop3); | 1179 m.Bind(&exit_loop3); |
| 1146 m.PopCurrentPosition(); | 1180 m.PopCurrentPosition(); |
| 1147 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9] | 1181 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9] |
| 1148 | 1182 |
| 1149 m.Succeed(); | 1183 m.Succeed(); |
| 1150 | 1184 |
| 1151 m.Bind(&fail); | 1185 m.Bind(&fail); |
| 1152 m.Fail(); | 1186 m.Fail(); |
| 1153 | 1187 |
| 1154 Handle<String> source = | 1188 Handle<String> source = |
| 1155 Factory::NewStringFromAscii(CStrVector("<loop test>")); | 1189 Factory::NewStringFromAscii(CStrVector("<loop test>")); |
| 1156 Handle<Object> code_object = m.GetCode(source); | 1190 Handle<Object> code_object = m.GetCode(source); |
| 1157 Handle<Code> code = Handle<Code>::cast(code_object); | 1191 Handle<Code> code = Handle<Code>::cast(code_object); |
| 1158 | 1192 |
| 1159 // String long enough for test (content doesn't matter). | 1193 // String long enough for test (content doesn't matter). |
| 1160 Handle<String> input = | 1194 Handle<String> input = |
| 1161 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); | 1195 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); |
| 1162 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1196 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
| 1163 Address start_adr = seq_input->GetCharsAddress(); | 1197 Address start_adr = seq_input->GetCharsAddress(); |
| 1164 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); | 1198 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); |
| 1165 int end_offset = start_offset + seq_input->length(); | 1199 int end_offset = start_offset + seq_input->length(); |
| 1166 | 1200 |
| 1167 int output[5]; | 1201 int output[5]; |
| 1168 RegExpMacroAssemblerIA32::Result result = | 1202 RegExpMacroAssemblerIA32::Result result = |
| 1169 RegExpMacroAssemblerIA32::Execute(*code, | 1203 ExecuteIA32(*code, |
| 1170 seq_input.location(), | 1204 seq_input.location(), |
| 1171 start_offset, | 1205 start_offset, |
| 1172 end_offset, | 1206 end_offset, |
| 1173 output, | 1207 output, |
| 1174 true); | 1208 true); |
| 1175 | 1209 |
| 1176 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); | 1210 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result); |
| 1177 CHECK_EQ(0, output[0]); | 1211 CHECK_EQ(0, output[0]); |
| 1178 CHECK_EQ(3, output[1]); | 1212 CHECK_EQ(3, output[1]); |
| 1179 CHECK_EQ(6, output[2]); | 1213 CHECK_EQ(6, output[2]); |
| 1180 CHECK_EQ(9, output[3]); | 1214 CHECK_EQ(9, output[3]); |
| 1181 CHECK_EQ(9, output[4]); | 1215 CHECK_EQ(9, output[4]); |
| 1182 } | 1216 } |
| 1183 | 1217 |
| 1184 | 1218 |
| 1185 TEST(MacroAssemblerIA32StackOverflow) { | 1219 TEST(MacroAssemblerIA32StackOverflow) { |
| 1186 v8::V8::Initialize(); | 1220 v8::V8::Initialize(); |
| 1187 ContextInitializer initializer; | 1221 ContextInitializer initializer; |
| 1188 | 1222 |
| 1189 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); | 1223 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); |
| 1190 | 1224 |
| 1191 Label loop; | 1225 Label loop; |
| 1192 m.Bind(&loop); | 1226 m.Bind(&loop); |
| 1193 m.PushBacktrack(&loop); | 1227 m.PushBacktrack(&loop, RegExpMacroAssembler::kCheckStackLimit); |
| 1194 m.GoTo(&loop); | 1228 m.GoTo(&loop); |
| 1195 | 1229 |
| 1196 Handle<String> source = | 1230 Handle<String> source = |
| 1197 Factory::NewStringFromAscii(CStrVector("<stack overflow test>")); | 1231 Factory::NewStringFromAscii(CStrVector("<stack overflow test>")); |
| 1198 Handle<Object> code_object = m.GetCode(source); | 1232 Handle<Object> code_object = m.GetCode(source); |
| 1199 Handle<Code> code = Handle<Code>::cast(code_object); | 1233 Handle<Code> code = Handle<Code>::cast(code_object); |
| 1200 | 1234 |
| 1201 // String long enough for test (content doesn't matter). | 1235 // String long enough for test (content doesn't matter). |
| 1202 Handle<String> input = | 1236 Handle<String> input = |
| 1203 Factory::NewStringFromAscii(CStrVector("dummy")); | 1237 Factory::NewStringFromAscii(CStrVector("dummy")); |
| 1204 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1238 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
| 1205 Address start_adr = seq_input->GetCharsAddress(); | 1239 Address start_adr = seq_input->GetCharsAddress(); |
| 1206 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); | 1240 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); |
| 1207 int end_offset = start_offset + seq_input->length(); | 1241 int end_offset = start_offset + seq_input->length(); |
| 1208 | 1242 |
| 1209 RegExpMacroAssemblerIA32::Result result = | 1243 RegExpMacroAssemblerIA32::Result result = |
| 1210 RegExpMacroAssemblerIA32::Execute(*code, | 1244 ExecuteIA32(*code, |
| 1211 seq_input.location(), | 1245 seq_input.location(), |
| 1212 start_offset, | 1246 start_offset, |
| 1213 end_offset, | 1247 end_offset, |
| 1214 NULL, | 1248 NULL, |
| 1215 true); | 1249 true); |
| 1216 | 1250 |
| 1217 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result); | 1251 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result); |
| 1218 CHECK(Top::has_pending_exception()); | 1252 CHECK(Top::has_pending_exception()); |
| 1219 Top::clear_pending_exception(); | 1253 Top::clear_pending_exception(); |
| 1220 } | 1254 } |
| 1221 | 1255 |
| 1222 | 1256 |
| 1223 #endif // !defined ARM | 1257 #endif // !defined ARM |
| 1224 | 1258 |
| 1225 TEST(AddInverseToTable) { | 1259 TEST(AddInverseToTable) { |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 CHECK(!InClass(i, excluded)); | 1495 CHECK(!InClass(i, excluded)); |
| 1462 } | 1496 } |
| 1463 } | 1497 } |
| 1464 } | 1498 } |
| 1465 | 1499 |
| 1466 | 1500 |
| 1467 TEST(Graph) { | 1501 TEST(Graph) { |
| 1468 V8::Initialize(NULL); | 1502 V8::Initialize(NULL); |
| 1469 Execute("(?:a|)*", false, true, true); | 1503 Execute("(?:a|)*", false, true, true); |
| 1470 } | 1504 } |
| OLD | NEW |