OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 28 #ifndef V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ |
29 #define V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 29 #define V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ |
30 | 30 |
31 namespace v8 { | 31 namespace v8 { |
32 namespace internal { | 32 namespace internal { |
33 | 33 |
| 34 |
| 35 #ifndef V8_NATIVE_REGEXP |
34 class RegExpMacroAssemblerARM: public RegExpMacroAssembler { | 36 class RegExpMacroAssemblerARM: public RegExpMacroAssembler { |
35 public: | 37 public: |
36 RegExpMacroAssemblerARM(); | 38 RegExpMacroAssemblerARM(); |
37 virtual ~RegExpMacroAssemblerARM(); | 39 virtual ~RegExpMacroAssemblerARM(); |
38 }; | 40 }; |
39 | 41 |
| 42 #else |
| 43 class RegExpMacroAssemblerARM: public NativeRegExpMacroAssembler { |
| 44 public: |
| 45 RegExpMacroAssemblerARM(Mode mode, int registers_to_save); |
| 46 virtual ~RegExpMacroAssemblerARM(); |
| 47 virtual int stack_limit_slack(); |
| 48 virtual void AdvanceCurrentPosition(int by); |
| 49 virtual void AdvanceRegister(int reg, int by); |
| 50 virtual void Backtrack(); |
| 51 virtual void Bind(Label* label); |
| 52 virtual void CheckAtStart(Label* on_at_start); |
| 53 virtual void CheckCharacter(uint32_t c, Label* on_equal); |
| 54 virtual void CheckCharacterAfterAnd(uint32_t c, |
| 55 uint32_t mask, |
| 56 Label* on_equal); |
| 57 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); |
| 58 virtual void CheckCharacterLT(uc16 limit, Label* on_less); |
| 59 virtual void CheckCharacters(Vector<const uc16> str, |
| 60 int cp_offset, |
| 61 Label* on_failure, |
| 62 bool check_end_of_string); |
| 63 // A "greedy loop" is a loop that is both greedy and with a simple |
| 64 // body. It has a particularly simple implementation. |
| 65 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); |
| 66 virtual void CheckNotAtStart(Label* on_not_at_start); |
| 67 virtual void CheckNotBackReference(int start_reg, Label* on_no_match); |
| 68 virtual void CheckNotBackReferenceIgnoreCase(int start_reg, |
| 69 Label* on_no_match); |
| 70 virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal); |
| 71 virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal); |
| 72 virtual void CheckNotCharacterAfterAnd(uint32_t c, |
| 73 uint32_t mask, |
| 74 Label* on_not_equal); |
| 75 virtual void CheckNotCharacterAfterMinusAnd(uc16 c, |
| 76 uc16 minus, |
| 77 uc16 mask, |
| 78 Label* on_not_equal); |
| 79 // Checks whether the given offset from the current position is before |
| 80 // the end of the string. |
| 81 virtual void CheckPosition(int cp_offset, Label* on_outside_input); |
| 82 virtual bool CheckSpecialCharacterClass(uc16 type, |
| 83 int cp_offset, |
| 84 bool check_offset, |
| 85 Label* on_no_match); |
| 86 virtual void Fail(); |
| 87 virtual Handle<Object> GetCode(Handle<String> source); |
| 88 virtual void GoTo(Label* label); |
| 89 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge); |
| 90 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt); |
| 91 virtual void IfRegisterEqPos(int reg, Label* if_eq); |
| 92 virtual IrregexpImplementation Implementation(); |
| 93 virtual void LoadCurrentCharacter(int cp_offset, |
| 94 Label* on_end_of_input, |
| 95 bool check_bounds = true, |
| 96 int characters = 1); |
| 97 virtual void PopCurrentPosition(); |
| 98 virtual void PopRegister(int register_index); |
| 99 virtual void PushBacktrack(Label* label); |
| 100 virtual void PushCurrentPosition(); |
| 101 virtual void PushRegister(int register_index, |
| 102 StackCheckFlag check_stack_limit); |
| 103 virtual void ReadCurrentPositionFromRegister(int reg); |
| 104 virtual void ReadStackPointerFromRegister(int reg); |
| 105 virtual void SetRegister(int register_index, int to); |
| 106 virtual void Succeed(); |
| 107 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); |
| 108 virtual void ClearRegisters(int reg_from, int reg_to); |
| 109 virtual void WriteStackPointerToRegister(int reg); |
| 110 |
| 111 // Called from RegExp if the stack-guard is triggered. |
| 112 // If the code object is relocated, the return address is fixed before |
| 113 // returning. |
| 114 static int CheckStackGuardState(Address* return_address, |
| 115 Code* re_code, |
| 116 Address re_frame); |
| 117 private: |
| 118 // Offsets from frame_pointer() of function parameters and stored registers. |
| 119 static const int kFramePointer = 0; |
| 120 |
| 121 // Above the frame pointer - Stored registers and stack passed parameters. |
| 122 // Register 4..11. |
| 123 static const int kStoredRegisters = kFramePointer; |
| 124 // Return address (stored from link register, read into pc on return). |
| 125 static const int kReturnAddress = kStoredRegisters + 8 * kPointerSize; |
| 126 // Stack parameters placed by caller. |
| 127 static const int kRegisterOutput = kReturnAddress + kPointerSize; |
| 128 static const int kAtStart = kRegisterOutput + kPointerSize; |
| 129 static const int kStackHighEnd = kAtStart + kPointerSize; |
| 130 |
| 131 // Below the frame pointer. |
| 132 // Register parameters stored by setup code. |
| 133 static const int kInputEnd = kFramePointer - kPointerSize; |
| 134 static const int kInputStart = kInputEnd - kPointerSize; |
| 135 static const int kStartIndex = kInputStart - kPointerSize; |
| 136 static const int kInputString = kStartIndex - kPointerSize; |
| 137 // When adding local variables remember to push space for them in |
| 138 // the frame in GetCode. |
| 139 static const int kInputStartMinusOne = kInputString - kPointerSize; |
| 140 // First register address. Following registers are below it on the stack. |
| 141 static const int kRegisterZero = kInputStartMinusOne - kPointerSize; |
| 142 |
| 143 // Initial size of code buffer. |
| 144 static const size_t kRegExpCodeSize = 1024; |
| 145 |
| 146 static const int kBacktrackConstantPoolSize = 4; |
| 147 |
| 148 // Load a number of characters at the given offset from the |
| 149 // current position, into the current-character register. |
| 150 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); |
| 151 |
| 152 // Check whether preemption has been requested. |
| 153 void CheckPreemption(); |
| 154 |
| 155 // Check whether we are exceeding the stack limit on the backtrack stack. |
| 156 void CheckStackLimit(); |
| 157 |
| 158 void EmitBacktrackConstantPool(); |
| 159 int GetBacktrackConstantPoolEntry(); |
| 160 |
| 161 |
| 162 // Generate a call to CheckStackGuardState. |
| 163 void CallCheckStackGuardState(Register scratch); |
| 164 |
| 165 // The ebp-relative location of a regexp register. |
| 166 MemOperand register_location(int register_index); |
| 167 |
| 168 // Register holding the current input position as negative offset from |
| 169 // the end of the string. |
| 170 inline Register current_input_offset() { return r6; } |
| 171 |
| 172 // The register containing the current character after LoadCurrentCharacter. |
| 173 inline Register current_character() { return r7; } |
| 174 |
| 175 // Register holding address of the end of the input string. |
| 176 inline Register end_of_input_address() { return r10; } |
| 177 |
| 178 // Register holding the frame address. Local variables, parameters and |
| 179 // regexp registers are addressed relative to this. |
| 180 inline Register frame_pointer() { return fp; } |
| 181 |
| 182 // The register containing the backtrack stack top. Provides a meaningful |
| 183 // name to the register. |
| 184 inline Register backtrack_stackpointer() { return r8; } |
| 185 |
| 186 // Byte size of chars in the string to match (decided by the Mode argument) |
| 187 inline int char_size() { return static_cast<int>(mode_); } |
| 188 |
| 189 // Equivalent to a conditional branch to the label, unless the label |
| 190 // is NULL, in which case it is a conditional Backtrack. |
| 191 void BranchOrBacktrack(Condition condition, Label* to); |
| 192 |
| 193 // Call and return internally in the generated code in a way that |
| 194 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) |
| 195 inline void SafeCall(Label* to, Condition cond = al); |
| 196 inline void SafeReturn(); |
| 197 inline void SafeCallTarget(Label* name); |
| 198 |
| 199 // Pushes the value of a register on the backtrack stack. Decrements the |
| 200 // stack pointer by a word size and stores the register's value there. |
| 201 inline void Push(Register source); |
| 202 |
| 203 // Pops a value from the backtrack stack. Reads the word at the stack pointer |
| 204 // and increments it by a word size. |
| 205 inline void Pop(Register target); |
| 206 |
| 207 // Before calling a C-function from generated code, align arguments on stack. |
| 208 // After aligning the frame, non-register arguments must be stored in |
| 209 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments |
| 210 // are word sized. |
| 211 // Some compilers/platforms require the stack to be aligned when calling |
| 212 // C++ code. |
| 213 // Needs a scratch register to do some arithmetic. This register will be |
| 214 // trashed. |
| 215 inline void FrameAlign(int num_arguments, Register scratch); |
| 216 |
| 217 // Calls a C function and cleans up the space for arguments allocated |
| 218 // by FrameAlign. The called function is not allowed to trigger a garbage |
| 219 // collection. |
| 220 inline void CallCFunction(ExternalReference function, |
| 221 int num_arguments); |
| 222 |
| 223 // Calls a C function and cleans up the frame alignment done by |
| 224 // by FrameAlign. The called function *is* allowed to trigger a garbage |
| 225 // collection, but may not take more than four arguments (no arguments |
| 226 // passed on the stack), and the first argument will be a pointer to the |
| 227 // return address. |
| 228 inline void CallCFunctionUsingStub(ExternalReference function, |
| 229 int num_arguments); |
| 230 |
| 231 |
| 232 MacroAssembler* masm_; |
| 233 |
| 234 // Which mode to generate code for (ASCII or UC16). |
| 235 Mode mode_; |
| 236 |
| 237 // One greater than maximal register index actually used. |
| 238 int num_registers_; |
| 239 |
| 240 // Number of registers to output at the end (the saved registers |
| 241 // are always 0..num_saved_registers_-1) |
| 242 int num_saved_registers_; |
| 243 |
| 244 // Manage a small pre-allocated pool for writing label targets |
| 245 // to for pushing backtrack addresses. |
| 246 int backtrack_constant_pool_offset_; |
| 247 int backtrack_constant_pool_capacity_; |
| 248 |
| 249 // Labels used internally. |
| 250 Label entry_label_; |
| 251 Label start_label_; |
| 252 Label success_label_; |
| 253 Label backtrack_label_; |
| 254 Label exit_label_; |
| 255 Label check_preempt_label_; |
| 256 Label stack_overflow_label_; |
| 257 }; |
| 258 |
| 259 |
| 260 #endif // V8_NATIVE_REGEXP |
| 261 |
| 262 |
40 }} // namespace v8::internal | 263 }} // namespace v8::internal |
41 | 264 |
42 #endif // V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 265 #endif // V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ |
OLD | NEW |