diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /JavaScriptCore/wrec | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'JavaScriptCore/wrec')
-rw-r--r-- | JavaScriptCore/wrec/WREC.cpp | 7 | ||||
-rw-r--r-- | JavaScriptCore/wrec/WRECGenerator.cpp | 94 | ||||
-rw-r--r-- | JavaScriptCore/wrec/WRECGenerator.h | 22 |
3 files changed, 62 insertions, 61 deletions
diff --git a/JavaScriptCore/wrec/WREC.cpp b/JavaScriptCore/wrec/WREC.cpp index 099931b..145a1ce 100644 --- a/JavaScriptCore/wrec/WREC.cpp +++ b/JavaScriptCore/wrec/WREC.cpp @@ -40,12 +40,9 @@ using namespace WTF; namespace JSC { namespace WREC { -// Patterns longer than this can hang the compiler. -static const int MaxPatternSize = (1 << 13); - CompiledRegExp Generator::compileRegExp(JSGlobalData* globalData, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, RefPtr<ExecutablePool>& pool, bool ignoreCase, bool multiline) { - if (pattern.size() > MaxPatternSize) { + if (pattern.size() > MAX_PATTERN_SIZE) { *error_ptr = "regular expression too large"; return 0; } @@ -80,7 +77,7 @@ CompiledRegExp Generator::compileRegExp(JSGlobalData* globalData, const UString& } *numSubpatterns_ptr = parser.numSubpatterns(); - pool = globalData->poolForSize(generator.size()); + pool = globalData->executableAllocator.poolForSize(generator.size()); return reinterpret_cast<CompiledRegExp>(generator.copyCode(pool.get())); } diff --git a/JavaScriptCore/wrec/WRECGenerator.cpp b/JavaScriptCore/wrec/WRECGenerator.cpp index 4b5f3d4..e2e8aba 100644 --- a/JavaScriptCore/wrec/WRECGenerator.cpp +++ b/JavaScriptCore/wrec/WRECGenerator.cpp @@ -40,16 +40,7 @@ namespace JSC { namespace WREC { void Generator::generateEnter() { -#if PLATFORM(X86_64) - // On x86-64 edi and esi are caller preserved, so nothing to do here. - // The four arguments have been passed in the registers %rdi, %rsi, - // %rdx, %rcx - shuffle these into the expected locations. - move(X86::edi, input); // (arg 1) edi -> eax - move(X86::ecx, output); // (arg 4) ecx -> edi - move(X86::edx, length); // (arg 3) edx -> ecx - move(X86::esi, index); // (arg 2) esi -> edx - -#else +#if PLATFORM(X86) // On x86 edi & esi are callee preserved registers. push(X86::edi); push(X86::esi); @@ -67,24 +58,20 @@ void Generator::generateEnter() peek(output, 3); #endif #endif - -#ifndef NDEBUG - // ASSERT that the output register is not null. - Jump outputNotNull = jnzPtr(output); - breakpoint(); - outputNotNull.link(this); -#endif } void Generator::generateReturnSuccess() { + ASSERT(returnRegister != index); + ASSERT(returnRegister != output); + // Set return value. - pop(X86::eax); // match begin - store32(X86::eax, output); + pop(returnRegister); // match begin + store32(returnRegister, output); store32(index, Address(output, 4)); // match end // Restore callee save registers. -#if !PLATFORM(X86_64) +#if PLATFORM(X86) pop(X86::esi); pop(X86::edi); #endif @@ -100,14 +87,14 @@ void Generator::generateIncrementIndex(Jump* failure) { peek(index); if (failure) - *failure = je32(length, index); + *failure = branch32(Equal, length, index); add32(Imm32(1), index); poke(index); } void Generator::generateLoadCharacter(JumpList& failures) { - failures.append(je32(length, index)); + failures.append(branch32(Equal, length, index)); load16(BaseIndex(input, index, TimesTwo), character); } @@ -115,14 +102,15 @@ void Generator::generateLoadCharacter(JumpList& failures) // were part of the input string. void Generator::generateJumpIfNotEndOfInput(Label target) { - jle32(index, length, target); + branch32(LessThanOrEqual, index, length, target); } void Generator::generateReturnFailure() { pop(); - move(Imm32(-1), X86::eax); -#if !PLATFORM(X86_64) + move(Imm32(-1), returnRegister); + +#if PLATFORM(X86) pop(X86::esi); pop(X86::edi); #endif @@ -145,7 +133,7 @@ void Generator::generateBackreferenceQuantifier(JumpList& failures, Quantifier:: GenerateBackreferenceFunctor functor(subpatternId); load32(Address(output, (2 * subpatternId) * sizeof(int)), character); - Jump skipIfEmpty = je32(Address(output, ((2 * subpatternId) + 1) * sizeof(int)), character); + Jump skipIfEmpty = branch32(Equal, Address(output, ((2 * subpatternId) + 1) * sizeof(int)), character); ASSERT(quantifierType == Quantifier::Greedy || quantifierType == Quantifier::NonGreedy); if (quantifierType == Quantifier::Greedy) @@ -175,7 +163,7 @@ void Generator::generateNonGreedyQuantifier(JumpList& failures, GenerateAtomFunc Label alternativeFailed(this); pop(index); if (max != Quantifier::Infinity) - je32(repeatCount, Imm32(max), quantifierFailed); + branch32(Equal, repeatCount, Imm32(max), quantifierFailed); // (1) Read an atom. if (min) @@ -187,7 +175,7 @@ void Generator::generateNonGreedyQuantifier(JumpList& failures, GenerateAtomFunc // (2) Keep reading if we're under the minimum. if (min > 1) - jl32(repeatCount, Imm32(min), readAtom); + branch32(LessThan, repeatCount, Imm32(min), readAtom); // (3) Test the rest of the alternative. if (!min) @@ -221,7 +209,7 @@ void Generator::generateGreedyQuantifier(JumpList& failures, GenerateAtomFunctor else if (max == 1) doneReadingAtomsList.append(jump()); else { - jne32(repeatCount, Imm32(max), readAtom); + branch32(NotEqual, repeatCount, Imm32(max), readAtom); doneReadingAtomsList.append(jump()); } @@ -238,7 +226,7 @@ void Generator::generateGreedyQuantifier(JumpList& failures, GenerateAtomFunctor // (2) Verify that we have enough atoms. doneReadingAtomsList.link(this); - jl32(repeatCount, Imm32(min), quantifierFailed); + branch32(LessThan, repeatCount, Imm32(min), quantifierFailed); // (3) Test the rest of the alternative. push(index); @@ -277,7 +265,7 @@ bool Generator::generatePatternCharacterPair(JumpList& failures, int ch1, int ch // Optimistically consume 2 characters. add32(Imm32(2), index); - failures.append(jg32(index, length)); + failures.append(branch32(GreaterThan, index, length)); // Load the characters we just consumed, offset -2 characters from index. load32(BaseIndex(input, index, TimesTwo, -2 * 2), character); @@ -306,7 +294,7 @@ bool Generator::generatePatternCharacterPair(JumpList& failures, int ch1, int ch } int pair = ch1 | (ch2 << 16); - failures.append(jne32(character, Imm32(pair))); + failures.append(branch32(NotEqual, character, Imm32(pair))); return true; } @@ -328,14 +316,14 @@ void Generator::generatePatternCharacter(JumpList& failures, int ch) ch |= 32; } else if (!isASCII(ch) && ((lower = Unicode::toLower(ch)) != (upper = Unicode::toUpper(ch)))) { // handle unicode case sentitive characters - branch to success on upper - isUpper = je32(character, Imm32(upper)); + isUpper = branch32(Equal, character, Imm32(upper)); hasUpper = true; ch = lower; } } // checks for ch, or lower case version of ch, if insensitive - failures.append(jne32(character, Imm32((unsigned short)ch))); + failures.append(branch32(NotEqual, character, Imm32((unsigned short)ch))); if (m_parser.ignoreCase() && hasUpper) { // for unicode case insensitive matches, branch here if upper matches. @@ -357,33 +345,33 @@ void Generator::generateCharacterClassInvertedRange(JumpList& failures, JumpList // check if there are any ranges or matches below lo. If not, just jl to failure - // if there is anything else to check, check that first, if it falls through jmp to failure. if ((*matchIndex < matchCount) && (matches[*matchIndex] < lo)) { - Jump loOrAbove = jge32(character, Imm32((unsigned short)lo)); + Jump loOrAbove = branch32(GreaterThanOrEqual, character, Imm32((unsigned short)lo)); // generate code for all ranges before this one if (which) generateCharacterClassInvertedRange(failures, matchDest, ranges, which, matchIndex, matches, matchCount); while ((*matchIndex < matchCount) && (matches[*matchIndex] < lo)) { - matchDest.append(je32(character, Imm32((unsigned short)matches[*matchIndex]))); + matchDest.append(branch32(Equal, character, Imm32((unsigned short)matches[*matchIndex]))); ++*matchIndex; } failures.append(jump()); loOrAbove.link(this); } else if (which) { - Jump loOrAbove = jge32(character, Imm32((unsigned short)lo)); + Jump loOrAbove = branch32(GreaterThanOrEqual, character, Imm32((unsigned short)lo)); generateCharacterClassInvertedRange(failures, matchDest, ranges, which, matchIndex, matches, matchCount); failures.append(jump()); loOrAbove.link(this); } else - failures.append(jl32(character, Imm32((unsigned short)lo))); + failures.append(branch32(LessThan, character, Imm32((unsigned short)lo))); while ((*matchIndex < matchCount) && (matches[*matchIndex] <= hi)) ++*matchIndex; - matchDest.append(jle32(character, Imm32((unsigned short)hi))); + matchDest.append(branch32(LessThanOrEqual, character, Imm32((unsigned short)hi))); // fall through to here, the value is above hi. // shuffle along & loop around if there are any more matches to handle. @@ -397,12 +385,12 @@ void Generator::generateCharacterClassInverted(JumpList& matchDest, const Charac { Jump unicodeFail; if (charClass.numMatchesUnicode || charClass.numRangesUnicode) { - Jump isAscii = jle32(character, Imm32(0x7f)); + Jump isAscii = branch32(LessThanOrEqual, character, Imm32(0x7f)); if (charClass.numMatchesUnicode) { for (unsigned i = 0; i < charClass.numMatchesUnicode; ++i) { UChar ch = charClass.matchesUnicode[i]; - matchDest.append(je32(character, Imm32(ch))); + matchDest.append(branch32(Equal, character, Imm32(ch))); } } @@ -411,8 +399,8 @@ void Generator::generateCharacterClassInverted(JumpList& matchDest, const Charac UChar lo = charClass.rangesUnicode[i].begin; UChar hi = charClass.rangesUnicode[i].end; - Jump below = jl32(character, Imm32(lo)); - matchDest.append(jle32(character, Imm32(hi))); + Jump below = branch32(LessThan, character, Imm32(lo)); + matchDest.append(branch32(LessThanOrEqual, character, Imm32(hi))); below.link(this); } } @@ -426,7 +414,7 @@ void Generator::generateCharacterClassInverted(JumpList& matchDest, const Charac JumpList failures; generateCharacterClassInvertedRange(failures, matchDest, charClass.ranges, charClass.numRanges, &matchIndex, charClass.matches, charClass.numMatches); while (matchIndex < charClass.numMatches) - matchDest.append(je32(character, Imm32((unsigned short)charClass.matches[matchIndex++]))); + matchDest.append(branch32(Equal, character, Imm32((unsigned short)charClass.matches[matchIndex++]))); failures.link(this); } else if (charClass.numMatches) { @@ -443,13 +431,13 @@ void Generator::generateCharacterClassInverted(JumpList& matchDest, const Charac if (isASCIIUpper(ch)) continue; } - matchDest.append(je32(character, Imm32((unsigned short)ch))); + matchDest.append(branch32(Equal, character, Imm32((unsigned short)ch))); } if (unsigned countAZaz = matchesAZaz.size()) { or32(Imm32(32), character); for (unsigned i = 0; i < countAZaz; ++i) - matchDest.append(je32(character, Imm32(matchesAZaz[i]))); + matchDest.append(branch32(Equal, character, Imm32(matchesAZaz[i]))); } } @@ -533,7 +521,7 @@ void Generator::generateAssertionBOL(JumpList& failures) JumpList previousIsNewline; // begin of input == success - previousIsNewline.append(je32(index, Imm32(0))); + previousIsNewline.append(branch32(Equal, index, Imm32(0))); // now check prev char against newline characters. load16(BaseIndex(input, index, TimesTwo, -2), character); @@ -543,7 +531,7 @@ void Generator::generateAssertionBOL(JumpList& failures) previousIsNewline.link(this); } else - failures.append(jne32(index, Imm32(0))); + failures.append(branch32(NotEqual, index, Imm32(0))); } void Generator::generateAssertionEOL(JumpList& failures) @@ -556,7 +544,7 @@ void Generator::generateAssertionEOL(JumpList& failures) failures.append(jump()); nextIsNewline.link(this); } else { - failures.append(jne32(length, index)); + failures.append(branch32(NotEqual, length, index)); } } @@ -568,7 +556,7 @@ void Generator::generateAssertionWordBoundary(JumpList& failures, bool invert) // (1) Check if the previous value was a word char // (1.1) check for begin of input - Jump atBegin = je32(index, Imm32(0)); + Jump atBegin = branch32(Equal, index, Imm32(0)); // (1.2) load the last char, and chck if is word character load16(BaseIndex(input, index, TimesTwo, -2), character); JumpList previousIsWord; @@ -625,14 +613,14 @@ void Generator::generateBackreference(JumpList& failures, unsigned subpatternId) skipIncrement.link(this); // check if we're at the end of backref (if we are, success!) - Jump endOfBackRef = je32(Address(output, ((2 * subpatternId) + 1) * sizeof(int)), repeatCount); + Jump endOfBackRef = branch32(Equal, Address(output, ((2 * subpatternId) + 1) * sizeof(int)), repeatCount); load16(BaseIndex(input, repeatCount, MacroAssembler::TimesTwo), character); // check if we've run out of input (this would be a can o'fail) - Jump endOfInput = je32(length, index); + Jump endOfInput = branch32(Equal, length, index); - je16(character, BaseIndex(input, index, TimesTwo), topOfLoop); + branch16(Equal, BaseIndex(input, index, TimesTwo), character, topOfLoop); endOfInput.link(this); diff --git a/JavaScriptCore/wrec/WRECGenerator.h b/JavaScriptCore/wrec/WRECGenerator.h index af4101a..8562cac 100644 --- a/JavaScriptCore/wrec/WRECGenerator.h +++ b/JavaScriptCore/wrec/WRECGenerator.h @@ -62,13 +62,29 @@ namespace JSC { { } +#if PLATFORM(X86) static const RegisterID input = X86::eax; - static const RegisterID length = X86::ecx; static const RegisterID index = X86::edx; - static const RegisterID character = X86::esi; + static const RegisterID length = X86::ecx; static const RegisterID output = X86::edi; + + static const RegisterID character = X86::esi; static const RegisterID repeatCount = X86::ebx; // How many times the current atom repeats in the current match. - + + static const RegisterID returnRegister = X86::eax; +#endif +#if PLATFORM(X86_64) + static const RegisterID input = X86::edi; + static const RegisterID index = X86::esi; + static const RegisterID length = X86::edx; + static const RegisterID output = X86::ecx; + + static const RegisterID character = X86::eax; + static const RegisterID repeatCount = X86::ebx; // How many times the current atom repeats in the current match. + + static const RegisterID returnRegister = X86::eax; +#endif + void generateEnter(); void generateSaveIndex(); void generateIncrementIndex(Jump* failure = 0); |