| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 15 matching lines...) Expand all Loading... |
| 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 REGEXP_MACRO_ASSEMBLER_IA32_H_ | 28 #ifndef REGEXP_MACRO_ASSEMBLER_IA32_H_ |
| 29 #define REGEXP_MACRO_ASSEMBLER_IA32_H_ | 29 #define REGEXP_MACRO_ASSEMBLER_IA32_H_ |
| 30 | 30 |
| 31 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
| 32 | 32 |
| 33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { | 33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { |
| 34 public: | 34 public: |
| 35 // Type of input string to generate code for. | 35 // Type of input string to generate code for. |
| 36 enum Mode {ASCII = 1, UC16 = 2}; | 36 enum Mode { ASCII = 1, UC16 = 2 }; |
| 37 enum Result { EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 }; |
| 37 | 38 |
| 38 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); | 39 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); |
| 39 virtual ~RegExpMacroAssemblerIA32(); | 40 virtual ~RegExpMacroAssemblerIA32(); |
| 40 virtual void AdvanceCurrentPosition(int by); | 41 virtual void AdvanceCurrentPosition(int by); |
| 41 virtual void AdvanceRegister(int reg, int by); | 42 virtual void AdvanceRegister(int reg, int by); |
| 42 virtual void Backtrack(); | 43 virtual void Backtrack(); |
| 43 virtual void Bind(Label* label); | 44 virtual void Bind(Label* label); |
| 44 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero); | 45 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero); |
| 45 virtual void CheckCharacter(uc16 c, Label* on_equal); | 46 virtual void CheckCharacter(uc16 c, Label* on_equal); |
| 46 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); | 47 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 virtual void PushCurrentPosition(); | 86 virtual void PushCurrentPosition(); |
| 86 virtual void PushRegister(int register_index); | 87 virtual void PushRegister(int register_index); |
| 87 virtual void ReadCurrentPositionFromRegister(int reg); | 88 virtual void ReadCurrentPositionFromRegister(int reg); |
| 88 virtual void ReadStackPointerFromRegister(int reg); | 89 virtual void ReadStackPointerFromRegister(int reg); |
| 89 virtual void SetRegister(int register_index, int to); | 90 virtual void SetRegister(int register_index, int to); |
| 90 virtual void Succeed(); | 91 virtual void Succeed(); |
| 91 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); | 92 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); |
| 92 virtual void WriteStackPointerToRegister(int reg); | 93 virtual void WriteStackPointerToRegister(int reg); |
| 93 | 94 |
| 94 template <typename T> | 95 template <typename T> |
| 95 static inline bool Execute(Code* code, | 96 static inline Result Execute(Code* code, |
| 96 T** input, | 97 T** input, |
| 97 int start_offset, | 98 int start_offset, |
| 98 int end_offset, | 99 int end_offset, |
| 99 int* output, | 100 int* output, |
| 100 bool at_start) { | 101 bool at_start) { |
| 101 typedef bool (*matcher)(T**, int, int, int*, int); | 102 typedef int (*matcher)(T**, int, int, int*, int); |
| 102 matcher matcher_func = FUNCTION_CAST<matcher>(code->entry()); | 103 matcher matcher_func = FUNCTION_CAST<matcher>(code->entry()); |
| 103 int at_start_val = at_start ? 1 : 0; | 104 int at_start_val = at_start ? 1 : 0; |
| 104 return matcher_func(input, start_offset, end_offset, output, at_start_val); | 105 int result = matcher_func(input, |
| 106 start_offset, |
| 107 end_offset, |
| 108 output, |
| 109 at_start_val); |
| 110 return (result < 0) ? EXCEPTION : (result ? SUCCESS : FAILURE); |
| 105 } | 111 } |
| 106 | 112 |
| 107 private: | 113 private: |
| 108 // Offsets from ebp of arguments to function. | 114 // Offsets from ebp of arguments to function. |
| 109 static const int kBackup_ebx = sizeof(uint32_t); | 115 static const int kBackup_ebx = sizeof(uint32_t); |
| 110 static const int kBackup_edi = kBackup_ebx + sizeof(uint32_t); | 116 static const int kBackup_edi = kBackup_ebx + sizeof(uint32_t); |
| 111 static const int kBackup_esi = kBackup_edi + sizeof(uint32_t); | 117 static const int kBackup_esi = kBackup_edi + sizeof(uint32_t); |
| 112 static const int kReturn_eip = kBackup_esi + sizeof(uint32_t); | 118 static const int kReturn_eip = kBackup_esi + sizeof(uint32_t); |
| 113 static const int kInputBuffer = kReturn_eip + sizeof(uint32_t); | 119 static const int kInputBuffer = kReturn_eip + sizeof(uint32_t); |
| 114 static const int kInputStartOffset = kInputBuffer + sizeof(uint32_t); | 120 static const int kInputStartOffset = kInputBuffer + sizeof(uint32_t); |
| 115 static const int kInputEndOffset = kInputStartOffset + sizeof(uint32_t); | 121 static const int kInputEndOffset = kInputStartOffset + sizeof(uint32_t); |
| 116 static const int kRegisterOutput = kInputEndOffset + sizeof(uint32_t); | 122 static const int kRegisterOutput = kInputEndOffset + sizeof(uint32_t); |
| 117 static const int kAtStart = kRegisterOutput + sizeof(uint32_t); | 123 static const int kAtStart = kRegisterOutput + sizeof(uint32_t); |
| 118 | 124 |
| 119 // Initial size of code buffer. | 125 // Initial size of code buffer. |
| 120 static const size_t kRegExpCodeSize = 1024; | 126 static const size_t kRegExpCodeSize = 1024; |
| 121 // Initial size of constant buffers allocated during compilation. | 127 // Initial size of constant buffers allocated during compilation. |
| 122 static const int kRegExpConstantsSize = 256; | 128 static const int kRegExpConstantsSize = 256; |
| 123 // Only unroll loops up to this length. | 129 // Only unroll loops up to this length. |
| 124 static const int kMaxInlineStringTests = 8; | 130 static const int kMaxInlineStringTests = 8; |
| 125 | 131 |
| 126 // Compares two-byte strings case insenstively. | 132 // Compares two-byte strings case insenstively. |
| 127 static int CaseInsensitiveCompareUC16(uc16** buffer, | 133 static int CaseInsensitiveCompareUC16(uc16** buffer, |
| 128 int byte_offset1, | 134 int byte_offset1, |
| 129 int byte_offset2, | 135 int byte_offset2, |
| 130 size_t byte_length); | 136 size_t byte_length); |
| 131 | 137 |
| 138 // Called from RegExp if the stack-guard is triggered. |
| 139 // If the code object is relocated, the return address is fixed before |
| 140 // returning. |
| 141 static int CheckStackGuardState(Address return_address, Code* re_code); |
| 142 |
| 132 // The ebp-relative location of a regexp register. | 143 // The ebp-relative location of a regexp register. |
| 133 Operand register_location(int register_index); | 144 Operand register_location(int register_index); |
| 134 | 145 |
| 135 // The register containing the current character after LoadCurrentCharacter. | 146 // The register containing the current character after LoadCurrentCharacter. |
| 136 Register current_character(); | 147 Register current_character(); |
| 137 | 148 |
| 138 // Byte size of chars in the string to match (decided by the Mode argument) | 149 // Byte size of chars in the string to match (decided by the Mode argument) |
| 139 size_t char_size(); | 150 size_t char_size(); |
| 140 | 151 |
| 141 // Equivalent to a conditional branch to the label, unless the label | 152 // Equivalent to a conditional branch to the label, unless the label |
| 142 // is NULL, in which case it is a conditional Backtrack. | 153 // is NULL, in which case it is a conditional Backtrack. |
| 143 void BranchOrBacktrack(Condition condition, Label* to); | 154 void BranchOrBacktrack(Condition condition, Label* to); |
| 144 | 155 |
| 145 // Load the address of a "constant buffer" (a slice of a byte array) | 156 // Load the address of a "constant buffer" (a slice of a byte array) |
| 146 // into a register. The address is computed from the ByteArray* address | 157 // into a register. The address is computed from the ByteArray* address |
| 147 // and an offset. Uses no extra registers. | 158 // and an offset. Uses no extra registers. |
| 148 void LoadConstantBufferAddress(Register reg, ArraySlice* buffer); | 159 void LoadConstantBufferAddress(Register reg, ArraySlice* buffer); |
| 149 | 160 |
| 150 // Adds code that checks whether preemption has been requested | 161 // Adds code that checks whether preemption has been requested |
| 151 // (and checks if we have hit the stack limit too). | 162 // (and checks if we have hit the stack limit too). |
| 152 void CheckStackLimit(); | 163 void CheckStackLimit(); |
| 153 | 164 |
| 165 // Call and return internally in the generated code in a way that |
| 166 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) |
| 167 void SafeCall(Label* to); |
| 168 void SafeReturn(); |
| 169 |
| 170 // Before calling a C-function from generated code, align arguments on stack. |
| 171 // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 172 // etc., not pushed. The argument count assumes all arguments are word sized. |
| 173 void FrameAlign(int num_arguments); |
| 174 // Calls a C function and cleans up the space for arguments allocated |
| 175 // by FrameAlign. The called function is not allowed to trigger a garbage |
| 176 // collection, since that might move the code and invalidate the return |
| 177 // address |
| 178 void CallCFunction(Address function_address, int num_arguments); |
| 179 |
| 154 MacroAssembler* masm_; | 180 MacroAssembler* masm_; |
| 155 // Constant buffer provider. Allocates external storage for storing | 181 // Constant buffer provider. Allocates external storage for storing |
| 156 // constants. | 182 // constants. |
| 157 ByteArrayProvider constants_; | 183 ByteArrayProvider constants_; |
| 158 // Which mode to generate code for (ASCII or UTF16). | 184 // Which mode to generate code for (ASCII or UTF16). |
| 159 Mode mode_; | 185 Mode mode_; |
| 160 // One greater than maximal register index actually used. | 186 // One greater than maximal register index actually used. |
| 161 int num_registers_; | 187 int num_registers_; |
| 162 // Number of registers to output at the end (the saved registers | 188 // Number of registers to output at the end (the saved registers |
| 163 // are always 0..num_saved_registers_-1) | 189 // are always 0..num_saved_registers_-1) |
| 164 int num_saved_registers_; | 190 int num_saved_registers_; |
| 165 // Labels used internally. | 191 // Labels used internally. |
| 166 Label entry_label_; | 192 Label entry_label_; |
| 167 Label start_label_; | 193 Label start_label_; |
| 168 Label success_label_; | 194 Label success_label_; |
| 169 Label exit_label_; | 195 Label exit_label_; |
| 196 Label check_preempt_label_; |
| 170 // Handle used to represent the generated code object itself. | 197 // Handle used to represent the generated code object itself. |
| 171 Handle<Object> self_; | 198 Handle<Object> self_; |
| 172 }; | 199 }; |
| 173 | 200 |
| 174 }} // namespace v8::internal | 201 }} // namespace v8::internal |
| 175 | 202 |
| 176 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */ | 203 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */ |
| OLD | NEW |