| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef WRECGenerator_h |
| 27 |
#define WRECGenerator_h |
| 28 |
|
| 29 |
#include <wtf/Platform.h> |
| 30 |
|
| 31 |
#if ENABLE(WREC) |
| 32 |
|
| 33 |
#include "Quantifier.h" |
| 34 |
#include "MacroAssembler.h" |
| 35 |
#include <wtf/ASCIICType.h> |
| 36 |
#include <wtf/unicode/Unicode.h> |
| 37 |
#include "WREC.h" |
| 38 |
|
| 39 |
namespace JSC { |
| 40 |
|
| 41 |
class JSGlobalData; |
| 42 |
|
| 43 |
namespace WREC { |
| 44 |
|
| 45 |
class CharacterRange; |
| 46 |
class GenerateAtomFunctor; |
| 47 |
class Parser; |
| 48 |
struct CharacterClass; |
| 49 |
|
| 50 |
class Generator : private MacroAssembler { |
| 51 |
public: |
| 52 |
using MacroAssembler::Jump; |
| 53 |
using MacroAssembler::JumpList; |
| 54 |
using MacroAssembler::Label; |
| 55 |
|
| 56 |
enum ParenthesesType { Capturing, NonCapturing, Assertion, InvertedAssertion, Error }; |
| 57 |
|
| 58 |
static CompiledRegExp compileRegExp(JSGlobalData*, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, RefPtr<ExecutablePool>& pool, bool ignoreCase = false, bool multiline = false); |
| 59 |
|
| 60 |
Generator(Parser& parser) |
| 61 |
: m_parser(parser) |
| 62 |
{ |
| 63 |
} |
| 64 |
|
| 65 |
#if CPU(X86) |
| 66 |
static const RegisterID input = X86Registers::eax; |
| 67 |
static const RegisterID index = X86Registers::edx; |
| 68 |
static const RegisterID length = X86Registers::ecx; |
| 69 |
static const RegisterID output = X86Registers::edi; |
| 70 |
|
| 71 |
static const RegisterID character = X86Registers::esi; |
| 72 |
static const RegisterID repeatCount = X86Registers::ebx; |
| 73 |
|
| 74 |
static const RegisterID returnRegister = X86Registers::eax; |
| 75 |
#endif |
| 76 |
#if CPU(X86_64) |
| 77 |
static const RegisterID input = X86Registers::edi; |
| 78 |
static const RegisterID index = X86Registers::esi; |
| 79 |
static const RegisterID length = X86Registers::edx; |
| 80 |
static const RegisterID output = X86Registers::ecx; |
| 81 |
|
| 82 |
static const RegisterID character = X86Registers::eax; |
| 83 |
static const RegisterID repeatCount = X86Registers::ebx; |
| 84 |
|
| 85 |
static const RegisterID returnRegister = X86Registers::eax; |
| 86 |
#endif |
| 87 |
|
| 88 |
void generateEnter(); |
| 89 |
void generateSaveIndex(); |
| 90 |
void generateIncrementIndex(Jump* failure = 0); |
| 91 |
void generateLoadCharacter(JumpList& failures); |
| 92 |
void generateJumpIfNotEndOfInput(Label); |
| 93 |
void generateReturnSuccess(); |
| 94 |
void generateReturnFailure(); |
| 95 |
|
| 96 |
void generateGreedyQuantifier(JumpList& failures, GenerateAtomFunctor& functor, unsigned min, unsigned max); |
| 97 |
void generateNonGreedyQuantifier(JumpList& failures, GenerateAtomFunctor& functor, unsigned min, unsigned max); |
| 98 |
void generateBacktrack1(); |
| 99 |
void generateBacktrackBackreference(unsigned subpatternId); |
| 100 |
void generateCharacterClass(JumpList& failures, const CharacterClass& charClass, bool invert); |
| 101 |
void generateCharacterClassInverted(JumpList& failures, const CharacterClass& charClass); |
| 102 |
void generateCharacterClassInvertedRange(JumpList& failures, JumpList& matchDest, const CharacterRange* ranges, unsigned count, unsigned* matchIndex, const UChar* matches, unsigned matchCount); |
| 103 |
void generatePatternCharacter(JumpList& failures, int ch); |
| 104 |
void generatePatternCharacterSequence(JumpList& failures, int* sequence, size_t count); |
| 105 |
void generateAssertionWordBoundary(JumpList& failures, bool invert); |
| 106 |
void generateAssertionBOL(JumpList& failures); |
| 107 |
void generateAssertionEOL(JumpList& failures); |
| 108 |
void generateBackreference(JumpList& failures, unsigned subpatternID); |
| 109 |
void generateBackreferenceQuantifier(JumpList& failures, Quantifier::Type quantifierType, unsigned subpatternId, unsigned min, unsigned max); |
| 110 |
void generateParenthesesAssertion(JumpList& failures); |
| 111 |
void generateParenthesesInvertedAssertion(JumpList& failures); |
| 112 |
Jump generateParenthesesResetTrampoline(JumpList& newFailures, unsigned subpatternIdBefore, unsigned subpatternIdAfter); |
| 113 |
void generateParenthesesNonGreedy(JumpList& failures, Label start, Jump success, Jump fail); |
| 114 |
|
| 115 |
void terminateAlternative(JumpList& successes, JumpList& failures); |
| 116 |
void terminateDisjunction(JumpList& successes); |
| 117 |
|
| 118 |
private: |
| 119 |
bool generatePatternCharacterPair(JumpList& failures, int ch1, int ch2); |
| 120 |
|
| 121 |
Parser& m_parser; |
| 122 |
}; |
| 123 |
|
| 124 |
} } |
| 125 |
|
| 126 |
#endif |
| 127 |
|
| 128 |
#endif |