Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/3rdparty/masm/yarr/YarrJIT.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||
2 | * Copyright (C) 2009, 2013 Apple Inc. All rights reserved. | - | ||||||||||||||||||
3 | * | - | ||||||||||||||||||
4 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
5 | * modification, are permitted provided that the following conditions | - | ||||||||||||||||||
6 | * are met: | - | ||||||||||||||||||
7 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||||||||
8 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||
9 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
10 | * notice, this list of conditions and the following disclaimer in the | - | ||||||||||||||||||
11 | * documentation and/or other materials provided with the distribution. | - | ||||||||||||||||||
12 | * | - | ||||||||||||||||||
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | - | ||||||||||||||||||
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||||||||
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | - | ||||||||||||||||||
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | - | ||||||||||||||||||
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | - | ||||||||||||||||||
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | - | ||||||||||||||||||
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | - | ||||||||||||||||||
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | - | ||||||||||||||||||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | - | ||||||||||||||||||
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||
24 | */ | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | #include "config.h" | - | ||||||||||||||||||
27 | #include "YarrJIT.h" | - | ||||||||||||||||||
28 | #include <wtf/ASCIICType.h> | - | ||||||||||||||||||
29 | #include "Options.h" | - | ||||||||||||||||||
30 | #include "Yarr.h" | - | ||||||||||||||||||
31 | #include "YarrCanonicalizeUCS2.h" | - | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | #if ENABLE(YARR_JIT) | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | #include "LinkBuffer.h" | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | using namespace WTF; | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | namespace JSC { namespace Yarr { | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | template<YarrJITCompileMode compileMode> | - | ||||||||||||||||||
42 | class YarrGenerator : private DefaultMacroAssembler { | - | ||||||||||||||||||
43 | friend void jitCompile(JSGlobalData*, YarrCodeBlock& jitObject, const String& pattern, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline); | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #if CPU(ARM) | - | ||||||||||||||||||
46 | static const RegisterID input = ARMRegisters::r0; | - | ||||||||||||||||||
47 | static const RegisterID index = ARMRegisters::r1; | - | ||||||||||||||||||
48 | static const RegisterID length = ARMRegisters::r2; | - | ||||||||||||||||||
49 | static const RegisterID output = ARMRegisters::r3; | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | static const RegisterID regT0 = ARMRegisters::r4; | - | ||||||||||||||||||
52 | static const RegisterID regT1 = ARMRegisters::r5; | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | static const RegisterID returnRegister = ARMRegisters::r0; | - | ||||||||||||||||||
55 | static const RegisterID returnRegister2 = ARMRegisters::r1; | - | ||||||||||||||||||
56 | #elif CPU(ARM64) | - | ||||||||||||||||||
57 | static const RegisterID input = ARM64Registers::x0; | - | ||||||||||||||||||
58 | static const RegisterID index = ARM64Registers::x1; | - | ||||||||||||||||||
59 | static const RegisterID length = ARM64Registers::x2; | - | ||||||||||||||||||
60 | static const RegisterID output = ARM64Registers::x3; | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | static const RegisterID regT0 = ARM64Registers::x4; | - | ||||||||||||||||||
63 | static const RegisterID regT1 = ARM64Registers::x5; | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | static const RegisterID returnRegister = ARM64Registers::x0; | - | ||||||||||||||||||
66 | static const RegisterID returnRegister2 = ARM64Registers::x1; | - | ||||||||||||||||||
67 | #elif CPU(MIPS) | - | ||||||||||||||||||
68 | static const RegisterID input = MIPSRegisters::a0; | - | ||||||||||||||||||
69 | static const RegisterID index = MIPSRegisters::a1; | - | ||||||||||||||||||
70 | static const RegisterID length = MIPSRegisters::a2; | - | ||||||||||||||||||
71 | static const RegisterID output = MIPSRegisters::a3; | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | static const RegisterID regT0 = MIPSRegisters::t4; | - | ||||||||||||||||||
74 | static const RegisterID regT1 = MIPSRegisters::t5; | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | static const RegisterID returnRegister = MIPSRegisters::v0; | - | ||||||||||||||||||
77 | static const RegisterID returnRegister2 = MIPSRegisters::v1; | - | ||||||||||||||||||
78 | #elif CPU(SH4) | - | ||||||||||||||||||
79 | static const RegisterID input = SH4Registers::r4; | - | ||||||||||||||||||
80 | static const RegisterID index = SH4Registers::r5; | - | ||||||||||||||||||
81 | static const RegisterID length = SH4Registers::r6; | - | ||||||||||||||||||
82 | static const RegisterID output = SH4Registers::r7; | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | static const RegisterID regT0 = SH4Registers::r0; | - | ||||||||||||||||||
85 | static const RegisterID regT1 = SH4Registers::r1; | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | static const RegisterID returnRegister = SH4Registers::r0; | - | ||||||||||||||||||
88 | static const RegisterID returnRegister2 = SH4Registers::r1; | - | ||||||||||||||||||
89 | #elif CPU(X86) | - | ||||||||||||||||||
90 | static const RegisterID input = X86Registers::eax; | - | ||||||||||||||||||
91 | static const RegisterID index = X86Registers::edx; | - | ||||||||||||||||||
92 | static const RegisterID length = X86Registers::ecx; | - | ||||||||||||||||||
93 | static const RegisterID output = X86Registers::edi; | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | static const RegisterID regT0 = X86Registers::ebx; | - | ||||||||||||||||||
96 | static const RegisterID regT1 = X86Registers::esi; | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | static const RegisterID returnRegister = X86Registers::eax; | - | ||||||||||||||||||
99 | static const RegisterID returnRegister2 = X86Registers::edx; | - | ||||||||||||||||||
100 | #elif CPU(X86_64) | - | ||||||||||||||||||
101 | #if !OS(WINDOWS) | - | ||||||||||||||||||
102 | static const RegisterID input = X86Registers::edi; | - | ||||||||||||||||||
103 | static const RegisterID index = X86Registers::esi; | - | ||||||||||||||||||
104 | static const RegisterID length = X86Registers::edx; | - | ||||||||||||||||||
105 | static const RegisterID output = X86Registers::ecx; | - | ||||||||||||||||||
106 | #else | - | ||||||||||||||||||
107 | // If the return value doesn't fit in 64bits, its destination is pointed by rcx and the parameters are shifted. | - | ||||||||||||||||||
108 | // http://msdn.microsoft.com/en-us/library/7572ztz4.aspx | - | ||||||||||||||||||
109 | COMPILE_ASSERT(sizeof(MatchResult) > sizeof(void*), MatchResult_does_not_fit_in_64bits); | - | ||||||||||||||||||
110 | static const RegisterID input = X86Registers::edx; | - | ||||||||||||||||||
111 | static const RegisterID index = X86Registers::r8; | - | ||||||||||||||||||
112 | static const RegisterID length = X86Registers::r9; | - | ||||||||||||||||||
113 | static const RegisterID output = X86Registers::r10; | - | ||||||||||||||||||
114 | #endif | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | static const RegisterID regT0 = X86Registers::eax; | - | ||||||||||||||||||
117 | static const RegisterID regT1 = X86Registers::ebx; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | static const RegisterID returnRegister = X86Registers::eax; | - | ||||||||||||||||||
120 | static const RegisterID returnRegister2 = X86Registers::edx; | - | ||||||||||||||||||
121 | #endif | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | void optimizeAlternative(PatternAlternative* alternative) | - | ||||||||||||||||||
124 | { | - | ||||||||||||||||||
125 | if (!alternative->m_terms.size())
| 98105-1052025 | ||||||||||||||||||
126 | return; executed 98086 times by 153 tests: return; Executed by:
| 98086 | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | for (unsigned i = 0; i < alternative->m_terms.size() - 1; ++i) {
| 1054988-1321864 | ||||||||||||||||||
129 | PatternTerm& term = alternative->m_terms[i]; | - | ||||||||||||||||||
130 | PatternTerm& nextTerm = alternative->m_terms[i + 1]; | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | if ((term.type == PatternTerm::TypeCharacterClass)
| 2994-1318854 | ||||||||||||||||||
133 | && (term.quantityType == QuantifierFixedCount)
| 1425-1570 | ||||||||||||||||||
134 | && (nextTerm.type == PatternTerm::TypePatternCharacter)
| 458-968 | ||||||||||||||||||
135 | && (nextTerm.quantityType == QuantifierFixedCount)) {
| 4-454 | ||||||||||||||||||
136 | PatternTerm termCopy = term; | - | ||||||||||||||||||
137 | alternative->m_terms[i] = nextTerm; | - | ||||||||||||||||||
138 | alternative->m_terms[i + 1] = termCopy; | - | ||||||||||||||||||
139 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
140 | } executed 1321828 times by 8 tests: end of block Executed by:
| 1321828 | ||||||||||||||||||
141 | } executed 1054186 times by 9 tests: end of block Executed by:
| 1054186 | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | void matchCharacterClassRange(RegisterID character, JumpList& failures, JumpList& matchDest, const CharacterRange* ranges, unsigned count, unsigned* matchIndex, const UChar* matches, unsigned matchCount) | - | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | do { | - | ||||||||||||||||||
146 | // pick which range we're going to generate | - | ||||||||||||||||||
147 | int which = count >> 1; | - | ||||||||||||||||||
148 | char lo = ranges[which].begin; | - | ||||||||||||||||||
149 | char hi = ranges[which].end; | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | // check if there are any ranges or matches below lo. If not, just jl to failure - | - | ||||||||||||||||||
152 | // if there is anything else to check, check that first, if it falls through jmp to failure. | - | ||||||||||||||||||
153 | if ((*matchIndex < matchCount) && (matches[*matchIndex] < lo)) {
| 933-2896 | ||||||||||||||||||
154 | Jump loOrAbove = branch32(GreaterThanOrEqual, character, Imm32((unsigned short)lo)); | - | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | // generate code for all ranges before this one | - | ||||||||||||||||||
157 | if (which)
| 44-1423 | ||||||||||||||||||
158 | matchCharacterClassRange(character, failures, matchDest, ranges, which, matchIndex, matches, matchCount); executed 1423 times by 1 test: matchCharacterClassRange(character, failures, matchDest, ranges, which, matchIndex, matches, matchCount); Executed by:
| 1423 | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | while ((*matchIndex < matchCount) && (matches[*matchIndex] < lo)) {
| 28-1508 | ||||||||||||||||||
161 | matchDest.append(branch32(Equal, character, Imm32((unsigned short)matches[*matchIndex]))); | - | ||||||||||||||||||
162 | ++*matchIndex; | - | ||||||||||||||||||
163 | } executed 1479 times by 1 test: end of block Executed by:
| 1479 | ||||||||||||||||||
164 | failures.append(jump()); | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | loOrAbove.link(this); | - | ||||||||||||||||||
167 | } else if (which) { executed 1467 times by 1 test: end of block Executed by:
| 60-2305 | ||||||||||||||||||
168 | Jump loOrAbove = branch32(GreaterThanOrEqual, character, Imm32((unsigned short)lo)); | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | matchCharacterClassRange(character, failures, matchDest, ranges, which, matchIndex, matches, matchCount); | - | ||||||||||||||||||
171 | failures.append(jump()); | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | loOrAbove.link(this); | - | ||||||||||||||||||
174 | } else executed 60 times by 3 tests: end of block Executed by:
| 60 | ||||||||||||||||||
175 | failures.append(branch32(LessThan, character, Imm32((unsigned short)lo))); executed 2306 times by 6 tests: failures.append(branch32(LessThan, character, Imm32((unsigned short)lo))); Executed by:
| 2306 | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | while ((*matchIndex < matchCount) && (matches[*matchIndex] <= hi))
| 0-2380 | ||||||||||||||||||
178 | ++*matchIndex; never executed: ++*matchIndex; | 0 | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | matchDest.append(branch32(LessThanOrEqual, character, Imm32((unsigned short)hi))); | - | ||||||||||||||||||
181 | // fall through to here, the value is above hi. | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | // shuffle along & loop around if there are any more matches to handle. | - | ||||||||||||||||||
184 | unsigned next = which + 1; | - | ||||||||||||||||||
185 | ranges += next; | - | ||||||||||||||||||
186 | count -= next; | - | ||||||||||||||||||
187 | } while (count); executed 3837 times by 6 tests: end of block Executed by:
| 12-3837 | ||||||||||||||||||
188 | } executed 3824 times by 6 tests: end of block Executed by:
| 3824 | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | void matchCharacterClass(RegisterID character, JumpList& matchDest, const CharacterClass* charClass) | - | ||||||||||||||||||
191 | { | - | ||||||||||||||||||
192 | if (charClass->m_table) {
| 3414-3755 | ||||||||||||||||||
193 | ExtendedAddress tableEntry(character, reinterpret_cast<intptr_t>(charClass->m_table)); | - | ||||||||||||||||||
194 | matchDest.append(branchTest8(charClass->m_tableInverted ? Zero : NonZero, tableEntry)); | - | ||||||||||||||||||
195 | return; executed 3757 times by 3 tests: return; Executed by:
| 3757 | ||||||||||||||||||
196 | } | - | ||||||||||||||||||
197 | Jump unicodeFail; | - | ||||||||||||||||||
198 | if (charClass->m_matchesUnicode.size() || charClass->m_rangesUnicode.size()) {
| 0-2081 | ||||||||||||||||||
199 | Jump isAscii = branch32(LessThanOrEqual, character, TrustedImm32(0x7f)); | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | if (charClass->m_matchesUnicode.size()) {
| 0-2086 | ||||||||||||||||||
202 | for (unsigned i = 0; i < charClass->m_matchesUnicode.size(); ++i) {
| 2088-14040 | ||||||||||||||||||
203 | UChar ch = charClass->m_matchesUnicode[i]; | - | ||||||||||||||||||
204 | matchDest.append(branch32(Equal, character, Imm32(ch))); | - | ||||||||||||||||||
205 | } executed 14042 times by 3 tests: end of block Executed by:
| 14042 | ||||||||||||||||||
206 | } executed 2088 times by 3 tests: end of block Executed by:
| 2088 | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | if (charClass->m_rangesUnicode.size()) {
| 672-1416 | ||||||||||||||||||
209 | for (unsigned i = 0; i < charClass->m_rangesUnicode.size(); ++i) {
| 1415-12631 | ||||||||||||||||||
210 | UChar lo = charClass->m_rangesUnicode[i].begin; | - | ||||||||||||||||||
211 | UChar hi = charClass->m_rangesUnicode[i].end; | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | Jump below = branch32(LessThan, character, Imm32(lo)); | - | ||||||||||||||||||
214 | matchDest.append(branch32(LessThanOrEqual, character, Imm32(hi))); | - | ||||||||||||||||||
215 | below.link(this); | - | ||||||||||||||||||
216 | } executed 12627 times by 1 test: end of block Executed by:
| 12627 | ||||||||||||||||||
217 | } executed 1415 times by 1 test: end of block Executed by:
| 1415 | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | unicodeFail = jump(); | - | ||||||||||||||||||
220 | isAscii.link(this); | - | ||||||||||||||||||
221 | } executed 2086 times by 3 tests: end of block Executed by:
| 2086 | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | if (charClass->m_ranges.size()) {
| 1089-2338 | ||||||||||||||||||
224 | unsigned matchIndex = 0; | - | ||||||||||||||||||
225 | JumpList failures; | - | ||||||||||||||||||
226 | ASSERT(charClass->m_ranges.size() <= UINT_MAX); | - | ||||||||||||||||||
227 | matchCharacterClassRange(character, failures, matchDest, &charClass->m_ranges[0], | - | ||||||||||||||||||
228 | static_cast<unsigned>(charClass->m_ranges.size()), | - | ||||||||||||||||||
229 | &matchIndex, charClass->m_matches.isEmpty() ? 0 : &charClass->m_matches[0], | - | ||||||||||||||||||
230 | static_cast<unsigned>(charClass->m_matches.size())); | - | ||||||||||||||||||
231 | while (matchIndex < charClass->m_matches.size())
| 16-2341 | ||||||||||||||||||
232 | matchDest.append(branch32(Equal, character, Imm32((unsigned short)charClass->m_matches[matchIndex++]))); executed 16 times by 1 test: matchDest.append(branch32(Equal, character, Imm32((unsigned short)charClass->m_matches[matchIndex++]))); Executed by:
| 16 | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | failures.link(this); | - | ||||||||||||||||||
235 | } else if (charClass->m_matches.size()) { executed 2338 times by 6 tests: end of block Executed by:
| 27-2338 | ||||||||||||||||||
236 | // optimization: gather 'a','A' etc back together, can mask & test once. | - | ||||||||||||||||||
237 | Vector<char> matchesAZaz; | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | for (unsigned i = 0; i < charClass->m_matches.size(); ++i) {
| 1064-2403 | ||||||||||||||||||
240 | char ch = charClass->m_matches[i]; | - | ||||||||||||||||||
241 | if (m_pattern.m_ignoreCase) {
| 24-2382 | ||||||||||||||||||
242 | if (isASCIILower(ch)) {
| 4-20 | ||||||||||||||||||
243 | matchesAZaz.append(ch); | - | ||||||||||||||||||
244 | continue; executed 4 times by 1 test: continue; Executed by:
| 4 | ||||||||||||||||||
245 | } | - | ||||||||||||||||||
246 | if (isASCIIUpper(ch))
| 4-16 | ||||||||||||||||||
247 | continue; executed 4 times by 1 test: continue; Executed by:
| 4 | ||||||||||||||||||
248 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||
249 | matchDest.append(branch32(Equal, character, Imm32((unsigned short)ch))); | - | ||||||||||||||||||
250 | } executed 2399 times by 4 tests: end of block Executed by:
| 2399 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | ASSERT(matchesAZaz.size() <= UINT_MAX); | - | ||||||||||||||||||
253 | if (unsigned countAZaz = static_cast<int>(matchesAZaz.size())) {
| 4-1060 | ||||||||||||||||||
254 | or32(TrustedImm32(32), character); | - | ||||||||||||||||||
255 | for (unsigned i = 0; i < countAZaz; ++i)
| 4 | ||||||||||||||||||
256 | matchDest.append(branch32(Equal, character, TrustedImm32(matchesAZaz[i]))); executed 4 times by 1 test: matchDest.append(branch32(Equal, character, TrustedImm32(matchesAZaz[i]))); Executed by:
| 4 | ||||||||||||||||||
257 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
258 | } executed 1064 times by 4 tests: end of block Executed by:
| 1064 | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | if (charClass->m_matchesUnicode.size() || charClass->m_rangesUnicode.size())
| 0-2083 | ||||||||||||||||||
261 | unicodeFail.link(this); executed 2085 times by 3 tests: unicodeFail.link(this); Executed by:
| 2085 | ||||||||||||||||||
262 | } executed 3429 times by 8 tests: end of block Executed by:
| 3429 | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | // Jumps if input not available; will have (incorrectly) incremented already! | - | ||||||||||||||||||
265 | Jump jumpIfNoAvailableInput(unsigned countToCheck = 0) | - | ||||||||||||||||||
266 | { | - | ||||||||||||||||||
267 | if (countToCheck)
| 1050406-1248657 | ||||||||||||||||||
268 | add32(Imm32(countToCheck), index); executed 1050561 times by 9 tests: add32(Imm32(countToCheck), index); Executed by:
| 1050561 | ||||||||||||||||||
269 | return branch32(Above, index, length); executed 2299917 times by 153 tests: return branch32(Above, index, length); Executed by:
| 2299917 | ||||||||||||||||||
270 | } | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | Jump jumpIfAvailableInput(unsigned countToCheck) | - | ||||||||||||||||||
273 | { | - | ||||||||||||||||||
274 | add32(Imm32(countToCheck), index); | - | ||||||||||||||||||
275 | return branch32(BelowOrEqual, index, length); never executed: return branch32(BelowOrEqual, index, length); | 0 | ||||||||||||||||||
276 | } | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | Jump checkInput() | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | return branch32(BelowOrEqual, index, length); executed 2298223 times by 153 tests: return branch32(BelowOrEqual, index, length); Executed by:
| 2298223 | ||||||||||||||||||
281 | } | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | Jump atEndOfInput() | - | ||||||||||||||||||
284 | { | - | ||||||||||||||||||
285 | return branch32(Equal, index, length); executed 2445 times by 8 tests: return branch32(Equal, index, length); Executed by:
| 2445 | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | Jump notAtEndOfInput() | - | ||||||||||||||||||
289 | { | - | ||||||||||||||||||
290 | return branch32(NotEqual, index, length); executed 139 times by 5 tests: return branch32(NotEqual, index, length); Executed by:
| 139 | ||||||||||||||||||
291 | } | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | Jump jumpIfCharNotEquals(UChar ch, int inputPosition, RegisterID character) | - | ||||||||||||||||||
294 | { | - | ||||||||||||||||||
295 | readCharacter(inputPosition, character); | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | // For case-insesitive compares, non-ascii characters that have different | - | ||||||||||||||||||
298 | // upper & lower case representations are converted to a character class. | - | ||||||||||||||||||
299 | ASSERT(!m_pattern.m_ignoreCase || isASCIIAlpha(ch) || isCanonicallyUnique(ch)); | - | ||||||||||||||||||
300 | if (m_pattern.m_ignoreCase && isASCIIAlpha(ch)) {
| 32-789400 | ||||||||||||||||||
301 | or32(TrustedImm32(0x20), character); | - | ||||||||||||||||||
302 | ch |= 0x20; | - | ||||||||||||||||||
303 | } executed 78 times by 3 tests: end of block Executed by:
| 78 | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | return branch32(NotEqual, character, Imm32(ch)); executed 789898 times by 5 tests: return branch32(NotEqual, character, Imm32(ch)); Executed by:
| 789898 | ||||||||||||||||||
306 | } | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | void readCharacter(int inputPosition, RegisterID reg) | - | ||||||||||||||||||
309 | { | - | ||||||||||||||||||
310 | if (m_charSize == Char8)
| 0-796356 | ||||||||||||||||||
311 | load8(BaseIndex(input, index, TimesOne, inputPosition * sizeof(char)), reg); never executed: load8(BaseIndex(input, index, TimesOne, inputPosition * sizeof(char)), reg); | 0 | ||||||||||||||||||
312 | else | - | ||||||||||||||||||
313 | load16(BaseIndex(input, index, TimesTwo, inputPosition * sizeof(UChar)), reg); executed 796380 times by 9 tests: load16(BaseIndex(input, index, TimesTwo, inputPosition * sizeof(UChar)), reg); Executed by:
| 796380 | ||||||||||||||||||
314 | } | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | void storeToFrame(RegisterID reg, unsigned frameLocation) | - | ||||||||||||||||||
317 | { | - | ||||||||||||||||||
318 | poke(reg, frameLocation); | - | ||||||||||||||||||
319 | } executed 2414 times by 8 tests: end of block Executed by:
| 2414 | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | void storeToFrame(TrustedImm32 imm, unsigned frameLocation) | - | ||||||||||||||||||
322 | { | - | ||||||||||||||||||
323 | poke(imm, frameLocation); | - | ||||||||||||||||||
324 | } executed 130 times by 2 tests: end of block Executed by:
| 130 | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | DataLabelPtr storeToFrameWithPatch(unsigned frameLocation) | - | ||||||||||||||||||
327 | { | - | ||||||||||||||||||
328 | return storePtrWithPatch(TrustedImmPtr(0), Address(stackPointerRegister, frameLocation * sizeof(void*))); executed 511 times by 3 tests: return storePtrWithPatch(TrustedImmPtr(0), Address(stackPointerRegister, frameLocation * sizeof(void*))); Executed by:
| 511 | ||||||||||||||||||
329 | } | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | void loadFromFrame(unsigned frameLocation, RegisterID reg) | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | peek(reg, frameLocation); | - | ||||||||||||||||||
334 | } executed 2274 times by 8 tests: end of block Executed by:
| 2274 | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | void loadFromFrameAndJump(unsigned frameLocation) | - | ||||||||||||||||||
337 | { | - | ||||||||||||||||||
338 | jump(Address(stackPointerRegister, frameLocation * sizeof(void*))); | - | ||||||||||||||||||
339 | } executed 164 times by 3 tests: end of block Executed by:
| 164 | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | unsigned alignCallFrameSizeInBytes(unsigned callFrameSize) | - | ||||||||||||||||||
342 | { | - | ||||||||||||||||||
343 | callFrameSize *= sizeof(void*); | - | ||||||||||||||||||
344 | if (callFrameSize / sizeof(void*) != m_pattern.m_body->m_callFrameSize)
| 0-3198 | ||||||||||||||||||
345 | CRASH(); never executed: (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | 0 | ||||||||||||||||||
346 | // Originally, the code was: | - | ||||||||||||||||||
347 | // callFrameSize = (callFrameSize + 0x3f) & ~0x3f; | - | ||||||||||||||||||
348 | // However, 64 bytes is a bit surprising. The biggest "alignment" requirement is on Aarch64, where: | - | ||||||||||||||||||
349 | // "SP mod 16 = 0. The stack must be quad-word aligned." (IHI0055B_aapcs64.pdf) | - | ||||||||||||||||||
350 | callFrameSize = (callFrameSize + 0xf) & ~0xf; | - | ||||||||||||||||||
351 | if (!callFrameSize)
| 0-3199 | ||||||||||||||||||
352 | CRASH(); never executed: (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | 0 | ||||||||||||||||||
353 | return callFrameSize; executed 3196 times by 8 tests: return callFrameSize; Executed by:
| 3196 | ||||||||||||||||||
354 | } | - | ||||||||||||||||||
355 | void initCallFrame() | - | ||||||||||||||||||
356 | { | - | ||||||||||||||||||
357 | unsigned callFrameSize = m_pattern.m_body->m_callFrameSize; | - | ||||||||||||||||||
358 | if (callFrameSize)
| 1138-1145957 | ||||||||||||||||||
359 | subPtr(Imm32(alignCallFrameSizeInBytes(callFrameSize)), stackPointerRegister); executed 1139 times by 8 tests: subPtr(Imm32(alignCallFrameSizeInBytes(callFrameSize)), stackPointerRegister); Executed by:
| 1139 | ||||||||||||||||||
360 | } executed 1146835 times by 153 tests: end of block Executed by:
| 1146835 | ||||||||||||||||||
361 | void removeCallFrame() | - | ||||||||||||||||||
362 | { | - | ||||||||||||||||||
363 | unsigned callFrameSize = m_pattern.m_body->m_callFrameSize; | - | ||||||||||||||||||
364 | if (callFrameSize)
| 2067-2299007 | ||||||||||||||||||
365 | addPtr(Imm32(alignCallFrameSizeInBytes(callFrameSize)), stackPointerRegister); executed 2067 times by 8 tests: addPtr(Imm32(alignCallFrameSizeInBytes(callFrameSize)), stackPointerRegister); Executed by:
| 2067 | ||||||||||||||||||
366 | } executed 2301104 times by 153 tests: end of block Executed by:
| 2301104 | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | // Used to record subpatters, should only be called if compileMode is IncludeSubpatterns. | - | ||||||||||||||||||
369 | void setSubpatternStart(RegisterID reg, unsigned subpattern) | - | ||||||||||||||||||
370 | { | - | ||||||||||||||||||
371 | ASSERT(subpattern); | - | ||||||||||||||||||
372 | // FIXME: should be able to ASSERT(compileMode == IncludeSubpatterns), but then this function is conditionally NORETURN. :-( | - | ||||||||||||||||||
373 | store32(reg, Address(output, (subpattern << 1) * sizeof(int))); | - | ||||||||||||||||||
374 | } executed 1478 times by 3 tests: end of block Executed by:
| 1478 | ||||||||||||||||||
375 | void setSubpatternEnd(RegisterID reg, unsigned subpattern) | - | ||||||||||||||||||
376 | { | - | ||||||||||||||||||
377 | ASSERT(subpattern); | - | ||||||||||||||||||
378 | // FIXME: should be able to ASSERT(compileMode == IncludeSubpatterns), but then this function is conditionally NORETURN. :-( | - | ||||||||||||||||||
379 | store32(reg, Address(output, ((subpattern << 1) + 1) * sizeof(int))); | - | ||||||||||||||||||
380 | } executed 1478 times by 3 tests: end of block Executed by:
| 1478 | ||||||||||||||||||
381 | void clearSubpatternStart(unsigned subpattern) | - | ||||||||||||||||||
382 | { | - | ||||||||||||||||||
383 | ASSERT(subpattern); | - | ||||||||||||||||||
384 | // FIXME: should be able to ASSERT(compileMode == IncludeSubpatterns), but then this function is conditionally NORETURN. :-( | - | ||||||||||||||||||
385 | store32(TrustedImm32(-1), Address(output, (subpattern << 1) * sizeof(int))); | - | ||||||||||||||||||
386 | } executed 1476 times by 3 tests: end of block Executed by:
| 1476 | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | // We use one of three different strategies to track the start of the current match, | - | ||||||||||||||||||
389 | // while matching. | - | ||||||||||||||||||
390 | // 1) If the pattern has a fixed size, do nothing! - we calculate the value lazily | - | ||||||||||||||||||
391 | // at the end of matching. This is irrespective of compileMode, and in this case | - | ||||||||||||||||||
392 | // these methods should never be called. | - | ||||||||||||||||||
393 | // 2) If we're compiling IncludeSubpatterns, 'output' contains a pointer to an output | - | ||||||||||||||||||
394 | // vector, store the match start in the output vector. | - | ||||||||||||||||||
395 | // 3) If we're compiling MatchOnly, 'output' is unused, store the match start directly | - | ||||||||||||||||||
396 | // in this register. | - | ||||||||||||||||||
397 | void setMatchStart(RegisterID reg) | - | ||||||||||||||||||
398 | { | - | ||||||||||||||||||
399 | ASSERT(!m_pattern.m_body->m_hasFixedSize); | - | ||||||||||||||||||
400 | if (compileMode == IncludeSubpatterns)
| 0-3424 | ||||||||||||||||||
401 | store32(reg, output); executed 3422 times by 8 tests: store32(reg, output); Executed by:
| 3422 | ||||||||||||||||||
402 | else | - | ||||||||||||||||||
403 | move(reg, output); never executed: move(reg, output); | 0 | ||||||||||||||||||
404 | } | - | ||||||||||||||||||
405 | void getMatchStart(RegisterID reg) | - | ||||||||||||||||||
406 | { | - | ||||||||||||||||||
407 | ASSERT(!m_pattern.m_body->m_hasFixedSize); | - | ||||||||||||||||||
408 | if (compileMode == IncludeSubpatterns)
| 0-1197 | ||||||||||||||||||
409 | load32(output, reg); executed 1197 times by 8 tests: load32(output, reg); Executed by:
| 1197 | ||||||||||||||||||
410 | else | - | ||||||||||||||||||
411 | move(output, reg); never executed: move(output, reg); | 0 | ||||||||||||||||||
412 | } | - | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | enum YarrOpCode { | - | ||||||||||||||||||
415 | // These nodes wrap body alternatives - those in the main disjunction, | - | ||||||||||||||||||
416 | // rather than subpatterns or assertions. These are chained together in | - | ||||||||||||||||||
417 | // a doubly linked list, with a 'begin' node for the first alternative, | - | ||||||||||||||||||
418 | // a 'next' node for each subsequent alternative, and an 'end' node at | - | ||||||||||||||||||
419 | // the end. In the case of repeating alternatives, the 'end' node also | - | ||||||||||||||||||
420 | // has a reference back to 'begin'. | - | ||||||||||||||||||
421 | OpBodyAlternativeBegin, | - | ||||||||||||||||||
422 | OpBodyAlternativeNext, | - | ||||||||||||||||||
423 | OpBodyAlternativeEnd, | - | ||||||||||||||||||
424 | // Similar to the body alternatives, but used for subpatterns with two | - | ||||||||||||||||||
425 | // or more alternatives. | - | ||||||||||||||||||
426 | OpNestedAlternativeBegin, | - | ||||||||||||||||||
427 | OpNestedAlternativeNext, | - | ||||||||||||||||||
428 | OpNestedAlternativeEnd, | - | ||||||||||||||||||
429 | // Used for alternatives in subpatterns where there is only a single | - | ||||||||||||||||||
430 | // alternative (backtrackingis easier in these cases), or for alternatives | - | ||||||||||||||||||
431 | // which never need to be backtracked (those in parenthetical assertions, | - | ||||||||||||||||||
432 | // terminal subpatterns). | - | ||||||||||||||||||
433 | OpSimpleNestedAlternativeBegin, | - | ||||||||||||||||||
434 | OpSimpleNestedAlternativeNext, | - | ||||||||||||||||||
435 | OpSimpleNestedAlternativeEnd, | - | ||||||||||||||||||
436 | // Used to wrap 'Once' subpattern matches (quantityCount == 1). | - | ||||||||||||||||||
437 | OpParenthesesSubpatternOnceBegin, | - | ||||||||||||||||||
438 | OpParenthesesSubpatternOnceEnd, | - | ||||||||||||||||||
439 | // Used to wrap 'Terminal' subpattern matches (at the end of the regexp). | - | ||||||||||||||||||
440 | OpParenthesesSubpatternTerminalBegin, | - | ||||||||||||||||||
441 | OpParenthesesSubpatternTerminalEnd, | - | ||||||||||||||||||
442 | // Used to wrap parenthetical assertions. | - | ||||||||||||||||||
443 | OpParentheticalAssertionBegin, | - | ||||||||||||||||||
444 | OpParentheticalAssertionEnd, | - | ||||||||||||||||||
445 | // Wraps all simple terms (pattern characters, character classes). | - | ||||||||||||||||||
446 | OpTerm, | - | ||||||||||||||||||
447 | // Where an expression contains only 'once through' body alternatives | - | ||||||||||||||||||
448 | // and no repeating ones, this op is used to return match failure. | - | ||||||||||||||||||
449 | OpMatchFailed | - | ||||||||||||||||||
450 | }; | - | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | // This structure is used to hold the compiled opcode information, | - | ||||||||||||||||||
453 | // including reference back to the original PatternTerm/PatternAlternatives, | - | ||||||||||||||||||
454 | // and JIT compilation data structures. | - | ||||||||||||||||||
455 | struct YarrOp { | - | ||||||||||||||||||
456 | explicit YarrOp(PatternTerm* term) | - | ||||||||||||||||||
457 | : m_op(OpTerm) | - | ||||||||||||||||||
458 | , m_term(term) | - | ||||||||||||||||||
459 | , m_isDeadCode(false) | - | ||||||||||||||||||
460 | { | - | ||||||||||||||||||
461 | } executed 2373561 times by 9 tests: end of block Executed by:
| 2373561 | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | explicit YarrOp(YarrOpCode op) | - | ||||||||||||||||||
464 | : m_op(op) | - | ||||||||||||||||||
465 | , m_isDeadCode(false) | - | ||||||||||||||||||
466 | { | - | ||||||||||||||||||
467 | } executed 2312673 times by 153 tests: end of block Executed by:
| 2312673 | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | // The operation, as a YarrOpCode, and also a reference to the PatternTerm. | - | ||||||||||||||||||
470 | YarrOpCode m_op; | - | ||||||||||||||||||
471 | PatternTerm* m_term = nullptr; | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | // For alternatives, this holds the PatternAlternative and doubly linked | - | ||||||||||||||||||
474 | // references to this alternative's siblings. In the case of the | - | ||||||||||||||||||
475 | // OpBodyAlternativeEnd node at the end of a section of repeating nodes, | - | ||||||||||||||||||
476 | // m_nextOp will reference the OpBodyAlternativeBegin node of the first | - | ||||||||||||||||||
477 | // repeating alternative. | - | ||||||||||||||||||
478 | PatternAlternative* m_alternative = nullptr; | - | ||||||||||||||||||
479 | size_t m_previousOp = 0; | - | ||||||||||||||||||
480 | size_t m_nextOp = 0; | - | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | // Used to record a set of Jumps out of the generated code, typically | - | ||||||||||||||||||
483 | // used for jumps out to backtracking code, and a single reentry back | - | ||||||||||||||||||
484 | // into the code for a node (likely where a backtrack will trigger | - | ||||||||||||||||||
485 | // rematching). | - | ||||||||||||||||||
486 | Label m_reentry; | - | ||||||||||||||||||
487 | JumpList m_jumps; | - | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | // Used for backtracking when the prior alternative did not consume any | - | ||||||||||||||||||
490 | // characters but matched. | - | ||||||||||||||||||
491 | Jump m_zeroLengthMatch; | - | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | // This flag is used to null out the second pattern character, when | - | ||||||||||||||||||
494 | // two are fused to match a pair together. | - | ||||||||||||||||||
495 | bool m_isDeadCode; | - | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | // Currently used in the case of some of the more complex management of | - | ||||||||||||||||||
498 | // 'm_checked', to cache the offset used in this alternative, to avoid | - | ||||||||||||||||||
499 | // recalculating it. | - | ||||||||||||||||||
500 | int m_checkAdjust; | - | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | // Used by OpNestedAlternativeNext/End to hold the pointer to the | - | ||||||||||||||||||
503 | // value that will be pushed into the pattern's frame to return to, | - | ||||||||||||||||||
504 | // upon backtracking back into the disjunction. | - | ||||||||||||||||||
505 | DataLabelPtr m_returnAddress; | - | ||||||||||||||||||
506 | }; | - | ||||||||||||||||||
507 | - | |||||||||||||||||||
508 | // BacktrackingState | - | ||||||||||||||||||
509 | // This class encapsulates information about the state of code generation | - | ||||||||||||||||||
510 | // whilst generating the code for backtracking, when a term fails to match. | - | ||||||||||||||||||
511 | // Upon entry to code generation of the backtracking code for a given node, | - | ||||||||||||||||||
512 | // the Backtracking state will hold references to all control flow sources | - | ||||||||||||||||||
513 | // that are outputs in need of further backtracking from the prior node | - | ||||||||||||||||||
514 | // generated (which is the subsequent operation in the regular expression, | - | ||||||||||||||||||
515 | // and in the m_ops Vector, since we generated backtracking backwards). | - | ||||||||||||||||||
516 | // These references to control flow take the form of: | - | ||||||||||||||||||
517 | // - A jump list of jumps, to be linked to code that will backtrack them | - | ||||||||||||||||||
518 | // further. | - | ||||||||||||||||||
519 | // - A set of DataLabelPtr values, to be populated with values to be | - | ||||||||||||||||||
520 | // treated effectively as return addresses backtracking into complex | - | ||||||||||||||||||
521 | // subpatterns. | - | ||||||||||||||||||
522 | // - A flag indicating that the current sequence of generated code up to | - | ||||||||||||||||||
523 | // this point requires backtracking. | - | ||||||||||||||||||
524 | class BacktrackingState { | - | ||||||||||||||||||
525 | public: | - | ||||||||||||||||||
526 | BacktrackingState() | - | ||||||||||||||||||
527 | : m_pendingFallthrough(false) | - | ||||||||||||||||||
528 | { | - | ||||||||||||||||||
529 | } executed 1148632 times by 153 tests: end of block Executed by:
| 1148632 | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | // Add a jump or jumps, a return address, or set the flag indicating | - | ||||||||||||||||||
532 | // that the current 'fallthrough' control flow requires backtracking. | - | ||||||||||||||||||
533 | void append(const Jump& jump) | - | ||||||||||||||||||
534 | { | - | ||||||||||||||||||
535 | m_laterFailures.append(jump); | - | ||||||||||||||||||
536 | } executed 2176 times by 8 tests: end of block Executed by:
| 2176 | ||||||||||||||||||
537 | void append(JumpList& jumpList) | - | ||||||||||||||||||
538 | { | - | ||||||||||||||||||
539 | m_laterFailures.append(jumpList); | - | ||||||||||||||||||
540 | } executed 2379600 times by 9 tests: end of block Executed by:
| 2379600 | ||||||||||||||||||
541 | void append(const DataLabelPtr& returnAddress) | - | ||||||||||||||||||
542 | { | - | ||||||||||||||||||
543 | m_pendingReturns.append(returnAddress); | - | ||||||||||||||||||
544 | } executed 512 times by 3 tests: end of block Executed by:
| 512 | ||||||||||||||||||
545 | void fallthrough() | - | ||||||||||||||||||
546 | { | - | ||||||||||||||||||
547 | ASSERT(!m_pendingFallthrough); | - | ||||||||||||||||||
548 | m_pendingFallthrough = true; | - | ||||||||||||||||||
549 | } executed 1854 times by 3 tests: end of block Executed by:
| 1854 | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | // These methods clear the backtracking state, either linking to the | - | ||||||||||||||||||
552 | // current location, a provided label, or copying the backtracking out | - | ||||||||||||||||||
553 | // to a JumpList. All actions may require code generation to take place, | - | ||||||||||||||||||
554 | // and as such are passed a pointer to the assembler. | - | ||||||||||||||||||
555 | void link(MacroAssembler* assembler) | - | ||||||||||||||||||
556 | { | - | ||||||||||||||||||
557 | if (m_pendingReturns.size()) {
| 76-1154950 | ||||||||||||||||||
558 | Label here(assembler); | - | ||||||||||||||||||
559 | for (unsigned i = 0; i < m_pendingReturns.size(); ++i)
| 76 | ||||||||||||||||||
560 | m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], here)); executed 76 times by 3 tests: m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], here)); Executed by:
| 76 | ||||||||||||||||||
561 | m_pendingReturns.clear(); | - | ||||||||||||||||||
562 | } executed 76 times by 3 tests: end of block Executed by:
| 76 | ||||||||||||||||||
563 | m_laterFailures.link(assembler); | - | ||||||||||||||||||
564 | m_laterFailures.clear(); | - | ||||||||||||||||||
565 | m_pendingFallthrough = false; | - | ||||||||||||||||||
566 | } executed 1154003 times by 153 tests: end of block Executed by:
| 1154003 | ||||||||||||||||||
567 | void linkTo(Label label, MacroAssembler* assembler) | - | ||||||||||||||||||
568 | { | - | ||||||||||||||||||
569 | if (m_pendingReturns.size()) {
| 288-416 | ||||||||||||||||||
570 | for (unsigned i = 0; i < m_pendingReturns.size(); ++i)
| 287-288 | ||||||||||||||||||
571 | m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], label)); executed 286 times by 1 test: m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], label)); Executed by:
| 286 | ||||||||||||||||||
572 | m_pendingReturns.clear(); | - | ||||||||||||||||||
573 | } executed 287 times by 1 test: end of block Executed by:
| 287 | ||||||||||||||||||
574 | if (m_pendingFallthrough)
| 108-594 | ||||||||||||||||||
575 | assembler->jump(label); executed 108 times by 1 test: assembler->jump(label); Executed by:
| 108 | ||||||||||||||||||
576 | m_laterFailures.linkTo(label, assembler); | - | ||||||||||||||||||
577 | m_laterFailures.clear(); | - | ||||||||||||||||||
578 | m_pendingFallthrough = false; | - | ||||||||||||||||||
579 | } executed 704 times by 5 tests: end of block Executed by:
| 704 | ||||||||||||||||||
580 | void takeBacktracksToJumpList(JumpList& jumpList, MacroAssembler* assembler) | - | ||||||||||||||||||
581 | { | - | ||||||||||||||||||
582 | if (m_pendingReturns.size()) {
| 58-145 | ||||||||||||||||||
583 | Label here(assembler); | - | ||||||||||||||||||
584 | for (unsigned i = 0; i < m_pendingReturns.size(); ++i)
| 146-148 | ||||||||||||||||||
585 | m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], here)); executed 147 times by 2 tests: m_backtrackRecords.append(ReturnAddressRecord(m_pendingReturns[i], here)); Executed by:
| 147 | ||||||||||||||||||
586 | m_pendingReturns.clear(); | - | ||||||||||||||||||
587 | m_pendingFallthrough = true; | - | ||||||||||||||||||
588 | } executed 148 times by 2 tests: end of block Executed by:
| 148 | ||||||||||||||||||
589 | if (m_pendingFallthrough)
| 40-166 | ||||||||||||||||||
590 | jumpList.append(assembler->jump()); executed 165 times by 3 tests: jumpList.append(assembler->jump()); Executed by:
| 165 | ||||||||||||||||||
591 | jumpList.append(m_laterFailures); | - | ||||||||||||||||||
592 | m_laterFailures.clear(); | - | ||||||||||||||||||
593 | m_pendingFallthrough = false; | - | ||||||||||||||||||
594 | } executed 206 times by 3 tests: end of block Executed by:
| 206 | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | bool isEmpty() | - | ||||||||||||||||||
597 | { | - | ||||||||||||||||||
598 | return m_laterFailures.empty() && m_pendingReturns.isEmpty() && !m_pendingFallthrough; executed 2298275 times by 153 tests: return m_laterFailures.empty() && m_pendingReturns.isEmpty() && !m_pendingFallthrough; Executed by:
| 2298275 | ||||||||||||||||||
599 | } | - | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | // Called at the end of code generation to link all return addresses. | - | ||||||||||||||||||
602 | void linkDataLabels(LinkBuffer<JSC::DefaultMacroAssembler>& linkBuffer) | - | ||||||||||||||||||
603 | { | - | ||||||||||||||||||
604 | ASSERT(isEmpty()); | - | ||||||||||||||||||
605 | for (unsigned i = 0; i < m_backtrackRecords.size(); ++i)
| 512-1150961 | ||||||||||||||||||
606 | linkBuffer.patch(m_backtrackRecords[i].m_dataLabel, linkBuffer.locationOf(m_backtrackRecords[i].m_backtrackLocation)); executed 512 times by 3 tests: linkBuffer.patch(m_backtrackRecords[i].m_dataLabel, linkBuffer.locationOf(m_backtrackRecords[i].m_backtrackLocation)); Executed by:
| 512 | ||||||||||||||||||
607 | } executed 1151131 times by 153 tests: end of block Executed by:
| 1151131 | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | private: | - | ||||||||||||||||||
610 | struct ReturnAddressRecord { | - | ||||||||||||||||||
611 | ReturnAddressRecord(DataLabelPtr dataLabel, Label backtrackLocation) | - | ||||||||||||||||||
612 | : m_dataLabel(dataLabel) | - | ||||||||||||||||||
613 | , m_backtrackLocation(backtrackLocation) | - | ||||||||||||||||||
614 | { | - | ||||||||||||||||||
615 | } executed 509 times by 3 tests: end of block Executed by:
| 509 | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | DataLabelPtr m_dataLabel; | - | ||||||||||||||||||
618 | Label m_backtrackLocation; | - | ||||||||||||||||||
619 | }; | - | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | JumpList m_laterFailures; | - | ||||||||||||||||||
622 | bool m_pendingFallthrough; | - | ||||||||||||||||||
623 | Vector<DataLabelPtr, 4> m_pendingReturns; | - | ||||||||||||||||||
624 | Vector<ReturnAddressRecord, 4> m_backtrackRecords; | - | ||||||||||||||||||
625 | }; | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | // Generation methods: | - | ||||||||||||||||||
628 | // =================== | - | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | // This method provides a default implementation of backtracking common | - | ||||||||||||||||||
631 | // to many terms; terms commonly jump out of the forwards matching path | - | ||||||||||||||||||
632 | // on any failed conditions, and add these jumps to the m_jumps list. If | - | ||||||||||||||||||
633 | // no special handling is required we can often just backtrack to m_jumps. | - | ||||||||||||||||||
634 | void backtrackTermDefault(size_t opIndex) | - | ||||||||||||||||||
635 | { | - | ||||||||||||||||||
636 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
637 | m_backtrackingState.append(op.m_jumps); | - | ||||||||||||||||||
638 | } executed 2371685 times by 9 tests: end of block Executed by:
| 2371685 | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | void generateAssertionBOL(size_t opIndex) | - | ||||||||||||||||||
641 | { | - | ||||||||||||||||||
642 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
643 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | if (m_pattern.m_multiline) {
| 20-134 | ||||||||||||||||||
646 | const RegisterID character = regT0; | - | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | JumpList matchDest; | - | ||||||||||||||||||
649 | if (!term->inputPosition)
| 0-20 | ||||||||||||||||||
650 | matchDest.append(branch32(Equal, index, Imm32(m_checked))); executed 20 times by 1 test: matchDest.append(branch32(Equal, index, Imm32(m_checked))); Executed by:
| 20 | ||||||||||||||||||
651 | - | |||||||||||||||||||
652 | readCharacter((term->inputPosition - m_checked) - 1, character); | - | ||||||||||||||||||
653 | matchCharacterClass(character, matchDest, m_pattern.newlineCharacterClass()); | - | ||||||||||||||||||
654 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | matchDest.link(this); | - | ||||||||||||||||||
657 | } else { executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
658 | // Erk, really should poison out these alternatives early. :-/ | - | ||||||||||||||||||
659 | if (term->inputPosition)
| 8-126 | ||||||||||||||||||
660 | op.m_jumps.append(jump()); executed 8 times by 1 test: op.m_jumps.append(jump()); Executed by:
| 8 | ||||||||||||||||||
661 | else | - | ||||||||||||||||||
662 | op.m_jumps.append(branch32(NotEqual, index, Imm32(m_checked))); executed 126 times by 5 tests: op.m_jumps.append(branch32(NotEqual, index, Imm32(m_checked))); Executed by:
| 126 | ||||||||||||||||||
663 | } | - | ||||||||||||||||||
664 | } | - | ||||||||||||||||||
665 | void backtrackAssertionBOL(size_t opIndex) | - | ||||||||||||||||||
666 | { | - | ||||||||||||||||||
667 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
668 | } executed 154 times by 5 tests: end of block Executed by:
| 154 | ||||||||||||||||||
669 | - | |||||||||||||||||||
670 | void generateAssertionEOL(size_t opIndex) | - | ||||||||||||||||||
671 | { | - | ||||||||||||||||||
672 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
673 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | if (m_pattern.m_multiline) {
| 16-139 | ||||||||||||||||||
676 | const RegisterID character = regT0; | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | JumpList matchDest; | - | ||||||||||||||||||
679 | if (term->inputPosition == m_checked)
| 0-16 | ||||||||||||||||||
680 | matchDest.append(atEndOfInput()); executed 16 times by 1 test: matchDest.append(atEndOfInput()); Executed by:
| 16 | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | readCharacter(term->inputPosition - m_checked, character); | - | ||||||||||||||||||
683 | matchCharacterClass(character, matchDest, m_pattern.newlineCharacterClass()); | - | ||||||||||||||||||
684 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | matchDest.link(this); | - | ||||||||||||||||||
687 | } else { executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
688 | if (term->inputPosition == m_checked)
| 0-139 | ||||||||||||||||||
689 | op.m_jumps.append(notAtEndOfInput()); executed 139 times by 5 tests: op.m_jumps.append(notAtEndOfInput()); Executed by:
| 139 | ||||||||||||||||||
690 | // Erk, really should poison out these alternatives early. :-/ | - | ||||||||||||||||||
691 | else | - | ||||||||||||||||||
692 | op.m_jumps.append(jump()); never executed: op.m_jumps.append(jump()); | 0 | ||||||||||||||||||
693 | } | - | ||||||||||||||||||
694 | } | - | ||||||||||||||||||
695 | void backtrackAssertionEOL(size_t opIndex) | - | ||||||||||||||||||
696 | { | - | ||||||||||||||||||
697 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
698 | } executed 155 times by 5 tests: end of block Executed by:
| 155 | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | // Also falls though on nextIsNotWordChar. | - | ||||||||||||||||||
701 | void matchAssertionWordchar(size_t opIndex, JumpList& nextIsWordChar, JumpList& nextIsNotWordChar) | - | ||||||||||||||||||
702 | { | - | ||||||||||||||||||
703 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
704 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
705 | - | |||||||||||||||||||
706 | const RegisterID character = regT0; | - | ||||||||||||||||||
707 | - | |||||||||||||||||||
708 | if (term->inputPosition == m_checked)
| 224-2032 | ||||||||||||||||||
709 | nextIsNotWordChar.append(atEndOfInput()); executed 224 times by 1 test: nextIsNotWordChar.append(atEndOfInput()); Executed by:
| 224 | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | readCharacter((term->inputPosition - m_checked), character); | - | ||||||||||||||||||
712 | matchCharacterClass(character, nextIsWordChar, m_pattern.wordcharCharacterClass()); | - | ||||||||||||||||||
713 | } executed 2255 times by 1 test: end of block Executed by:
| 2255 | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | void generateAssertionWordBoundary(size_t opIndex) | - | ||||||||||||||||||
716 | { | - | ||||||||||||||||||
717 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
718 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | const RegisterID character = regT0; | - | ||||||||||||||||||
721 | - | |||||||||||||||||||
722 | Jump atBegin; | - | ||||||||||||||||||
723 | JumpList matchDest; | - | ||||||||||||||||||
724 | if (!term->inputPosition)
| 247-880 | ||||||||||||||||||
725 | atBegin = branch32(Equal, index, Imm32(m_checked)); executed 247 times by 1 test: atBegin = branch32(Equal, index, Imm32(m_checked)); Executed by:
| 247 | ||||||||||||||||||
726 | readCharacter((term->inputPosition - m_checked) - 1, character); | - | ||||||||||||||||||
727 | matchCharacterClass(character, matchDest, m_pattern.wordcharCharacterClass()); | - | ||||||||||||||||||
728 | if (!term->inputPosition)
| 248-880 | ||||||||||||||||||
729 | atBegin.link(this); executed 248 times by 1 test: atBegin.link(this); Executed by:
| 248 | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | // We fall through to here if the last character was not a wordchar. | - | ||||||||||||||||||
732 | JumpList nonWordCharThenWordChar; | - | ||||||||||||||||||
733 | JumpList nonWordCharThenNonWordChar; | - | ||||||||||||||||||
734 | if (term->invert()) {
| 84-1044 | ||||||||||||||||||
735 | matchAssertionWordchar(opIndex, nonWordCharThenNonWordChar, nonWordCharThenWordChar); | - | ||||||||||||||||||
736 | nonWordCharThenWordChar.append(jump()); | - | ||||||||||||||||||
737 | } else { executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||||||||
738 | matchAssertionWordchar(opIndex, nonWordCharThenWordChar, nonWordCharThenNonWordChar); | - | ||||||||||||||||||
739 | nonWordCharThenNonWordChar.append(jump()); | - | ||||||||||||||||||
740 | } executed 1044 times by 1 test: end of block Executed by:
| 1044 | ||||||||||||||||||
741 | op.m_jumps.append(nonWordCharThenNonWordChar); | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | // We jump here if the last character was a wordchar. | - | ||||||||||||||||||
744 | matchDest.link(this); | - | ||||||||||||||||||
745 | JumpList wordCharThenWordChar; | - | ||||||||||||||||||
746 | JumpList wordCharThenNonWordChar; | - | ||||||||||||||||||
747 | if (term->invert()) {
| 84-1044 | ||||||||||||||||||
748 | matchAssertionWordchar(opIndex, wordCharThenNonWordChar, wordCharThenWordChar); | - | ||||||||||||||||||
749 | wordCharThenWordChar.append(jump()); | - | ||||||||||||||||||
750 | } else { executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||||||||
751 | matchAssertionWordchar(opIndex, wordCharThenWordChar, wordCharThenNonWordChar); | - | ||||||||||||||||||
752 | // This can fall-though! | - | ||||||||||||||||||
753 | } executed 1044 times by 1 test: end of block Executed by:
| 1044 | ||||||||||||||||||
754 | - | |||||||||||||||||||
755 | op.m_jumps.append(wordCharThenWordChar); | - | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | nonWordCharThenWordChar.link(this); | - | ||||||||||||||||||
758 | wordCharThenNonWordChar.link(this); | - | ||||||||||||||||||
759 | } executed 1127 times by 1 test: end of block Executed by:
| 1127 | ||||||||||||||||||
760 | void backtrackAssertionWordBoundary(size_t opIndex) | - | ||||||||||||||||||
761 | { | - | ||||||||||||||||||
762 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
763 | } executed 1127 times by 1 test: end of block Executed by:
| 1127 | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | void generatePatternCharacterOnce(size_t opIndex) | - | ||||||||||||||||||
766 | { | - | ||||||||||||||||||
767 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | if (op.m_isDeadCode)
| 789416-1575565 | ||||||||||||||||||
770 | return; executed 789193 times by 5 tests: return; Executed by:
| 789193 | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | // m_ops always ends with a OpBodyAlternativeEnd or OpMatchFailed | - | ||||||||||||||||||
773 | // node, so there must always be at least one more node. | - | ||||||||||||||||||
774 | ASSERT(opIndex + 1 < m_ops.size()); | - | ||||||||||||||||||
775 | YarrOp* nextOp = &m_ops[opIndex + 1]; | - | ||||||||||||||||||
776 | - | |||||||||||||||||||
777 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
778 | UChar ch = term->patternCharacter; | - | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | if ((ch > 0xff) && (m_charSize == Char8)) {
| 0-795117 | ||||||||||||||||||
781 | // Have a 16 bit pattern character and an 8 bit string - short circuit | - | ||||||||||||||||||
782 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
783 | return; never executed: return; | 0 | ||||||||||||||||||
784 | } | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | const RegisterID character = regT0; | - | ||||||||||||||||||
787 | int maxCharactersAtOnce = m_charSize == Char8 ? 4 : 2;
| 0-1575640 | ||||||||||||||||||
788 | unsigned ignoreCaseMask = 0; | - | ||||||||||||||||||
789 | #if CPU(BIG_ENDIAN) | - | ||||||||||||||||||
790 | int allCharacters = ch << (m_charSize == Char8 ? 24 : 16); | - | ||||||||||||||||||
791 | #else | - | ||||||||||||||||||
792 | int allCharacters = ch; | - | ||||||||||||||||||
793 | #endif | - | ||||||||||||||||||
794 | int numberCharacters; | - | ||||||||||||||||||
795 | int startTermPosition = term->inputPosition; | - | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | // For case-insesitive compares, non-ascii characters that have different | - | ||||||||||||||||||
798 | // upper & lower case representations are converted to a character class. | - | ||||||||||||||||||
799 | ASSERT(!m_pattern.m_ignoreCase || isASCIIAlpha(ch) || isCanonicallyUnique(ch)); | - | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | if (m_pattern.m_ignoreCase && isASCIIAlpha(ch))
| 40-1575222 | ||||||||||||||||||
802 | #if CPU(BIG_ENDIAN) | - | ||||||||||||||||||
803 | ignoreCaseMask |= 32 << (m_charSize == Char8 ? 24 : 16); | - | ||||||||||||||||||
804 | #else | - | ||||||||||||||||||
805 | ignoreCaseMask |= 32; executed 201 times by 3 tests: ignoreCaseMask |= 32; Executed by:
| 201 | ||||||||||||||||||
806 | #endif | - | ||||||||||||||||||
807 | - | |||||||||||||||||||
808 | for (numberCharacters = 1; numberCharacters < maxCharactersAtOnce && nextOp->m_op == OpTerm; ++numberCharacters, nextOp = &m_ops[opIndex + numberCharacters]) {
| 788200-1579245 | ||||||||||||||||||
809 | PatternTerm* nextTerm = nextOp->m_term; | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | if (nextTerm->type != PatternTerm::TypePatternCharacter
| 1141-788846 | ||||||||||||||||||
812 | || nextTerm->quantityType != QuantifierFixedCount
| 100-789342 | ||||||||||||||||||
813 | || nextTerm->quantityCount != 1
| 4-789416 | ||||||||||||||||||
814 | || nextTerm->inputPosition != (startTermPosition + numberCharacters))
| 30-789349 | ||||||||||||||||||
815 | break; executed 1275 times by 4 tests: break; Executed by:
| 1275 | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | nextOp->m_isDeadCode = true; | - | ||||||||||||||||||
818 | - | |||||||||||||||||||
819 | #if CPU(BIG_ENDIAN) | - | ||||||||||||||||||
820 | int shiftAmount = (m_charSize == Char8 ? 24 : 16) - ((m_charSize == Char8 ? 8 : 16) * numberCharacters); | - | ||||||||||||||||||
821 | #else | - | ||||||||||||||||||
822 | int shiftAmount = (m_charSize == Char8 ? 8 : 16) * numberCharacters;
| 0-788825 | ||||||||||||||||||
823 | #endif | - | ||||||||||||||||||
824 | - | |||||||||||||||||||
825 | UChar currentCharacter = nextTerm->patternCharacter; | - | ||||||||||||||||||
826 | - | |||||||||||||||||||
827 | if ((currentCharacter > 0xff) && (m_charSize == Char8)) {
| 0-528327 | ||||||||||||||||||
828 | // Have a 16 bit pattern character and an 8 bit string - short circuit | - | ||||||||||||||||||
829 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
830 | return; never executed: return; | 0 | ||||||||||||||||||
831 | } | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | // For case-insesitive compares, non-ascii characters that have different | - | ||||||||||||||||||
834 | // upper & lower case representations are converted to a character class. | - | ||||||||||||||||||
835 | ASSERT(!m_pattern.m_ignoreCase || isASCIIAlpha(currentCharacter) || isCanonicallyUnique(currentCharacter)); | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | allCharacters |= (currentCharacter << shiftAmount); | - | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | if ((m_pattern.m_ignoreCase) && (isASCIIAlpha(currentCharacter)))
| 14-788566 | ||||||||||||||||||
840 | ignoreCaseMask |= 32 << shiftAmount; executed 137 times by 3 tests: ignoreCaseMask |= 32 << shiftAmount; Executed by:
| 137 | ||||||||||||||||||
841 | } executed 788656 times by 5 tests: end of block Executed by:
| 788656 | ||||||||||||||||||
842 | - | |||||||||||||||||||
843 | if (m_charSize == Char8) {
| 0-1577934 | ||||||||||||||||||
844 | switch (numberCharacters) { | - | ||||||||||||||||||
845 | case 1: never executed: case 1: | 0 | ||||||||||||||||||
846 | op.m_jumps.append(jumpIfCharNotEquals(ch, startTermPosition - m_checked, character)); | - | ||||||||||||||||||
847 | return; never executed: return; | 0 | ||||||||||||||||||
848 | case 2: { never executed: case 2: | 0 | ||||||||||||||||||
849 | BaseIndex address(input, index, TimesOne, (startTermPosition - m_checked) * sizeof(LChar)); | - | ||||||||||||||||||
850 | load16Unaligned(address, character); | - | ||||||||||||||||||
851 | break; never executed: break; | 0 | ||||||||||||||||||
852 | } | - | ||||||||||||||||||
853 | case 3: { never executed: case 3: | 0 | ||||||||||||||||||
854 | BaseIndex highAddress(input, index, TimesOne, (startTermPosition - m_checked) * sizeof(LChar)); | - | ||||||||||||||||||
855 | load16Unaligned(highAddress, character); | - | ||||||||||||||||||
856 | if (ignoreCaseMask)
| 0 | ||||||||||||||||||
857 | or32(Imm32(ignoreCaseMask), character); never executed: or32(Imm32(ignoreCaseMask), character); | 0 | ||||||||||||||||||
858 | op.m_jumps.append(branch32(NotEqual, character, Imm32((allCharacters & 0xffff) | ignoreCaseMask))); | - | ||||||||||||||||||
859 | op.m_jumps.append(jumpIfCharNotEquals(allCharacters >> 16, startTermPosition + 2 - m_checked, character)); | - | ||||||||||||||||||
860 | return; never executed: return; | 0 | ||||||||||||||||||
861 | } | - | ||||||||||||||||||
862 | case 4: { never executed: case 4: | 0 | ||||||||||||||||||
863 | BaseIndex address(input, index, TimesOne, (startTermPosition - m_checked) * sizeof(LChar)); | - | ||||||||||||||||||
864 | load32WithUnalignedHalfWords(address, character); | - | ||||||||||||||||||
865 | break; never executed: break; | 0 | ||||||||||||||||||
866 | } | - | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
868 | } else { never executed: end of block | 0 | ||||||||||||||||||
869 | switch (numberCharacters) { | - | ||||||||||||||||||
870 | case 1: executed 789795 times by 5 tests: case 1: Executed by:
| 789795 | ||||||||||||||||||
871 | op.m_jumps.append(jumpIfCharNotEquals(ch, term->inputPosition - m_checked, character)); | - | ||||||||||||||||||
872 | return; executed 789751 times by 5 tests: return; Executed by:
| 789751 | ||||||||||||||||||
873 | case 2: executed 788772 times by 5 tests: case 2: Executed by:
| 788772 | ||||||||||||||||||
874 | BaseIndex address(input, index, TimesTwo, (term->inputPosition - m_checked) * sizeof(UChar)); | - | ||||||||||||||||||
875 | load32WithUnalignedHalfWords(address, character); | - | ||||||||||||||||||
876 | break; executed 789302 times by 5 tests: break; Executed by:
| 789302 | ||||||||||||||||||
877 | } | - | ||||||||||||||||||
878 | } executed 789163 times by 5 tests: end of block Executed by:
| 789163 | ||||||||||||||||||
879 | - | |||||||||||||||||||
880 | if (ignoreCaseMask)
| 148-789059 | ||||||||||||||||||
881 | or32(Imm32(ignoreCaseMask), character); executed 148 times by 3 tests: or32(Imm32(ignoreCaseMask), character); Executed by:
| 148 | ||||||||||||||||||
882 | op.m_jumps.append(branch32(NotEqual, character, Imm32(allCharacters | ignoreCaseMask))); | - | ||||||||||||||||||
883 | return; executed 789168 times by 5 tests: return; Executed by:
| 789168 | ||||||||||||||||||
884 | } | - | ||||||||||||||||||
885 | void backtrackPatternCharacterOnce(size_t opIndex) | - | ||||||||||||||||||
886 | { | - | ||||||||||||||||||
887 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
888 | } executed 2368455 times by 6 tests: end of block Executed by:
| 2368455 | ||||||||||||||||||
889 | - | |||||||||||||||||||
890 | void generatePatternCharacterFixed(size_t opIndex) | - | ||||||||||||||||||
891 | { | - | ||||||||||||||||||
892 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
893 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
894 | UChar ch = term->patternCharacter; | - | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | const RegisterID character = regT0; | - | ||||||||||||||||||
897 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | move(index, countRegister); | - | ||||||||||||||||||
900 | sub32(Imm32(term->quantityCount.unsafeGet()), countRegister); | - | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | Label loop(this); | - | ||||||||||||||||||
903 | BaseIndex address(input, countRegister, m_charScale, (Checked<int>(term->inputPosition - m_checked + Checked<int64_t>(term->quantityCount)) * static_cast<int>(m_charSize == Char8 ? sizeof(char) : sizeof(UChar))).unsafeGet()); | - | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | if (m_charSize == Char8)
| 0-32 | ||||||||||||||||||
906 | load8(address, character); never executed: load8(address, character); | 0 | ||||||||||||||||||
907 | else | - | ||||||||||||||||||
908 | load16(address, character); executed 32 times by 2 tests: load16(address, character); Executed by:
| 32 | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | // For case-insesitive compares, non-ascii characters that have different | - | ||||||||||||||||||
911 | // upper & lower case representations are converted to a character class. | - | ||||||||||||||||||
912 | ASSERT(!m_pattern.m_ignoreCase || isASCIIAlpha(ch) || isCanonicallyUnique(ch)); | - | ||||||||||||||||||
913 | if (m_pattern.m_ignoreCase && isASCIIAlpha(ch)) {
| 0-32 | ||||||||||||||||||
914 | or32(TrustedImm32(0x20), character); | - | ||||||||||||||||||
915 | ch |= 0x20; | - | ||||||||||||||||||
916 | } never executed: end of block | 0 | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | op.m_jumps.append(branch32(NotEqual, character, Imm32(ch))); | - | ||||||||||||||||||
919 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
920 | branch32(NotEqual, countRegister, index).linkTo(loop, this); | - | ||||||||||||||||||
921 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
922 | void backtrackPatternCharacterFixed(size_t opIndex) | - | ||||||||||||||||||
923 | { | - | ||||||||||||||||||
924 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
925 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | void generatePatternCharacterGreedy(size_t opIndex) | - | ||||||||||||||||||
928 | { | - | ||||||||||||||||||
929 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
930 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
931 | UChar ch = term->patternCharacter; | - | ||||||||||||||||||
932 | - | |||||||||||||||||||
933 | const RegisterID character = regT0; | - | ||||||||||||||||||
934 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
935 | - | |||||||||||||||||||
936 | move(TrustedImm32(0), countRegister); | - | ||||||||||||||||||
937 | - | |||||||||||||||||||
938 | // Unless have a 16 bit pattern character and an 8 bit string - short circuit | - | ||||||||||||||||||
939 | if (!((ch > 0xff) && (m_charSize == Char8))) {
| 0-242 | ||||||||||||||||||
940 | JumpList failures; | - | ||||||||||||||||||
941 | Label loop(this); | - | ||||||||||||||||||
942 | failures.append(atEndOfInput()); | - | ||||||||||||||||||
943 | failures.append(jumpIfCharNotEquals(ch, term->inputPosition - m_checked, character)); | - | ||||||||||||||||||
944 | - | |||||||||||||||||||
945 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
946 | add32(TrustedImm32(1), index); | - | ||||||||||||||||||
947 | if (term->quantityCount == quantifyInfinite)
| 112-130 | ||||||||||||||||||
948 | jump(loop); executed 112 times by 2 tests: jump(loop); Executed by:
| 112 | ||||||||||||||||||
949 | else | - | ||||||||||||||||||
950 | branch32(NotEqual, countRegister, Imm32(term->quantityCount.unsafeGet())).linkTo(loop, this); executed 130 times by 2 tests: branch32(NotEqual, countRegister, Imm32(term->quantityCount.unsafeGet())).linkTo(loop, this); Executed by:
| 130 | ||||||||||||||||||
951 | - | |||||||||||||||||||
952 | failures.link(this); | - | ||||||||||||||||||
953 | } executed 242 times by 2 tests: end of block Executed by:
| 242 | ||||||||||||||||||
954 | op.m_reentry = label(); | - | ||||||||||||||||||
955 | - | |||||||||||||||||||
956 | storeToFrame(countRegister, term->frameLocation); | - | ||||||||||||||||||
957 | } executed 242 times by 2 tests: end of block Executed by:
| 242 | ||||||||||||||||||
958 | void backtrackPatternCharacterGreedy(size_t opIndex) | - | ||||||||||||||||||
959 | { | - | ||||||||||||||||||
960 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
961 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
962 | - | |||||||||||||||||||
963 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
964 | - | |||||||||||||||||||
965 | m_backtrackingState.link(this); | - | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | loadFromFrame(term->frameLocation, countRegister); | - | ||||||||||||||||||
968 | m_backtrackingState.append(branchTest32(Zero, countRegister)); | - | ||||||||||||||||||
969 | sub32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
970 | sub32(TrustedImm32(1), index); | - | ||||||||||||||||||
971 | jump(op.m_reentry); | - | ||||||||||||||||||
972 | } executed 242 times by 2 tests: end of block Executed by:
| 242 | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | void generatePatternCharacterNonGreedy(size_t opIndex) | - | ||||||||||||||||||
975 | { | - | ||||||||||||||||||
976 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
977 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
980 | - | |||||||||||||||||||
981 | move(TrustedImm32(0), countRegister); | - | ||||||||||||||||||
982 | op.m_reentry = label(); | - | ||||||||||||||||||
983 | storeToFrame(countRegister, term->frameLocation); | - | ||||||||||||||||||
984 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
985 | void backtrackPatternCharacterNonGreedy(size_t opIndex) | - | ||||||||||||||||||
986 | { | - | ||||||||||||||||||
987 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
988 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
989 | UChar ch = term->patternCharacter; | - | ||||||||||||||||||
990 | - | |||||||||||||||||||
991 | const RegisterID character = regT0; | - | ||||||||||||||||||
992 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
993 | - | |||||||||||||||||||
994 | m_backtrackingState.link(this); | - | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | loadFromFrame(term->frameLocation, countRegister); | - | ||||||||||||||||||
997 | - | |||||||||||||||||||
998 | // Unless have a 16 bit pattern character and an 8 bit string - short circuit | - | ||||||||||||||||||
999 | if (!((ch > 0xff) && (m_charSize == Char8))) {
| 0-2 | ||||||||||||||||||
1000 | JumpList nonGreedyFailures; | - | ||||||||||||||||||
1001 | nonGreedyFailures.append(atEndOfInput()); | - | ||||||||||||||||||
1002 | if (term->quantityCount != quantifyInfinite)
| 0-2 | ||||||||||||||||||
1003 | nonGreedyFailures.append(branch32(Equal, countRegister, Imm32(term->quantityCount.unsafeGet()))); executed 2 times by 1 test: nonGreedyFailures.append(branch32(Equal, countRegister, Imm32(term->quantityCount.unsafeGet()))); Executed by:
| 2 | ||||||||||||||||||
1004 | nonGreedyFailures.append(jumpIfCharNotEquals(ch, term->inputPosition - m_checked, character)); | - | ||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
1007 | add32(TrustedImm32(1), index); | - | ||||||||||||||||||
1008 | - | |||||||||||||||||||
1009 | jump(op.m_reentry); | - | ||||||||||||||||||
1010 | nonGreedyFailures.link(this); | - | ||||||||||||||||||
1011 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | sub32(countRegister, index); | - | ||||||||||||||||||
1014 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
1015 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | void generateCharacterClassOnce(size_t opIndex) | - | ||||||||||||||||||
1018 | { | - | ||||||||||||||||||
1019 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1020 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | const RegisterID character = regT0; | - | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | JumpList matchDest; | - | ||||||||||||||||||
1025 | readCharacter(term->inputPosition - m_checked, character); | - | ||||||||||||||||||
1026 | matchCharacterClass(character, matchDest, term->characterClass); | - | ||||||||||||||||||
1027 | - | |||||||||||||||||||
1028 | if (term->invert())
| 647-842 | ||||||||||||||||||
1029 | op.m_jumps.append(matchDest); executed 646 times by 2 tests: op.m_jumps.append(matchDest); Executed by:
| 646 | ||||||||||||||||||
1030 | else { | - | ||||||||||||||||||
1031 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
1032 | matchDest.link(this); | - | ||||||||||||||||||
1033 | } executed 843 times by 8 tests: end of block Executed by:
| 843 | ||||||||||||||||||
1034 | } | - | ||||||||||||||||||
1035 | void backtrackCharacterClassOnce(size_t opIndex) | - | ||||||||||||||||||
1036 | { | - | ||||||||||||||||||
1037 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
1038 | } executed 1489 times by 8 tests: end of block Executed by:
| 1489 | ||||||||||||||||||
1039 | - | |||||||||||||||||||
1040 | void generateCharacterClassFixed(size_t opIndex) | - | ||||||||||||||||||
1041 | { | - | ||||||||||||||||||
1042 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1043 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1044 | - | |||||||||||||||||||
1045 | const RegisterID character = regT0; | - | ||||||||||||||||||
1046 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
1047 | - | |||||||||||||||||||
1048 | move(index, countRegister); | - | ||||||||||||||||||
1049 | sub32(Imm32(term->quantityCount.unsafeGet()), countRegister); | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | Label loop(this); | - | ||||||||||||||||||
1052 | JumpList matchDest; | - | ||||||||||||||||||
1053 | if (m_charSize == Char8)
| 0-292 | ||||||||||||||||||
1054 | load8(BaseIndex(input, countRegister, TimesOne, (Checked<int>(term->inputPosition - m_checked + Checked<int64_t>(term->quantityCount)) * static_cast<int>(sizeof(char))).unsafeGet()), character); never executed: load8(BaseIndex(input, countRegister, TimesOne, (Checked<int>(term->inputPosition - m_checked + Checked<int64_t>(term->quantityCount)) * static_cast<int>(sizeof(char))).unsafeGet()), character); | 0 | ||||||||||||||||||
1055 | else | - | ||||||||||||||||||
1056 | load16(BaseIndex(input, countRegister, TimesTwo, (Checked<int>(term->inputPosition - m_checked + Checked<int64_t>(term->quantityCount)) * static_cast<int>(sizeof(UChar))).unsafeGet()), character); executed 292 times by 2 tests: load16(BaseIndex(input, countRegister, TimesTwo, (Checked<int>(term->inputPosition - m_checked + Checked<int64_t>(term->quantityCount)) * static_cast<int>(sizeof(UChar))).unsafeGet()), character); Executed by:
| 292 | ||||||||||||||||||
1057 | matchCharacterClass(character, matchDest, term->characterClass); | - | ||||||||||||||||||
1058 | - | |||||||||||||||||||
1059 | if (term->invert())
| 24-268 | ||||||||||||||||||
1060 | op.m_jumps.append(matchDest); executed 24 times by 1 test: op.m_jumps.append(matchDest); Executed by:
| 24 | ||||||||||||||||||
1061 | else { | - | ||||||||||||||||||
1062 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
1063 | matchDest.link(this); | - | ||||||||||||||||||
1064 | } executed 270 times by 2 tests: end of block Executed by:
| 270 | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
1067 | branch32(NotEqual, countRegister, index).linkTo(loop, this); | - | ||||||||||||||||||
1068 | } executed 292 times by 2 tests: end of block Executed by:
| 292 | ||||||||||||||||||
1069 | void backtrackCharacterClassFixed(size_t opIndex) | - | ||||||||||||||||||
1070 | { | - | ||||||||||||||||||
1071 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
1072 | } executed 292 times by 2 tests: end of block Executed by:
| 292 | ||||||||||||||||||
1073 | - | |||||||||||||||||||
1074 | void generateCharacterClassGreedy(size_t opIndex) | - | ||||||||||||||||||
1075 | { | - | ||||||||||||||||||
1076 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1077 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | const RegisterID character = regT0; | - | ||||||||||||||||||
1080 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | move(TrustedImm32(0), countRegister); | - | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | JumpList failures; | - | ||||||||||||||||||
1085 | Label loop(this); | - | ||||||||||||||||||
1086 | failures.append(atEndOfInput()); | - | ||||||||||||||||||
1087 | - | |||||||||||||||||||
1088 | if (term->invert()) {
| 207-1722 | ||||||||||||||||||
1089 | readCharacter(term->inputPosition - m_checked, character); | - | ||||||||||||||||||
1090 | matchCharacterClass(character, failures, term->characterClass); | - | ||||||||||||||||||
1091 | } else { executed 208 times by 3 tests: end of block Executed by:
| 208 | ||||||||||||||||||
1092 | JumpList matchDest; | - | ||||||||||||||||||
1093 | readCharacter(term->inputPosition - m_checked, character); | - | ||||||||||||||||||
1094 | matchCharacterClass(character, matchDest, term->characterClass); | - | ||||||||||||||||||
1095 | failures.append(jump()); | - | ||||||||||||||||||
1096 | matchDest.link(this); | - | ||||||||||||||||||
1097 | } executed 1722 times by 7 tests: end of block Executed by:
| 1722 | ||||||||||||||||||
1098 | - | |||||||||||||||||||
1099 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
1100 | add32(TrustedImm32(1), index); | - | ||||||||||||||||||
1101 | if (term->quantityCount != quantifyInfinite) {
| 214-1718 | ||||||||||||||||||
1102 | branch32(NotEqual, countRegister, Imm32(term->quantityCount.unsafeGet())).linkTo(loop, this); | - | ||||||||||||||||||
1103 | failures.append(jump()); | - | ||||||||||||||||||
1104 | } else executed 215 times by 3 tests: end of block Executed by:
| 215 | ||||||||||||||||||
1105 | jump(loop); executed 1718 times by 7 tests: jump(loop); Executed by:
| 1718 | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | failures.link(this); | - | ||||||||||||||||||
1108 | op.m_reentry = label(); | - | ||||||||||||||||||
1109 | - | |||||||||||||||||||
1110 | storeToFrame(countRegister, term->frameLocation); | - | ||||||||||||||||||
1111 | } executed 1930 times by 8 tests: end of block Executed by:
| 1930 | ||||||||||||||||||
1112 | void backtrackCharacterClassGreedy(size_t opIndex) | - | ||||||||||||||||||
1113 | { | - | ||||||||||||||||||
1114 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1115 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
1118 | - | |||||||||||||||||||
1119 | m_backtrackingState.link(this); | - | ||||||||||||||||||
1120 | - | |||||||||||||||||||
1121 | loadFromFrame(term->frameLocation, countRegister); | - | ||||||||||||||||||
1122 | m_backtrackingState.append(branchTest32(Zero, countRegister)); | - | ||||||||||||||||||
1123 | sub32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
1124 | sub32(TrustedImm32(1), index); | - | ||||||||||||||||||
1125 | jump(op.m_reentry); | - | ||||||||||||||||||
1126 | } executed 1931 times by 8 tests: end of block Executed by:
| 1931 | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | void generateCharacterClassNonGreedy(size_t opIndex) | - | ||||||||||||||||||
1129 | { | - | ||||||||||||||||||
1130 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1131 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
1134 | - | |||||||||||||||||||
1135 | move(TrustedImm32(0), countRegister); | - | ||||||||||||||||||
1136 | op.m_reentry = label(); | - | ||||||||||||||||||
1137 | storeToFrame(countRegister, term->frameLocation); | - | ||||||||||||||||||
1138 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
1139 | void backtrackCharacterClassNonGreedy(size_t opIndex) | - | ||||||||||||||||||
1140 | { | - | ||||||||||||||||||
1141 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1142 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1143 | - | |||||||||||||||||||
1144 | const RegisterID character = regT0; | - | ||||||||||||||||||
1145 | const RegisterID countRegister = regT1; | - | ||||||||||||||||||
1146 | - | |||||||||||||||||||
1147 | JumpList nonGreedyFailures; | - | ||||||||||||||||||
1148 | - | |||||||||||||||||||
1149 | m_backtrackingState.link(this); | - | ||||||||||||||||||
1150 | - | |||||||||||||||||||
1151 | loadFromFrame(term->frameLocation, countRegister); | - | ||||||||||||||||||
1152 | - | |||||||||||||||||||
1153 | nonGreedyFailures.append(atEndOfInput()); | - | ||||||||||||||||||
1154 | nonGreedyFailures.append(branch32(Equal, countRegister, Imm32(term->quantityCount.unsafeGet()))); | - | ||||||||||||||||||
1155 | - | |||||||||||||||||||
1156 | JumpList matchDest; | - | ||||||||||||||||||
1157 | readCharacter(term->inputPosition - m_checked, character); | - | ||||||||||||||||||
1158 | matchCharacterClass(character, matchDest, term->characterClass); | - | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | if (term->invert())
| 12-20 | ||||||||||||||||||
1161 | nonGreedyFailures.append(matchDest); executed 20 times by 2 tests: nonGreedyFailures.append(matchDest); Executed by:
| 20 | ||||||||||||||||||
1162 | else { | - | ||||||||||||||||||
1163 | nonGreedyFailures.append(jump()); | - | ||||||||||||||||||
1164 | matchDest.link(this); | - | ||||||||||||||||||
1165 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
1166 | - | |||||||||||||||||||
1167 | add32(TrustedImm32(1), countRegister); | - | ||||||||||||||||||
1168 | add32(TrustedImm32(1), index); | - | ||||||||||||||||||
1169 | - | |||||||||||||||||||
1170 | jump(op.m_reentry); | - | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | nonGreedyFailures.link(this); | - | ||||||||||||||||||
1173 | sub32(countRegister, index); | - | ||||||||||||||||||
1174 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
1175 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
1176 | - | |||||||||||||||||||
1177 | void generateDotStarEnclosure(size_t opIndex) | - | ||||||||||||||||||
1178 | { | - | ||||||||||||||||||
1179 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1180 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1181 | - | |||||||||||||||||||
1182 | const RegisterID character = regT0; | - | ||||||||||||||||||
1183 | const RegisterID matchPos = regT1; | - | ||||||||||||||||||
1184 | - | |||||||||||||||||||
1185 | JumpList foundBeginningNewLine; | - | ||||||||||||||||||
1186 | JumpList saveStartIndex; | - | ||||||||||||||||||
1187 | JumpList foundEndingNewLine; | - | ||||||||||||||||||
1188 | - | |||||||||||||||||||
1189 | ASSERT(!m_pattern.m_body->m_hasFixedSize); | - | ||||||||||||||||||
1190 | getMatchStart(matchPos); | - | ||||||||||||||||||
1191 | - | |||||||||||||||||||
1192 | saveStartIndex.append(branchTest32(Zero, matchPos)); | - | ||||||||||||||||||
1193 | Label findBOLLoop(this); | - | ||||||||||||||||||
1194 | sub32(TrustedImm32(1), matchPos); | - | ||||||||||||||||||
1195 | if (m_charSize == Char8)
| 0-8 | ||||||||||||||||||
1196 | load8(BaseIndex(input, matchPos, TimesOne, 0), character); never executed: load8(BaseIndex(input, matchPos, TimesOne, 0), character); | 0 | ||||||||||||||||||
1197 | else | - | ||||||||||||||||||
1198 | load16(BaseIndex(input, matchPos, TimesTwo, 0), character); executed 8 times by 1 test: load16(BaseIndex(input, matchPos, TimesTwo, 0), character); Executed by:
| 8 | ||||||||||||||||||
1199 | matchCharacterClass(character, foundBeginningNewLine, m_pattern.newlineCharacterClass()); | - | ||||||||||||||||||
1200 | branchTest32(NonZero, matchPos).linkTo(findBOLLoop, this); | - | ||||||||||||||||||
1201 | saveStartIndex.append(jump()); | - | ||||||||||||||||||
1202 | - | |||||||||||||||||||
1203 | foundBeginningNewLine.link(this); | - | ||||||||||||||||||
1204 | add32(TrustedImm32(1), matchPos); // Advance past newline | - | ||||||||||||||||||
1205 | saveStartIndex.link(this); | - | ||||||||||||||||||
1206 | - | |||||||||||||||||||
1207 | if (!m_pattern.m_multiline && term->anchors.bolAnchor)
| 0-8 | ||||||||||||||||||
1208 | op.m_jumps.append(branchTest32(NonZero, matchPos)); never executed: op.m_jumps.append(branchTest32(NonZero, matchPos)); | 0 | ||||||||||||||||||
1209 | - | |||||||||||||||||||
1210 | ASSERT(!m_pattern.m_body->m_hasFixedSize); | - | ||||||||||||||||||
1211 | setMatchStart(matchPos); | - | ||||||||||||||||||
1212 | - | |||||||||||||||||||
1213 | move(index, matchPos); | - | ||||||||||||||||||
1214 | - | |||||||||||||||||||
1215 | Label findEOLLoop(this); | - | ||||||||||||||||||
1216 | foundEndingNewLine.append(branch32(Equal, matchPos, length)); | - | ||||||||||||||||||
1217 | if (m_charSize == Char8)
| 0-8 | ||||||||||||||||||
1218 | load8(BaseIndex(input, matchPos, TimesOne, 0), character); never executed: load8(BaseIndex(input, matchPos, TimesOne, 0), character); | 0 | ||||||||||||||||||
1219 | else | - | ||||||||||||||||||
1220 | load16(BaseIndex(input, matchPos, TimesTwo, 0), character); executed 8 times by 1 test: load16(BaseIndex(input, matchPos, TimesTwo, 0), character); Executed by:
| 8 | ||||||||||||||||||
1221 | matchCharacterClass(character, foundEndingNewLine, m_pattern.newlineCharacterClass()); | - | ||||||||||||||||||
1222 | add32(TrustedImm32(1), matchPos); | - | ||||||||||||||||||
1223 | jump(findEOLLoop); | - | ||||||||||||||||||
1224 | - | |||||||||||||||||||
1225 | foundEndingNewLine.link(this); | - | ||||||||||||||||||
1226 | - | |||||||||||||||||||
1227 | if (!m_pattern.m_multiline && term->anchors.eolAnchor)
| 0-8 | ||||||||||||||||||
1228 | op.m_jumps.append(branch32(NotEqual, matchPos, length)); never executed: op.m_jumps.append(branch32(NotEqual, matchPos, length)); | 0 | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | move(matchPos, index); | - | ||||||||||||||||||
1231 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1232 | - | |||||||||||||||||||
1233 | void backtrackDotStarEnclosure(size_t opIndex) | - | ||||||||||||||||||
1234 | { | - | ||||||||||||||||||
1235 | backtrackTermDefault(opIndex); | - | ||||||||||||||||||
1236 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1237 | - | |||||||||||||||||||
1238 | // Code generation/backtracking for simple terms | - | ||||||||||||||||||
1239 | // (pattern characters, character classes, and assertions). | - | ||||||||||||||||||
1240 | // These methods farm out work to the set of functions above. | - | ||||||||||||||||||
1241 | void generateTerm(size_t opIndex) | - | ||||||||||||||||||
1242 | { | - | ||||||||||||||||||
1243 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1244 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | switch (term->type) { | - | ||||||||||||||||||
1247 | case PatternTerm::TypePatternCharacter: executed 2366048 times by 6 tests: case PatternTerm::TypePatternCharacter: Executed by:
| 2366048 | ||||||||||||||||||
1248 | switch (term->quantityType) { | - | ||||||||||||||||||
1249 | case QuantifierFixedCount: executed 2366259 times by 6 tests: case QuantifierFixedCount: Executed by:
| 2366259 | ||||||||||||||||||
1250 | if (term->quantityCount == 1)
| 32-2365861 | ||||||||||||||||||
1251 | generatePatternCharacterOnce(opIndex); executed 2365820 times by 6 tests: generatePatternCharacterOnce(opIndex); Executed by:
| 2365820 | ||||||||||||||||||
1252 | else | - | ||||||||||||||||||
1253 | generatePatternCharacterFixed(opIndex); executed 32 times by 2 tests: generatePatternCharacterFixed(opIndex); Executed by:
| 32 | ||||||||||||||||||
1254 | break; executed 2367419 times by 6 tests: break; Executed by:
| 2367419 | ||||||||||||||||||
1255 | case QuantifierGreedy: executed 242 times by 2 tests: case QuantifierGreedy: Executed by:
| 242 | ||||||||||||||||||
1256 | generatePatternCharacterGreedy(opIndex); | - | ||||||||||||||||||
1257 | break; executed 242 times by 2 tests: break; Executed by:
| 242 | ||||||||||||||||||
1258 | case QuantifierNonGreedy: executed 2 times by 1 test: case QuantifierNonGreedy: Executed by:
| 2 | ||||||||||||||||||
1259 | generatePatternCharacterNonGreedy(opIndex); | - | ||||||||||||||||||
1260 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
1261 | } | - | ||||||||||||||||||
1262 | break; executed 2367526 times by 6 tests: break; Executed by:
| 2367526 | ||||||||||||||||||
1263 | - | |||||||||||||||||||
1264 | case PatternTerm::TypeCharacterClass: executed 3741 times by 9 tests: case PatternTerm::TypeCharacterClass: Executed by:
| 3741 | ||||||||||||||||||
1265 | switch (term->quantityType) { | - | ||||||||||||||||||
1266 | case QuantifierFixedCount: executed 1781 times by 8 tests: case QuantifierFixedCount: Executed by:
| 1781 | ||||||||||||||||||
1267 | if (term->quantityCount == 1)
| 290-1489 | ||||||||||||||||||
1268 | generateCharacterClassOnce(opIndex); executed 1489 times by 8 tests: generateCharacterClassOnce(opIndex); Executed by:
| 1489 | ||||||||||||||||||
1269 | else | - | ||||||||||||||||||
1270 | generateCharacterClassFixed(opIndex); executed 290 times by 2 tests: generateCharacterClassFixed(opIndex); Executed by:
| 290 | ||||||||||||||||||
1271 | break; executed 1789 times by 8 tests: break; Executed by:
| 1789 | ||||||||||||||||||
1272 | case QuantifierGreedy: executed 1929 times by 8 tests: case QuantifierGreedy: Executed by:
| 1929 | ||||||||||||||||||
1273 | generateCharacterClassGreedy(opIndex); | - | ||||||||||||||||||
1274 | break; executed 1933 times by 8 tests: break; Executed by:
| 1933 | ||||||||||||||||||
1275 | case QuantifierNonGreedy: executed 32 times by 2 tests: case QuantifierNonGreedy: Executed by:
| 32 | ||||||||||||||||||
1276 | generateCharacterClassNonGreedy(opIndex); | - | ||||||||||||||||||
1277 | break; executed 32 times by 2 tests: break; Executed by:
| 32 | ||||||||||||||||||
1278 | } | - | ||||||||||||||||||
1279 | break; executed 3754 times by 9 tests: break; Executed by:
| 3754 | ||||||||||||||||||
1280 | - | |||||||||||||||||||
1281 | case PatternTerm::TypeAssertionBOL: executed 154 times by 5 tests: case PatternTerm::TypeAssertionBOL: Executed by:
| 154 | ||||||||||||||||||
1282 | generateAssertionBOL(opIndex); | - | ||||||||||||||||||
1283 | break; executed 153 times by 5 tests: break; Executed by:
| 153 | ||||||||||||||||||
1284 | - | |||||||||||||||||||
1285 | case PatternTerm::TypeAssertionEOL: executed 155 times by 5 tests: case PatternTerm::TypeAssertionEOL: Executed by:
| 155 | ||||||||||||||||||
1286 | generateAssertionEOL(opIndex); | - | ||||||||||||||||||
1287 | break; executed 155 times by 5 tests: break; Executed by:
| 155 | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | case PatternTerm::TypeAssertionWordBoundary: executed 1127 times by 1 test: case PatternTerm::TypeAssertionWordBoundary: Executed by:
| 1127 | ||||||||||||||||||
1290 | generateAssertionWordBoundary(opIndex); | - | ||||||||||||||||||
1291 | break; executed 1128 times by 1 test: break; Executed by:
| 1128 | ||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | case PatternTerm::TypeForwardReference: never executed: case PatternTerm::TypeForwardReference: | 0 | ||||||||||||||||||
1294 | break; never executed: break; | 0 | ||||||||||||||||||
1295 | - | |||||||||||||||||||
1296 | case PatternTerm::TypeParenthesesSubpattern: never executed: case PatternTerm::TypeParenthesesSubpattern: | 0 | ||||||||||||||||||
1297 | case PatternTerm::TypeParentheticalAssertion: never executed: case PatternTerm::TypeParentheticalAssertion: | 0 | ||||||||||||||||||
1298 | RELEASE_ASSERT_NOT_REACHED(); | - | ||||||||||||||||||
1299 | case PatternTerm::TypeBackReference: code before this statement never executed: case PatternTerm::TypeBackReference: never executed: case PatternTerm::TypeBackReference: | 0 | ||||||||||||||||||
1300 | m_shouldFallBack = true; | - | ||||||||||||||||||
1301 | break; never executed: break; | 0 | ||||||||||||||||||
1302 | case PatternTerm::TypeDotStarEnclosure: executed 8 times by 1 test: case PatternTerm::TypeDotStarEnclosure: Executed by:
| 8 | ||||||||||||||||||
1303 | generateDotStarEnclosure(opIndex); | - | ||||||||||||||||||
1304 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||
1305 | } | - | ||||||||||||||||||
1306 | } executed 2372545 times by 9 tests: end of block Executed by:
| 2372545 | ||||||||||||||||||
1307 | void backtrackTerm(size_t opIndex) | - | ||||||||||||||||||
1308 | { | - | ||||||||||||||||||
1309 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1310 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1311 | - | |||||||||||||||||||
1312 | switch (term->type) { | - | ||||||||||||||||||
1313 | case PatternTerm::TypePatternCharacter: executed 2366700 times by 6 tests: case PatternTerm::TypePatternCharacter: Executed by:
| 2366700 | ||||||||||||||||||
1314 | switch (term->quantityType) { | - | ||||||||||||||||||
1315 | case QuantifierFixedCount: executed 2367519 times by 6 tests: case QuantifierFixedCount: Executed by:
| 2367519 | ||||||||||||||||||
1316 | if (term->quantityCount == 1)
| 32-2368124 | ||||||||||||||||||
1317 | backtrackPatternCharacterOnce(opIndex); executed 2367008 times by 6 tests: backtrackPatternCharacterOnce(opIndex); Executed by:
| 2367008 | ||||||||||||||||||
1318 | else | - | ||||||||||||||||||
1319 | backtrackPatternCharacterFixed(opIndex); executed 32 times by 2 tests: backtrackPatternCharacterFixed(opIndex); Executed by:
| 32 | ||||||||||||||||||
1320 | break; executed 2368467 times by 6 tests: break; Executed by:
| 2368467 | ||||||||||||||||||
1321 | case QuantifierGreedy: executed 242 times by 2 tests: case QuantifierGreedy: Executed by:
| 242 | ||||||||||||||||||
1322 | backtrackPatternCharacterGreedy(opIndex); | - | ||||||||||||||||||
1323 | break; executed 242 times by 2 tests: break; Executed by:
| 242 | ||||||||||||||||||
1324 | case QuantifierNonGreedy: executed 2 times by 1 test: case QuantifierNonGreedy: Executed by:
| 2 | ||||||||||||||||||
1325 | backtrackPatternCharacterNonGreedy(opIndex); | - | ||||||||||||||||||
1326 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
1327 | } | - | ||||||||||||||||||
1328 | break; executed 2368773 times by 6 tests: break; Executed by:
| 2368773 | ||||||||||||||||||
1329 | - | |||||||||||||||||||
1330 | case PatternTerm::TypeCharacterClass: executed 3739 times by 9 tests: case PatternTerm::TypeCharacterClass: Executed by:
| 3739 | ||||||||||||||||||
1331 | switch (term->quantityType) { | - | ||||||||||||||||||
1332 | case QuantifierFixedCount: executed 1780 times by 8 tests: case QuantifierFixedCount: Executed by:
| 1780 | ||||||||||||||||||
1333 | if (term->quantityCount == 1)
| 293-1491 | ||||||||||||||||||
1334 | backtrackCharacterClassOnce(opIndex); executed 1491 times by 8 tests: backtrackCharacterClassOnce(opIndex); Executed by:
| 1491 | ||||||||||||||||||
1335 | else | - | ||||||||||||||||||
1336 | backtrackCharacterClassFixed(opIndex); executed 292 times by 2 tests: backtrackCharacterClassFixed(opIndex); Executed by:
| 292 | ||||||||||||||||||
1337 | break; executed 1782 times by 8 tests: break; Executed by:
| 1782 | ||||||||||||||||||
1338 | case QuantifierGreedy: executed 1925 times by 8 tests: case QuantifierGreedy: Executed by:
| 1925 | ||||||||||||||||||
1339 | backtrackCharacterClassGreedy(opIndex); | - | ||||||||||||||||||
1340 | break; executed 1928 times by 8 tests: break; Executed by:
| 1928 | ||||||||||||||||||
1341 | case QuantifierNonGreedy: executed 32 times by 2 tests: case QuantifierNonGreedy: Executed by:
| 32 | ||||||||||||||||||
1342 | backtrackCharacterClassNonGreedy(opIndex); | - | ||||||||||||||||||
1343 | break; executed 32 times by 2 tests: break; Executed by:
| 32 | ||||||||||||||||||
1344 | } | - | ||||||||||||||||||
1345 | break; executed 3739 times by 9 tests: break; Executed by:
| 3739 | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | case PatternTerm::TypeAssertionBOL: executed 154 times by 5 tests: case PatternTerm::TypeAssertionBOL: Executed by:
| 154 | ||||||||||||||||||
1348 | backtrackAssertionBOL(opIndex); | - | ||||||||||||||||||
1349 | break; executed 154 times by 5 tests: break; Executed by:
| 154 | ||||||||||||||||||
1350 | - | |||||||||||||||||||
1351 | case PatternTerm::TypeAssertionEOL: executed 154 times by 5 tests: case PatternTerm::TypeAssertionEOL: Executed by:
| 154 | ||||||||||||||||||
1352 | backtrackAssertionEOL(opIndex); | - | ||||||||||||||||||
1353 | break; executed 155 times by 5 tests: break; Executed by:
| 155 | ||||||||||||||||||
1354 | - | |||||||||||||||||||
1355 | case PatternTerm::TypeAssertionWordBoundary: executed 1128 times by 1 test: case PatternTerm::TypeAssertionWordBoundary: Executed by:
| 1128 | ||||||||||||||||||
1356 | backtrackAssertionWordBoundary(opIndex); | - | ||||||||||||||||||
1357 | break; executed 1127 times by 1 test: break; Executed by:
| 1127 | ||||||||||||||||||
1358 | - | |||||||||||||||||||
1359 | case PatternTerm::TypeForwardReference: never executed: case PatternTerm::TypeForwardReference: | 0 | ||||||||||||||||||
1360 | break; never executed: break; | 0 | ||||||||||||||||||
1361 | - | |||||||||||||||||||
1362 | case PatternTerm::TypeParenthesesSubpattern: never executed: case PatternTerm::TypeParenthesesSubpattern: | 0 | ||||||||||||||||||
1363 | case PatternTerm::TypeParentheticalAssertion: never executed: case PatternTerm::TypeParentheticalAssertion: | 0 | ||||||||||||||||||
1364 | RELEASE_ASSERT_NOT_REACHED(); | - | ||||||||||||||||||
1365 | - | |||||||||||||||||||
1366 | case PatternTerm::TypeDotStarEnclosure: code before this statement never executed: case PatternTerm::TypeDotStarEnclosure: executed 8 times by 1 test: case PatternTerm::TypeDotStarEnclosure: Executed by:
| 0-8 | ||||||||||||||||||
1367 | backtrackDotStarEnclosure(opIndex); | - | ||||||||||||||||||
1368 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | case PatternTerm::TypeBackReference: never executed: case PatternTerm::TypeBackReference: | 0 | ||||||||||||||||||
1371 | m_shouldFallBack = true; | - | ||||||||||||||||||
1372 | break; never executed: break; | 0 | ||||||||||||||||||
1373 | } | - | ||||||||||||||||||
1374 | } executed 2373956 times by 9 tests: end of block Executed by:
| 2373956 | ||||||||||||||||||
1375 | - | |||||||||||||||||||
1376 | void generate() | - | ||||||||||||||||||
1377 | { | - | ||||||||||||||||||
1378 | // Forwards generate the matching code. | - | ||||||||||||||||||
1379 | ASSERT(m_ops.size()); | - | ||||||||||||||||||
1380 | size_t opIndex = 0; | - | ||||||||||||||||||
1381 | - | |||||||||||||||||||
1382 | do { | - | ||||||||||||||||||
1383 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1384 | switch (op.m_op) { | - | ||||||||||||||||||
1385 | - | |||||||||||||||||||
1386 | case OpTerm: executed 2372202 times by 9 tests: case OpTerm: Executed by:
| 2372202 | ||||||||||||||||||
1387 | generateTerm(opIndex); | - | ||||||||||||||||||
1388 | break; executed 2372874 times by 9 tests: break; Executed by:
| 2372874 | ||||||||||||||||||
1389 | - | |||||||||||||||||||
1390 | // OpBodyAlternativeBegin/Next/End | - | ||||||||||||||||||
1391 | // | - | ||||||||||||||||||
1392 | // These nodes wrap the set of alternatives in the body of the regular expression. | - | ||||||||||||||||||
1393 | // There may be either one or two chains of OpBodyAlternative nodes, one representing | - | ||||||||||||||||||
1394 | // the 'once through' sequence of alternatives (if any exist), and one representing | - | ||||||||||||||||||
1395 | // the repeating alternatives (again, if any exist). | - | ||||||||||||||||||
1396 | // | - | ||||||||||||||||||
1397 | // Upon normal entry to the Begin alternative, we will check that input is available. | - | ||||||||||||||||||
1398 | // Reentry to the Begin alternative will take place after the check has taken place, | - | ||||||||||||||||||
1399 | // and will assume that the input position has already been progressed as appropriate. | - | ||||||||||||||||||
1400 | // | - | ||||||||||||||||||
1401 | // Entry to subsequent Next/End alternatives occurs when the prior alternative has | - | ||||||||||||||||||
1402 | // successfully completed a match - return a success state from JIT code. | - | ||||||||||||||||||
1403 | // | - | ||||||||||||||||||
1404 | // Next alternatives allow for reentry optimized to suit backtracking from its | - | ||||||||||||||||||
1405 | // preceding alternative. It expects the input position to still be set to a position | - | ||||||||||||||||||
1406 | // appropriate to its predecessor, and it will only perform an input check if the | - | ||||||||||||||||||
1407 | // predecessor had a minimum size less than its own. | - | ||||||||||||||||||
1408 | // | - | ||||||||||||||||||
1409 | // In the case 'once through' expressions, the End node will also have a reentry | - | ||||||||||||||||||
1410 | // point to jump to when the last alternative fails. Again, this expects the input | - | ||||||||||||||||||
1411 | // position to still reflect that expected by the prior alternative. | - | ||||||||||||||||||
1412 | case OpBodyAlternativeBegin: { executed 1148705 times by 153 tests: case OpBodyAlternativeBegin: Executed by:
| 1148705 | ||||||||||||||||||
1413 | PatternAlternative* alternative = op.m_alternative; | - | ||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | // Upon entry at the head of the set of alternatives, check if input is available | - | ||||||||||||||||||
1416 | // to run the first alternative. (This progresses the input position). | - | ||||||||||||||||||
1417 | op.m_jumps.append(jumpIfNoAvailableInput(alternative->m_minimumSize)); | - | ||||||||||||||||||
1418 | // We will reenter after the check, and assume the input position to have been | - | ||||||||||||||||||
1419 | // set as appropriate to this alternative. | - | ||||||||||||||||||
1420 | op.m_reentry = label(); | - | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | m_checked += alternative->m_minimumSize; | - | ||||||||||||||||||
1423 | break; executed 1148003 times by 153 tests: break; Executed by:
| 1148003 | ||||||||||||||||||
1424 | } | - | ||||||||||||||||||
1425 | case OpBodyAlternativeNext: executed 206 times by 2 tests: case OpBodyAlternativeNext: Executed by:
| 206 | ||||||||||||||||||
1426 | case OpBodyAlternativeEnd: { executed 1149995 times by 153 tests: case OpBodyAlternativeEnd: Executed by:
| 1149995 | ||||||||||||||||||
1427 | PatternAlternative* priorAlternative = m_ops[op.m_previousOp].m_alternative; | - | ||||||||||||||||||
1428 | PatternAlternative* alternative = op.m_alternative; | - | ||||||||||||||||||
1429 | - | |||||||||||||||||||
1430 | // If we get here, the prior alternative matched - return success. | - | ||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | // Adjust the stack pointer to remove the pattern's frame. | - | ||||||||||||||||||
1433 | removeCallFrame(); | - | ||||||||||||||||||
1434 | - | |||||||||||||||||||
1435 | // Load appropriate values into the return register and the first output | - | ||||||||||||||||||
1436 | // slot, and return. In the case of pattern with a fixed size, we will | - | ||||||||||||||||||
1437 | // not have yet set the value in the first | - | ||||||||||||||||||
1438 | ASSERT(index != returnRegister); | - | ||||||||||||||||||
1439 | if (m_pattern.m_body->m_hasFixedSize) {
| 1187-1148949 | ||||||||||||||||||
1440 | move(index, returnRegister); | - | ||||||||||||||||||
1441 | if (priorAlternative->m_minimumSize)
| 97985-1050741 | ||||||||||||||||||
1442 | sub32(Imm32(priorAlternative->m_minimumSize), returnRegister); executed 1050772 times by 6 tests: sub32(Imm32(priorAlternative->m_minimumSize), returnRegister); Executed by:
| 1050772 | ||||||||||||||||||
1443 | if (compileMode == IncludeSubpatterns)
| 0-1148591 | ||||||||||||||||||
1444 | store32(returnRegister, output); executed 1148546 times by 153 tests: store32(returnRegister, output); Executed by:
| 1148546 | ||||||||||||||||||
1445 | } else executed 1149696 times by 153 tests: end of block Executed by:
| 1149696 | ||||||||||||||||||
1446 | getMatchStart(returnRegister); executed 1188 times by 8 tests: getMatchStart(returnRegister); Executed by:
| 1188 | ||||||||||||||||||
1447 | if (compileMode == IncludeSubpatterns)
| 0-1150881 | ||||||||||||||||||
1448 | store32(index, Address(output, 4)); executed 1150981 times by 153 tests: store32(index, Address(output, 4)); Executed by:
| 1150981 | ||||||||||||||||||
1449 | move(index, returnRegister2); | - | ||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | generateReturn(); | - | ||||||||||||||||||
1452 | - | |||||||||||||||||||
1453 | // This is the divide between the tail of the prior alternative, above, and | - | ||||||||||||||||||
1454 | // the head of the subsequent alternative, below. | - | ||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | if (op.m_op == OpBodyAlternativeNext) {
| 205-1150967 | ||||||||||||||||||
1457 | // This is the reentry point for the Next alternative. We expect any code | - | ||||||||||||||||||
1458 | // that jumps here to do so with the input position matching that of the | - | ||||||||||||||||||
1459 | // PRIOR alteranative, and we will only check input availability if we | - | ||||||||||||||||||
1460 | // need to progress it forwards. | - | ||||||||||||||||||
1461 | op.m_reentry = label(); | - | ||||||||||||||||||
1462 | if (alternative->m_minimumSize > priorAlternative->m_minimumSize) {
| 68-137 | ||||||||||||||||||
1463 | add32(Imm32(alternative->m_minimumSize - priorAlternative->m_minimumSize), index); | - | ||||||||||||||||||
1464 | op.m_jumps.append(jumpIfNoAvailableInput()); | - | ||||||||||||||||||
1465 | } else if (priorAlternative->m_minimumSize > alternative->m_minimumSize) executed 68 times by 1 test: end of block Executed by:
| 20-118 | ||||||||||||||||||
1466 | sub32(Imm32(priorAlternative->m_minimumSize - alternative->m_minimumSize), index); executed 20 times by 1 test: sub32(Imm32(priorAlternative->m_minimumSize - alternative->m_minimumSize), index); Executed by:
| 20 | ||||||||||||||||||
1467 | } else if (op.m_nextOp == notFound) { executed 206 times by 2 tests: end of block Executed by:
| 98-1150257 | ||||||||||||||||||
1468 | // This is the reentry point for the End of 'once through' alternatives, | - | ||||||||||||||||||
1469 | // jumped to when the last alternative fails to match. | - | ||||||||||||||||||
1470 | op.m_reentry = label(); | - | ||||||||||||||||||
1471 | sub32(Imm32(priorAlternative->m_minimumSize), index); | - | ||||||||||||||||||
1472 | } executed 98 times by 5 tests: end of block Executed by:
| 98 | ||||||||||||||||||
1473 | - | |||||||||||||||||||
1474 | if (op.m_op == OpBodyAlternativeNext)
| 205-1150700 | ||||||||||||||||||
1475 | m_checked += alternative->m_minimumSize; executed 206 times by 2 tests: m_checked += alternative->m_minimumSize; Executed by:
| 206 | ||||||||||||||||||
1476 | m_checked -= priorAlternative->m_minimumSize; | - | ||||||||||||||||||
1477 | break; executed 1150138 times by 153 tests: break; Executed by:
| 1150138 | ||||||||||||||||||
1478 | } | - | ||||||||||||||||||
1479 | - | |||||||||||||||||||
1480 | // OpSimpleNestedAlternativeBegin/Next/End | - | ||||||||||||||||||
1481 | // OpNestedAlternativeBegin/Next/End | - | ||||||||||||||||||
1482 | // | - | ||||||||||||||||||
1483 | // These nodes are used to handle sets of alternatives that are nested within | - | ||||||||||||||||||
1484 | // subpatterns and parenthetical assertions. The 'simple' forms are used where | - | ||||||||||||||||||
1485 | // we do not need to be able to backtrack back into any alternative other than | - | ||||||||||||||||||
1486 | // the last, the normal forms allow backtracking into any alternative. | - | ||||||||||||||||||
1487 | // | - | ||||||||||||||||||
1488 | // Each Begin/Next node is responsible for planting an input check to ensure | - | ||||||||||||||||||
1489 | // sufficient input is available on entry. Next nodes additionally need to | - | ||||||||||||||||||
1490 | // jump to the end - Next nodes use the End node's m_jumps list to hold this | - | ||||||||||||||||||
1491 | // set of jumps. | - | ||||||||||||||||||
1492 | // | - | ||||||||||||||||||
1493 | // In the non-simple forms, successful alternative matches must store a | - | ||||||||||||||||||
1494 | // 'return address' using a DataLabelPtr, used to store the address to jump | - | ||||||||||||||||||
1495 | // to when backtracking, to get to the code for the appropriate alternative. | - | ||||||||||||||||||
1496 | case OpSimpleNestedAlternativeBegin: executed 2344 times by 3 tests: case OpSimpleNestedAlternativeBegin: Executed by:
| 2344 | ||||||||||||||||||
1497 | case OpNestedAlternativeBegin: { executed 165 times by 3 tests: case OpNestedAlternativeBegin: Executed by:
| 165 | ||||||||||||||||||
1498 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1499 | PatternAlternative* alternative = op.m_alternative; | - | ||||||||||||||||||
1500 | PatternDisjunction* disjunction = term->parentheses.disjunction; | - | ||||||||||||||||||
1501 | - | |||||||||||||||||||
1502 | // Calculate how much input we need to check for, and if non-zero check. | - | ||||||||||||||||||
1503 | op.m_checkAdjust = alternative->m_minimumSize; | - | ||||||||||||||||||
1504 | if ((term->quantityType == QuantifierFixedCount) && (term->type != PatternTerm::TypeParentheticalAssertion))
| 68-2363 | ||||||||||||||||||
1505 | op.m_checkAdjust -= disjunction->m_minimumSize; executed 2296 times by 3 tests: op.m_checkAdjust -= disjunction->m_minimumSize; Executed by:
| 2296 | ||||||||||||||||||
1506 | if (op.m_checkAdjust)
| 228-2278 | ||||||||||||||||||
1507 | op.m_jumps.append(jumpIfNoAvailableInput(op.m_checkAdjust)); executed 228 times by 3 tests: op.m_jumps.append(jumpIfNoAvailableInput(op.m_checkAdjust)); Executed by:
| 228 | ||||||||||||||||||
1508 | - | |||||||||||||||||||
1509 | m_checked += op.m_checkAdjust; | - | ||||||||||||||||||
1510 | break; executed 2508 times by 3 tests: break; Executed by:
| 2508 | ||||||||||||||||||
1511 | } | - | ||||||||||||||||||
1512 | case OpSimpleNestedAlternativeNext: executed 36 times by 1 test: case OpSimpleNestedAlternativeNext: Executed by:
| 36 | ||||||||||||||||||
1513 | case OpNestedAlternativeNext: { executed 343 times by 3 tests: case OpNestedAlternativeNext: Executed by:
| 343 | ||||||||||||||||||
1514 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1515 | PatternAlternative* alternative = op.m_alternative; | - | ||||||||||||||||||
1516 | PatternDisjunction* disjunction = term->parentheses.disjunction; | - | ||||||||||||||||||
1517 | - | |||||||||||||||||||
1518 | // In the non-simple case, store a 'return address' so we can backtrack correctly. | - | ||||||||||||||||||
1519 | if (op.m_op == OpNestedAlternativeNext) {
| 36-345 | ||||||||||||||||||
1520 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
1521 | unsigned alternativeFrameLocation = parenthesesFrameLocation; | - | ||||||||||||||||||
1522 | if (term->quantityType != QuantifierFixedCount)
| 0-342 | ||||||||||||||||||
1523 | alternativeFrameLocation += YarrStackSpaceForBackTrackInfoParenthesesOnce; never executed: alternativeFrameLocation += 1; | 0 | ||||||||||||||||||
1524 | op.m_returnAddress = storeToFrameWithPatch(alternativeFrameLocation); | - | ||||||||||||||||||
1525 | } executed 344 times by 3 tests: end of block Executed by:
| 344 | ||||||||||||||||||
1526 | - | |||||||||||||||||||
1527 | if (term->quantityType != QuantifierFixedCount && !m_ops[op.m_previousOp].m_alternative->m_minimumSize) {
| 0-368 | ||||||||||||||||||
1528 | // If the previous alternative matched without consuming characters then | - | ||||||||||||||||||
1529 | // backtrack to try to match while consumming some input. | - | ||||||||||||||||||
1530 | op.m_zeroLengthMatch = branch32(Equal, index, Address(stackPointerRegister, term->frameLocation * sizeof(void*))); | - | ||||||||||||||||||
1531 | } never executed: end of block | 0 | ||||||||||||||||||
1532 | - | |||||||||||||||||||
1533 | // If we reach here then the last alternative has matched - jump to the | - | ||||||||||||||||||
1534 | // End node, to skip over any further alternatives. | - | ||||||||||||||||||
1535 | // | - | ||||||||||||||||||
1536 | // FIXME: this is logically O(N^2) (though N can be expected to be very | - | ||||||||||||||||||
1537 | // small). We could avoid this either by adding an extra jump to the JIT | - | ||||||||||||||||||
1538 | // data structures, or by making backtracking code that jumps to Next | - | ||||||||||||||||||
1539 | // alternatives are responsible for checking that input is available (if | - | ||||||||||||||||||
1540 | // we didn't need to plant the input checks, then m_jumps would be free). | - | ||||||||||||||||||
1541 | YarrOp* endOp = &m_ops[op.m_nextOp]; | - | ||||||||||||||||||
1542 | while (endOp->m_nextOp != notFound) {
| 380-840 | ||||||||||||||||||
1543 | ASSERT(endOp->m_op == OpSimpleNestedAlternativeNext || endOp->m_op == OpNestedAlternativeNext); | - | ||||||||||||||||||
1544 | endOp = &m_ops[endOp->m_nextOp]; | - | ||||||||||||||||||
1545 | } executed 840 times by 1 test: end of block Executed by:
| 840 | ||||||||||||||||||
1546 | ASSERT(endOp->m_op == OpSimpleNestedAlternativeEnd || endOp->m_op == OpNestedAlternativeEnd); | - | ||||||||||||||||||
1547 | endOp->m_jumps.append(jump()); | - | ||||||||||||||||||
1548 | - | |||||||||||||||||||
1549 | // This is the entry point for the next alternative. | - | ||||||||||||||||||
1550 | op.m_reentry = label(); | - | ||||||||||||||||||
1551 | - | |||||||||||||||||||
1552 | // Calculate how much input we need to check for, and if non-zero check. | - | ||||||||||||||||||
1553 | op.m_checkAdjust = alternative->m_minimumSize; | - | ||||||||||||||||||
1554 | if ((term->quantityType == QuantifierFixedCount) && (term->type != PatternTerm::TypeParentheticalAssertion))
| 12-369 | ||||||||||||||||||
1555 | op.m_checkAdjust -= disjunction->m_minimumSize; executed 345 times by 3 tests: op.m_checkAdjust -= disjunction->m_minimumSize; Executed by:
| 345 | ||||||||||||||||||
1556 | if (op.m_checkAdjust)
| 64-317 | ||||||||||||||||||
1557 | op.m_jumps.append(jumpIfNoAvailableInput(op.m_checkAdjust)); executed 64 times by 1 test: op.m_jumps.append(jumpIfNoAvailableInput(op.m_checkAdjust)); Executed by:
| 64 | ||||||||||||||||||
1558 | - | |||||||||||||||||||
1559 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
1560 | m_checked -= lastOp.m_checkAdjust; | - | ||||||||||||||||||
1561 | m_checked += op.m_checkAdjust; | - | ||||||||||||||||||
1562 | break; executed 381 times by 3 tests: break; Executed by:
| 381 | ||||||||||||||||||
1563 | } | - | ||||||||||||||||||
1564 | case OpSimpleNestedAlternativeEnd: executed 2344 times by 3 tests: case OpSimpleNestedAlternativeEnd: Executed by:
| 2344 | ||||||||||||||||||
1565 | case OpNestedAlternativeEnd: { executed 166 times by 3 tests: case OpNestedAlternativeEnd: Executed by:
| 166 | ||||||||||||||||||
1566 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1567 | - | |||||||||||||||||||
1568 | // In the non-simple case, store a 'return address' so we can backtrack correctly. | - | ||||||||||||||||||
1569 | if (op.m_op == OpNestedAlternativeEnd) {
| 166-2343 | ||||||||||||||||||
1570 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
1571 | unsigned alternativeFrameLocation = parenthesesFrameLocation; | - | ||||||||||||||||||
1572 | if (term->quantityType != QuantifierFixedCount)
| 0-165 | ||||||||||||||||||
1573 | alternativeFrameLocation += YarrStackSpaceForBackTrackInfoParenthesesOnce; never executed: alternativeFrameLocation += 1; | 0 | ||||||||||||||||||
1574 | op.m_returnAddress = storeToFrameWithPatch(alternativeFrameLocation); | - | ||||||||||||||||||
1575 | } executed 164 times by 3 tests: end of block Executed by:
| 164 | ||||||||||||||||||
1576 | - | |||||||||||||||||||
1577 | if (term->quantityType != QuantifierFixedCount && !m_ops[op.m_previousOp].m_alternative->m_minimumSize) {
| 0-2365 | ||||||||||||||||||
1578 | // If the previous alternative matched without consuming characters then | - | ||||||||||||||||||
1579 | // backtrack to try to match while consumming some input. | - | ||||||||||||||||||
1580 | op.m_zeroLengthMatch = branch32(Equal, index, Address(stackPointerRegister, term->frameLocation * sizeof(void*))); | - | ||||||||||||||||||
1581 | } never executed: end of block | 0 | ||||||||||||||||||
1582 | - | |||||||||||||||||||
1583 | // If this set of alternatives contains more than one alternative, | - | ||||||||||||||||||
1584 | // then the Next nodes will have planted jumps to the End, and added | - | ||||||||||||||||||
1585 | // them to this node's m_jumps list. | - | ||||||||||||||||||
1586 | op.m_jumps.link(this); | - | ||||||||||||||||||
1587 | op.m_jumps.clear(); | - | ||||||||||||||||||
1588 | - | |||||||||||||||||||
1589 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
1590 | m_checked -= lastOp.m_checkAdjust; | - | ||||||||||||||||||
1591 | break; executed 2508 times by 3 tests: break; Executed by:
| 2508 | ||||||||||||||||||
1592 | } | - | ||||||||||||||||||
1593 | - | |||||||||||||||||||
1594 | // OpParenthesesSubpatternOnceBegin/End | - | ||||||||||||||||||
1595 | // | - | ||||||||||||||||||
1596 | // These nodes support (optionally) capturing subpatterns, that have a | - | ||||||||||||||||||
1597 | // quantity count of 1 (this covers fixed once, and ?/?? quantifiers). | - | ||||||||||||||||||
1598 | case OpParenthesesSubpatternOnceBegin: { executed 2425 times by 3 tests: case OpParenthesesSubpatternOnceBegin: Executed by:
| 2425 | ||||||||||||||||||
1599 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1600 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
1601 | const RegisterID indexTemporary = regT0; | - | ||||||||||||||||||
1602 | ASSERT(term->quantityCount == 1); | - | ||||||||||||||||||
1603 | - | |||||||||||||||||||
1604 | // Upon entry to a Greedy quantified set of parenthese store the index. | - | ||||||||||||||||||
1605 | // We'll use this for two purposes: | - | ||||||||||||||||||
1606 | // - To indicate which iteration we are on of mathing the remainder of | - | ||||||||||||||||||
1607 | // the expression after the parentheses - the first, including the | - | ||||||||||||||||||
1608 | // match within the parentheses, or the second having skipped over them. | - | ||||||||||||||||||
1609 | // - To check for empty matches, which must be rejected. | - | ||||||||||||||||||
1610 | // | - | ||||||||||||||||||
1611 | // At the head of a NonGreedy set of parentheses we'll immediately set the | - | ||||||||||||||||||
1612 | // value on the stack to -1 (indicating a match skipping the subpattern), | - | ||||||||||||||||||
1613 | // and plant a jump to the end. We'll also plant a label to backtrack to | - | ||||||||||||||||||
1614 | // to reenter the subpattern later, with a store to set up index on the | - | ||||||||||||||||||
1615 | // second iteration. | - | ||||||||||||||||||
1616 | // | - | ||||||||||||||||||
1617 | // FIXME: for capturing parens, could use the index in the capture array? | - | ||||||||||||||||||
1618 | if (term->quantityType == QuantifierGreedy)
| 130-2296 | ||||||||||||||||||
1619 | storeToFrame(index, parenthesesFrameLocation); executed 130 times by 2 tests: storeToFrame(index, parenthesesFrameLocation); Executed by:
| 130 | ||||||||||||||||||
1620 | else if (term->quantityType == QuantifierNonGreedy) {
| 0-2296 | ||||||||||||||||||
1621 | storeToFrame(TrustedImm32(-1), parenthesesFrameLocation); | - | ||||||||||||||||||
1622 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
1623 | op.m_reentry = label(); | - | ||||||||||||||||||
1624 | storeToFrame(index, parenthesesFrameLocation); | - | ||||||||||||||||||
1625 | } never executed: end of block | 0 | ||||||||||||||||||
1626 | - | |||||||||||||||||||
1627 | // If the parenthese are capturing, store the starting index value to the | - | ||||||||||||||||||
1628 | // captures array, offsetting as necessary. | - | ||||||||||||||||||
1629 | // | - | ||||||||||||||||||
1630 | // FIXME: could avoid offsetting this value in JIT code, apply | - | ||||||||||||||||||
1631 | // offsets only afterwards, at the point the results array is | - | ||||||||||||||||||
1632 | // being accessed. | - | ||||||||||||||||||
1633 | if (term->capture() && compileMode == IncludeSubpatterns) {
| 0-1475 | ||||||||||||||||||
1634 | int inputOffset = term->inputPosition - m_checked; | - | ||||||||||||||||||
1635 | if (term->quantityType == QuantifierFixedCount)
| 130-1345 | ||||||||||||||||||
1636 | inputOffset -= term->parentheses.disjunction->m_minimumSize; executed 1344 times by 3 tests: inputOffset -= term->parentheses.disjunction->m_minimumSize; Executed by:
| 1344 | ||||||||||||||||||
1637 | if (inputOffset) {
| 108-1367 | ||||||||||||||||||
1638 | move(index, indexTemporary); | - | ||||||||||||||||||
1639 | add32(Imm32(inputOffset), indexTemporary); | - | ||||||||||||||||||
1640 | setSubpatternStart(indexTemporary, term->parentheses.subpatternId); | - | ||||||||||||||||||
1641 | } else executed 1370 times by 3 tests: end of block Executed by:
| 1370 | ||||||||||||||||||
1642 | setSubpatternStart(index, term->parentheses.subpatternId); executed 108 times by 3 tests: setSubpatternStart(index, term->parentheses.subpatternId); Executed by:
| 108 | ||||||||||||||||||
1643 | } | - | ||||||||||||||||||
1644 | break; executed 2427 times by 3 tests: break; Executed by:
| 2427 | ||||||||||||||||||
1645 | } | - | ||||||||||||||||||
1646 | case OpParenthesesSubpatternOnceEnd: { executed 2428 times by 3 tests: case OpParenthesesSubpatternOnceEnd: Executed by:
| 2428 | ||||||||||||||||||
1647 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1648 | const RegisterID indexTemporary = regT0; | - | ||||||||||||||||||
1649 | ASSERT(term->quantityCount == 1); | - | ||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | #ifndef NDEBUG | - | ||||||||||||||||||
1652 | // Runtime ASSERT to make sure that the nested alternative handled the | - | ||||||||||||||||||
1653 | // "no input consumed" check. | - | ||||||||||||||||||
1654 | if (term->quantityType != QuantifierFixedCount && !term->parentheses.disjunction->m_minimumSize) {
| 0-2297 | ||||||||||||||||||
1655 | Jump pastBreakpoint; | - | ||||||||||||||||||
1656 | pastBreakpoint = branch32(NotEqual, index, Address(stackPointerRegister, term->frameLocation * sizeof(void*))); | - | ||||||||||||||||||
1657 | breakpoint(); | - | ||||||||||||||||||
1658 | pastBreakpoint.link(this); | - | ||||||||||||||||||
1659 | } never executed: end of block | 0 | ||||||||||||||||||
1660 | #endif | - | ||||||||||||||||||
1661 | - | |||||||||||||||||||
1662 | // If the parenthese are capturing, store the ending index value to the | - | ||||||||||||||||||
1663 | // captures array, offsetting as necessary. | - | ||||||||||||||||||
1664 | // | - | ||||||||||||||||||
1665 | // FIXME: could avoid offsetting this value in JIT code, apply | - | ||||||||||||||||||
1666 | // offsets only afterwards, at the point the results array is | - | ||||||||||||||||||
1667 | // being accessed. | - | ||||||||||||||||||
1668 | if (term->capture() && compileMode == IncludeSubpatterns) {
| 0-1478 | ||||||||||||||||||
1669 | int inputOffset = term->inputPosition - m_checked; | - | ||||||||||||||||||
1670 | if (inputOffset) {
| 266-1212 | ||||||||||||||||||
1671 | move(index, indexTemporary); | - | ||||||||||||||||||
1672 | add32(Imm32(inputOffset), indexTemporary); | - | ||||||||||||||||||
1673 | setSubpatternEnd(indexTemporary, term->parentheses.subpatternId); | - | ||||||||||||||||||
1674 | } else executed 266 times by 2 tests: end of block Executed by:
| 266 | ||||||||||||||||||
1675 | setSubpatternEnd(index, term->parentheses.subpatternId); executed 1212 times by 3 tests: setSubpatternEnd(index, term->parentheses.subpatternId); Executed by:
| 1212 | ||||||||||||||||||
1676 | } | - | ||||||||||||||||||
1677 | - | |||||||||||||||||||
1678 | // If the parentheses are quantified Greedy then add a label to jump back | - | ||||||||||||||||||
1679 | // to if get a failed match from after the parentheses. For NonGreedy | - | ||||||||||||||||||
1680 | // parentheses, link the jump from before the subpattern to here. | - | ||||||||||||||||||
1681 | if (term->quantityType == QuantifierGreedy)
| 130-2298 | ||||||||||||||||||
1682 | op.m_reentry = label(); executed 130 times by 2 tests: op.m_reentry = label(); Executed by:
| 130 | ||||||||||||||||||
1683 | else if (term->quantityType == QuantifierNonGreedy) {
| 0-2296 | ||||||||||||||||||
1684 | YarrOp& beginOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
1685 | beginOp.m_jumps.link(this); | - | ||||||||||||||||||
1686 | } never executed: end of block | 0 | ||||||||||||||||||
1687 | break; executed 2425 times by 3 tests: break; Executed by:
| 2425 | ||||||||||||||||||
1688 | } | - | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | // OpParenthesesSubpatternTerminalBegin/End | - | ||||||||||||||||||
1691 | case OpParenthesesSubpatternTerminalBegin: { executed 12 times by 1 test: case OpParenthesesSubpatternTerminalBegin: Executed by:
| 12 | ||||||||||||||||||
1692 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1693 | ASSERT(term->quantityType == QuantifierGreedy); | - | ||||||||||||||||||
1694 | ASSERT(term->quantityCount == quantifyInfinite); | - | ||||||||||||||||||
1695 | ASSERT(!term->capture()); | - | ||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | // Upon entry set a label to loop back to. | - | ||||||||||||||||||
1698 | op.m_reentry = label(); | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | // Store the start index of the current match; we need to reject zero | - | ||||||||||||||||||
1701 | // length matches. | - | ||||||||||||||||||
1702 | storeToFrame(index, term->frameLocation); | - | ||||||||||||||||||
1703 | break; executed 11 times by 1 test: break; Executed by:
| 11 | ||||||||||||||||||
1704 | } | - | ||||||||||||||||||
1705 | case OpParenthesesSubpatternTerminalEnd: { executed 12 times by 1 test: case OpParenthesesSubpatternTerminalEnd: Executed by:
| 12 | ||||||||||||||||||
1706 | YarrOp& beginOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
1707 | #ifndef NDEBUG | - | ||||||||||||||||||
1708 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1709 | - | |||||||||||||||||||
1710 | // Runtime ASSERT to make sure that the nested alternative handled the | - | ||||||||||||||||||
1711 | // "no input consumed" check. | - | ||||||||||||||||||
1712 | Jump pastBreakpoint; | - | ||||||||||||||||||
1713 | pastBreakpoint = branch32(NotEqual, index, Address(stackPointerRegister, term->frameLocation * sizeof(void*))); | - | ||||||||||||||||||
1714 | breakpoint(); | - | ||||||||||||||||||
1715 | pastBreakpoint.link(this); | - | ||||||||||||||||||
1716 | #endif | - | ||||||||||||||||||
1717 | - | |||||||||||||||||||
1718 | // We know that the match is non-zero, we can accept it and | - | ||||||||||||||||||
1719 | // loop back up to the head of the subpattern. | - | ||||||||||||||||||
1720 | jump(beginOp.m_reentry); | - | ||||||||||||||||||
1721 | - | |||||||||||||||||||
1722 | // This is the entry point to jump to when we stop matching - we will | - | ||||||||||||||||||
1723 | // do so once the subpattern cannot match any more. | - | ||||||||||||||||||
1724 | op.m_reentry = label(); | - | ||||||||||||||||||
1725 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||
1726 | } | - | ||||||||||||||||||
1727 | - | |||||||||||||||||||
1728 | // OpParentheticalAssertionBegin/End | - | ||||||||||||||||||
1729 | case OpParentheticalAssertionBegin: { executed 68 times by 1 test: case OpParentheticalAssertionBegin: Executed by:
| 68 | ||||||||||||||||||
1730 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1731 | - | |||||||||||||||||||
1732 | // Store the current index - assertions should not update index, so | - | ||||||||||||||||||
1733 | // we will need to restore it upon a successful match. | - | ||||||||||||||||||
1734 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
1735 | storeToFrame(index, parenthesesFrameLocation); | - | ||||||||||||||||||
1736 | - | |||||||||||||||||||
1737 | // Check | - | ||||||||||||||||||
1738 | op.m_checkAdjust = m_checked - term->inputPosition; | - | ||||||||||||||||||
1739 | if (op.m_checkAdjust)
| 16-52 | ||||||||||||||||||
1740 | sub32(Imm32(op.m_checkAdjust), index); executed 16 times by 1 test: sub32(Imm32(op.m_checkAdjust), index); Executed by:
| 16 | ||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | m_checked -= op.m_checkAdjust; | - | ||||||||||||||||||
1743 | break; executed 68 times by 1 test: break; Executed by:
| 68 | ||||||||||||||||||
1744 | } | - | ||||||||||||||||||
1745 | case OpParentheticalAssertionEnd: { executed 68 times by 1 test: case OpParentheticalAssertionEnd: Executed by:
| 68 | ||||||||||||||||||
1746 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
1747 | - | |||||||||||||||||||
1748 | // Restore the input index value. | - | ||||||||||||||||||
1749 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
1750 | loadFromFrame(parenthesesFrameLocation, index); | - | ||||||||||||||||||
1751 | - | |||||||||||||||||||
1752 | // If inverted, a successful match of the assertion must be treated | - | ||||||||||||||||||
1753 | // as a failure, so jump to backtracking. | - | ||||||||||||||||||
1754 | if (term->invert()) {
| 28-40 | ||||||||||||||||||
1755 | op.m_jumps.append(jump()); | - | ||||||||||||||||||
1756 | op.m_reentry = label(); | - | ||||||||||||||||||
1757 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||
1758 | - | |||||||||||||||||||
1759 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
1760 | m_checked += lastOp.m_checkAdjust; | - | ||||||||||||||||||
1761 | break; executed 68 times by 1 test: break; Executed by:
| 68 | ||||||||||||||||||
1762 | } | - | ||||||||||||||||||
1763 | - | |||||||||||||||||||
1764 | case OpMatchFailed: executed 92 times by 4 tests: case OpMatchFailed: Executed by:
| 92 | ||||||||||||||||||
1765 | removeCallFrame(); | - | ||||||||||||||||||
1766 | move(TrustedImmPtr((void*)WTF::notFound), returnRegister); | - | ||||||||||||||||||
1767 | move(TrustedImm32(0), returnRegister2); | - | ||||||||||||||||||
1768 | generateReturn(); | - | ||||||||||||||||||
1769 | break; executed 92 times by 4 tests: break; Executed by:
| 92 | ||||||||||||||||||
1770 | } | - | ||||||||||||||||||
1771 | - | |||||||||||||||||||
1772 | ++opIndex; | - | ||||||||||||||||||
1773 | } while (opIndex < m_ops.size()); executed 4680815 times by 153 tests: end of block Executed by:
| 1150127-4680815 | ||||||||||||||||||
1774 | } executed 1150025 times by 153 tests: end of block Executed by:
| 1150025 | ||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | void backtrack() | - | ||||||||||||||||||
1777 | { | - | ||||||||||||||||||
1778 | // Backwards generate the backtracking code. | - | ||||||||||||||||||
1779 | size_t opIndex = m_ops.size(); | - | ||||||||||||||||||
1780 | ASSERT(opIndex); | - | ||||||||||||||||||
1781 | - | |||||||||||||||||||
1782 | do { | - | ||||||||||||||||||
1783 | --opIndex; | - | ||||||||||||||||||
1784 | YarrOp& op = m_ops[opIndex]; | - | ||||||||||||||||||
1785 | switch (op.m_op) { | - | ||||||||||||||||||
1786 | - | |||||||||||||||||||
1787 | case OpTerm: executed 2372176 times by 9 tests: case OpTerm: Executed by:
| 2372176 | ||||||||||||||||||
1788 | backtrackTerm(opIndex); | - | ||||||||||||||||||
1789 | break; executed 2373967 times by 9 tests: break; Executed by:
| 2373967 | ||||||||||||||||||
1790 | - | |||||||||||||||||||
1791 | // OpBodyAlternativeBegin/Next/End | - | ||||||||||||||||||
1792 | // | - | ||||||||||||||||||
1793 | // For each Begin/Next node representing an alternative, we need to decide what to do | - | ||||||||||||||||||
1794 | // in two circumstances: | - | ||||||||||||||||||
1795 | // - If we backtrack back into this node, from within the alternative. | - | ||||||||||||||||||
1796 | // - If the input check at the head of the alternative fails (if this exists). | - | ||||||||||||||||||
1797 | // | - | ||||||||||||||||||
1798 | // We treat these two cases differently since in the former case we have slightly | - | ||||||||||||||||||
1799 | // more information - since we are backtracking out of a prior alternative we know | - | ||||||||||||||||||
1800 | // that at least enough input was available to run it. For example, given the regular | - | ||||||||||||||||||
1801 | // expression /a|b/, if we backtrack out of the first alternative (a failed pattern | - | ||||||||||||||||||
1802 | // character match of 'a'), then we need not perform an additional input availability | - | ||||||||||||||||||
1803 | // check before running the second alternative. | - | ||||||||||||||||||
1804 | // | - | ||||||||||||||||||
1805 | // Backtracking required differs for the last alternative, which in the case of the | - | ||||||||||||||||||
1806 | // repeating set of alternatives must loop. The code generated for the last alternative | - | ||||||||||||||||||
1807 | // will also be used to handle all input check failures from any prior alternatives - | - | ||||||||||||||||||
1808 | // these require similar functionality, in seeking the next available alternative for | - | ||||||||||||||||||
1809 | // which there is sufficient input. | - | ||||||||||||||||||
1810 | // | - | ||||||||||||||||||
1811 | // Since backtracking of all other alternatives simply requires us to link backtracks | - | ||||||||||||||||||
1812 | // to the reentry point for the subsequent alternative, we will only be generating any | - | ||||||||||||||||||
1813 | // code when backtracking the last alternative. | - | ||||||||||||||||||
1814 | case OpBodyAlternativeBegin: executed 1149916 times by 153 tests: case OpBodyAlternativeBegin: Executed by:
| 1149916 | ||||||||||||||||||
1815 | case OpBodyAlternativeNext: { executed 206 times by 2 tests: case OpBodyAlternativeNext: Executed by:
| 206 | ||||||||||||||||||
1816 | PatternAlternative* alternative = op.m_alternative; | - | ||||||||||||||||||
1817 | - | |||||||||||||||||||
1818 | if (op.m_op == OpBodyAlternativeNext) {
| 205-1149200 | ||||||||||||||||||
1819 | PatternAlternative* priorAlternative = m_ops[op.m_previousOp].m_alternative; | - | ||||||||||||||||||
1820 | m_checked += priorAlternative->m_minimumSize; | - | ||||||||||||||||||
1821 | } executed 205 times by 2 tests: end of block Executed by:
| 205 | ||||||||||||||||||
1822 | m_checked -= alternative->m_minimumSize; | - | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | // Is this the last alternative? If not, then if we backtrack to this point we just | - | ||||||||||||||||||
1825 | // need to jump to try to match the next alternative. | - | ||||||||||||||||||
1826 | if (m_ops[op.m_nextOp].m_op != OpBodyAlternativeEnd) {
| 206-1150771 | ||||||||||||||||||
1827 | m_backtrackingState.linkTo(m_ops[op.m_nextOp].m_reentry, this); | - | ||||||||||||||||||
1828 | break; executed 206 times by 2 tests: break; Executed by:
| 206 | ||||||||||||||||||
1829 | } | - | ||||||||||||||||||
1830 | YarrOp& endOp = m_ops[op.m_nextOp]; | - | ||||||||||||||||||
1831 | - | |||||||||||||||||||
1832 | YarrOp* beginOp = &op; | - | ||||||||||||||||||
1833 | while (beginOp->m_op != OpBodyAlternativeBegin) {
| 205-1149349 | ||||||||||||||||||
1834 | ASSERT(beginOp->m_op == OpBodyAlternativeNext); | - | ||||||||||||||||||
1835 | beginOp = &m_ops[beginOp->m_previousOp]; | - | ||||||||||||||||||
1836 | } executed 205 times by 2 tests: end of block Executed by:
| 205 | ||||||||||||||||||
1837 | - | |||||||||||||||||||
1838 | bool onceThrough = endOp.m_nextOp == notFound; | - | ||||||||||||||||||
1839 | - | |||||||||||||||||||
1840 | // First, generate code to handle cases where we backtrack out of an attempted match | - | ||||||||||||||||||
1841 | // of the last alternative. If this is a 'once through' set of alternatives then we | - | ||||||||||||||||||
1842 | // have nothing to do - link this straight through to the End. | - | ||||||||||||||||||
1843 | if (onceThrough)
| 98-1148175 | ||||||||||||||||||
1844 | m_backtrackingState.linkTo(endOp.m_reentry, this); executed 98 times by 5 tests: m_backtrackingState.linkTo(endOp.m_reentry, this); Executed by:
| 98 | ||||||||||||||||||
1845 | else { | - | ||||||||||||||||||
1846 | // If we don't need to move the input poistion, and the pattern has a fixed size | - | ||||||||||||||||||
1847 | // (in which case we omit the store of the start index until the pattern has matched) | - | ||||||||||||||||||
1848 | // then we can just link the backtrack out of the last alternative straight to the | - | ||||||||||||||||||
1849 | // head of the first alternative. | - | ||||||||||||||||||
1850 | if (m_pattern.m_body->m_hasFixedSize
| 1075-1147173 | ||||||||||||||||||
1851 | && (alternative->m_minimumSize > beginOp->m_alternative->m_minimumSize)
| 60-1147026 | ||||||||||||||||||
1852 | && (alternative->m_minimumSize - beginOp->m_alternative->m_minimumSize == 1))
| 0-60 | ||||||||||||||||||
1853 | m_backtrackingState.linkTo(beginOp->m_reentry, this); executed 60 times by 1 test: m_backtrackingState.linkTo(beginOp->m_reentry, this); Executed by:
| 60 | ||||||||||||||||||
1854 | else { | - | ||||||||||||||||||
1855 | // We need to generate a trampoline of code to execute before looping back | - | ||||||||||||||||||
1856 | // around to the first alternative. | - | ||||||||||||||||||
1857 | m_backtrackingState.link(this); | - | ||||||||||||||||||
1858 | - | |||||||||||||||||||
1859 | // If the pattern size is not fixed, then store the start index, for use if we match. | - | ||||||||||||||||||
1860 | if (!m_pattern.m_body->m_hasFixedSize) {
| 1081-1148412 | ||||||||||||||||||
1861 | if (alternative->m_minimumSize == 1)
| 254-826 | ||||||||||||||||||
1862 | setMatchStart(index); executed 254 times by 5 tests: setMatchStart(index); Executed by:
| 254 | ||||||||||||||||||
1863 | else { | - | ||||||||||||||||||
1864 | move(index, regT0); | - | ||||||||||||||||||
1865 | if (alternative->m_minimumSize)
| 148-680 | ||||||||||||||||||
1866 | sub32(Imm32(alternative->m_minimumSize - 1), regT0); executed 677 times by 3 tests: sub32(Imm32(alternative->m_minimumSize - 1), regT0); Executed by:
| 677 | ||||||||||||||||||
1867 | else | - | ||||||||||||||||||
1868 | add32(TrustedImm32(1), regT0); executed 148 times by 2 tests: add32(TrustedImm32(1), regT0); Executed by:
| 148 | ||||||||||||||||||
1869 | setMatchStart(regT0); | - | ||||||||||||||||||
1870 | } executed 824 times by 3 tests: end of block Executed by:
| 824 | ||||||||||||||||||
1871 | } | - | ||||||||||||||||||
1872 | - | |||||||||||||||||||
1873 | // Generate code to loop. Check whether the last alternative is longer than the | - | ||||||||||||||||||
1874 | // first (e.g. /a|xy/ or /a|xyz/). | - | ||||||||||||||||||
1875 | if (alternative->m_minimumSize > beginOp->m_alternative->m_minimumSize) {
| 4-1149876 | ||||||||||||||||||
1876 | // We want to loop, and increment input position. If the delta is 1, it is | - | ||||||||||||||||||
1877 | // already correctly incremented, if more than one then decrement as appropriate. | - | ||||||||||||||||||
1878 | unsigned delta = alternative->m_minimumSize - beginOp->m_alternative->m_minimumSize; | - | ||||||||||||||||||
1879 | ASSERT(delta); | - | ||||||||||||||||||
1880 | if (delta != 1)
| 0-4 | ||||||||||||||||||
1881 | sub32(Imm32(delta - 1), index); executed 4 times by 1 test: sub32(Imm32(delta - 1), index); Executed by:
| 4 | ||||||||||||||||||
1882 | jump(beginOp->m_reentry); | - | ||||||||||||||||||
1883 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1884 | // If the first alternative has minimum size 0xFFFFFFFFu, then there cannot | - | ||||||||||||||||||
1885 | // be sufficent input available to handle this, so just fall through. | - | ||||||||||||||||||
1886 | unsigned delta = beginOp->m_alternative->m_minimumSize - alternative->m_minimumSize; | - | ||||||||||||||||||
1887 | if (delta != 0xFFFFFFFFu) {
| 0-1148115 | ||||||||||||||||||
1888 | // We need to check input because we are incrementing the input. | - | ||||||||||||||||||
1889 | add32(Imm32(delta + 1), index); | - | ||||||||||||||||||
1890 | checkInput().linkTo(beginOp->m_reentry, this); | - | ||||||||||||||||||
1891 | } executed 1149429 times by 153 tests: end of block Executed by:
| 1149429 | ||||||||||||||||||
1892 | } executed 1149538 times by 153 tests: end of block Executed by:
| 1149538 | ||||||||||||||||||
1893 | } | - | ||||||||||||||||||
1894 | } | - | ||||||||||||||||||
1895 | - | |||||||||||||||||||
1896 | // We can reach this point in the code in two ways: | - | ||||||||||||||||||
1897 | // - Fallthrough from the code above (a repeating alternative backtracked out of its | - | ||||||||||||||||||
1898 | // last alternative, and did not have sufficent input to run the first). | - | ||||||||||||||||||
1899 | // - We will loop back up to the following label when a releating alternative loops, | - | ||||||||||||||||||
1900 | // following a failed input check. | - | ||||||||||||||||||
1901 | // | - | ||||||||||||||||||
1902 | // Either way, we have just failed the input check for the first alternative. | - | ||||||||||||||||||
1903 | Label firstInputCheckFailed(this); | - | ||||||||||||||||||
1904 | - | |||||||||||||||||||
1905 | // Generate code to handle input check failures from alternatives except the last. | - | ||||||||||||||||||
1906 | // prevOp is the alternative we're handling a bail out from (initially Begin), and | - | ||||||||||||||||||
1907 | // nextOp is the alternative we will be attempting to reenter into. | - | ||||||||||||||||||
1908 | // | - | ||||||||||||||||||
1909 | // We will link input check failures from the forwards matching path back to the code | - | ||||||||||||||||||
1910 | // that can handle them. | - | ||||||||||||||||||
1911 | YarrOp* prevOp = beginOp; | - | ||||||||||||||||||
1912 | YarrOp* nextOp = &m_ops[beginOp->m_nextOp]; | - | ||||||||||||||||||
1913 | while (nextOp->m_op != OpBodyAlternativeEnd) {
| 206-1150607 | ||||||||||||||||||
1914 | prevOp->m_jumps.link(this); | - | ||||||||||||||||||
1915 | - | |||||||||||||||||||
1916 | // We only get here if an input check fails, it is only worth checking again | - | ||||||||||||||||||
1917 | // if the next alternative has a minimum size less than the last. | - | ||||||||||||||||||
1918 | if (prevOp->m_alternative->m_minimumSize > nextOp->m_alternative->m_minimumSize) {
| 20-186 | ||||||||||||||||||
1919 | // FIXME: if we added an extra label to YarrOp, we could avoid needing to | - | ||||||||||||||||||
1920 | // subtract delta back out, and reduce this code. Should performance test | - | ||||||||||||||||||
1921 | // the benefit of this. | - | ||||||||||||||||||
1922 | unsigned delta = prevOp->m_alternative->m_minimumSize - nextOp->m_alternative->m_minimumSize; | - | ||||||||||||||||||
1923 | sub32(Imm32(delta), index); | - | ||||||||||||||||||
1924 | Jump fail = jumpIfNoAvailableInput(); | - | ||||||||||||||||||
1925 | add32(Imm32(delta), index); | - | ||||||||||||||||||
1926 | jump(nextOp->m_reentry); | - | ||||||||||||||||||
1927 | fail.link(this); | - | ||||||||||||||||||
1928 | } else if (prevOp->m_alternative->m_minimumSize < nextOp->m_alternative->m_minimumSize) executed 20 times by 1 test: end of block Executed by:
| 20-118 | ||||||||||||||||||
1929 | add32(Imm32(nextOp->m_alternative->m_minimumSize - prevOp->m_alternative->m_minimumSize), index); executed 68 times by 1 test: add32(Imm32(nextOp->m_alternative->m_minimumSize - prevOp->m_alternative->m_minimumSize), index); Executed by:
| 68 | ||||||||||||||||||
1930 | prevOp = nextOp; | - | ||||||||||||||||||
1931 | nextOp = &m_ops[nextOp->m_nextOp]; | - | ||||||||||||||||||
1932 | } executed 206 times by 2 tests: end of block Executed by:
| 206 | ||||||||||||||||||
1933 | - | |||||||||||||||||||
1934 | // We fall through to here if there is insufficient input to run the last alternative. | - | ||||||||||||||||||
1935 | - | |||||||||||||||||||
1936 | // If there is insufficient input to run the last alternative, then for 'once through' | - | ||||||||||||||||||
1937 | // alternatives we are done - just jump back up into the forwards matching path at the End. | - | ||||||||||||||||||
1938 | if (onceThrough) {
| 98-1149378 | ||||||||||||||||||
1939 | op.m_jumps.linkTo(endOp.m_reentry, this); | - | ||||||||||||||||||
1940 | jump(endOp.m_reentry); | - | ||||||||||||||||||
1941 | break; executed 98 times by 5 tests: break; Executed by:
| 98 | ||||||||||||||||||
1942 | } | - | ||||||||||||||||||
1943 | - | |||||||||||||||||||
1944 | // For repeating alternatives, link any input check failure from the last alternative to | - | ||||||||||||||||||
1945 | // this point. | - | ||||||||||||||||||
1946 | op.m_jumps.link(this); | - | ||||||||||||||||||
1947 | - | |||||||||||||||||||
1948 | bool needsToUpdateMatchStart = !m_pattern.m_body->m_hasFixedSize; | - | ||||||||||||||||||
1949 | - | |||||||||||||||||||
1950 | // Check for cases where input position is already incremented by 1 for the last | - | ||||||||||||||||||
1951 | // alternative (this is particularly useful where the minimum size of the body | - | ||||||||||||||||||
1952 | // disjunction is 0, e.g. /a*|b/). | - | ||||||||||||||||||
1953 | if (needsToUpdateMatchStart && alternative->m_minimumSize == 1) {
| 254-1148712 | ||||||||||||||||||
1954 | // index is already incremented by 1, so just store it now! | - | ||||||||||||||||||
1955 | setMatchStart(index); | - | ||||||||||||||||||
1956 | needsToUpdateMatchStart = false; | - | ||||||||||||||||||
1957 | } executed 254 times by 5 tests: end of block Executed by:
| 254 | ||||||||||||||||||
1958 | - | |||||||||||||||||||
1959 | // Check whether there is sufficient input to loop. Increment the input position by | - | ||||||||||||||||||
1960 | // one, and check. Also add in the minimum disjunction size before checking - there | - | ||||||||||||||||||
1961 | // is no point in looping if we're just going to fail all the input checks around | - | ||||||||||||||||||
1962 | // the next iteration. | - | ||||||||||||||||||
1963 | ASSERT(alternative->m_minimumSize >= m_pattern.m_body->m_minimumSize); | - | ||||||||||||||||||
1964 | if (alternative->m_minimumSize == m_pattern.m_body->m_minimumSize) {
| 68-1148419 | ||||||||||||||||||
1965 | // If the last alternative had the same minimum size as the disjunction, | - | ||||||||||||||||||
1966 | // just simply increment input pos by 1, no adjustment based on minimum size. | - | ||||||||||||||||||
1967 | add32(TrustedImm32(1), index); | - | ||||||||||||||||||
1968 | } else { executed 1150407 times by 153 tests: end of block Executed by:
| 1150407 | ||||||||||||||||||
1969 | // If the minumum for the last alternative was one greater than than that | - | ||||||||||||||||||
1970 | // for the disjunction, we're already progressed by 1, nothing to do! | - | ||||||||||||||||||
1971 | unsigned delta = (alternative->m_minimumSize - m_pattern.m_body->m_minimumSize) - 1; | - | ||||||||||||||||||
1972 | if (delta)
| 4-64 | ||||||||||||||||||
1973 | sub32(Imm32(delta), index); executed 4 times by 1 test: sub32(Imm32(delta), index); Executed by:
| 4 | ||||||||||||||||||
1974 | } executed 68 times by 1 test: end of block Executed by:
| 68 | ||||||||||||||||||
1975 | Jump matchFailed = jumpIfNoAvailableInput(); | - | ||||||||||||||||||
1976 | - | |||||||||||||||||||
1977 | if (needsToUpdateMatchStart) {
| 826-1148728 | ||||||||||||||||||
1978 | if (!m_pattern.m_body->m_minimumSize)
| 148-678 | ||||||||||||||||||
1979 | setMatchStart(index); executed 148 times by 2 tests: setMatchStart(index); Executed by:
| 148 | ||||||||||||||||||
1980 | else { | - | ||||||||||||||||||
1981 | move(index, regT0); | - | ||||||||||||||||||
1982 | sub32(Imm32(m_pattern.m_body->m_minimumSize), regT0); | - | ||||||||||||||||||
1983 | setMatchStart(regT0); | - | ||||||||||||||||||
1984 | } executed 680 times by 3 tests: end of block Executed by:
| 680 | ||||||||||||||||||
1985 | } | - | ||||||||||||||||||
1986 | - | |||||||||||||||||||
1987 | // Calculate how much more input the first alternative requires than the minimum | - | ||||||||||||||||||
1988 | // for the body as a whole. If no more is needed then we dont need an additional | - | ||||||||||||||||||
1989 | // input check here - jump straight back up to the start of the first alternative. | - | ||||||||||||||||||
1990 | if (beginOp->m_alternative->m_minimumSize == m_pattern.m_body->m_minimumSize)
| 20-1149781 | ||||||||||||||||||
1991 | jump(beginOp->m_reentry); executed 1149975 times by 153 tests: jump(beginOp->m_reentry); Executed by:
| 1149975 | ||||||||||||||||||
1992 | else { | - | ||||||||||||||||||
1993 | if (beginOp->m_alternative->m_minimumSize > m_pattern.m_body->m_minimumSize)
| 0-20 | ||||||||||||||||||
1994 | add32(Imm32(beginOp->m_alternative->m_minimumSize - m_pattern.m_body->m_minimumSize), index); executed 20 times by 1 test: add32(Imm32(beginOp->m_alternative->m_minimumSize - m_pattern.m_body->m_minimumSize), index); Executed by:
| 20 | ||||||||||||||||||
1995 | else | - | ||||||||||||||||||
1996 | sub32(Imm32(m_pattern.m_body->m_minimumSize - beginOp->m_alternative->m_minimumSize), index); never executed: sub32(Imm32(m_pattern.m_body->m_minimumSize - beginOp->m_alternative->m_minimumSize), index); | 0 | ||||||||||||||||||
1997 | checkInput().linkTo(beginOp->m_reentry, this); | - | ||||||||||||||||||
1998 | jump(firstInputCheckFailed); | - | ||||||||||||||||||
1999 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | // We jump to here if we iterate to the point that there is insufficient input to | - | ||||||||||||||||||
2002 | // run any matches, and need to return a failure state from JIT code. | - | ||||||||||||||||||
2003 | matchFailed.link(this); | - | ||||||||||||||||||
2004 | - | |||||||||||||||||||
2005 | removeCallFrame(); | - | ||||||||||||||||||
2006 | move(TrustedImmPtr((void*)WTF::notFound), returnRegister); | - | ||||||||||||||||||
2007 | move(TrustedImm32(0), returnRegister2); | - | ||||||||||||||||||
2008 | generateReturn(); | - | ||||||||||||||||||
2009 | break; executed 1150840 times by 153 tests: break; Executed by:
| 1150840 | ||||||||||||||||||
2010 | } | - | ||||||||||||||||||
2011 | case OpBodyAlternativeEnd: { executed 1148142 times by 153 tests: case OpBodyAlternativeEnd: Executed by:
| 1148142 | ||||||||||||||||||
2012 | // We should never backtrack back into a body disjunction. | - | ||||||||||||||||||
2013 | ASSERT(m_backtrackingState.isEmpty()); | - | ||||||||||||||||||
2014 | - | |||||||||||||||||||
2015 | PatternAlternative* priorAlternative = m_ops[op.m_previousOp].m_alternative; | - | ||||||||||||||||||
2016 | m_checked += priorAlternative->m_minimumSize; | - | ||||||||||||||||||
2017 | break; executed 1147760 times by 153 tests: break; Executed by:
| 1147760 | ||||||||||||||||||
2018 | } | - | ||||||||||||||||||
2019 | - | |||||||||||||||||||
2020 | // OpSimpleNestedAlternativeBegin/Next/End | - | ||||||||||||||||||
2021 | // OpNestedAlternativeBegin/Next/End | - | ||||||||||||||||||
2022 | // | - | ||||||||||||||||||
2023 | // Generate code for when we backtrack back out of an alternative into | - | ||||||||||||||||||
2024 | // a Begin or Next node, or when the entry input count check fails. If | - | ||||||||||||||||||
2025 | // there are more alternatives we need to jump to the next alternative, | - | ||||||||||||||||||
2026 | // if not we backtrack back out of the current set of parentheses. | - | ||||||||||||||||||
2027 | // | - | ||||||||||||||||||
2028 | // In the case of non-simple nested assertions we need to also link the | - | ||||||||||||||||||
2029 | // 'return address' appropriately to backtrack back out into the correct | - | ||||||||||||||||||
2030 | // alternative. | - | ||||||||||||||||||
2031 | case OpSimpleNestedAlternativeBegin: executed 2343 times by 3 tests: case OpSimpleNestedAlternativeBegin: Executed by:
| 2343 | ||||||||||||||||||
2032 | case OpSimpleNestedAlternativeNext: executed 36 times by 1 test: case OpSimpleNestedAlternativeNext: Executed by:
| 36 | ||||||||||||||||||
2033 | case OpNestedAlternativeBegin: executed 166 times by 3 tests: case OpNestedAlternativeBegin: Executed by:
| 166 | ||||||||||||||||||
2034 | case OpNestedAlternativeNext: { executed 346 times by 3 tests: case OpNestedAlternativeNext: Executed by:
| 346 | ||||||||||||||||||
2035 | YarrOp& nextOp = m_ops[op.m_nextOp]; | - | ||||||||||||||||||
2036 | bool isBegin = op.m_previousOp == notFound; | - | ||||||||||||||||||
2037 | bool isLastAlternative = nextOp.m_nextOp == notFound; | - | ||||||||||||||||||
2038 | ASSERT(isBegin == (op.m_op == OpSimpleNestedAlternativeBegin || op.m_op == OpNestedAlternativeBegin)); | - | ||||||||||||||||||
2039 | ASSERT(isLastAlternative == (nextOp.m_op == OpSimpleNestedAlternativeEnd || nextOp.m_op == OpNestedAlternativeEnd)); | - | ||||||||||||||||||
2040 | - | |||||||||||||||||||
2041 | // Treat an input check failure the same as a failed match. | - | ||||||||||||||||||
2042 | m_backtrackingState.append(op.m_jumps); | - | ||||||||||||||||||
2043 | - | |||||||||||||||||||
2044 | // Set the backtracks to jump to the appropriate place. We may need | - | ||||||||||||||||||
2045 | // to link the backtracks in one of three different way depending on | - | ||||||||||||||||||
2046 | // the type of alternative we are dealing with: | - | ||||||||||||||||||
2047 | // - A single alternative, with no simplings. | - | ||||||||||||||||||
2048 | // - The last alternative of a set of two or more. | - | ||||||||||||||||||
2049 | // - An alternative other than the last of a set of two or more. | - | ||||||||||||||||||
2050 | // | - | ||||||||||||||||||
2051 | // In the case of a single alternative on its own, we don't need to | - | ||||||||||||||||||
2052 | // jump anywhere - if the alternative fails to match we can just | - | ||||||||||||||||||
2053 | // continue to backtrack out of the parentheses without jumping. | - | ||||||||||||||||||
2054 | // | - | ||||||||||||||||||
2055 | // In the case of the last alternative in a set of more than one, we | - | ||||||||||||||||||
2056 | // need to jump to return back out to the beginning. We'll do so by | - | ||||||||||||||||||
2057 | // adding a jump to the End node's m_jumps list, and linking this | - | ||||||||||||||||||
2058 | // when we come to generate the Begin node. For alternatives other | - | ||||||||||||||||||
2059 | // than the last, we need to jump to the next alternative. | - | ||||||||||||||||||
2060 | // | - | ||||||||||||||||||
2061 | // If the alternative had adjusted the input position we must link | - | ||||||||||||||||||
2062 | // backtracking to here, correct, and then jump on. If not we can | - | ||||||||||||||||||
2063 | // link the backtracks directly to their destination. | - | ||||||||||||||||||
2064 | if (op.m_checkAdjust) {
| 291-2596 | ||||||||||||||||||
2065 | // Handle the cases where we need to link the backtracks here. | - | ||||||||||||||||||
2066 | m_backtrackingState.link(this); | - | ||||||||||||||||||
2067 | sub32(Imm32(op.m_checkAdjust), index); | - | ||||||||||||||||||
2068 | if (!isLastAlternative) {
| 54-238 | ||||||||||||||||||
2069 | // An alternative that is not the last should jump to its successor. | - | ||||||||||||||||||
2070 | jump(nextOp.m_reentry); | - | ||||||||||||||||||
2071 | } else if (!isBegin) { executed 54 times by 3 tests: end of block Executed by:
| 54-174 | ||||||||||||||||||
2072 | // The last of more than one alternatives must jump back to the beginning. | - | ||||||||||||||||||
2073 | nextOp.m_jumps.append(jump()); | - | ||||||||||||||||||
2074 | } else { executed 63 times by 1 test: end of block Executed by:
| 63 | ||||||||||||||||||
2075 | // A single alternative on its own can fall through. | - | ||||||||||||||||||
2076 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
2077 | } executed 174 times by 2 tests: end of block Executed by:
| 174 | ||||||||||||||||||
2078 | } else { | - | ||||||||||||||||||
2079 | // Handle the cases where we can link the backtracks directly to their destinations. | - | ||||||||||||||||||
2080 | if (!isLastAlternative) {
| 328-2267 | ||||||||||||||||||
2081 | // An alternative that is not the last should jump to its successor. | - | ||||||||||||||||||
2082 | m_backtrackingState.linkTo(nextOp.m_reentry, this); | - | ||||||||||||||||||
2083 | } else if (!isBegin) { executed 327 times by 1 test: end of block Executed by:
| 137-2131 | ||||||||||||||||||
2084 | // The last of more than one alternatives must jump back to the beginning. | - | ||||||||||||||||||
2085 | m_backtrackingState.takeBacktracksToJumpList(nextOp.m_jumps, this); | - | ||||||||||||||||||
2086 | } executed 137 times by 3 tests: end of block Executed by:
| 137 | ||||||||||||||||||
2087 | // In the case of a single alternative on its own do nothing - it can fall through. | - | ||||||||||||||||||
2088 | } executed 2595 times by 3 tests: end of block Executed by:
| 2595 | ||||||||||||||||||
2089 | - | |||||||||||||||||||
2090 | // If there is a backtrack jump from a zero length match link it here. | - | ||||||||||||||||||
2091 | if (op.m_zeroLengthMatch.isSet())
| 0-2887 | ||||||||||||||||||
2092 | m_backtrackingState.append(op.m_zeroLengthMatch); never executed: m_backtrackingState.append(op.m_zeroLengthMatch); | 0 | ||||||||||||||||||
2093 | - | |||||||||||||||||||
2094 | // At this point we've handled the backtracking back into this node. | - | ||||||||||||||||||
2095 | // Now link any backtracks that need to jump to here. | - | ||||||||||||||||||
2096 | - | |||||||||||||||||||
2097 | // For non-simple alternatives, link the alternative's 'return address' | - | ||||||||||||||||||
2098 | // so that we backtrack back out into the previous alternative. | - | ||||||||||||||||||
2099 | if (op.m_op == OpNestedAlternativeNext)
| 346-2539 | ||||||||||||||||||
2100 | m_backtrackingState.append(op.m_returnAddress); executed 346 times by 3 tests: m_backtrackingState.append(op.m_returnAddress); Executed by:
| 346 | ||||||||||||||||||
2101 | - | |||||||||||||||||||
2102 | // If there is more than one alternative, then the last alternative will | - | ||||||||||||||||||
2103 | // have planted a jump to be linked to the end. This jump was added to the | - | ||||||||||||||||||
2104 | // End node's m_jumps list. If we are back at the beginning, link it here. | - | ||||||||||||||||||
2105 | if (isBegin) {
| 382-2505 | ||||||||||||||||||
2106 | YarrOp* endOp = &m_ops[op.m_nextOp]; | - | ||||||||||||||||||
2107 | while (endOp->m_nextOp != notFound) {
| 381-2506 | ||||||||||||||||||
2108 | ASSERT(endOp->m_op == OpSimpleNestedAlternativeNext || endOp->m_op == OpNestedAlternativeNext); | - | ||||||||||||||||||
2109 | endOp = &m_ops[endOp->m_nextOp]; | - | ||||||||||||||||||
2110 | } executed 381 times by 3 tests: end of block Executed by:
| 381 | ||||||||||||||||||
2111 | ASSERT(endOp->m_op == OpSimpleNestedAlternativeEnd || endOp->m_op == OpNestedAlternativeEnd); | - | ||||||||||||||||||
2112 | m_backtrackingState.append(endOp->m_jumps); | - | ||||||||||||||||||
2113 | } executed 2507 times by 3 tests: end of block Executed by:
| 2507 | ||||||||||||||||||
2114 | - | |||||||||||||||||||
2115 | if (!isBegin) {
| 382-2506 | ||||||||||||||||||
2116 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
2117 | m_checked += lastOp.m_checkAdjust; | - | ||||||||||||||||||
2118 | } executed 382 times by 3 tests: end of block Executed by:
| 382 | ||||||||||||||||||
2119 | m_checked -= op.m_checkAdjust; | - | ||||||||||||||||||
2120 | break; executed 2890 times by 3 tests: break; Executed by:
| 2890 | ||||||||||||||||||
2121 | } | - | ||||||||||||||||||
2122 | case OpSimpleNestedAlternativeEnd: executed 2343 times by 3 tests: case OpSimpleNestedAlternativeEnd: Executed by:
| 2343 | ||||||||||||||||||
2123 | case OpNestedAlternativeEnd: { executed 163 times by 3 tests: case OpNestedAlternativeEnd: Executed by:
| 163 | ||||||||||||||||||
2124 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
2125 | - | |||||||||||||||||||
2126 | // If there is a backtrack jump from a zero length match link it here. | - | ||||||||||||||||||
2127 | if (op.m_zeroLengthMatch.isSet())
| 0-2505 | ||||||||||||||||||
2128 | m_backtrackingState.append(op.m_zeroLengthMatch); never executed: m_backtrackingState.append(op.m_zeroLengthMatch); | 0 | ||||||||||||||||||
2129 | - | |||||||||||||||||||
2130 | // If we backtrack into the end of a simple subpattern do nothing; | - | ||||||||||||||||||
2131 | // just continue through into the last alternative. If we backtrack | - | ||||||||||||||||||
2132 | // into the end of a non-simple set of alterntives we need to jump | - | ||||||||||||||||||
2133 | // to the backtracking return address set up during generation. | - | ||||||||||||||||||
2134 | if (op.m_op == OpNestedAlternativeEnd) {
| 164-2341 | ||||||||||||||||||
2135 | m_backtrackingState.link(this); | - | ||||||||||||||||||
2136 | - | |||||||||||||||||||
2137 | // Plant a jump to the return address. | - | ||||||||||||||||||
2138 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
2139 | unsigned alternativeFrameLocation = parenthesesFrameLocation; | - | ||||||||||||||||||
2140 | if (term->quantityType != QuantifierFixedCount)
| 0-165 | ||||||||||||||||||
2141 | alternativeFrameLocation += YarrStackSpaceForBackTrackInfoParenthesesOnce; never executed: alternativeFrameLocation += 1; | 0 | ||||||||||||||||||
2142 | loadFromFrameAndJump(alternativeFrameLocation); | - | ||||||||||||||||||
2143 | - | |||||||||||||||||||
2144 | // Link the DataLabelPtr associated with the end of the last | - | ||||||||||||||||||
2145 | // alternative to this point. | - | ||||||||||||||||||
2146 | m_backtrackingState.append(op.m_returnAddress); | - | ||||||||||||||||||
2147 | } executed 166 times by 3 tests: end of block Executed by:
| 166 | ||||||||||||||||||
2148 | - | |||||||||||||||||||
2149 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
2150 | m_checked += lastOp.m_checkAdjust; | - | ||||||||||||||||||
2151 | break; executed 2507 times by 3 tests: break; Executed by:
| 2507 | ||||||||||||||||||
2152 | } | - | ||||||||||||||||||
2153 | - | |||||||||||||||||||
2154 | // OpParenthesesSubpatternOnceBegin/End | - | ||||||||||||||||||
2155 | // | - | ||||||||||||||||||
2156 | // When we are backtracking back out of a capturing subpattern we need | - | ||||||||||||||||||
2157 | // to clear the start index in the matches output array, to record that | - | ||||||||||||||||||
2158 | // this subpattern has not been captured. | - | ||||||||||||||||||
2159 | // | - | ||||||||||||||||||
2160 | // When backtracking back out of a Greedy quantified subpattern we need | - | ||||||||||||||||||
2161 | // to catch this, and try running the remainder of the alternative after | - | ||||||||||||||||||
2162 | // the subpattern again, skipping the parentheses. | - | ||||||||||||||||||
2163 | // | - | ||||||||||||||||||
2164 | // Upon backtracking back into a quantified set of parentheses we need to | - | ||||||||||||||||||
2165 | // check whether we were currently skipping the subpattern. If not, we | - | ||||||||||||||||||
2166 | // can backtrack into them, if we were we need to either backtrack back | - | ||||||||||||||||||
2167 | // out of the start of the parentheses, or jump back to the forwards | - | ||||||||||||||||||
2168 | // matching start, depending of whether the match is Greedy or NonGreedy. | - | ||||||||||||||||||
2169 | case OpParenthesesSubpatternOnceBegin: { executed 2425 times by 3 tests: case OpParenthesesSubpatternOnceBegin: Executed by:
| 2425 | ||||||||||||||||||
2170 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
2171 | ASSERT(term->quantityCount == 1); | - | ||||||||||||||||||
2172 | - | |||||||||||||||||||
2173 | // We only need to backtrack to thispoint if capturing or greedy. | - | ||||||||||||||||||
2174 | if ((term->capture() && compileMode == IncludeSubpatterns) || term->quantityType == QuantifierGreedy) {
| 0-1476 | ||||||||||||||||||
2175 | m_backtrackingState.link(this); | - | ||||||||||||||||||
2176 | - | |||||||||||||||||||
2177 | // If capturing, clear the capture (we only need to reset start). | - | ||||||||||||||||||
2178 | if (term->capture() && compileMode == IncludeSubpatterns)
| 0-1478 | ||||||||||||||||||
2179 | clearSubpatternStart(term->parentheses.subpatternId); executed 1478 times by 3 tests: clearSubpatternStart(term->parentheses.subpatternId); Executed by:
| 1478 | ||||||||||||||||||
2180 | - | |||||||||||||||||||
2181 | // If Greedy, jump to the end. | - | ||||||||||||||||||
2182 | if (term->quantityType == QuantifierGreedy) {
| 129-1347 | ||||||||||||||||||
2183 | // Clear the flag in the stackframe indicating we ran through the subpattern. | - | ||||||||||||||||||
2184 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
2185 | storeToFrame(TrustedImm32(-1), parenthesesFrameLocation); | - | ||||||||||||||||||
2186 | // Jump to after the parentheses, skipping the subpattern. | - | ||||||||||||||||||
2187 | jump(m_ops[op.m_nextOp].m_reentry); | - | ||||||||||||||||||
2188 | // A backtrack from after the parentheses, when skipping the subpattern, | - | ||||||||||||||||||
2189 | // will jump back to here. | - | ||||||||||||||||||
2190 | op.m_jumps.link(this); | - | ||||||||||||||||||
2191 | } executed 130 times by 2 tests: end of block Executed by:
| 130 | ||||||||||||||||||
2192 | - | |||||||||||||||||||
2193 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
2194 | } executed 1477 times by 3 tests: end of block Executed by:
| 1477 | ||||||||||||||||||
2195 | break; executed 2429 times by 3 tests: break; Executed by:
| 2429 | ||||||||||||||||||
2196 | } | - | ||||||||||||||||||
2197 | case OpParenthesesSubpatternOnceEnd: { executed 2429 times by 3 tests: case OpParenthesesSubpatternOnceEnd: Executed by:
| 2429 | ||||||||||||||||||
2198 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
2199 | - | |||||||||||||||||||
2200 | if (term->quantityType != QuantifierFixedCount) {
| 129-2298 | ||||||||||||||||||
2201 | m_backtrackingState.link(this); | - | ||||||||||||||||||
2202 | - | |||||||||||||||||||
2203 | // Check whether we should backtrack back into the parentheses, or if we | - | ||||||||||||||||||
2204 | // are currently in a state where we had skipped over the subpattern | - | ||||||||||||||||||
2205 | // (in which case the flag value on the stack will be -1). | - | ||||||||||||||||||
2206 | unsigned parenthesesFrameLocation = term->frameLocation; | - | ||||||||||||||||||
2207 | Jump hadSkipped = branch32(Equal, Address(stackPointerRegister, parenthesesFrameLocation * sizeof(void*)), TrustedImm32(-1)); | - | ||||||||||||||||||
2208 | - | |||||||||||||||||||
2209 | if (term->quantityType == QuantifierGreedy) {
| 0-129 | ||||||||||||||||||
2210 | // For Greedy parentheses, we skip after having already tried going | - | ||||||||||||||||||
2211 | // through the subpattern, so if we get here we're done. | - | ||||||||||||||||||
2212 | YarrOp& beginOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
2213 | beginOp.m_jumps.append(hadSkipped); | - | ||||||||||||||||||
2214 | } else { executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||||||||
2215 | // For NonGreedy parentheses, we try skipping the subpattern first, | - | ||||||||||||||||||
2216 | // so if we get here we need to try running through the subpattern | - | ||||||||||||||||||
2217 | // next. Jump back to the start of the parentheses in the forwards | - | ||||||||||||||||||
2218 | // matching path. | - | ||||||||||||||||||
2219 | ASSERT(term->quantityType == QuantifierNonGreedy); | - | ||||||||||||||||||
2220 | YarrOp& beginOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
2221 | hadSkipped.linkTo(beginOp.m_reentry, this); | - | ||||||||||||||||||
2222 | } never executed: end of block | 0 | ||||||||||||||||||
2223 | - | |||||||||||||||||||
2224 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
2225 | } executed 130 times by 2 tests: end of block Executed by:
| 130 | ||||||||||||||||||
2226 | - | |||||||||||||||||||
2227 | m_backtrackingState.append(op.m_jumps); | - | ||||||||||||||||||
2228 | break; executed 2426 times by 3 tests: break; Executed by:
| 2426 | ||||||||||||||||||
2229 | } | - | ||||||||||||||||||
2230 | - | |||||||||||||||||||
2231 | // OpParenthesesSubpatternTerminalBegin/End | - | ||||||||||||||||||
2232 | // | - | ||||||||||||||||||
2233 | // Terminal subpatterns will always match - there is nothing after them to | - | ||||||||||||||||||
2234 | // force a backtrack, and they have a minimum count of 0, and as such will | - | ||||||||||||||||||
2235 | // always produce an acceptable result. | - | ||||||||||||||||||
2236 | case OpParenthesesSubpatternTerminalBegin: { executed 12 times by 1 test: case OpParenthesesSubpatternTerminalBegin: Executed by:
| 12 | ||||||||||||||||||
2237 | // We will backtrack to this point once the subpattern cannot match any | - | ||||||||||||||||||
2238 | // more. Since no match is accepted as a successful match (we are Greedy | - | ||||||||||||||||||
2239 | // quantified with a minimum of zero) jump back to the forwards matching | - | ||||||||||||||||||
2240 | // path at the end. | - | ||||||||||||||||||
2241 | YarrOp& endOp = m_ops[op.m_nextOp]; | - | ||||||||||||||||||
2242 | m_backtrackingState.linkTo(endOp.m_reentry, this); | - | ||||||||||||||||||
2243 | break; executed 11 times by 1 test: break; Executed by:
| 11 | ||||||||||||||||||
2244 | } | - | ||||||||||||||||||
2245 | case OpParenthesesSubpatternTerminalEnd: executed 11 times by 1 test: case OpParenthesesSubpatternTerminalEnd: Executed by:
| 11 | ||||||||||||||||||
2246 | // We should never be backtracking to here (hence the 'terminal' in the name). | - | ||||||||||||||||||
2247 | ASSERT(m_backtrackingState.isEmpty()); | - | ||||||||||||||||||
2248 | m_backtrackingState.append(op.m_jumps); | - | ||||||||||||||||||
2249 | break; executed 11 times by 1 test: break; Executed by:
| 11 | ||||||||||||||||||
2250 | - | |||||||||||||||||||
2251 | // OpParentheticalAssertionBegin/End | - | ||||||||||||||||||
2252 | case OpParentheticalAssertionBegin: { executed 68 times by 1 test: case OpParentheticalAssertionBegin: Executed by:
| 68 | ||||||||||||||||||
2253 | PatternTerm* term = op.m_term; | - | ||||||||||||||||||
2254 | YarrOp& endOp = m_ops[op.m_nextOp]; | - | ||||||||||||||||||
2255 | - | |||||||||||||||||||
2256 | // We need to handle the backtracks upon backtracking back out | - | ||||||||||||||||||
2257 | // of a parenthetical assertion if either we need to correct | - | ||||||||||||||||||
2258 | // the input index, or the assertion was inverted. | - | ||||||||||||||||||
2259 | if (op.m_checkAdjust || term->invert()) {
| 16-52 | ||||||||||||||||||
2260 | m_backtrackingState.link(this); | - | ||||||||||||||||||
2261 | - | |||||||||||||||||||
2262 | if (op.m_checkAdjust)
| 16-24 | ||||||||||||||||||
2263 | add32(Imm32(op.m_checkAdjust), index); executed 16 times by 1 test: add32(Imm32(op.m_checkAdjust), index); Executed by:
| 16 | ||||||||||||||||||
2264 | - | |||||||||||||||||||
2265 | // In an inverted assertion failure to match the subpattern | - | ||||||||||||||||||
2266 | // is treated as a successful match - jump to the end of the | - | ||||||||||||||||||
2267 | // subpattern. We already have adjusted the input position | - | ||||||||||||||||||
2268 | // back to that before the assertion, which is correct. | - | ||||||||||||||||||
2269 | if (term->invert())
| 0-40 | ||||||||||||||||||
2270 | jump(endOp.m_reentry); executed 40 times by 1 test: jump(endOp.m_reentry); Executed by:
| 40 | ||||||||||||||||||
2271 | - | |||||||||||||||||||
2272 | m_backtrackingState.fallthrough(); | - | ||||||||||||||||||
2273 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||
2274 | - | |||||||||||||||||||
2275 | // The End node's jump list will contain any backtracks into | - | ||||||||||||||||||
2276 | // the end of the assertion. Also, if inverted, we will have | - | ||||||||||||||||||
2277 | // added the failure caused by a successful match to this. | - | ||||||||||||||||||
2278 | m_backtrackingState.append(endOp.m_jumps); | - | ||||||||||||||||||
2279 | - | |||||||||||||||||||
2280 | m_checked += op.m_checkAdjust; | - | ||||||||||||||||||
2281 | break; executed 68 times by 1 test: break; Executed by:
| 68 | ||||||||||||||||||
2282 | } | - | ||||||||||||||||||
2283 | case OpParentheticalAssertionEnd: { executed 68 times by 1 test: case OpParentheticalAssertionEnd: Executed by:
| 68 | ||||||||||||||||||
2284 | // FIXME: We should really be clearing any nested subpattern | - | ||||||||||||||||||
2285 | // matches on bailing out from after the pattern. Firefox has | - | ||||||||||||||||||
2286 | // this bug too (presumably because they use YARR!) | - | ||||||||||||||||||
2287 | - | |||||||||||||||||||
2288 | // Never backtrack into an assertion; later failures bail to before the begin. | - | ||||||||||||||||||
2289 | m_backtrackingState.takeBacktracksToJumpList(op.m_jumps, this); | - | ||||||||||||||||||
2290 | - | |||||||||||||||||||
2291 | YarrOp& lastOp = m_ops[op.m_previousOp]; | - | ||||||||||||||||||
2292 | m_checked -= lastOp.m_checkAdjust; | - | ||||||||||||||||||
2293 | break; executed 68 times by 1 test: break; Executed by:
| 68 | ||||||||||||||||||
2294 | } | - | ||||||||||||||||||
2295 | - | |||||||||||||||||||
2296 | case OpMatchFailed: executed 92 times by 4 tests: case OpMatchFailed: Executed by:
| 92 | ||||||||||||||||||
2297 | break; executed 92 times by 4 tests: break; Executed by:
| 92 | ||||||||||||||||||
2298 | } | - | ||||||||||||||||||
2299 | - | |||||||||||||||||||
2300 | } while (opIndex); executed 4683088 times by 153 tests: end of block Executed by:
| 1150184-4683088 | ||||||||||||||||||
2301 | } executed 1151009 times by 153 tests: end of block Executed by:
| 1151009 | ||||||||||||||||||
2302 | - | |||||||||||||||||||
2303 | // Compilation methods: | - | ||||||||||||||||||
2304 | // ==================== | - | ||||||||||||||||||
2305 | - | |||||||||||||||||||
2306 | // opCompileParenthesesSubpattern | - | ||||||||||||||||||
2307 | // Emits ops for a subpattern (set of parentheses). These consist | - | ||||||||||||||||||
2308 | // of a set of alternatives wrapped in an outer set of nodes for | - | ||||||||||||||||||
2309 | // the parentheses. | - | ||||||||||||||||||
2310 | // Supported types of parentheses are 'Once' (quantityCount == 1) | - | ||||||||||||||||||
2311 | // and 'Terminal' (non-capturing parentheses quantified as greedy | - | ||||||||||||||||||
2312 | // and infinite). | - | ||||||||||||||||||
2313 | // Alternatives will use the 'Simple' set of ops if either the | - | ||||||||||||||||||
2314 | // subpattern is terminal (in which case we will never need to | - | ||||||||||||||||||
2315 | // backtrack), or if the subpattern only contains one alternative. | - | ||||||||||||||||||
2316 | void opCompileParenthesesSubpattern(PatternTerm* term) | - | ||||||||||||||||||
2317 | { | - | ||||||||||||||||||
2318 | YarrOpCode parenthesesBeginOpCode; | - | ||||||||||||||||||
2319 | YarrOpCode parenthesesEndOpCode; | - | ||||||||||||||||||
2320 | YarrOpCode alternativeBeginOpCode = OpSimpleNestedAlternativeBegin; | - | ||||||||||||||||||
2321 | YarrOpCode alternativeNextOpCode = OpSimpleNestedAlternativeNext; | - | ||||||||||||||||||
2322 | YarrOpCode alternativeEndOpCode = OpSimpleNestedAlternativeEnd; | - | ||||||||||||||||||
2323 | - | |||||||||||||||||||
2324 | // We can currently only compile quantity 1 subpatterns that are | - | ||||||||||||||||||
2325 | // not copies. We generate a copy in the case of a range quantifier, | - | ||||||||||||||||||
2326 | // e.g. /(?:x){3,9}/, or /(?:x)+/ (These are effectively expanded to | - | ||||||||||||||||||
2327 | // /(?:x){3,3}(?:x){0,6}/ and /(?:x)(?:x)*/ repectively). The problem | - | ||||||||||||||||||
2328 | // comes where the subpattern is capturing, in which case we would | - | ||||||||||||||||||
2329 | // need to restore the capture from the first subpattern upon a | - | ||||||||||||||||||
2330 | // failure in the second. | - | ||||||||||||||||||
2331 | if (term->quantityCount == 1 && !term->parentheses.isCopy) {
| 0-2702 | ||||||||||||||||||
2332 | // Select the 'Once' nodes. | - | ||||||||||||||||||
2333 | parenthesesBeginOpCode = OpParenthesesSubpatternOnceBegin; | - | ||||||||||||||||||
2334 | parenthesesEndOpCode = OpParenthesesSubpatternOnceEnd; | - | ||||||||||||||||||
2335 | - | |||||||||||||||||||
2336 | // If there is more than one alternative we cannot use the 'simple' nodes. | - | ||||||||||||||||||
2337 | if (term->parentheses.disjunction->m_alternatives.size() != 1) {
| 272-2429 | ||||||||||||||||||
2338 | alternativeBeginOpCode = OpNestedAlternativeBegin; | - | ||||||||||||||||||
2339 | alternativeNextOpCode = OpNestedAlternativeNext; | - | ||||||||||||||||||
2340 | alternativeEndOpCode = OpNestedAlternativeEnd; | - | ||||||||||||||||||
2341 | } executed 272 times by 3 tests: end of block Executed by:
| 272 | ||||||||||||||||||
2342 | } else if (term->parentheses.isTerminal) { executed 2702 times by 3 tests: end of block Executed by:
| 12-2702 | ||||||||||||||||||
2343 | // Select the 'Terminal' nodes. | - | ||||||||||||||||||
2344 | parenthesesBeginOpCode = OpParenthesesSubpatternTerminalBegin; | - | ||||||||||||||||||
2345 | parenthesesEndOpCode = OpParenthesesSubpatternTerminalEnd; | - | ||||||||||||||||||
2346 | } else { executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
2347 | // This subpattern is not supported by the JIT. | - | ||||||||||||||||||
2348 | m_shouldFallBack = true; | - | ||||||||||||||||||
2349 | return; executed 272 times by 1 test: return; Executed by:
| 272 | ||||||||||||||||||
2350 | } | - | ||||||||||||||||||
2351 | - | |||||||||||||||||||
2352 | size_t parenBegin = m_ops.size(); | - | ||||||||||||||||||
2353 | m_ops.append(parenthesesBeginOpCode); | - | ||||||||||||||||||
2354 | - | |||||||||||||||||||
2355 | m_ops.append(alternativeBeginOpCode); | - | ||||||||||||||||||
2356 | m_ops.last().m_previousOp = notFound; | - | ||||||||||||||||||
2357 | m_ops.last().m_term = term; | - | ||||||||||||||||||
2358 | Vector<OwnPtr<PatternAlternative> >& alternatives = term->parentheses.disjunction->m_alternatives; | - | ||||||||||||||||||
2359 | for (unsigned i = 0; i < alternatives.size(); ++i) {
| 2718-3208 | ||||||||||||||||||
2360 | size_t lastOpIndex = m_ops.size() - 1; | - | ||||||||||||||||||
2361 | - | |||||||||||||||||||
2362 | PatternAlternative* nestedAlternative = alternatives[i].get(); | - | ||||||||||||||||||
2363 | opCompileAlternative(nestedAlternative); | - | ||||||||||||||||||
2364 | - | |||||||||||||||||||
2365 | size_t thisOpIndex = m_ops.size(); | - | ||||||||||||||||||
2366 | m_ops.append(YarrOp(alternativeNextOpCode)); | - | ||||||||||||||||||
2367 | - | |||||||||||||||||||
2368 | YarrOp& lastOp = m_ops[lastOpIndex]; | - | ||||||||||||||||||
2369 | YarrOp& thisOp = m_ops[thisOpIndex]; | - | ||||||||||||||||||
2370 | - | |||||||||||||||||||
2371 | lastOp.m_alternative = nestedAlternative; | - | ||||||||||||||||||
2372 | lastOp.m_nextOp = thisOpIndex; | - | ||||||||||||||||||
2373 | thisOp.m_previousOp = lastOpIndex; | - | ||||||||||||||||||
2374 | thisOp.m_term = term; | - | ||||||||||||||||||
2375 | } executed 3208 times by 3 tests: end of block Executed by:
| 3208 | ||||||||||||||||||
2376 | YarrOp& lastOp = m_ops.last(); | - | ||||||||||||||||||
2377 | ASSERT(lastOp.m_op == alternativeNextOpCode); | - | ||||||||||||||||||
2378 | lastOp.m_op = alternativeEndOpCode; | - | ||||||||||||||||||
2379 | lastOp.m_alternative = 0; | - | ||||||||||||||||||
2380 | lastOp.m_nextOp = notFound; | - | ||||||||||||||||||
2381 | - | |||||||||||||||||||
2382 | size_t parenEnd = m_ops.size(); | - | ||||||||||||||||||
2383 | m_ops.append(parenthesesEndOpCode); | - | ||||||||||||||||||
2384 | - | |||||||||||||||||||
2385 | m_ops[parenBegin].m_term = term; | - | ||||||||||||||||||
2386 | m_ops[parenBegin].m_previousOp = notFound; | - | ||||||||||||||||||
2387 | m_ops[parenBegin].m_nextOp = parenEnd; | - | ||||||||||||||||||
2388 | m_ops[parenEnd].m_term = term; | - | ||||||||||||||||||
2389 | m_ops[parenEnd].m_previousOp = parenBegin; | - | ||||||||||||||||||
2390 | m_ops[parenEnd].m_nextOp = notFound; | - | ||||||||||||||||||
2391 | } executed 2718 times by 3 tests: end of block Executed by:
| 2718 | ||||||||||||||||||
2392 | - | |||||||||||||||||||
2393 | // opCompileParentheticalAssertion | - | ||||||||||||||||||
2394 | // Emits ops for a parenthetical assertion. These consist of an | - | ||||||||||||||||||
2395 | // OpSimpleNestedAlternativeBegin/Next/End set of nodes wrapping | - | ||||||||||||||||||
2396 | // the alternatives, with these wrapped by an outer pair of | - | ||||||||||||||||||
2397 | // OpParentheticalAssertionBegin/End nodes. | - | ||||||||||||||||||
2398 | // We can always use the OpSimpleNestedAlternative nodes in the | - | ||||||||||||||||||
2399 | // case of parenthetical assertions since these only ever match | - | ||||||||||||||||||
2400 | // once, and will never backtrack back into the assertion. | - | ||||||||||||||||||
2401 | void opCompileParentheticalAssertion(PatternTerm* term) | - | ||||||||||||||||||
2402 | { | - | ||||||||||||||||||
2403 | size_t parenBegin = m_ops.size(); | - | ||||||||||||||||||
2404 | m_ops.append(OpParentheticalAssertionBegin); | - | ||||||||||||||||||
2405 | - | |||||||||||||||||||
2406 | m_ops.append(OpSimpleNestedAlternativeBegin); | - | ||||||||||||||||||
2407 | m_ops.last().m_previousOp = notFound; | - | ||||||||||||||||||
2408 | m_ops.last().m_term = term; | - | ||||||||||||||||||
2409 | Vector<OwnPtr<PatternAlternative> >& alternatives = term->parentheses.disjunction->m_alternatives; | - | ||||||||||||||||||
2410 | for (unsigned i = 0; i < alternatives.size(); ++i) {
| 68-92 | ||||||||||||||||||
2411 | size_t lastOpIndex = m_ops.size() - 1; | - | ||||||||||||||||||
2412 | - | |||||||||||||||||||
2413 | PatternAlternative* nestedAlternative = alternatives[i].get(); | - | ||||||||||||||||||
2414 | opCompileAlternative(nestedAlternative); | - | ||||||||||||||||||
2415 | - | |||||||||||||||||||
2416 | size_t thisOpIndex = m_ops.size(); | - | ||||||||||||||||||
2417 | m_ops.append(YarrOp(OpSimpleNestedAlternativeNext)); | - | ||||||||||||||||||
2418 | - | |||||||||||||||||||
2419 | YarrOp& lastOp = m_ops[lastOpIndex]; | - | ||||||||||||||||||
2420 | YarrOp& thisOp = m_ops[thisOpIndex]; | - | ||||||||||||||||||
2421 | - | |||||||||||||||||||
2422 | lastOp.m_alternative = nestedAlternative; | - | ||||||||||||||||||
2423 | lastOp.m_nextOp = thisOpIndex; | - | ||||||||||||||||||
2424 | thisOp.m_previousOp = lastOpIndex; | - | ||||||||||||||||||
2425 | thisOp.m_term = term; | - | ||||||||||||||||||
2426 | } executed 92 times by 1 test: end of block Executed by:
| 92 | ||||||||||||||||||
2427 | YarrOp& lastOp = m_ops.last(); | - | ||||||||||||||||||
2428 | ASSERT(lastOp.m_op == OpSimpleNestedAlternativeNext); | - | ||||||||||||||||||
2429 | lastOp.m_op = OpSimpleNestedAlternativeEnd; | - | ||||||||||||||||||
2430 | lastOp.m_alternative = 0; | - | ||||||||||||||||||
2431 | lastOp.m_nextOp = notFound; | - | ||||||||||||||||||
2432 | - | |||||||||||||||||||
2433 | size_t parenEnd = m_ops.size(); | - | ||||||||||||||||||
2434 | m_ops.append(OpParentheticalAssertionEnd); | - | ||||||||||||||||||
2435 | - | |||||||||||||||||||
2436 | m_ops[parenBegin].m_term = term; | - | ||||||||||||||||||
2437 | m_ops[parenBegin].m_previousOp = notFound; | - | ||||||||||||||||||
2438 | m_ops[parenBegin].m_nextOp = parenEnd; | - | ||||||||||||||||||
2439 | m_ops[parenEnd].m_term = term; | - | ||||||||||||||||||
2440 | m_ops[parenEnd].m_previousOp = parenBegin; | - | ||||||||||||||||||
2441 | m_ops[parenEnd].m_nextOp = notFound; | - | ||||||||||||||||||
2442 | } executed 68 times by 1 test: end of block Executed by:
| 68 | ||||||||||||||||||
2443 | - | |||||||||||||||||||
2444 | // opCompileAlternative | - | ||||||||||||||||||
2445 | // Called to emit nodes for all terms in an alternative. | - | ||||||||||||||||||
2446 | void opCompileAlternative(PatternAlternative* alternative) | - | ||||||||||||||||||
2447 | { | - | ||||||||||||||||||
2448 | optimizeAlternative(alternative); | - | ||||||||||||||||||
2449 | - | |||||||||||||||||||
2450 | for (unsigned i = 0; i < alternative->m_terms.size(); ++i) {
| 1153843-2376037 | ||||||||||||||||||
2451 | PatternTerm* term = &alternative->m_terms[i]; | - | ||||||||||||||||||
2452 | - | |||||||||||||||||||
2453 | switch (term->type) { | - | ||||||||||||||||||
2454 | case PatternTerm::TypeParenthesesSubpattern: executed 2984 times by 3 tests: case PatternTerm::TypeParenthesesSubpattern: Executed by:
| 2984 | ||||||||||||||||||
2455 | opCompileParenthesesSubpattern(term); | - | ||||||||||||||||||
2456 | break; executed 2990 times by 3 tests: break; Executed by:
| 2990 | ||||||||||||||||||
2457 | - | |||||||||||||||||||
2458 | case PatternTerm::TypeParentheticalAssertion: executed 68 times by 1 test: case PatternTerm::TypeParentheticalAssertion: Executed by:
| 68 | ||||||||||||||||||
2459 | opCompileParentheticalAssertion(term); | - | ||||||||||||||||||
2460 | break; executed 68 times by 1 test: break; Executed by:
| 68 | ||||||||||||||||||
2461 | - | |||||||||||||||||||
2462 | default: executed 2372984 times by 9 tests: default: Executed by:
| 2372984 | ||||||||||||||||||
2463 | m_ops.append(term); | - | ||||||||||||||||||
2464 | } executed 2374493 times by 9 tests: end of block Executed by:
| 2374493 | ||||||||||||||||||
2465 | } | - | ||||||||||||||||||
2466 | } executed 1153607 times by 153 tests: end of block Executed by:
| 1153607 | ||||||||||||||||||
2467 | - | |||||||||||||||||||
2468 | // opCompileBody | - | ||||||||||||||||||
2469 | // This method compiles the body disjunction of the regular expression. | - | ||||||||||||||||||
2470 | // The body consists of two sets of alternatives - zero or more 'once | - | ||||||||||||||||||
2471 | // through' (BOL anchored) alternatives, followed by zero or more | - | ||||||||||||||||||
2472 | // repeated alternatives. | - | ||||||||||||||||||
2473 | // For each of these two sets of alteratives, if not empty they will be | - | ||||||||||||||||||
2474 | // wrapped in a set of OpBodyAlternativeBegin/Next/End nodes (with the | - | ||||||||||||||||||
2475 | // 'begin' node referencing the first alternative, and 'next' nodes | - | ||||||||||||||||||
2476 | // referencing any further alternatives. The begin/next/end nodes are | - | ||||||||||||||||||
2477 | // linked together in a doubly linked list. In the case of repeating | - | ||||||||||||||||||
2478 | // alternatives, the end node is also linked back to the beginning. | - | ||||||||||||||||||
2479 | // If no repeating alternatives exist, then a OpMatchFailed node exists | - | ||||||||||||||||||
2480 | // to return the failing result. | - | ||||||||||||||||||
2481 | void opCompileBody(PatternDisjunction* disjunction) | - | ||||||||||||||||||
2482 | { | - | ||||||||||||||||||
2483 | Vector<OwnPtr<PatternAlternative> >& alternatives = disjunction->m_alternatives; | - | ||||||||||||||||||
2484 | size_t currentAlternativeIndex = 0; | - | ||||||||||||||||||
2485 | - | |||||||||||||||||||
2486 | // Emit the 'once through' alternatives. | - | ||||||||||||||||||
2487 | if (alternatives.size() && alternatives[0]->onceThrough()) {
| 0-1150093 | ||||||||||||||||||
2488 | m_ops.append(YarrOp(OpBodyAlternativeBegin)); | - | ||||||||||||||||||
2489 | m_ops.last().m_previousOp = notFound; | - | ||||||||||||||||||
2490 | - | |||||||||||||||||||
2491 | do { | - | ||||||||||||||||||
2492 | size_t lastOpIndex = m_ops.size() - 1; | - | ||||||||||||||||||
2493 | PatternAlternative* alternative = alternatives[currentAlternativeIndex].get(); | - | ||||||||||||||||||
2494 | opCompileAlternative(alternative); | - | ||||||||||||||||||
2495 | - | |||||||||||||||||||
2496 | size_t thisOpIndex = m_ops.size(); | - | ||||||||||||||||||
2497 | m_ops.append(YarrOp(OpBodyAlternativeNext)); | - | ||||||||||||||||||
2498 | - | |||||||||||||||||||
2499 | YarrOp& lastOp = m_ops[lastOpIndex]; | - | ||||||||||||||||||
2500 | YarrOp& thisOp = m_ops[thisOpIndex]; | - | ||||||||||||||||||
2501 | - | |||||||||||||||||||
2502 | lastOp.m_alternative = alternative; | - | ||||||||||||||||||
2503 | lastOp.m_nextOp = thisOpIndex; | - | ||||||||||||||||||
2504 | thisOp.m_previousOp = lastOpIndex; | - | ||||||||||||||||||
2505 | - | |||||||||||||||||||
2506 | ++currentAlternativeIndex; | - | ||||||||||||||||||
2507 | } while (currentAlternativeIndex < alternatives.size() && alternatives[currentAlternativeIndex]->onceThrough()); executed 128 times by 5 tests: end of block Executed by:
| 6-128 | ||||||||||||||||||
2508 | - | |||||||||||||||||||
2509 | YarrOp& lastOp = m_ops.last(); | - | ||||||||||||||||||
2510 | - | |||||||||||||||||||
2511 | ASSERT(lastOp.m_op == OpBodyAlternativeNext); | - | ||||||||||||||||||
2512 | lastOp.m_op = OpBodyAlternativeEnd; | - | ||||||||||||||||||
2513 | lastOp.m_alternative = 0; | - | ||||||||||||||||||
2514 | lastOp.m_nextOp = notFound; | - | ||||||||||||||||||
2515 | } executed 118 times by 5 tests: end of block Executed by:
| 118 | ||||||||||||||||||
2516 | - | |||||||||||||||||||
2517 | if (currentAlternativeIndex == alternatives.size()) {
| 112-1150080 | ||||||||||||||||||
2518 | m_ops.append(YarrOp(OpMatchFailed)); | - | ||||||||||||||||||
2519 | return; executed 112 times by 4 tests: return; Executed by:
| 112 | ||||||||||||||||||
2520 | } | - | ||||||||||||||||||
2521 | - | |||||||||||||||||||
2522 | // Emit the repeated alternatives. | - | ||||||||||||||||||
2523 | size_t repeatLoop = m_ops.size(); | - | ||||||||||||||||||
2524 | m_ops.append(YarrOp(OpBodyAlternativeBegin)); | - | ||||||||||||||||||
2525 | m_ops.last().m_previousOp = notFound; | - | ||||||||||||||||||
2526 | do { | - | ||||||||||||||||||
2527 | size_t lastOpIndex = m_ops.size() - 1; | - | ||||||||||||||||||
2528 | PatternAlternative* alternative = alternatives[currentAlternativeIndex].get(); | - | ||||||||||||||||||
2529 | ASSERT(!alternative->onceThrough()); | - | ||||||||||||||||||
2530 | opCompileAlternative(alternative); | - | ||||||||||||||||||
2531 | - | |||||||||||||||||||
2532 | size_t thisOpIndex = m_ops.size(); | - | ||||||||||||||||||
2533 | m_ops.append(YarrOp(OpBodyAlternativeNext)); | - | ||||||||||||||||||
2534 | - | |||||||||||||||||||
2535 | YarrOp& lastOp = m_ops[lastOpIndex]; | - | ||||||||||||||||||
2536 | YarrOp& thisOp = m_ops[thisOpIndex]; | - | ||||||||||||||||||
2537 | - | |||||||||||||||||||
2538 | lastOp.m_alternative = alternative; | - | ||||||||||||||||||
2539 | lastOp.m_nextOp = thisOpIndex; | - | ||||||||||||||||||
2540 | thisOp.m_previousOp = lastOpIndex; | - | ||||||||||||||||||
2541 | - | |||||||||||||||||||
2542 | ++currentAlternativeIndex; | - | ||||||||||||||||||
2543 | } while (currentAlternativeIndex < alternatives.size()); executed 1151295 times by 153 tests: end of block Executed by:
| 220-1151295 | ||||||||||||||||||
2544 | YarrOp& lastOp = m_ops.last(); | - | ||||||||||||||||||
2545 | ASSERT(lastOp.m_op == OpBodyAlternativeNext); | - | ||||||||||||||||||
2546 | lastOp.m_op = OpBodyAlternativeEnd; | - | ||||||||||||||||||
2547 | lastOp.m_alternative = 0; | - | ||||||||||||||||||
2548 | lastOp.m_nextOp = repeatLoop; | - | ||||||||||||||||||
2549 | } executed 1150367 times by 153 tests: end of block Executed by:
| 1150367 | ||||||||||||||||||
2550 | - | |||||||||||||||||||
2551 | void generateEnter() | - | ||||||||||||||||||
2552 | { | - | ||||||||||||||||||
2553 | #if CPU(X86_64) | - | ||||||||||||||||||
2554 | push(X86Registers::ebp); | - | ||||||||||||||||||
2555 | move(stackPointerRegister, X86Registers::ebp); | - | ||||||||||||||||||
2556 | push(X86Registers::ebx); | - | ||||||||||||||||||
2557 | // The ABI doesn't guarantee the upper bits are zero on unsigned arguments, so clear them ourselves. | - | ||||||||||||||||||
2558 | zeroExtend32ToPtr(index, index); | - | ||||||||||||||||||
2559 | zeroExtend32ToPtr(length, length); | - | ||||||||||||||||||
2560 | #if OS(WINDOWS) | - | ||||||||||||||||||
2561 | if (compileMode == IncludeSubpatterns) | - | ||||||||||||||||||
2562 | loadPtr(Address(X86Registers::ebp, 6 * sizeof(void*)), output); | - | ||||||||||||||||||
2563 | #endif | - | ||||||||||||||||||
2564 | #elif CPU(X86) | - | ||||||||||||||||||
2565 | push(X86Registers::ebp); | - | ||||||||||||||||||
2566 | move(stackPointerRegister, X86Registers::ebp); | - | ||||||||||||||||||
2567 | // TODO: do we need spill registers to fill the output pointer if there are no sub captures? | - | ||||||||||||||||||
2568 | push(X86Registers::ebx); | - | ||||||||||||||||||
2569 | push(X86Registers::edi); | - | ||||||||||||||||||
2570 | push(X86Registers::esi); | - | ||||||||||||||||||
2571 | // load output into edi (2 = saved ebp + return address). | - | ||||||||||||||||||
2572 | #if COMPILER(MSVC) | - | ||||||||||||||||||
2573 | loadPtr(Address(X86Registers::ebp, 2 * sizeof(void*)), input); | - | ||||||||||||||||||
2574 | loadPtr(Address(X86Registers::ebp, 3 * sizeof(void*)), index); | - | ||||||||||||||||||
2575 | loadPtr(Address(X86Registers::ebp, 4 * sizeof(void*)), length); | - | ||||||||||||||||||
2576 | if (compileMode == IncludeSubpatterns) | - | ||||||||||||||||||
2577 | loadPtr(Address(X86Registers::ebp, 5 * sizeof(void*)), output); | - | ||||||||||||||||||
2578 | #else | - | ||||||||||||||||||
2579 | if (compileMode == IncludeSubpatterns) | - | ||||||||||||||||||
2580 | loadPtr(Address(X86Registers::ebp, 2 * sizeof(void*)), output); | - | ||||||||||||||||||
2581 | #endif | - | ||||||||||||||||||
2582 | #elif CPU(ARM64) | - | ||||||||||||||||||
2583 | // The ABI doesn't guarantee the upper bits are zero on unsigned arguments, so clear them ourselves. | - | ||||||||||||||||||
2584 | zeroExtend32ToPtr(index, index); | - | ||||||||||||||||||
2585 | zeroExtend32ToPtr(length, length); | - | ||||||||||||||||||
2586 | #elif CPU(ARM) | - | ||||||||||||||||||
2587 | push(ARMRegisters::r4); | - | ||||||||||||||||||
2588 | push(ARMRegisters::r5); | - | ||||||||||||||||||
2589 | push(ARMRegisters::r6); | - | ||||||||||||||||||
2590 | #if CPU(ARM_TRADITIONAL) | - | ||||||||||||||||||
2591 | push(ARMRegisters::r8); // scratch register | - | ||||||||||||||||||
2592 | #endif | - | ||||||||||||||||||
2593 | if (compileMode == IncludeSubpatterns) | - | ||||||||||||||||||
2594 | move(ARMRegisters::r3, output); | - | ||||||||||||||||||
2595 | #elif CPU(SH4) | - | ||||||||||||||||||
2596 | push(SH4Registers::r11); | - | ||||||||||||||||||
2597 | push(SH4Registers::r13); | - | ||||||||||||||||||
2598 | #elif CPU(MIPS) | - | ||||||||||||||||||
2599 | // Do nothing. | - | ||||||||||||||||||
2600 | #endif | - | ||||||||||||||||||
2601 | } executed 1150894 times by 153 tests: end of block Executed by:
| 1150894 | ||||||||||||||||||
2602 | - | |||||||||||||||||||
2603 | void generateReturn() | - | ||||||||||||||||||
2604 | { | - | ||||||||||||||||||
2605 | #if CPU(X86_64) | - | ||||||||||||||||||
2606 | #if OS(WINDOWS) | - | ||||||||||||||||||
2607 | // Store the return value in the allocated space pointed by rcx. | - | ||||||||||||||||||
2608 | store64(returnRegister, Address(X86Registers::ecx)); | - | ||||||||||||||||||
2609 | store64(returnRegister2, Address(X86Registers::ecx, sizeof(void*))); | - | ||||||||||||||||||
2610 | move(X86Registers::ecx, returnRegister); | - | ||||||||||||||||||
2611 | #endif | - | ||||||||||||||||||
2612 | pop(X86Registers::ebx); | - | ||||||||||||||||||
2613 | pop(X86Registers::ebp); | - | ||||||||||||||||||
2614 | #elif CPU(X86) | - | ||||||||||||||||||
2615 | pop(X86Registers::esi); | - | ||||||||||||||||||
2616 | pop(X86Registers::edi); | - | ||||||||||||||||||
2617 | pop(X86Registers::ebx); | - | ||||||||||||||||||
2618 | pop(X86Registers::ebp); | - | ||||||||||||||||||
2619 | #elif CPU(ARM) | - | ||||||||||||||||||
2620 | #if CPU(ARM_TRADITIONAL) | - | ||||||||||||||||||
2621 | pop(ARMRegisters::r8); // scratch register | - | ||||||||||||||||||
2622 | #endif | - | ||||||||||||||||||
2623 | pop(ARMRegisters::r6); | - | ||||||||||||||||||
2624 | pop(ARMRegisters::r5); | - | ||||||||||||||||||
2625 | pop(ARMRegisters::r4); | - | ||||||||||||||||||
2626 | #elif CPU(SH4) | - | ||||||||||||||||||
2627 | pop(SH4Registers::r13); | - | ||||||||||||||||||
2628 | pop(SH4Registers::r11); | - | ||||||||||||||||||
2629 | #elif CPU(MIPS) | - | ||||||||||||||||||
2630 | // Do nothing | - | ||||||||||||||||||
2631 | #endif | - | ||||||||||||||||||
2632 | ret(); | - | ||||||||||||||||||
2633 | } executed 3449818 times by 153 tests: end of block Executed by:
| 3449818 | ||||||||||||||||||
2634 | - | |||||||||||||||||||
2635 | public: | - | ||||||||||||||||||
2636 | YarrGenerator(YarrPattern& pattern, YarrCharSize charSize) | - | ||||||||||||||||||
2637 | : m_pattern(pattern) | - | ||||||||||||||||||
2638 | , m_charSize(charSize) | - | ||||||||||||||||||
2639 | , m_charScale(m_charSize == Char8 ? TimesOne: TimesTwo) | - | ||||||||||||||||||
2640 | , m_shouldFallBack(false) | - | ||||||||||||||||||
2641 | , m_checked(0) | - | ||||||||||||||||||
2642 | { | - | ||||||||||||||||||
2643 | } executed 1148563 times by 153 tests: end of block Executed by:
| 1148563 | ||||||||||||||||||
2644 | - | |||||||||||||||||||
2645 | void compile(JSGlobalData* globalData, YarrCodeBlock& jitObject) | - | ||||||||||||||||||
2646 | { | - | ||||||||||||||||||
2647 | generateEnter(); | - | ||||||||||||||||||
2648 | - | |||||||||||||||||||
2649 | Jump hasInput = checkInput(); | - | ||||||||||||||||||
2650 | move(TrustedImmPtr((void*)WTF::notFound), returnRegister); | - | ||||||||||||||||||
2651 | move(TrustedImm32(0), returnRegister2); | - | ||||||||||||||||||
2652 | generateReturn(); | - | ||||||||||||||||||
2653 | hasInput.link(this); | - | ||||||||||||||||||
2654 | - | |||||||||||||||||||
2655 | if (compileMode == IncludeSubpatterns) {
| 0-1146398 | ||||||||||||||||||
2656 | for (unsigned i = 0; i < m_pattern.m_numSubpatterns + 1; ++i)
| 1148636-1149381 | ||||||||||||||||||
2657 | store32(TrustedImm32(-1), Address(output, (i << 1) * sizeof(int))); executed 1148639 times by 153 tests: store32(TrustedImm32(-1), Address(output, (i << 1) * sizeof(int))); Executed by:
| 1148639 | ||||||||||||||||||
2658 | } executed 1149361 times by 153 tests: end of block Executed by:
| 1149361 | ||||||||||||||||||
2659 | - | |||||||||||||||||||
2660 | if (!m_pattern.m_body->m_hasFixedSize)
| 1257-1148427 | ||||||||||||||||||
2661 | setMatchStart(index); executed 1257 times by 8 tests: setMatchStart(index); Executed by:
| 1257 | ||||||||||||||||||
2662 | - | |||||||||||||||||||
2663 | initCallFrame(); | - | ||||||||||||||||||
2664 | - | |||||||||||||||||||
2665 | // Compile the pattern to the internal 'YarrOp' representation. | - | ||||||||||||||||||
2666 | opCompileBody(m_pattern.m_body); | - | ||||||||||||||||||
2667 | - | |||||||||||||||||||
2668 | // If we encountered anything we can't handle in the JIT code | - | ||||||||||||||||||
2669 | // (e.g. backreferences) then return early. | - | ||||||||||||||||||
2670 | if (m_shouldFallBack) {
| 124-1150024 | ||||||||||||||||||
2671 | jitObject.setFallBack(true); | - | ||||||||||||||||||
2672 | return; executed 124 times by 1 test: return; Executed by:
| 124 | ||||||||||||||||||
2673 | } | - | ||||||||||||||||||
2674 | - | |||||||||||||||||||
2675 | generate(); | - | ||||||||||||||||||
2676 | backtrack(); | - | ||||||||||||||||||
2677 | - | |||||||||||||||||||
2678 | // Link & finalize the code. | - | ||||||||||||||||||
2679 | LinkBuffer<JSC::DefaultMacroAssembler> linkBuffer(*globalData, this, REGEXP_CODE_ID); | - | ||||||||||||||||||
2680 | m_backtrackingState.linkDataLabels(linkBuffer); | - | ||||||||||||||||||
2681 | - | |||||||||||||||||||
2682 | if (compileMode == MatchOnly) {
| 0-1150905 | ||||||||||||||||||
2683 | if (m_charSize == Char8)
| 0 | ||||||||||||||||||
2684 | jitObject.set8BitCodeMatchOnly(FINALIZE_CODE(linkBuffer, ("Match-only 8-bit regular expression"))); never executed: jitObject.set8BitCodeMatchOnly((__builtin_expect(((Options::showDisassembly())), 0) ? ((linkBuffer).finalizeCodeWithDisassembly ("Match-only 8-bit regular expression")) : (linkBuffer).finalizeCodeWithoutDisassembly())); | 0 | ||||||||||||||||||
2685 | else | - | ||||||||||||||||||
2686 | jitObject.set16BitCodeMatchOnly(FINALIZE_CODE(linkBuffer, ("Match-only 16-bit regular expression"))); never executed: jitObject.set16BitCodeMatchOnly((__builtin_expect(((Options::showDisassembly())), 0) ? ((linkBuffer).finalizeCodeWithDisassembly ("Match-only 16-bit regular expression")) : (linkBuffer).finalizeCodeWithoutDisassembly())); | 0 | ||||||||||||||||||
2687 | } else { | - | ||||||||||||||||||
2688 | if (m_charSize == Char8)
| 0-1150890 | ||||||||||||||||||
2689 | jitObject.set8BitCode(FINALIZE_CODE(linkBuffer, ("8-bit regular expression"))); never executed: jitObject.set8BitCode((__builtin_expect(((Options::showDisassembly())), 0) ? ((linkBuffer).finalizeCodeWithDisassembly ("8-bit regular expression")) : (linkBuffer).finalizeCodeWithoutDisassembly())); | 0 | ||||||||||||||||||
2690 | else | - | ||||||||||||||||||
2691 | jitObject.set16BitCode(FINALIZE_CODE(linkBuffer, ("16-bit regular expression"))); executed 1150849 times by 153 tests: jitObject.set16BitCode((__builtin_expect(((Options::showDisassembly())), 0) ? ((linkBuffer).finalizeCodeWithDisassembly ("16-bit regular expression")) : (linkBuffer).finalizeCodeWithoutDisassembly())); Executed by:
| 1150849 | ||||||||||||||||||
2692 | } | - | ||||||||||||||||||
2693 | jitObject.setFallBack(m_shouldFallBack); | - | ||||||||||||||||||
2694 | } executed 1151302 times by 153 tests: end of block Executed by:
| 1151302 | ||||||||||||||||||
2695 | - | |||||||||||||||||||
2696 | private: | - | ||||||||||||||||||
2697 | YarrPattern& m_pattern; | - | ||||||||||||||||||
2698 | - | |||||||||||||||||||
2699 | YarrCharSize m_charSize; | - | ||||||||||||||||||
2700 | - | |||||||||||||||||||
2701 | Scale m_charScale; | - | ||||||||||||||||||
2702 | - | |||||||||||||||||||
2703 | // Used to detect regular expression constructs that are not currently | - | ||||||||||||||||||
2704 | // supported in the JIT; fall back to the interpreter when this is detected. | - | ||||||||||||||||||
2705 | bool m_shouldFallBack; | - | ||||||||||||||||||
2706 | - | |||||||||||||||||||
2707 | // The regular expression expressed as a linear sequence of operations. | - | ||||||||||||||||||
2708 | Vector<YarrOp, 128> m_ops; | - | ||||||||||||||||||
2709 | - | |||||||||||||||||||
2710 | // This records the current input offset being applied due to the current | - | ||||||||||||||||||
2711 | // set of alternatives we are nested within. E.g. when matching the | - | ||||||||||||||||||
2712 | // character 'b' within the regular expression /abc/, we will know that | - | ||||||||||||||||||
2713 | // the minimum size for the alternative is 3, checked upon entry to the | - | ||||||||||||||||||
2714 | // alternative, and that 'b' is at offset 1 from the start, and as such | - | ||||||||||||||||||
2715 | // when matching 'b' we need to apply an offset of -2 to the load. | - | ||||||||||||||||||
2716 | // | - | ||||||||||||||||||
2717 | // FIXME: This should go away. Rather than tracking this value throughout | - | ||||||||||||||||||
2718 | // code generation, we should gather this information up front & store it | - | ||||||||||||||||||
2719 | // on the YarrOp structure. | - | ||||||||||||||||||
2720 | int m_checked; | - | ||||||||||||||||||
2721 | - | |||||||||||||||||||
2722 | // This class records state whilst generating the backtracking path of code. | - | ||||||||||||||||||
2723 | BacktrackingState m_backtrackingState; | - | ||||||||||||||||||
2724 | }; | - | ||||||||||||||||||
2725 | - | |||||||||||||||||||
2726 | void jitCompile(YarrPattern& pattern, YarrCharSize charSize, JSGlobalData* globalData, YarrCodeBlock& jitObject, YarrJITCompileMode mode) | - | ||||||||||||||||||
2727 | { | - | ||||||||||||||||||
2728 | if (mode == MatchOnly)
| 0-1148484 | ||||||||||||||||||
2729 | YarrGenerator<MatchOnly>(pattern, charSize).compile(globalData, jitObject); never executed: YarrGenerator<MatchOnly>(pattern, charSize).compile(globalData, jitObject); | 0 | ||||||||||||||||||
2730 | else | - | ||||||||||||||||||
2731 | YarrGenerator<IncludeSubpatterns>(pattern, charSize).compile(globalData, jitObject); executed 1148533 times by 153 tests: YarrGenerator<IncludeSubpatterns>(pattern, charSize).compile(globalData, jitObject); Executed by:
| 1148533 | ||||||||||||||||||
2732 | } | - | ||||||||||||||||||
2733 | - | |||||||||||||||||||
2734 | }} | - | ||||||||||||||||||
2735 | - | |||||||||||||||||||
2736 | #endif | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |