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 18 matching lines...) Expand all Loading... |
29 #include <stdlib.h> | 29 #include <stdlib.h> |
30 #include <set> | 30 #include <set> |
31 | 31 |
32 #include "v8.h" | 32 #include "v8.h" |
33 | 33 |
34 #include "cctest.h" | 34 #include "cctest.h" |
35 #include "zone-inl.h" | 35 #include "zone-inl.h" |
36 #include "parser.h" | 36 #include "parser.h" |
37 #include "ast.h" | 37 #include "ast.h" |
38 #include "jsregexp-inl.h" | 38 #include "jsregexp-inl.h" |
39 #include "assembler-irregexp.h" | |
40 #include "regexp-macro-assembler.h" | 39 #include "regexp-macro-assembler.h" |
41 #include "regexp-macro-assembler-irregexp.h" | 40 #include "regexp-macro-assembler-irregexp.h" |
42 #ifdef ARM | 41 #ifdef ARM |
43 #include "regexp-macro-assembler-arm.h" | 42 #include "regexp-macro-assembler-arm.h" |
44 #else // IA32 | 43 #else // IA32 |
45 #include "macro-assembler-ia32.h" | 44 #include "macro-assembler-ia32.h" |
46 #include "regexp-macro-assembler-ia32.h" | 45 #include "regexp-macro-assembler-ia32.h" |
47 #endif | 46 #endif |
48 #include "interpreter-irregexp.h" | 47 #include "interpreter-irregexp.h" |
49 | 48 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 uc16* range = ranges[j]; | 511 uc16* range = ranges[j]; |
513 bool is_on = false; | 512 bool is_on = false; |
514 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) | 513 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) |
515 is_on = (range[k] <= p && p <= range[k + 1]); | 514 is_on = (range[k] <= p && p <= range[k + 1]); |
516 CHECK_EQ(is_on, outs->Get(j)); | 515 CHECK_EQ(is_on, outs->Get(j)); |
517 } | 516 } |
518 } | 517 } |
519 } | 518 } |
520 | 519 |
521 | 520 |
522 TEST(Assembler) { | |
523 V8::Initialize(NULL); | |
524 byte codes[1024]; | |
525 IrregexpAssembler assembler(Vector<byte>(codes, 1024)); | |
526 #define __ assembler. | |
527 Label advance; | |
528 Label look_for_foo; | |
529 Label fail; | |
530 __ GoTo(&look_for_foo); | |
531 __ Bind(&advance); | |
532 __ AdvanceCP(1); | |
533 __ Bind(&look_for_foo); | |
534 __ LoadCurrentChar(0, &fail); | |
535 __ CheckNotCharacter('f', &advance); | |
536 __ LoadCurrentChar(1, &fail); | |
537 __ CheckNotCharacter('o', &advance); | |
538 __ LoadCurrentChar(2, &fail); | |
539 __ CheckNotCharacter('o', &advance); | |
540 __ WriteCurrentPositionToRegister(0); | |
541 __ WriteCurrentPositionToRegister(1, 2); | |
542 __ Succeed(); | |
543 __ Bind(&fail); | |
544 __ Fail(); | |
545 | |
546 v8::HandleScope scope; | |
547 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | |
548 assembler.Copy(array->GetDataStartAddress()); | |
549 int captures[2]; | |
550 | |
551 Handle<String> f1 = | |
552 Factory::NewStringFromAscii(CStrVector("Now is the time")); | |
553 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); | |
554 CHECK(!IrregexpInterpreter::Match(array, f1_16, captures, 0)); | |
555 | |
556 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); | |
557 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); | |
558 CHECK(IrregexpInterpreter::Match(array, f2_16, captures, 0)); | |
559 CHECK_EQ(0, captures[0]); | |
560 CHECK_EQ(2, captures[1]); | |
561 | |
562 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); | |
563 Handle<String> f3_16 = RegExpImpl::StringToTwoByte(f3); | |
564 CHECK(IrregexpInterpreter::Match(array, f3_16, captures, 0)); | |
565 CHECK_EQ(3, captures[0]); | |
566 CHECK_EQ(5, captures[1]); | |
567 } | |
568 | |
569 | |
570 TEST(Assembler2) { | |
571 V8::Initialize(NULL); | |
572 byte codes[1024]; | |
573 IrregexpAssembler assembler(Vector<byte>(codes, 1024)); | |
574 #define __ assembler. | |
575 // /^.*foo/ | |
576 Label more_dots; | |
577 Label unwind_dot; | |
578 Label failure; | |
579 Label foo; | |
580 Label foo_failed; | |
581 Label dot_match; | |
582 // ^ | |
583 __ PushCurrentPosition(); | |
584 __ PushRegister(0); | |
585 __ WriteCurrentPositionToRegister(0); | |
586 __ PushBacktrack(&failure); | |
587 __ GoTo(&dot_match); | |
588 // .* | |
589 __ Bind(&more_dots); | |
590 __ AdvanceCP(1); | |
591 __ Bind(&dot_match); | |
592 __ PushCurrentPosition(); | |
593 __ PushBacktrack(&unwind_dot); | |
594 __ LoadCurrentChar(0, &foo); | |
595 __ CheckNotCharacter('\n', &more_dots); | |
596 // foo | |
597 __ Bind(&foo); | |
598 __ CheckNotCharacter('f', &foo_failed); | |
599 __ LoadCurrentChar(1, &foo_failed); | |
600 __ CheckNotCharacter('o', &foo_failed); | |
601 __ LoadCurrentChar(2, &foo_failed); | |
602 __ CheckNotCharacter('o', &foo_failed); | |
603 __ WriteCurrentPositionToRegister(1, 2); | |
604 __ Succeed(); | |
605 __ Break(); | |
606 | |
607 __ Bind(&foo_failed); | |
608 __ PopBacktrack(); | |
609 __ Break(); | |
610 | |
611 __ Bind(&unwind_dot); | |
612 __ PopCurrentPosition(); | |
613 __ LoadCurrentChar(0, &foo_failed); | |
614 __ GoTo(&foo); | |
615 | |
616 __ Bind(&failure); | |
617 __ PopRegister(0); | |
618 __ PopCurrentPosition(); | |
619 __ Fail(); | |
620 | |
621 v8::HandleScope scope; | |
622 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | |
623 assembler.Copy(array->GetDataStartAddress()); | |
624 int captures[2]; | |
625 | |
626 Handle<String> f1 = | |
627 Factory::NewStringFromAscii(CStrVector("Now is the time")); | |
628 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); | |
629 CHECK(!IrregexpInterpreter::Match(array, f1_16, captures, 0)); | |
630 | |
631 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); | |
632 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); | |
633 CHECK(IrregexpInterpreter::Match(array, f2_16, captures, 0)); | |
634 CHECK_EQ(0, captures[0]); | |
635 CHECK_EQ(2, captures[1]); | |
636 | |
637 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); | |
638 Handle<String> f3_16 = RegExpImpl::StringToTwoByte(f3); | |
639 CHECK(IrregexpInterpreter::Match(array, f3_16, captures, 0)); | |
640 CHECK_EQ(0, captures[0]); | |
641 CHECK_EQ(5, captures[1]); | |
642 | |
643 Handle<String> f4 = | |
644 Factory::NewStringFromAscii(CStrVector("football buffoonery")); | |
645 Handle<String> f4_16 = RegExpImpl::StringToTwoByte(f4); | |
646 CHECK(IrregexpInterpreter::Match(array, f4_16, captures, 0)); | |
647 CHECK_EQ(0, captures[0]); | |
648 CHECK_EQ(14, captures[1]); | |
649 | |
650 Handle<String> f5 = | |
651 Factory::NewStringFromAscii(CStrVector("walking\nbarefoot")); | |
652 Handle<String> f5_16 = RegExpImpl::StringToTwoByte(f5); | |
653 CHECK(!IrregexpInterpreter::Match(array, f5_16, captures, 0)); | |
654 } | |
655 | |
656 | |
657 TEST(MacroAssembler) { | 521 TEST(MacroAssembler) { |
658 V8::Initialize(NULL); | 522 V8::Initialize(NULL); |
659 byte codes[1024]; | 523 byte codes[1024]; |
660 IrregexpAssembler assembler(Vector<byte>(codes, 1024)); | 524 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024)); |
661 RegExpMacroAssemblerIrregexp m(&assembler); | |
662 // ^f(o)o. | 525 // ^f(o)o. |
663 Label fail, fail2, start; | 526 Label fail, fail2, start; |
664 uc16 foo_chars[3]; | 527 uc16 foo_chars[3]; |
665 foo_chars[0] = 'f'; | 528 foo_chars[0] = 'f'; |
666 foo_chars[1] = 'o'; | 529 foo_chars[1] = 'o'; |
667 foo_chars[2] = 'o'; | 530 foo_chars[2] = 'o'; |
668 Vector<const uc16> foo(foo_chars, 3); | 531 Vector<const uc16> foo(foo_chars, 3); |
669 m.SetRegister(4, 42); | 532 m.SetRegister(4, 42); |
670 m.PushRegister(4); | 533 m.PushRegister(4); |
671 m.AdvanceRegister(4, 42); | 534 m.AdvanceRegister(4, 42); |
(...skipping 16 matching lines...) Expand all Loading... |
688 m.Bind(&fail); | 551 m.Bind(&fail); |
689 m.Backtrack(); | 552 m.Backtrack(); |
690 m.Succeed(); | 553 m.Succeed(); |
691 | 554 |
692 m.Bind(&fail2); | 555 m.Bind(&fail2); |
693 m.PopRegister(0); | 556 m.PopRegister(0); |
694 m.Fail(); | 557 m.Fail(); |
695 | 558 |
696 v8::HandleScope scope; | 559 v8::HandleScope scope; |
697 | 560 |
698 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); | 561 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode()); |
699 assembler.Copy(array->GetDataStartAddress()); | |
700 int captures[5]; | 562 int captures[5]; |
701 | 563 |
702 Handle<String> f1 = | 564 Handle<String> f1 = |
703 Factory::NewStringFromAscii(CStrVector("foobar")); | 565 Factory::NewStringFromAscii(CStrVector("foobar")); |
704 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); | 566 Handle<String> f1_16 = RegExpImpl::StringToTwoByte(f1); |
705 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0)); | 567 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0)); |
706 CHECK_EQ(0, captures[0]); | 568 CHECK_EQ(0, captures[0]); |
707 CHECK_EQ(3, captures[1]); | 569 CHECK_EQ(3, captures[1]); |
708 CHECK_EQ(1, captures[2]); | 570 CHECK_EQ(1, captures[2]); |
709 CHECK_EQ(2, captures[3]); | 571 CHECK_EQ(2, captures[3]); |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 // whole block at a time. | 1083 // whole block at a time. |
1222 TestSimpleRangeCaseIndependence(CharacterRange('A', 'k'), | 1084 TestSimpleRangeCaseIndependence(CharacterRange('A', 'k'), |
1223 CharacterRange('a', 'z')); | 1085 CharacterRange('a', 'z')); |
1224 } | 1086 } |
1225 | 1087 |
1226 | 1088 |
1227 TEST(Graph) { | 1089 TEST(Graph) { |
1228 V8::Initialize(NULL); | 1090 V8::Initialize(NULL); |
1229 Execute("foo$(?!bar)", false, true); | 1091 Execute("foo$(?!bar)", false, true); |
1230 } | 1092 } |
OLD | NEW |