OLD | NEW |
(Empty) | |
| 1 // Copyright 2008 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_REGEXP_MACRO_ASSEMBLER_H_ |
| 29 #define V8_REGEXP_MACRO_ASSEMBLER_H_ |
| 30 |
| 31 namespace v8 { namespace internal { |
| 32 |
| 33 |
| 34 struct DisjunctDecisionRow { |
| 35 RegExpCharacterClass cc; |
| 36 Label* on_match; |
| 37 }; |
| 38 |
| 39 |
| 40 class RegExpMacroAssembler { |
| 41 public: |
| 42 enum IrregexpImplementation { |
| 43 kIA32Implementation, |
| 44 kARMImplementation, |
| 45 kBytecodeImplementation}; |
| 46 |
| 47 RegExpMacroAssembler(); |
| 48 virtual ~RegExpMacroAssembler(); |
| 49 virtual void AdvanceCurrentPosition(int by) = 0; // Signed cp change. |
| 50 virtual void AdvanceRegister(int reg, int by) = 0; // r[reg] += by. |
| 51 virtual void Backtrack() = 0; |
| 52 virtual void Bind(Label* label) = 0; |
| 53 // Check the current character against a bitmap. The range of the current |
| 54 // character must be from start to start + length_of_bitmap_in_bits. |
| 55 virtual void CheckBitmap( |
| 56 uc16 start, // The bitmap is indexed from this character. |
| 57 Label* bitmap, // Where the bitmap is emitted. |
| 58 Label* on_zero) = 0; // Where to go if the bit is 0. Fall through on 1. |
| 59 // Dispatch after looking the current character up in a 2-bits-per-entry |
| 60 // map. The destinations vector has up to 4 labels. |
| 61 virtual void CheckCharacter(uc16 c, Label* on_equal) = 0; |
| 62 virtual void CheckCharacterGT(uc16 limit, Label* on_greater) = 0; |
| 63 virtual void CheckCharacterLT(uc16 limit, Label* on_less) = 0; |
| 64 // Check the current character for a match with a literal string. If we |
| 65 // fail to match then goto the on_failure label. End of input always |
| 66 // matches. If the label is NULL then we should pop a backtrack address off |
| 67 // the stack abnd go to that. |
| 68 virtual void CheckCharacters( |
| 69 Vector<const uc16> str, |
| 70 int cp_offset, |
| 71 Label* on_failure) = 0; |
| 72 // Check the current input position against a register. If the register is |
| 73 // equal to the current position then go to the label. If the label is NULL |
| 74 // then backtrack instead. |
| 75 virtual void CheckCurrentPosition( |
| 76 int register_index, |
| 77 Label* on_equal) = 0; |
| 78 virtual void CheckNotBackReference(int start_reg, Label* on_no_match) = 0; |
| 79 // Check the current character for a match with a literal character. If we |
| 80 // fail to match then goto the on_failure label. End of input always |
| 81 // matches. If the label is NULL then we should pop a backtrack address off |
| 82 // the stack and go to that. |
| 83 virtual void CheckNotCharacter(uc16 c, Label* on_not_equal) = 0; |
| 84 // Bitwise or the current character with the given constant and then |
| 85 // check for a match with c. |
| 86 virtual void CheckNotCharacterAfterOr(uc16 c, |
| 87 uc16 or_with, |
| 88 Label* on_not_equal) = 0; |
| 89 // Subtract a constant from the current character, then or with the given |
| 90 // constant and then check for a match with c. |
| 91 virtual void CheckNotCharacterAfterMinusOr(uc16 c, |
| 92 uc16 minus_then_or_with, |
| 93 Label* on_not_equal) = 0; |
| 94 // Dispatch after looking the current character up in a byte map. The |
| 95 // destinations vector has up to 256 labels. |
| 96 virtual void DispatchByteMap( |
| 97 uc16 start, |
| 98 Label* byte_map, |
| 99 const Vector<Label*>& destinations) = 0; |
| 100 virtual void DispatchHalfNibbleMap( |
| 101 uc16 start, |
| 102 Label* half_nibble_map, |
| 103 const Vector<Label*>& destinations) = 0; |
| 104 // Dispatch after looking the high byte of the current character up in a byte |
| 105 // map. The destinations vector has up to 256 labels. |
| 106 virtual void DispatchHighByteMap( |
| 107 byte start, |
| 108 Label* byte_map, |
| 109 const Vector<Label*>& destinations) = 0; |
| 110 virtual void EmitOrLink(Label* label) = 0; |
| 111 virtual void Fail() = 0; |
| 112 virtual Handle<Object> GetCode() = 0; |
| 113 virtual void GoTo(Label* label) = 0; |
| 114 // Check whether a register is >= a given constant and go to a label if it |
| 115 // is. Backtracks instead if the label is NULL. |
| 116 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge) = 0; |
| 117 // Check whether a register is < a given constant and go to a label if it is. |
| 118 // Backtracks instead if the label is NULL. |
| 119 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt) = 0; |
| 120 virtual IrregexpImplementation Implementation() = 0; |
| 121 virtual void LoadCurrentCharacter(int cp_offset, Label* on_end_of_input) = 0; |
| 122 virtual void PopCurrentPosition() = 0; |
| 123 virtual void PopRegister(int register_index) = 0; |
| 124 virtual void PushBacktrack(Label* label) = 0; |
| 125 virtual void PushCurrentPosition() = 0; |
| 126 virtual void PushRegister(int register_index) = 0; |
| 127 virtual void ReadCurrentPositionFromRegister(int reg) = 0; |
| 128 virtual void ReadStackPointerFromRegister(int reg) = 0; |
| 129 virtual void SetRegister(int register_index, int to) = 0; |
| 130 virtual void Succeed() = 0; |
| 131 virtual void WriteCurrentPositionToRegister(int reg) = 0; |
| 132 virtual void WriteStackPointerToRegister(int reg) = 0; |
| 133 |
| 134 private: |
| 135 }; |
| 136 |
| 137 |
| 138 struct ArraySlice { |
| 139 public: |
| 140 ArraySlice(Handle<ByteArray> array, size_t offset) |
| 141 : array_(array), offset_(offset) {} |
| 142 Handle<ByteArray> array() { return array_; } |
| 143 // Offset in the byte array data. |
| 144 size_t offset() { return offset_; } |
| 145 // Offset from the ByteArray pointer. |
| 146 size_t base_offset() { |
| 147 return ByteArray::kHeaderSize - kHeapObjectTag + offset_; |
| 148 } |
| 149 template <typename T> |
| 150 T* location() { |
| 151 return reinterpret_cast<T*>(array_->GetDataStartAddress() + offset_); |
| 152 } |
| 153 template <typename T> |
| 154 T& at(int idx) { |
| 155 return reinterpret_cast<T*>(array_->GetDataStartAddress() + offset_)[idx]; |
| 156 } |
| 157 private: |
| 158 Handle<ByteArray> array_; |
| 159 size_t offset_; |
| 160 }; |
| 161 |
| 162 |
| 163 class ByteArrayProvider { |
| 164 public: |
| 165 explicit ByteArrayProvider(unsigned int initial_size); |
| 166 // Provides a place to put "size" elements of size "element_size". |
| 167 // The information can be stored in the provided ByteArray at the "offset". |
| 168 // The offset is aligned to the element size. |
| 169 ArraySlice GetBuffer(unsigned int size, |
| 170 unsigned int element_size); |
| 171 template <typename T> |
| 172 ArraySlice GetBuffer(Vector<T> values); |
| 173 private: |
| 174 size_t byte_array_size_; |
| 175 Handle<ByteArray> current_byte_array_; |
| 176 int current_byte_array_free_offset_; |
| 177 }; |
| 178 |
| 179 } } // namespace v8::internal |
| 180 |
| 181 #endif // V8_REGEXP_MACRO_ASSEMBLER_H_ |
OLD | NEW |