v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
regexp-macro-assembler-arm.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_
29 #define V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_
30 
31 #include "arm/assembler-arm.h"
32 #include "arm/assembler-arm-inl.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 
38 #ifndef V8_INTERPRETED_REGEXP
40  public:
41  RegExpMacroAssemblerARM(Mode mode, int registers_to_save, Zone* zone);
42  virtual ~RegExpMacroAssemblerARM();
43  virtual int stack_limit_slack();
44  virtual void AdvanceCurrentPosition(int by);
45  virtual void AdvanceRegister(int reg, int by);
46  virtual void Backtrack();
47  virtual void Bind(Label* label);
48  virtual void CheckAtStart(Label* on_at_start);
49  virtual void CheckCharacter(unsigned c, Label* on_equal);
50  virtual void CheckCharacterAfterAnd(unsigned c,
51  unsigned mask,
52  Label* on_equal);
53  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
54  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
55  virtual void CheckCharacters(Vector<const uc16> str,
56  int cp_offset,
57  Label* on_failure,
58  bool check_end_of_string);
59  // A "greedy loop" is a loop that is both greedy and with a simple
60  // body. It has a particularly simple implementation.
61  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
62  virtual void CheckNotAtStart(Label* on_not_at_start);
63  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
64  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
65  Label* on_no_match);
66  virtual void CheckNotCharacter(unsigned c, Label* on_not_equal);
67  virtual void CheckNotCharacterAfterAnd(unsigned c,
68  unsigned mask,
69  Label* on_not_equal);
70  virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
71  uc16 minus,
72  uc16 mask,
73  Label* on_not_equal);
74  virtual void CheckCharacterInRange(uc16 from,
75  uc16 to,
76  Label* on_in_range);
77  virtual void CheckCharacterNotInRange(uc16 from,
78  uc16 to,
79  Label* on_not_in_range);
80  virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set);
81 
82  // Checks whether the given offset from the current position is before
83  // the end of the string.
84  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
85  virtual bool CheckSpecialCharacterClass(uc16 type,
86  Label* on_no_match);
87  virtual void Fail();
89  virtual void GoTo(Label* label);
90  virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
91  virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
92  virtual void IfRegisterEqPos(int reg, Label* if_eq);
94  virtual void LoadCurrentCharacter(int cp_offset,
95  Label* on_end_of_input,
96  bool check_bounds = true,
97  int characters = 1);
98  virtual void PopCurrentPosition();
99  virtual void PopRegister(int register_index);
100  virtual void PushBacktrack(Label* label);
101  virtual void PushCurrentPosition();
102  virtual void PushRegister(int register_index,
103  StackCheckFlag check_stack_limit);
104  virtual void ReadCurrentPositionFromRegister(int reg);
105  virtual void ReadStackPointerFromRegister(int reg);
106  virtual void SetCurrentPositionFromEnd(int by);
107  virtual void SetRegister(int register_index, int to);
108  virtual bool Succeed();
109  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
110  virtual void ClearRegisters(int reg_from, int reg_to);
111  virtual void WriteStackPointerToRegister(int reg);
112  virtual bool CanReadUnaligned();
113 
114  // Called from RegExp if the stack-guard is triggered.
115  // If the code object is relocated, the return address is fixed before
116  // returning.
117  static int CheckStackGuardState(Address* return_address,
118  Code* re_code,
119  Address re_frame);
120 
121  private:
122  // Offsets from frame_pointer() of function parameters and stored registers.
123  static const int kFramePointer = 0;
124 
125  // Above the frame pointer - Stored registers and stack passed parameters.
126  // Register 4..11.
127  static const int kStoredRegisters = kFramePointer;
128  // Return address (stored from link register, read into pc on return).
129  static const int kReturnAddress = kStoredRegisters + 8 * kPointerSize;
130  static const int kSecondaryReturnAddress = kReturnAddress + kPointerSize;
131  // Stack parameters placed by caller.
132  static const int kRegisterOutput = kSecondaryReturnAddress + kPointerSize;
133  static const int kNumOutputRegisters = kRegisterOutput + kPointerSize;
134  static const int kStackHighEnd = kNumOutputRegisters + kPointerSize;
135  static const int kDirectCall = kStackHighEnd + kPointerSize;
136  static const int kIsolate = kDirectCall + kPointerSize;
137 
138  // Below the frame pointer.
139  // Register parameters stored by setup code.
140  static const int kInputEnd = kFramePointer - kPointerSize;
141  static const int kInputStart = kInputEnd - kPointerSize;
142  static const int kStartIndex = kInputStart - kPointerSize;
143  static const int kInputString = kStartIndex - kPointerSize;
144  // When adding local variables remember to push space for them in
145  // the frame in GetCode.
146  static const int kSuccessfulCaptures = kInputString - kPointerSize;
147  static const int kInputStartMinusOne = kSuccessfulCaptures - kPointerSize;
148  // First register address. Following registers are below it on the stack.
149  static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
150 
151  // Initial size of code buffer.
152  static const size_t kRegExpCodeSize = 1024;
153 
154  static const int kBacktrackConstantPoolSize = 4;
155 
156  // Load a number of characters at the given offset from the
157  // current position, into the current-character register.
158  void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
159 
160  // Check whether preemption has been requested.
161  void CheckPreemption();
162 
163  // Check whether we are exceeding the stack limit on the backtrack stack.
164  void CheckStackLimit();
165 
166  void EmitBacktrackConstantPool();
167  int GetBacktrackConstantPoolEntry();
168 
169 
170  // Generate a call to CheckStackGuardState.
171  void CallCheckStackGuardState(Register scratch);
172 
173  // The ebp-relative location of a regexp register.
174  MemOperand register_location(int register_index);
175 
176  // Register holding the current input position as negative offset from
177  // the end of the string.
178  inline Register current_input_offset() { return r6; }
179 
180  // The register containing the current character after LoadCurrentCharacter.
181  inline Register current_character() { return r7; }
182 
183  // Register holding address of the end of the input string.
184  inline Register end_of_input_address() { return r10; }
185 
186  // Register holding the frame address. Local variables, parameters and
187  // regexp registers are addressed relative to this.
188  inline Register frame_pointer() { return fp; }
189 
190  // The register containing the backtrack stack top. Provides a meaningful
191  // name to the register.
192  inline Register backtrack_stackpointer() { return r8; }
193 
194  // Register holding pointer to the current code object.
195  inline Register code_pointer() { return r5; }
196 
197  // Byte size of chars in the string to match (decided by the Mode argument)
198  inline int char_size() { return static_cast<int>(mode_); }
199 
200  // Equivalent to a conditional branch to the label, unless the label
201  // is NULL, in which case it is a conditional Backtrack.
202  void BranchOrBacktrack(Condition condition, Label* to);
203 
204  // Call and return internally in the generated code in a way that
205  // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
206  inline void SafeCall(Label* to, Condition cond = al);
207  inline void SafeReturn();
208  inline void SafeCallTarget(Label* name);
209 
210  // Pushes the value of a register on the backtrack stack. Decrements the
211  // stack pointer by a word size and stores the register's value there.
212  inline void Push(Register source);
213 
214  // Pops a value from the backtrack stack. Reads the word at the stack pointer
215  // and increments it by a word size.
216  inline void Pop(Register target);
217 
218  // Calls a C function and cleans up the frame alignment done by
219  // by FrameAlign. The called function *is* allowed to trigger a garbage
220  // collection, but may not take more than four arguments (no arguments
221  // passed on the stack), and the first argument will be a pointer to the
222  // return address.
223  inline void CallCFunctionUsingStub(ExternalReference function,
224  int num_arguments);
225 
226 
227  MacroAssembler* masm_;
228 
229  // Which mode to generate code for (ASCII or UC16).
230  Mode mode_;
231 
232  // One greater than maximal register index actually used.
233  int num_registers_;
234 
235  // Number of registers to output at the end (the saved registers
236  // are always 0..num_saved_registers_-1)
237  int num_saved_registers_;
238 
239  // Manage a small pre-allocated pool for writing label targets
240  // to for pushing backtrack addresses.
241  int backtrack_constant_pool_offset_;
242  int backtrack_constant_pool_capacity_;
243 
244  // Labels used internally.
245  Label entry_label_;
246  Label start_label_;
247  Label success_label_;
248  Label backtrack_label_;
249  Label exit_label_;
250  Label check_preempt_label_;
251  Label stack_overflow_label_;
252 };
253 
254 #endif // V8_INTERPRETED_REGEXP
255 
256 
257 }} // namespace v8::internal
258 
259 #endif // V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_
byte * Address
Definition: globals.h:157
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)
virtual void Bind(Label *label)
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 mask, Label *on_not_equal)
virtual void CheckCharacter(unsigned c, Label *on_equal)
const Register r6
virtual void CheckAtStart(Label *on_at_start)
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)
virtual void CheckCharacterLT(uc16 limit, Label *on_less)
virtual void CheckNotAtStart(Label *on_not_at_start)
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)
virtual void ReadStackPointerFromRegister(int reg)
virtual IrregexpImplementation Implementation()
virtual void AdvanceCurrentPosition(int by)
virtual void PopRegister(int register_index)
virtual Handle< HeapObject > GetCode(Handle< String > source)
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
static int CheckStackGuardState(Address *return_address, Code *re_code, Address re_frame)
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)
virtual void CheckNotCharacter(unsigned c, Label *on_not_equal)
virtual void ReadCurrentPositionFromRegister(int reg)
const int kPointerSize
Definition: globals.h:220
virtual void SetCurrentPositionFromEnd(int by)
virtual void IfRegisterEqPos(int reg, Label *if_eq)
virtual void AdvanceRegister(int reg, int by)
virtual void ClearRegisters(int reg_from, int reg_to)
virtual void CheckPosition(int cp_offset, Label *on_outside_input)
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask, Label *on_not_equal)
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)
uint16_t uc16
Definition: globals.h:259
const Register r8
virtual void CheckCharacters(Vector< const uc16 > str, int cp_offset, Label *on_failure, bool check_end_of_string)
virtual void SetRegister(int register_index, int to)
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)
virtual void WriteStackPointerToRegister(int reg)
virtual void GoTo(Label *label)
virtual void PushBacktrack(Label *label)
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)
RegExpMacroAssemblerARM(Mode mode, int registers_to_save, Zone *zone)
const Register r10
const Register fp
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)
const Register r5
virtual void CheckCharacterAfterAnd(unsigned c, unsigned mask, Label *on_equal)
const Register r7