| OLD | NEW |
| 1 // Copyright 2008-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2008-2009 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_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ | 28 #ifndef V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ |
| 29 #define V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ | 29 #define V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ |
| 30 | 30 |
| 31 namespace v8 { | 31 namespace v8 { |
| 32 namespace internal { | 32 namespace internal { |
| 33 | 33 |
| 34 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { | 34 class RegExpMacroAssemblerIA32: public NativeRegExpMacroAssembler { |
| 35 public: | 35 public: |
| 36 // Type of input string to generate code for. | |
| 37 enum Mode { ASCII = 1, UC16 = 2 }; | |
| 38 // Result of calling the generated RegExp code: | |
| 39 // RETRY: Something significant changed during execution, and the matching | |
| 40 // should be retried from scratch. | |
| 41 // EXCEPTION: Something failed during execution. If no exception has been | |
| 42 // thrown, it's an internal out-of-memory, and the caller should | |
| 43 // throw the exception. | |
| 44 // FAILURE: Matching failed. | |
| 45 // SUCCESS: Matching succeeded, and the output array has been filled with | |
| 46 // capture positions. | |
| 47 enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 }; | |
| 48 | |
| 49 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); | 36 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); |
| 50 virtual ~RegExpMacroAssemblerIA32(); | 37 virtual ~RegExpMacroAssemblerIA32(); |
| 51 virtual int stack_limit_slack(); | 38 virtual int stack_limit_slack(); |
| 52 virtual void AdvanceCurrentPosition(int by); | 39 virtual void AdvanceCurrentPosition(int by); |
| 53 virtual void AdvanceRegister(int reg, int by); | 40 virtual void AdvanceRegister(int reg, int by); |
| 54 virtual void Backtrack(); | 41 virtual void Backtrack(); |
| 55 virtual void Bind(Label* label); | 42 virtual void Bind(Label* label); |
| 56 virtual void CheckAtStart(Label* on_at_start); | 43 virtual void CheckAtStart(Label* on_at_start); |
| 57 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero); | |
| 58 virtual void CheckCharacter(uint32_t c, Label* on_equal); | 44 virtual void CheckCharacter(uint32_t c, Label* on_equal); |
| 59 virtual void CheckCharacterAfterAnd(uint32_t c, | 45 virtual void CheckCharacterAfterAnd(uint32_t c, |
| 60 uint32_t mask, | 46 uint32_t mask, |
| 61 Label* on_equal); | 47 Label* on_equal); |
| 62 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); | 48 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); |
| 63 virtual void CheckCharacterLT(uc16 limit, Label* on_less); | 49 virtual void CheckCharacterLT(uc16 limit, Label* on_less); |
| 64 virtual void CheckCharacters(Vector<const uc16> str, | 50 virtual void CheckCharacters(Vector<const uc16> str, |
| 65 int cp_offset, | 51 int cp_offset, |
| 66 Label* on_failure, | 52 Label* on_failure, |
| 67 bool check_end_of_string); | 53 bool check_end_of_string); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 81 uc16 minus, | 67 uc16 minus, |
| 82 uc16 mask, | 68 uc16 mask, |
| 83 Label* on_not_equal); | 69 Label* on_not_equal); |
| 84 // Checks whether the given offset from the current position is before | 70 // Checks whether the given offset from the current position is before |
| 85 // the end of the string. | 71 // the end of the string. |
| 86 virtual void CheckPosition(int cp_offset, Label* on_outside_input); | 72 virtual void CheckPosition(int cp_offset, Label* on_outside_input); |
| 87 virtual bool CheckSpecialCharacterClass(uc16 type, | 73 virtual bool CheckSpecialCharacterClass(uc16 type, |
| 88 int cp_offset, | 74 int cp_offset, |
| 89 bool check_offset, | 75 bool check_offset, |
| 90 Label* on_no_match); | 76 Label* on_no_match); |
| 91 virtual void DispatchByteMap(uc16 start, | |
| 92 Label* byte_map, | |
| 93 const Vector<Label*>& destinations); | |
| 94 virtual void DispatchHalfNibbleMap(uc16 start, | |
| 95 Label* half_nibble_map, | |
| 96 const Vector<Label*>& destinations); | |
| 97 virtual void DispatchHighByteMap(byte start, | |
| 98 Label* byte_map, | |
| 99 const Vector<Label*>& destinations); | |
| 100 virtual void EmitOrLink(Label* label); | |
| 101 virtual void Fail(); | 77 virtual void Fail(); |
| 102 virtual Handle<Object> GetCode(Handle<String> source); | 78 virtual Handle<Object> GetCode(Handle<String> source); |
| 103 virtual void GoTo(Label* label); | 79 virtual void GoTo(Label* label); |
| 104 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge); | 80 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge); |
| 105 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt); | 81 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt); |
| 106 virtual void IfRegisterEqPos(int reg, Label* if_eq); | 82 virtual void IfRegisterEqPos(int reg, Label* if_eq); |
| 107 virtual IrregexpImplementation Implementation(); | 83 virtual IrregexpImplementation Implementation(); |
| 108 virtual void LoadCurrentCharacter(int cp_offset, | 84 virtual void LoadCurrentCharacter(int cp_offset, |
| 109 Label* on_end_of_input, | 85 Label* on_end_of_input, |
| 110 bool check_bounds = true, | 86 bool check_bounds = true, |
| 111 int characters = 1); | 87 int characters = 1); |
| 112 virtual void PopCurrentPosition(); | 88 virtual void PopCurrentPosition(); |
| 113 virtual void PopRegister(int register_index); | 89 virtual void PopRegister(int register_index); |
| 114 virtual void PushBacktrack(Label* label); | 90 virtual void PushBacktrack(Label* label); |
| 115 virtual void PushCurrentPosition(); | 91 virtual void PushCurrentPosition(); |
| 116 virtual void PushRegister(int register_index, | 92 virtual void PushRegister(int register_index, |
| 117 StackCheckFlag check_stack_limit); | 93 StackCheckFlag check_stack_limit); |
| 118 virtual void ReadCurrentPositionFromRegister(int reg); | 94 virtual void ReadCurrentPositionFromRegister(int reg); |
| 119 virtual void ReadStackPointerFromRegister(int reg); | 95 virtual void ReadStackPointerFromRegister(int reg); |
| 120 virtual void SetRegister(int register_index, int to); | 96 virtual void SetRegister(int register_index, int to); |
| 121 virtual void Succeed(); | 97 virtual void Succeed(); |
| 122 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); | 98 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); |
| 123 virtual void ClearRegisters(int reg_from, int reg_to); | 99 virtual void ClearRegisters(int reg_from, int reg_to); |
| 124 virtual void WriteStackPointerToRegister(int reg); | 100 virtual void WriteStackPointerToRegister(int reg); |
| 125 | 101 |
| 126 static Result Match(Handle<Code> regexp, | |
| 127 Handle<String> subject, | |
| 128 int* offsets_vector, | |
| 129 int offsets_vector_length, | |
| 130 int previous_index); | |
| 131 | |
| 132 static Result Execute(Code* code, | |
| 133 String* input, | |
| 134 int start_offset, | |
| 135 const byte* input_start, | |
| 136 const byte* input_end, | |
| 137 int* output, | |
| 138 bool at_start); | |
| 139 | |
| 140 private: | 102 private: |
| 141 // Offsets from ebp of function parameters and stored registers. | 103 // Offsets from ebp of function parameters and stored registers. |
| 142 static const int kFramePointer = 0; | 104 static const int kFramePointer = 0; |
| 143 // Above the frame pointer - function parameters and return address. | 105 // Above the frame pointer - function parameters and return address. |
| 144 static const int kReturn_eip = kFramePointer + kPointerSize; | 106 static const int kReturn_eip = kFramePointer + kPointerSize; |
| 145 static const int kFrameAlign = kReturn_eip + kPointerSize; | 107 static const int kFrameAlign = kReturn_eip + kPointerSize; |
| 146 // Parameters. | 108 // Parameters. |
| 147 static const int kInputString = kFrameAlign; | 109 static const int kInputString = kFrameAlign; |
| 148 static const int kStartIndex = kInputString + kPointerSize; | 110 static const int kStartIndex = kInputString + kPointerSize; |
| 149 static const int kInputStart = kStartIndex + kPointerSize; | 111 static const int kInputStart = kStartIndex + kPointerSize; |
| 150 static const int kInputEnd = kInputStart + kPointerSize; | 112 static const int kInputEnd = kInputStart + kPointerSize; |
| 151 static const int kRegisterOutput = kInputEnd + kPointerSize; | 113 static const int kRegisterOutput = kInputEnd + kPointerSize; |
| 152 static const int kAtStart = kRegisterOutput + kPointerSize; | 114 static const int kAtStart = kRegisterOutput + kPointerSize; |
| 153 static const int kStackHighEnd = kAtStart + kPointerSize; | 115 static const int kStackHighEnd = kAtStart + kPointerSize; |
| 154 // Below the frame pointer - local stack variables. | 116 // Below the frame pointer - local stack variables. |
| 155 // When adding local variables remember to push space for them in | 117 // When adding local variables remember to push space for them in |
| 156 // the frame in GetCode. | 118 // the frame in GetCode. |
| 157 static const int kBackup_esi = kFramePointer - kPointerSize; | 119 static const int kBackup_esi = kFramePointer - kPointerSize; |
| 158 static const int kBackup_edi = kBackup_esi - kPointerSize; | 120 static const int kBackup_edi = kBackup_esi - kPointerSize; |
| 159 static const int kBackup_ebx = kBackup_edi - kPointerSize; | 121 static const int kBackup_ebx = kBackup_edi - kPointerSize; |
| 160 static const int kInputStartMinusOne = kBackup_ebx - kPointerSize; | 122 static const int kInputStartMinusOne = kBackup_ebx - kPointerSize; |
| 161 // First register address. Following registers are below it on the stack. | 123 // First register address. Following registers are below it on the stack. |
| 162 static const int kRegisterZero = kInputStartMinusOne - kPointerSize; | 124 static const int kRegisterZero = kInputStartMinusOne - kPointerSize; |
| 163 | 125 |
| 164 // Initial size of code buffer. | 126 // Initial size of code buffer. |
| 165 static const size_t kRegExpCodeSize = 1024; | 127 static const size_t kRegExpCodeSize = 1024; |
| 166 // Initial size of constant buffers allocated during compilation. | |
| 167 static const int kRegExpConstantsSize = 256; | |
| 168 | |
| 169 static const byte* StringCharacterPosition(String* subject, int start_index); | |
| 170 | |
| 171 // Compares two-byte strings case insensitively. | |
| 172 // Called from generated RegExp code. | |
| 173 static int CaseInsensitiveCompareUC16(Address byte_offset1, | |
| 174 Address byte_offset2, | |
| 175 size_t byte_length); | |
| 176 | 128 |
| 177 // Load a number of characters at the given offset from the | 129 // Load a number of characters at the given offset from the |
| 178 // current position, into the current-character register. | 130 // current position, into the current-character register. |
| 179 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); | 131 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); |
| 180 | 132 |
| 181 // Check whether preemption has been requested. | 133 // Check whether preemption has been requested. |
| 182 void CheckPreemption(); | 134 void CheckPreemption(); |
| 183 | 135 |
| 184 // Check whether we are exceeding the stack limit on the backtrack stack. | 136 // Check whether we are exceeding the stack limit on the backtrack stack. |
| 185 void CheckStackLimit(); | 137 void CheckStackLimit(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 211 // name to the register. | 163 // name to the register. |
| 212 inline Register backtrack_stackpointer() { return ecx; } | 164 inline Register backtrack_stackpointer() { return ecx; } |
| 213 | 165 |
| 214 // Byte size of chars in the string to match (decided by the Mode argument) | 166 // Byte size of chars in the string to match (decided by the Mode argument) |
| 215 inline int char_size() { return static_cast<int>(mode_); } | 167 inline int char_size() { return static_cast<int>(mode_); } |
| 216 | 168 |
| 217 // Equivalent to a conditional branch to the label, unless the label | 169 // Equivalent to a conditional branch to the label, unless the label |
| 218 // is NULL, in which case it is a conditional Backtrack. | 170 // is NULL, in which case it is a conditional Backtrack. |
| 219 void BranchOrBacktrack(Condition condition, Label* to, Hint hint = no_hint); | 171 void BranchOrBacktrack(Condition condition, Label* to, Hint hint = no_hint); |
| 220 | 172 |
| 221 // Load the address of a "constant buffer" (a slice of a byte array) | |
| 222 // into a register. The address is computed from the ByteArray* address | |
| 223 // and an offset. Uses no extra registers. | |
| 224 void LoadConstantBufferAddress(Register reg, ArraySlice* buffer); | |
| 225 | |
| 226 // Call and return internally in the generated code in a way that | 173 // Call and return internally in the generated code in a way that |
| 227 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) | 174 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) |
| 228 inline void SafeCall(Label* to); | 175 inline void SafeCall(Label* to); |
| 229 inline void SafeReturn(); | 176 inline void SafeReturn(); |
| 230 inline void SafeCallTarget(Label* name); | 177 inline void SafeCallTarget(Label* name); |
| 231 | 178 |
| 232 // Pushes the value of a register on the backtrack stack. Decrements the | 179 // Pushes the value of a register on the backtrack stack. Decrements the |
| 233 // stack pointer (ecx) by a word size and stores the register's value there. | 180 // stack pointer (ecx) by a word size and stores the register's value there. |
| 234 inline void Push(Register source); | 181 inline void Push(Register source); |
| 235 | 182 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 251 inline void FrameAlign(int num_arguments, Register scratch); | 198 inline void FrameAlign(int num_arguments, Register scratch); |
| 252 | 199 |
| 253 // Calls a C function and cleans up the space for arguments allocated | 200 // Calls a C function and cleans up the space for arguments allocated |
| 254 // by FrameAlign. The called function is not allowed to trigger a garbage | 201 // by FrameAlign. The called function is not allowed to trigger a garbage |
| 255 // collection, since that might move the code and invalidate the return | 202 // collection, since that might move the code and invalidate the return |
| 256 // address (unless this is somehow accounted for). | 203 // address (unless this is somehow accounted for). |
| 257 inline void CallCFunction(Address function_address, int num_arguments); | 204 inline void CallCFunction(Address function_address, int num_arguments); |
| 258 | 205 |
| 259 MacroAssembler* masm_; | 206 MacroAssembler* masm_; |
| 260 | 207 |
| 261 // Constant buffer provider. Allocates external storage for storing | |
| 262 // constants. | |
| 263 ByteArrayProvider constants_; | |
| 264 | |
| 265 // Which mode to generate code for (ASCII or UC16). | 208 // Which mode to generate code for (ASCII or UC16). |
| 266 Mode mode_; | 209 Mode mode_; |
| 267 | 210 |
| 268 // One greater than maximal register index actually used. | 211 // One greater than maximal register index actually used. |
| 269 int num_registers_; | 212 int num_registers_; |
| 270 | 213 |
| 271 // Number of registers to output at the end (the saved registers | 214 // Number of registers to output at the end (the saved registers |
| 272 // are always 0..num_saved_registers_-1) | 215 // are always 0..num_saved_registers_-1) |
| 273 int num_saved_registers_; | 216 int num_saved_registers_; |
| 274 | 217 |
| 275 // Labels used internally. | 218 // Labels used internally. |
| 276 Label entry_label_; | 219 Label entry_label_; |
| 277 Label start_label_; | 220 Label start_label_; |
| 278 Label success_label_; | 221 Label success_label_; |
| 279 Label backtrack_label_; | 222 Label backtrack_label_; |
| 280 Label exit_label_; | 223 Label exit_label_; |
| 281 Label check_preempt_label_; | 224 Label check_preempt_label_; |
| 282 Label stack_overflow_label_; | 225 Label stack_overflow_label_; |
| 283 }; | 226 }; |
| 284 | 227 |
| 285 }} // namespace v8::internal | 228 }} // namespace v8::internal |
| 286 | 229 |
| 287 #endif // V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ | 230 #endif // V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_ |
| OLD | NEW |