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-mips.h
Go to the documentation of this file.
1 // Copyright 2011 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 
29 #ifndef V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
30 #define V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
31 
32 #include "mips/assembler-mips.h"
34 #include "macro-assembler.h"
35 #include "code.h"
37 
38 namespace v8 {
39 namespace internal {
40 
41 #ifndef V8_INTERPRETED_REGEXP
43  public:
44  RegExpMacroAssemblerMIPS(Mode mode, int registers_to_save, Zone* zone);
45  virtual ~RegExpMacroAssemblerMIPS();
46  virtual int stack_limit_slack();
47  virtual void AdvanceCurrentPosition(int by);
48  virtual void AdvanceRegister(int reg, int by);
49  virtual void Backtrack();
50  virtual void Bind(Label* label);
51  virtual void CheckAtStart(Label* on_at_start);
52  virtual void CheckCharacter(uint32_t c, Label* on_equal);
53  virtual void CheckCharacterAfterAnd(uint32_t c,
54  uint32_t mask,
55  Label* on_equal);
56  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
57  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
58  virtual void CheckCharacters(Vector<const uc16> str,
59  int cp_offset,
60  Label* on_failure,
61  bool check_end_of_string);
62  // A "greedy loop" is a loop that is both greedy and with a simple
63  // body. It has a particularly simple implementation.
64  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
65  virtual void CheckNotAtStart(Label* on_not_at_start);
66  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
67  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
68  Label* on_no_match);
69  virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
70  virtual void CheckNotCharacterAfterAnd(uint32_t c,
71  uint32_t mask,
72  Label* on_not_equal);
73  virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
74  uc16 minus,
75  uc16 mask,
76  Label* on_not_equal);
77  virtual void CheckCharacterInRange(uc16 from,
78  uc16 to,
79  Label* on_in_range);
80  virtual void CheckCharacterNotInRange(uc16 from,
81  uc16 to,
82  Label* on_not_in_range);
83  virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set);
84 
85  // Checks whether the given offset from the current position is before
86  // the end of the string.
87  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
88  virtual bool CheckSpecialCharacterClass(uc16 type,
89  Label* on_no_match);
90  virtual void Fail();
92  virtual void GoTo(Label* label);
93  virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
94  virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
95  virtual void IfRegisterEqPos(int reg, Label* if_eq);
97  virtual void LoadCurrentCharacter(int cp_offset,
98  Label* on_end_of_input,
99  bool check_bounds = true,
100  int characters = 1);
101  virtual void PopCurrentPosition();
102  virtual void PopRegister(int register_index);
103  virtual void PushBacktrack(Label* label);
104  virtual void PushCurrentPosition();
105  virtual void PushRegister(int register_index,
106  StackCheckFlag check_stack_limit);
107  virtual void ReadCurrentPositionFromRegister(int reg);
108  virtual void ReadStackPointerFromRegister(int reg);
109  virtual void SetCurrentPositionFromEnd(int by);
110  virtual void SetRegister(int register_index, int to);
111  virtual bool Succeed();
112  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
113  virtual void ClearRegisters(int reg_from, int reg_to);
114  virtual void WriteStackPointerToRegister(int reg);
115  virtual bool CanReadUnaligned();
116 
117  // Called from RegExp if the stack-guard is triggered.
118  // If the code object is relocated, the return address is fixed before
119  // returning.
120  static int CheckStackGuardState(Address* return_address,
121  Code* re_code,
122  Address re_frame);
123 
124  private:
125  // Offsets from frame_pointer() of function parameters and stored registers.
126  static const int kFramePointer = 0;
127 
128  // Above the frame pointer - Stored registers and stack passed parameters.
129  // Registers s0 to s7, fp, and ra.
130  static const int kStoredRegisters = kFramePointer;
131  // Return address (stored from link register, read into pc on return).
132  static const int kReturnAddress = kStoredRegisters + 9 * kPointerSize;
133  static const int kSecondaryReturnAddress = kReturnAddress + kPointerSize;
134  // Stack frame header.
135  static const int kStackFrameHeader = kReturnAddress + kPointerSize;
136  // Stack parameters placed by caller.
137  static const int kRegisterOutput = kStackFrameHeader + 20;
138  static const int kNumOutputRegisters = kRegisterOutput + kPointerSize;
139  static const int kStackHighEnd = kNumOutputRegisters + kPointerSize;
140  static const int kDirectCall = kStackHighEnd + kPointerSize;
141  static const int kIsolate = kDirectCall + kPointerSize;
142 
143  // Below the frame pointer.
144  // Register parameters stored by setup code.
145  static const int kInputEnd = kFramePointer - kPointerSize;
146  static const int kInputStart = kInputEnd - kPointerSize;
147  static const int kStartIndex = kInputStart - kPointerSize;
148  static const int kInputString = kStartIndex - kPointerSize;
149  // When adding local variables remember to push space for them in
150  // the frame in GetCode.
151  static const int kSuccessfulCaptures = kInputString - kPointerSize;
152  static const int kInputStartMinusOne = kSuccessfulCaptures - kPointerSize;
153  // First register address. Following registers are below it on the stack.
154  static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
155 
156  // Initial size of code buffer.
157  static const size_t kRegExpCodeSize = 1024;
158 
159  // Load a number of characters at the given offset from the
160  // current position, into the current-character register.
161  void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
162 
163  // Check whether preemption has been requested.
164  void CheckPreemption();
165 
166  // Check whether we are exceeding the stack limit on the backtrack stack.
167  void CheckStackLimit();
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 t2; }
179 
180  // The register containing the current character after LoadCurrentCharacter.
181  inline Register current_character() { return t3; }
182 
183  // Register holding address of the end of the input string.
184  inline Register end_of_input_address() { return t6; }
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 t4; }
193 
194  // Register holding pointer to the current code object.
195  inline Register code_pointer() { return t1; }
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(Label* to,
203  Condition condition,
204  Register rs,
205  const Operand& rt);
206 
207  // Call and return internally in the generated code in a way that
208  // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
209  inline void SafeCall(Label* to,
210  Condition cond,
211  Register rs,
212  const Operand& rt);
213  inline void SafeReturn();
214  inline void SafeCallTarget(Label* name);
215 
216  // Pushes the value of a register on the backtrack stack. Decrements the
217  // stack pointer by a word size and stores the register's value there.
218  inline void Push(Register source);
219 
220  // Pops a value from the backtrack stack. Reads the word at the stack pointer
221  // and increments it by a word size.
222  inline void Pop(Register target);
223 
224  // Calls a C function and cleans up the frame alignment done by
225  // by FrameAlign. The called function *is* allowed to trigger a garbage
226  // collection, but may not take more than four arguments (no arguments
227  // passed on the stack), and the first argument will be a pointer to the
228  // return address.
229  inline void CallCFunctionUsingStub(ExternalReference function,
230  int num_arguments);
231 
232 
233  MacroAssembler* masm_;
234 
235  // Which mode to generate code for (ASCII or UC16).
236  Mode mode_;
237 
238  // One greater than maximal register index actually used.
239  int num_registers_;
240 
241  // Number of registers to output at the end (the saved registers
242  // are always 0..num_saved_registers_-1).
243  int num_saved_registers_;
244 
245  // Labels used internally.
246  Label entry_label_;
247  Label start_label_;
248  Label success_label_;
249  Label backtrack_label_;
250  Label exit_label_;
251  Label check_preempt_label_;
252  Label stack_overflow_label_;
253  Label internal_failure_label_;
254 };
255 
256 #endif // V8_INTERPRETED_REGEXP
257 
258 
259 }} // namespace v8::internal
260 
261 #endif // V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
byte * Address
Definition: globals.h:157
RegExpMacroAssemblerMIPS(Mode mode, int registers_to_save, Zone *zone)
virtual void AdvanceRegister(int reg, int by)
virtual void CheckCharacter(uint32_t c, Label *on_equal)
virtual void CheckNotCharacterAfterAnd(uint32_t c, uint32_t mask, Label *on_not_equal)
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
virtual void CheckCharacterAfterAnd(uint32_t c, uint32_t mask, Label *on_equal)
virtual void CheckNotAtStart(Label *on_not_at_start)
virtual void CheckCharacters(Vector< const uc16 > str, int cp_offset, Label *on_failure, bool check_end_of_string)
virtual void ReadCurrentPositionFromRegister(int reg)
virtual void GoTo(Label *label)
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)
virtual void PushBacktrack(Label *label)
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)
virtual void CheckNotCharacter(uint32_t c, Label *on_not_equal)
virtual void SetCurrentPositionFromEnd(int by)
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)
virtual Handle< HeapObject > GetCode(Handle< String > source)
virtual void CheckAtStart(Label *on_at_start)
virtual void PopRegister(int register_index)
virtual void SetRegister(int register_index, int to)
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)
virtual void ClearRegisters(int reg_from, int reg_to)
const int kPointerSize
Definition: globals.h:220
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)
virtual void CheckCharacterLT(uc16 limit, Label *on_less)
virtual void AdvanceCurrentPosition(int by)
virtual void WriteStackPointerToRegister(int reg)
virtual void IfRegisterEqPos(int reg, Label *if_eq)
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)
virtual IrregexpImplementation Implementation()
static int CheckStackGuardState(Address *return_address, Code *re_code, Address re_frame)
uint16_t uc16
Definition: globals.h:259
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)
virtual void CheckPosition(int cp_offset, Label *on_outside_input)
const Register fp
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)
virtual void Bind(Label *label)
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 mask, Label *on_not_equal)
virtual void ReadStackPointerFromRegister(int reg)