5 #ifndef V8_REGEXP_REGEXP_MACRO_ASSEMBLER_H_ 6 #define V8_REGEXP_REGEXP_MACRO_ASSEMBLER_H_ 9 #include "src/regexp/regexp-ast.h" 14 static const uc32 kLeadSurrogateStart = 0xd800;
15 static const uc32 kLeadSurrogateEnd = 0xdbff;
16 static const uc32 kTrailSurrogateStart = 0xdc00;
17 static const uc32 kTrailSurrogateEnd = 0xdfff;
18 static const uc32 kNonBmpStart = 0x10000;
19 static const uc32 kNonBmpEnd = 0x10ffff;
30 static const int kMaxRegister = (1 << 16) - 1;
31 static const int kMaxCPOffset = (1 << 15) - 1;
32 static const int kMinCPOffset = -(1 << 15);
34 static const int kTableSizeBits = 7;
35 static const int kTableSize = 1 << kTableSizeBits;
36 static const int kTableMask = kTableSize - 1;
38 enum IrregexpImplementation {
47 kBytecodeImplementation
51 kNoStackLimitCheck =
false,
52 kCheckStackLimit =
true 59 virtual void AbortedCodeGeneration() {}
63 virtual int stack_limit_slack() = 0;
64 virtual bool CanReadUnaligned() = 0;
65 virtual void AdvanceCurrentPosition(
int by) = 0;
66 virtual void AdvanceRegister(
int reg,
int by) = 0;
69 virtual void Backtrack() = 0;
70 virtual void Bind(
Label* label) = 0;
71 virtual void CheckAtStart(
Label* on_at_start) = 0;
74 virtual void CheckCharacter(
unsigned c,
Label* on_equal) = 0;
77 virtual void CheckCharacterAfterAnd(
unsigned c,
80 virtual void CheckCharacterGT(uc16 limit,
Label* on_greater) = 0;
81 virtual void CheckCharacterLT(uc16 limit,
Label* on_less) = 0;
82 virtual void CheckGreedyLoop(
Label* on_tos_equals_current_position) = 0;
83 virtual void CheckNotAtStart(
int cp_offset,
Label* on_not_at_start) = 0;
84 virtual void CheckNotBackReference(
int start_reg,
bool read_backward,
85 Label* on_no_match) = 0;
86 virtual void CheckNotBackReferenceIgnoreCase(
int start_reg,
87 bool read_backward,
bool unicode,
88 Label* on_no_match) = 0;
93 virtual void CheckNotCharacter(
unsigned c,
Label* on_not_equal) = 0;
94 virtual void CheckNotCharacterAfterAnd(
unsigned c,
96 Label* on_not_equal) = 0;
99 virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
102 Label* on_not_equal) = 0;
103 virtual void CheckCharacterInRange(uc16 from,
105 Label* on_in_range) = 0;
106 virtual void CheckCharacterNotInRange(uc16 from,
108 Label* on_not_in_range) = 0;
116 virtual void CheckPosition(
int cp_offset,
Label* on_outside_input);
121 virtual bool CheckSpecialCharacterClass(uc16
type,
Label* on_no_match);
122 virtual void Fail() = 0;
124 virtual void GoTo(
Label* label) = 0;
127 virtual void IfRegisterGE(
int reg,
int comparand,
Label* if_ge) = 0;
130 virtual void IfRegisterLT(
int reg,
int comparand,
Label* if_lt) = 0;
133 virtual void IfRegisterEqPos(
int reg,
Label* if_eq) = 0;
134 virtual IrregexpImplementation Implementation() = 0;
135 virtual void LoadCurrentCharacter(
int cp_offset,
136 Label* on_end_of_input,
137 bool check_bounds =
true,
138 int characters = 1) = 0;
139 virtual void PopCurrentPosition() = 0;
140 virtual void PopRegister(
int register_index) = 0;
143 virtual void PushBacktrack(
Label* label) = 0;
144 virtual void PushCurrentPosition() = 0;
145 virtual void PushRegister(
int register_index,
146 StackCheckFlag check_stack_limit) = 0;
147 virtual void ReadCurrentPositionFromRegister(
int reg) = 0;
148 virtual void ReadStackPointerFromRegister(
int reg) = 0;
149 virtual void SetCurrentPositionFromEnd(
int by) = 0;
150 virtual void SetRegister(
int register_index,
int to) = 0;
152 virtual bool Succeed() = 0;
153 virtual void WriteCurrentPositionToRegister(
int reg,
int cp_offset) = 0;
154 virtual void ClearRegisters(
int reg_from,
int reg_to) = 0;
155 virtual void WriteStackPointerToRegister(
int reg) = 0;
159 static int CaseInsensitiveCompareUC16(
Address byte_offset1,
161 size_t byte_length,
Isolate* isolate);
164 void CheckNotInSurrogatePair(
int cp_offset,
Label* on_failure);
167 void set_slow_safe(
bool ssc) { slow_safe_compiler_ = ssc; }
168 bool slow_safe() {
return slow_safe_compiler_; }
172 GLOBAL_NO_ZERO_LENGTH_CHECK,
178 inline void set_global_mode(GlobalMode mode) { global_mode_ = mode; }
179 inline bool global() {
return global_mode_ != NOT_GLOBAL; }
180 inline bool global_with_zero_length_check() {
181 return global_mode_ == GLOBAL || global_mode_ == GLOBAL_UNICODE;
183 inline bool global_unicode() {
return global_mode_ == GLOBAL_UNICODE; }
185 Isolate* isolate()
const {
return isolate_; }
186 Zone* zone()
const {
return zone_; }
189 bool slow_safe_compiler_;
190 GlobalMode global_mode_;
196 #ifndef V8_INTERPRETED_REGEXP // Avoid compiling unused code. 201 enum Mode { LATIN1 = 1, UC16 = 2 };
212 enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 };
216 bool CanReadUnaligned()
override;
221 int offsets_vector_length,
233 static const byte* StringCharacterPosition(
String subject,
int start_index);
235 static int CheckStackGuardState(
Isolate* isolate,
int start_index,
236 bool is_direct_call,
Address* return_address,
238 const byte** input_start,
239 const byte** input_end);
244 static const byte word_character_map[256];
246 static Address word_character_map_address() {
247 return reinterpret_cast<Address>(&word_character_map[0]);
250 static Result Execute(
Code code,
String input,
int start_offset,
251 const byte* input_start,
const byte* input_end,
252 int* output,
int output_size,
Isolate* isolate);
255 #endif // V8_INTERPRETED_REGEXP 260 #endif // V8_REGEXP_REGEXP_MACRO_ASSEMBLER_H_