OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 | 777 |
778 | 778 |
779 TEST(MacroAssemblerNativeSimple) { | 779 TEST(MacroAssemblerNativeSimple) { |
780 v8::V8::Initialize(); | 780 v8::V8::Initialize(); |
781 ContextInitializer initializer; | 781 ContextInitializer initializer; |
782 Factory* factory = Isolate::Current()->factory(); | 782 Factory* factory = Isolate::Current()->factory(); |
783 | 783 |
784 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, | 784 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, |
785 Isolate::Current()->runtime_zone()); | 785 Isolate::Current()->runtime_zone()); |
786 | 786 |
787 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 787 Label fail, backtrack; |
788 Vector<const uc16> foo(foo_chars, 3); | 788 m.PushBacktrack(&fail); |
789 | 789 m.CheckNotAtStart(NULL); |
790 Label fail; | 790 m.LoadCurrentCharacter(2, NULL); |
791 m.CheckCharacters(foo, 0, &fail, true); | 791 m.CheckNotCharacter('o', NULL); |
| 792 m.LoadCurrentCharacter(1, NULL, false); |
| 793 m.CheckNotCharacter('o', NULL); |
| 794 m.LoadCurrentCharacter(0, NULL, false); |
| 795 m.CheckNotCharacter('f', NULL); |
792 m.WriteCurrentPositionToRegister(0, 0); | 796 m.WriteCurrentPositionToRegister(0, 0); |
| 797 m.WriteCurrentPositionToRegister(1, 3); |
793 m.AdvanceCurrentPosition(3); | 798 m.AdvanceCurrentPosition(3); |
794 m.WriteCurrentPositionToRegister(1, 0); | 799 m.PushBacktrack(&backtrack); |
795 m.Succeed(); | 800 m.Succeed(); |
| 801 m.Bind(&backtrack); |
| 802 m.Backtrack(); |
796 m.Bind(&fail); | 803 m.Bind(&fail); |
797 m.Fail(); | 804 m.Fail(); |
798 | 805 |
799 Handle<String> source = factory->NewStringFromAscii(CStrVector("^foo")); | 806 Handle<String> source = factory->NewStringFromAscii(CStrVector("^foo")); |
800 Handle<Object> code_object = m.GetCode(source); | 807 Handle<Object> code_object = m.GetCode(source); |
801 Handle<Code> code = Handle<Code>::cast(code_object); | 808 Handle<Code> code = Handle<Code>::cast(code_object); |
802 | 809 |
803 int captures[4] = {42, 37, 87, 117}; | 810 int captures[4] = {42, 37, 87, 117}; |
804 Handle<String> input = factory->NewStringFromAscii(CStrVector("foofoo")); | 811 Handle<String> input = factory->NewStringFromAscii(CStrVector("foofoo")); |
805 Handle<SeqOneByteString> seq_input = Handle<SeqOneByteString>::cast(input); | 812 Handle<SeqOneByteString> seq_input = Handle<SeqOneByteString>::cast(input); |
(...skipping 29 matching lines...) Expand all Loading... |
835 | 842 |
836 | 843 |
837 TEST(MacroAssemblerNativeSimpleUC16) { | 844 TEST(MacroAssemblerNativeSimpleUC16) { |
838 v8::V8::Initialize(); | 845 v8::V8::Initialize(); |
839 ContextInitializer initializer; | 846 ContextInitializer initializer; |
840 Factory* factory = Isolate::Current()->factory(); | 847 Factory* factory = Isolate::Current()->factory(); |
841 | 848 |
842 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, | 849 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, |
843 Isolate::Current()->runtime_zone()); | 850 Isolate::Current()->runtime_zone()); |
844 | 851 |
845 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 852 Label fail, backtrack; |
846 Vector<const uc16> foo(foo_chars, 3); | 853 m.PushBacktrack(&fail); |
847 | 854 m.CheckNotAtStart(NULL); |
848 Label fail; | 855 m.LoadCurrentCharacter(2, NULL); |
849 m.CheckCharacters(foo, 0, &fail, true); | 856 m.CheckNotCharacter('o', NULL); |
| 857 m.LoadCurrentCharacter(1, NULL, false); |
| 858 m.CheckNotCharacter('o', NULL); |
| 859 m.LoadCurrentCharacter(0, NULL, false); |
| 860 m.CheckNotCharacter('f', NULL); |
850 m.WriteCurrentPositionToRegister(0, 0); | 861 m.WriteCurrentPositionToRegister(0, 0); |
| 862 m.WriteCurrentPositionToRegister(1, 3); |
851 m.AdvanceCurrentPosition(3); | 863 m.AdvanceCurrentPosition(3); |
852 m.WriteCurrentPositionToRegister(1, 0); | 864 m.PushBacktrack(&backtrack); |
853 m.Succeed(); | 865 m.Succeed(); |
| 866 m.Bind(&backtrack); |
| 867 m.Backtrack(); |
854 m.Bind(&fail); | 868 m.Bind(&fail); |
855 m.Fail(); | 869 m.Fail(); |
856 | 870 |
857 Handle<String> source = factory->NewStringFromAscii(CStrVector("^foo")); | 871 Handle<String> source = factory->NewStringFromAscii(CStrVector("^foo")); |
858 Handle<Object> code_object = m.GetCode(source); | 872 Handle<Object> code_object = m.GetCode(source); |
859 Handle<Code> code = Handle<Code>::cast(code_object); | 873 Handle<Code> code = Handle<Code>::cast(code_object); |
860 | 874 |
861 int captures[4] = {42, 37, 87, 117}; | 875 int captures[4] = {42, 37, 87, 117}; |
862 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', | 876 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', |
863 static_cast<uc16>(0x2603)}; | 877 static_cast<uc16>(0x2603)}; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 } | 1356 } |
1343 | 1357 |
1344 #else // V8_INTERPRETED_REGEXP | 1358 #else // V8_INTERPRETED_REGEXP |
1345 | 1359 |
1346 TEST(MacroAssembler) { | 1360 TEST(MacroAssembler) { |
1347 V8::Initialize(NULL); | 1361 V8::Initialize(NULL); |
1348 byte codes[1024]; | 1362 byte codes[1024]; |
1349 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024), | 1363 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024), |
1350 Isolate::Current()->runtime_zone()); | 1364 Isolate::Current()->runtime_zone()); |
1351 // ^f(o)o. | 1365 // ^f(o)o. |
1352 Label fail, fail2, start; | 1366 Label start, fail, backtrack; |
1353 uc16 foo_chars[3]; | 1367 |
1354 foo_chars[0] = 'f'; | |
1355 foo_chars[1] = 'o'; | |
1356 foo_chars[2] = 'o'; | |
1357 Vector<const uc16> foo(foo_chars, 3); | |
1358 m.SetRegister(4, 42); | 1368 m.SetRegister(4, 42); |
1359 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); | 1369 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); |
1360 m.AdvanceRegister(4, 42); | 1370 m.AdvanceRegister(4, 42); |
1361 m.GoTo(&start); | 1371 m.GoTo(&start); |
1362 m.Fail(); | 1372 m.Fail(); |
1363 m.Bind(&start); | 1373 m.Bind(&start); |
1364 m.PushBacktrack(&fail2); | 1374 m.PushBacktrack(&fail); |
1365 m.CheckCharacters(foo, 0, &fail, true); | 1375 m.CheckNotAtStart(NULL); |
| 1376 m.LoadCurrentCharacter(0, NULL); |
| 1377 m.CheckNotCharacter('f', NULL); |
| 1378 m.LoadCurrentCharacter(1, NULL); |
| 1379 m.CheckNotCharacter('o', NULL); |
| 1380 m.LoadCurrentCharacter(2, NULL); |
| 1381 m.CheckNotCharacter('o', NULL); |
1366 m.WriteCurrentPositionToRegister(0, 0); | 1382 m.WriteCurrentPositionToRegister(0, 0); |
1367 m.PushCurrentPosition(); | 1383 m.WriteCurrentPositionToRegister(1, 3); |
| 1384 m.WriteCurrentPositionToRegister(2, 1); |
| 1385 m.WriteCurrentPositionToRegister(3, 2); |
1368 m.AdvanceCurrentPosition(3); | 1386 m.AdvanceCurrentPosition(3); |
1369 m.WriteCurrentPositionToRegister(1, 0); | 1387 m.PushBacktrack(&backtrack); |
1370 m.PopCurrentPosition(); | |
1371 m.AdvanceCurrentPosition(1); | |
1372 m.WriteCurrentPositionToRegister(2, 0); | |
1373 m.AdvanceCurrentPosition(1); | |
1374 m.WriteCurrentPositionToRegister(3, 0); | |
1375 m.Succeed(); | 1388 m.Succeed(); |
1376 | 1389 m.Bind(&backtrack); |
| 1390 m.ClearRegisters(2, 3); |
| 1391 m.Backtrack(); |
1377 m.Bind(&fail); | 1392 m.Bind(&fail); |
1378 m.Backtrack(); | |
1379 m.Succeed(); | |
1380 | |
1381 m.Bind(&fail2); | |
1382 m.PopRegister(0); | 1393 m.PopRegister(0); |
1383 m.Fail(); | 1394 m.Fail(); |
1384 | 1395 |
1385 Isolate* isolate = Isolate::Current(); | 1396 Isolate* isolate = Isolate::Current(); |
1386 Factory* factory = isolate->factory(); | 1397 Factory* factory = isolate->factory(); |
1387 HandleScope scope(isolate); | 1398 HandleScope scope(isolate); |
1388 | 1399 |
1389 Handle<String> source = factory->NewStringFromAscii(CStrVector("^f(o)o")); | 1400 Handle<String> source = factory->NewStringFromAscii(CStrVector("^f(o)o")); |
1390 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode(source)); | 1401 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode(source)); |
1391 int captures[5]; | 1402 int captures[5]; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone()); | 1810 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone()); |
1800 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone()); | 1811 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone()); |
1801 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone()); | 1812 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone()); |
1802 } | 1813 } |
1803 | 1814 |
1804 | 1815 |
1805 TEST(Graph) { | 1816 TEST(Graph) { |
1806 V8::Initialize(NULL); | 1817 V8::Initialize(NULL); |
1807 Execute("\\b\\w+\\b", false, true, true); | 1818 Execute("\\b\\w+\\b", false, true, true); |
1808 } | 1819 } |
OLD | NEW |