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


Ignore:
Timestamp:
Nov 21, 2008, 11:31:34 AM (17 years ago)
Author:
[email protected]
Message:

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

Reviewed by Sam Weinig.


A little more RegExp refactoring.


Moved all assembly from WREC.cpp into WRECGenerator helper functions.
This should help with portability and readability.


Removed ASSERTs after calls to executableCopy(), and changed
executableCopy() to ASSERT instead.

  • assembler/X86Assembler.h: (JSC::X86Assembler::executableCopy):
  • jit/JIT.cpp: (JSC::JIT::privateCompile): (JSC::JIT::privateCompileGetByIdSelf): (JSC::JIT::privateCompileGetByIdProto): (JSC::JIT::privateCompileGetByIdChain): (JSC::JIT::privateCompilePutByIdReplace): (JSC::JIT::privateCompilePutByIdTransition): (JSC::JIT::privateCompileCTIMachineTrampolines): (JSC::JIT::privateCompilePatchGetArrayLength):
  • wrec/WREC.cpp: (JSC::WREC::compileRegExp):
  • wrec/WRECGenerator.cpp: (JSC::WREC::Generator::generateEnter): (JSC::WREC::Generator::generateReturnSuccess): (JSC::WREC::Generator::generateSaveIndex): (JSC::WREC::Generator::generateIncrementIndex): (JSC::WREC::Generator::generateLoopIfNotEndOfInput): (JSC::WREC::Generator::generateReturnFailure):
  • wrec/WRECGenerator.h:
  • wrec/WRECParser.h: (JSC::WREC::Parser::ignoreCase): (JSC::WREC::Parser::generator):
File:
1 edited

Legend:

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

    r38641 r38669  
    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.
    48 static const int outputParameter = 16 + sizeof(const UChar*) + sizeof(unsigned) + sizeof(unsigned);
    49 #else
    50 static const int outputParameter = 16;
    51 #endif
    52 
    5346CompiledRegExp compileRegExp(Interpreter* interpreter, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, bool ignoreCase, bool multiline)
    5447{
     
    6053    X86Assembler assembler(interpreter->assemblerBuffer());
    6154    Parser parser(pattern, ignoreCase, multiline, assembler);
    62    
    63     // (0) Setup:
    64     //     Preserve callee save regs and initialize output register.
    65     __ convertToFastCall();
    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);
     55    Generator& generator = parser.generator();
     56    JmpSrcVector failures;
    7057
    71 #ifndef NDEBUG
    72     // ASSERT that the output register is not null.
    73     __ testl_rr(Generator::output, Generator::output);
    74     X86Assembler::JmpSrc outputNotNull = __ jne();
    75     __ int3();
    76     __ link(outputNotNull, __ label());
    77 #endif
    78    
    79     // Restart point for top-level disjunction.
     58    generator.generateEnter();
     59    generator.generateSaveIndex();
     60
    8061    Generator::JmpDst beginPattern = __ label();
    81 
    82     // (1) Parse Pattern:
    83 
    84     JmpSrcVector failures;
    8562    if (!parser.parsePattern(failures)) {
    8663        *error_ptr = "Regular expression malformed.";
    8764        return 0;
    8865    }
     66    generator.generateReturnSuccess();
    8967
    90     // (2) Success:
    91     //     Set return value & pop registers from the stack.
    92 
    93     __ popl_r(X86::eax);
    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);
    98     __ ret();
    99    
    100     // (3) Failure:
    101     //     All failures in the top-level disjunction link to here.
    10268    __ link(failures, __ label());
    103 
    104     // Move to the next input character and try again.
    105     __ movl_mr(X86::esp, Generator::index);
    106     __ addl_i8r(1, Generator::index);
    107     __ movl_rm(Generator::index, X86::esp);
    108     __ cmpl_rr(Generator::length, Generator::index);
    109     __ link(__ jle(), beginPattern);
    110 
    111     // No more input characters: return failure.
    112     __ addl_i8r(4, X86::esp);
    113     __ movl_i32r(-1, X86::eax);
    114     __ popl_r(Generator::character);
    115     __ popl_r(Generator::output);
    116     __ ret();
     69    generator.generateIncrementIndex();
     70    generator.generateLoopIfNotEndOfInput(beginPattern);
     71    generator.generateReturnFailure();
    11772
    11873    *numSubpatterns_ptr = parser.numSubpatterns();
    119 
    120     void* code = __ executableCopy();
    121     ASSERT(code);
    122     return reinterpret_cast<CompiledRegExp>(code);
     74    return reinterpret_cast<CompiledRegExp>(__ executableCopy());
    12375}
    12476
Note: See TracChangeset for help on using the changeset viewer.