Ignore:
Timestamp:
Nov 17, 2010, 5:15:56 AM (15 years ago)
Author:
Csaba Osztrogonác
Message:

YARR JIT should fallback to YARR Interpreter instead of PCRE.
https://bugs.webkit.org/show_bug.cgi?id=46719

Patch by Peter Varga <[email protected]> on 2010-11-17
Reviewed by Gavin Barraclough.

Remove the ENABLE_YARR macro and the option of matching regular
expressions with PCRE from JavaScriptCore.

JavaScriptCore:

  • runtime/JSGlobalData.h:
  • runtime/RegExp.cpp:

(JSC::RegExp::compile):
(JSC::RegExp::match):

  • tests/mozilla/expected.html:
  • wtf/Platform.h:
  • yarr/RegexCompiler.cpp:
  • yarr/RegexCompiler.h:
  • yarr/RegexInterpreter.cpp:

(JSC::Yarr::byteCompileRegex):

  • yarr/RegexInterpreter.h:
  • yarr/RegexJIT.cpp:

(JSC::Yarr::jitCompileRegex):

  • yarr/RegexJIT.h:

(JSC::Yarr::RegexCodeBlock::RegexCodeBlock):
(JSC::Yarr::RegexCodeBlock::~RegexCodeBlock):
(JSC::Yarr::RegexCodeBlock::getFallback):
(JSC::Yarr::RegexCodeBlock::isFallback):
(JSC::Yarr::RegexCodeBlock::setFallback):
(JSC::Yarr::executeRegex):

  • yarr/RegexParser.h:
  • yarr/RegexPattern.h:

LayoutTests:

  • fast/js/regexp-look-ahead-empty-expected.txt:
  • fast/js/regexp-overflow-expected.txt:
  • fast/js/script-tests/regexp-overflow.js:
  • fast/js/sputnik/Conformance/15_Native_Objects/15.10_RegExp/15.10.2/15.10.2.5_Term/S15.10.2.5_A1_T4-expected.txt:
  • fast/js/sputnik/Conformance/15_Native_Objects/15.10_RegExp/15.10.2/15.10.2.8_Atom/S15.10.2.8_A2_T1-expected.txt:
  • fast/js/sputnik/Conformance/15_Native_Objects/15.10_RegExp/15.10.6/15.10.6.2_RegExp.prototype.exec/S15.10.6.2_A1_T6-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r68639 r72197  
    2929#include <wtf/OwnArrayPtr.h>
    3030
    31 
    32 #if ENABLE(YARR)
    33 
    3431#include "yarr/RegexCompiler.h"
    3532#if ENABLE(YARR_JIT)
     
    3936#endif
    4037
    41 #else
    42 
    43 #include <pcre/pcre.h>
    44 
    45 #endif
    46 
    4738namespace JSC {
    4839
     
    5041#if ENABLE(YARR_JIT)
    5142    Yarr::RegexCodeBlock m_regExpJITCode;
    52 #elif ENABLE(YARR)
     43#else
    5344    OwnPtr<Yarr::BytecodePattern> m_regExpBytecode;
    54 #else
    55     JSRegExp* m_regExp;
    56 #endif
    57 
    58 #if !ENABLE(YARR)
    59     ~RegExpRepresentation()
    60     {
    61         jsRegExpFree(m_regExp);
    62     }
    6345#endif
    6446};
     
    10183}
    10284
    103 #if ENABLE(YARR)
    104 
    10585void RegExp::compile(JSGlobalData* globalData)
    10686{
    10787#if ENABLE(YARR_JIT)
    108     Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, ignoreCase(), multiline());
     88    Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator, ignoreCase(), multiline());
    10989#else
    11090    m_representation->m_regExpBytecode = Yarr::byteCompileRegex(m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator, ignoreCase(), multiline());
     
    129109    if (m_representation->m_regExpBytecode) {
    130110#endif
    131         int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre.
     111        int offsetVectorSize = (m_numSubpatterns + 1) * 2;
    132112        int* offsetVector;
    133113        Vector<int, 32> nonReturnedOvector;
     
    148128
    149129#if ENABLE(YARR_JIT)
    150         int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector, offsetVectorSize);
     130        int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector);
    151131#else
    152132        int result = Yarr::interpretRegex(m_representation->m_regExpBytecode.get(), s.characters(), startOffset, s.length(), offsetVector);
     
    171151    return -1;
    172152}
    173 
    174 #else
    175 
    176 void RegExp::compile(JSGlobalData*)
    177 {
    178     m_representation->m_regExp = 0;
    179     JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase;
    180     JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine;
    181     m_representation->m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.characters()), m_pattern.length(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
    182 }
    183 
    184 int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)
    185 {
    186 #if ENABLE(REGEXP_TRACING)
    187     m_rtMatchCallCount++;
    188 #endif
    189    
    190     if (startOffset < 0)
    191         startOffset = 0;
    192     if (ovector)
    193         ovector->clear();
    194 
    195     if (static_cast<unsigned>(startOffset) > s.length() || s.isNull())
    196         return -1;
    197 
    198     if (m_representation->m_regExp) {
    199         // Set up the offset vector for the result.
    200         // First 2/3 used for result, the last third used by PCRE.
    201         int* offsetVector;
    202         int offsetVectorSize;
    203         int fixedSizeOffsetVector[3];
    204         if (!ovector) {
    205             offsetVectorSize = 3;
    206             offsetVector = fixedSizeOffsetVector;
    207         } else {
    208             offsetVectorSize = (m_numSubpatterns + 1) * 3;
    209             ovector->resize(offsetVectorSize);
    210             offsetVector = ovector->data();
    211         }
    212 
    213         int numMatches = jsRegExpExecute(m_representation->m_regExp, reinterpret_cast<const UChar*>(s.characters()), s.length(), startOffset, offsetVector, offsetVectorSize);
    214    
    215         if (numMatches < 0) {
    216 #ifndef NDEBUG
    217             if (numMatches != JSRegExpErrorNoMatch)
    218                 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);
    219 #endif
    220             if (ovector)
    221                 ovector->clear();
    222             return -1;
    223         }
    224 
    225 #if ENABLE(REGEXP_TRACING)
    226         m_rtMatchFoundCount++;
    227 #endif
    228        
    229         return offsetVector[0];
    230     }
    231 
    232     return -1;
    233 }
    234    
    235 #endif
    236153
    237154#if ENABLE(REGEXP_TRACING)
Note: See TracChangeset for help on using the changeset viewer.