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