Changeset 39250 in webkit for trunk/JavaScriptCore/wrec/WRECGenerator.cpp
- Timestamp:
- Dec 12, 2008, 12:35:38 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wrec/WRECGenerator.cpp
r39197 r39250 159 159 void Generator::generateNonGreedyQuantifier(JumpList& failures, GenerateAtomFunctor& functor, unsigned min, unsigned max) 160 160 { 161 // comment me better! 162 JumpList newFailures; 163 164 // (0) Setup: 165 // init repeatCount 161 JumpList atomFailedList; 162 JumpList alternativeFailedList; 163 164 // (0) Setup: Save, then init repeatCount. 166 165 push(repeatCount); 167 166 move(Imm32(0), repeatCount); 168 Jump gotoStart = jump(); 169 170 // (4) Failure case 171 172 Label quantifierFailed(this); 173 // (4.1) Restore original value of repeatCount from the stack 174 pop(repeatCount); 175 failures.append(jump()); 176 177 // (3) We just tried an alternative, and it failed - check we can try more. 178 179 Label alternativeFailed(this); 180 // (3.1) remove the value pushed prior to testing the alternative 181 pop(index); 182 // (3.2) if there is a limit, and we have reached it, game over. 183 if (max != Quantifier::Infinity) { 184 je32(repeatCount, Imm32(max), quantifierFailed); 185 } 186 187 // (1) Do a check for the atom 188 189 // (1.0) This is where we start, if there is a minimum (then we must read at least one of the atom). 190 Label testQuantifiedAtom(this); 191 if (min) 192 gotoStart.link(this); 193 // (1.1) Do a check for the atom check. 194 functor.generateAtom(this, newFailures); 195 // (1.2) If we get here, successful match! 196 add32(Imm32(1), repeatCount); 197 // (1.3) We needed to read the atom, and we failed - that's terminally bad news. 198 newFailures.linkTo(quantifierFailed, this); 199 // (1.4) If there is a minimum, check we have read enough ... 200 // if there was no minimum, this is where we start. 201 if (!min) 202 gotoStart.link(this); 203 // if min > 1 we need to keep checking! 204 else if (min != 1) 205 jl32(repeatCount, Imm32(min), testQuantifiedAtom); 206 207 // (2) Plant an alternative check for the remainder of the expression 208 209 // (2.1) recursively call to parseAlternative, if it falls through, success! 210 push(index); 211 m_parser.parseAlternative(newFailures); 212 pop(); 213 pop(repeatCount); 214 // (2.2) link failure cases to jump back up to alternativeFailed. 215 newFailures.linkTo(alternativeFailed, this); 216 } 217 218 void Generator::generateGreedyQuantifier(JumpList& failures, GenerateAtomFunctor& functor, unsigned min, unsigned max) 219 { 220 if (!max) 221 return; 222 223 // (0) Setup: save, then init repeatCount. 224 push(repeatCount); 225 move(Imm32(0), repeatCount); 226 227 // (1) Greedily read as many copies of the atom as possible, then jump to (2). 228 JumpList doneReadingAtoms; 229 230 Label readAnAtom(this); 231 functor.generateAtom(this, doneReadingAtoms); 232 add32(Imm32(1), repeatCount); 233 if (max == Quantifier::Infinity) 234 jump(readAnAtom); 235 else if (max == 1) 236 doneReadingAtoms.append(jump()); 237 else { 238 jne32(repeatCount, Imm32(max), readAnAtom); 239 doneReadingAtoms.append(jump()); 240 } 241 242 // (5) Quantifier failed -- no more backtracking possible. 167 Jump start = jump(); 168 169 // (4) Quantifier failed: No more atom reading possible. 243 170 Label quantifierFailed(this); 244 171 pop(repeatCount); 245 172 failures.append(jump()); 246 173 247 // (4) Backtrack, then fall through to (2) to try again. 248 Label backtrack(this); 174 // (3) Alternative failed: If we can, read another atom, then fall through to (2) to try again. 175 Label alternativeFailed(this); 176 pop(index); 177 if (max != Quantifier::Infinity) 178 je32(repeatCount, Imm32(max), quantifierFailed); 179 180 // (1) Read an atom. 181 if (min) 182 start.link(this); 183 Label readAtom(this); 184 functor.generateAtom(this, atomFailedList); 185 atomFailedList.linkTo(quantifierFailed, this); 186 add32(Imm32(1), repeatCount); 187 188 // (2) Keep reading if we're under the minimum. 189 if (min > 1) 190 jl32(repeatCount, Imm32(min), readAtom); 191 192 // (3) Test the rest of the alternative. 193 if (!min) 194 start.link(this); 195 push(index); 196 m_parser.parseAlternative(alternativeFailedList); 197 alternativeFailedList.linkTo(alternativeFailed, this); 198 199 pop(); 200 pop(repeatCount); 201 } 202 203 void Generator::generateGreedyQuantifier(JumpList& failures, GenerateAtomFunctor& functor, unsigned min, unsigned max) 204 { 205 if (!max) 206 return; 207 208 JumpList doneReadingAtomsList; 209 JumpList alternativeFailedList; 210 211 // (0) Setup: Save, then init repeatCount. 212 push(repeatCount); 213 move(Imm32(0), repeatCount); 214 215 // (1) Greedily read as many copies of the atom as possible, then jump to (2). 216 Label readAtom(this); 217 functor.generateAtom(this, doneReadingAtomsList); 218 add32(Imm32(1), repeatCount); 219 if (max == Quantifier::Infinity) 220 jump(readAtom); 221 else if (max == 1) 222 doneReadingAtomsList.append(jump()); 223 else { 224 jne32(repeatCount, Imm32(max), readAtom); 225 doneReadingAtomsList.append(jump()); 226 } 227 228 // (5) Quantifier failed: No more backtracking possible. 229 Label quantifierFailed(this); 230 pop(repeatCount); 231 failures.append(jump()); 232 233 // (4) Alternative failed: Backtrack, then fall through to (2) to try again. 234 Label alternativeFailed(this); 249 235 pop(index); 250 236 functor.backtrack(this); … … 252 238 253 239 // (2) Verify that we have enough atoms. 254 doneReadingAtoms .link(this);240 doneReadingAtomsList.link(this); 255 241 jl32(repeatCount, Imm32(min), quantifierFailed); 256 242 257 243 // (3) Test the rest of the alternative. 258 244 push(index); 259 JumpList newFailures; 260 m_parser.parseAlternative(newFailures); 261 newFailures.linkTo(backtrack, this); 245 m_parser.parseAlternative(alternativeFailedList); 246 alternativeFailedList.linkTo(alternativeFailed, this); 262 247 263 248 pop();
Note:
See TracChangeset
for help on using the changeset viewer.