Changeset 38621 in webkit for trunk/JavaScriptCore/wrec/WREC.cpp


Ignore:
Timestamp:
Nov 20, 2008, 9:38:50 AM (17 years ago)
Author:
[email protected]
Message:

2008-11-20 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


A little more WREC refactoring.


Removed the "Register" suffix from register names in WREC, and renamed:

currentPosition => index
currentValue => character
quantifierCount => repeatCount


Added a top-level parsePattern function to the WREC parser, which
allowed me to remove the error() and atEndOfPattern() accessors.


Factored out an MSVC customization into a constant.


Renamed nextLabel => beginPattern.

  • wrec/WREC.cpp: (JSC::WREC::compileRegExp):
  • wrec/WRECGenerator.cpp: (JSC::WREC::Generator::generateBacktrack1): (JSC::WREC::Generator::generateBacktrackBackreference): (JSC::WREC::Generator::generateBackreferenceQuantifier): (JSC::WREC::Generator::generateNonGreedyQuantifier): (JSC::WREC::Generator::generateGreedyQuantifier): (JSC::WREC::Generator::generatePatternCharacter): (JSC::WREC::Generator::generateCharacterClassInvertedRange): (JSC::WREC::Generator::generateCharacterClassInverted): (JSC::WREC::Generator::generateCharacterClass): (JSC::WREC::Generator::generateParentheses): (JSC::WREC::Generator::generateParenthesesResetTrampoline): (JSC::WREC::Generator::generateAssertionBOL): (JSC::WREC::Generator::generateAssertionEOL): (JSC::WREC::Generator::generateAssertionWordBoundary): (JSC::WREC::Generator::generateBackreference): (JSC::WREC::Generator::generateDisjunction): (JSC::WREC::Generator::terminateDisjunction):
  • wrec/WRECGenerator.h:
  • wrec/WRECParser.h: (JSC::WREC::Parser::parsePattern):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wrec/WREC.cpp

    r38600 r38621  
    4444static const int MaxPatternSize = (1 << 16);
    4545
     46#if COMPILER(MSVC)
     47// MSVC has 3 extra arguments on the stack because it doesn't use the register calling convention.
     48static const int outputParameter = 16 + sizeof(const UChar*) + sizeof(unsigned) + sizeof(unsigned);
     49#else
     50static const int outputParameter = 16;
     51#endif
     52                   
    4653CompiledRegExp compileRegExp(Interpreter* interpreter, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, bool ignoreCase, bool multiline)
    4754{
     
    5461    Parser parser(pattern, ignoreCase, multiline, assembler);
    5562   
     63    // (0) Setup:
     64    //     Preserve callee save regs and initialize output register.
    5665    __ convertToFastCall();
    57     // (0) Setup:
    58     //     Preserve regs & initialize outputRegister.
    59     __ pushl_r(Generator::outputRegister);
    60     __ pushl_r(Generator::currentValueRegister);
    61     // push pos onto the stack, both to preserve and as a parameter available to parseDisjunction
    62     __ pushl_r(Generator::currentPositionRegister);
    63     // load output pointer
    64     __ movl_mr(16
    65 #if COMPILER(MSVC)
    66                     + 3 * sizeof(void*)
    67 #endif
    68                     , X86::esp, Generator::outputRegister);
     66    __ pushl_r(Generator::output);
     67    __ pushl_r(Generator::character);
     68    __ pushl_r(Generator::index); // load index into TOS as an argument to the top-level disjunction.
     69    __ movl_mr(outputParameter, X86::esp, Generator::output);
    6970
    7071#ifndef NDEBUG
    7172    // ASSERT that the output register is not null.
    72     __ testl_rr(Generator::outputRegister, Generator::outputRegister);
    73     X86Assembler::JmpSrc outputRegisterNotNull = __ jne();
     73    __ testl_rr(Generator::output, Generator::output);
     74    X86Assembler::JmpSrc outputNotNull = __ jne();
    7475    __ int3();
    75     __ link(outputRegisterNotNull, __ label());
     76    __ link(outputNotNull, __ label());
    7677#endif
    7778   
    78     // restart point on match fail.
    79     Generator::JmpDst nextLabel = __ label();
     79    // Restart point for top-level disjunction.
     80    Generator::JmpDst beginPattern = __ label();
    8081
    81     // (1) Parse Disjunction:
    82    
     82    // (1) Parse Pattern:
     83
    8384    JmpSrcVector failures;
    84     parser.parseDisjunction(failures);
    85 
    86     // Parsing the disjunction should fully consume the pattern.
    87     if (!parser.atEndOfPattern() || parser.error()) {
     85    if (!parser.parsePattern(failures)) {
    8886        *error_ptr = "Regular expression malformed.";
    8987        return 0;
     
    9391    //     Set return value & pop registers from the stack.
    9492
    95     __ movl_rm(Generator::currentPositionRegister, 4, Generator::outputRegister);
    9693    __ popl_r(X86::eax);
    97     __ movl_rm(X86::eax, Generator::outputRegister);
    98     __ popl_r(Generator::currentValueRegister);
    99     __ popl_r(Generator::outputRegister);
     94    __ movl_rm(X86::eax, Generator::output); // match begin
     95    __ movl_rm(Generator::index, 4, Generator::output); // match end
     96    __ popl_r(Generator::character);
     97    __ popl_r(Generator::output);
    10098    __ ret();
    10199   
    102100    // (3) Failure:
    103     //     All fails link to here.
    104     Generator::JmpDst here = __ label();
     101    //     All top-level failures link to here.
     102    Generator::JmpDst failure = __ label();
    105103    for (unsigned i = 0; i < failures.size(); ++i)
    106         __ link(failures[i], here);
     104        __ link(failures[i], failure);
    107105    failures.clear();
    108106
    109107    // Move to the next input character and try again.
    110     __ movl_mr(X86::esp, Generator::currentPositionRegister);
    111     __ addl_i8r(1, Generator::currentPositionRegister);
    112     __ movl_rm(Generator::currentPositionRegister, X86::esp);
    113     __ cmpl_rr(Generator::lengthRegister, Generator::currentPositionRegister);
    114     __ link(__ jle(), nextLabel);
     108    __ movl_mr(X86::esp, Generator::index);
     109    __ addl_i8r(1, Generator::index);
     110    __ movl_rm(Generator::index, X86::esp);
     111    __ cmpl_rr(Generator::length, Generator::index);
     112    __ link(__ jle(), beginPattern);
    115113
    116114    // No more input characters: return failure.
    117115    __ addl_i8r(4, X86::esp);
    118116    __ movl_i32r(-1, X86::eax);
    119     __ popl_r(Generator::currentValueRegister);
    120     __ popl_r(Generator::outputRegister);
     117    __ popl_r(Generator::character);
     118    __ popl_r(Generator::output);
    121119    __ ret();
    122120
Note: See TracChangeset for help on using the changeset viewer.