mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 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_IRREGEXP_H_ |
| 29 | #define V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ |
| 30 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 31 | namespace v8 { |
| 32 | namespace internal { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 33 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 34 | #ifdef V8_INTERPRETED_REGEXP |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 35 | |
| 36 | class RegExpMacroAssemblerIrregexp: public RegExpMacroAssembler { |
| 37 | public: |
| 38 | // Create an assembler. Instructions and relocation information are emitted |
| 39 | // into a buffer, with the instructions starting from the beginning and the |
| 40 | // relocation information starting from the end of the buffer. See CodeDesc |
| 41 | // for a detailed comment on the layout (globals.h). |
| 42 | // |
| 43 | // If the provided buffer is NULL, the assembler allocates and grows its own |
| 44 | // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 45 | // owned by the assembler and deallocated upon destruction of the assembler. |
| 46 | // |
| 47 | // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 48 | // for code generation and assumes its size to be buffer_size. If the buffer |
| 49 | // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 50 | // upon destruction of the assembler. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 51 | RegExpMacroAssemblerIrregexp(Vector<byte>, Zone* zone); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 52 | virtual ~RegExpMacroAssemblerIrregexp(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 53 | // The byte-code interpreter checks on each push anyway. |
| 54 | virtual int stack_limit_slack() { return 1; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 55 | virtual void Bind(Label* label); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 56 | virtual void AdvanceCurrentPosition(int by); // Signed cp change. |
| 57 | virtual void PopCurrentPosition(); |
| 58 | virtual void PushCurrentPosition(); |
| 59 | virtual void Backtrack(); |
| 60 | virtual void GoTo(Label* label); |
| 61 | virtual void PushBacktrack(Label* label); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 62 | virtual bool Succeed(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 63 | virtual void Fail(); |
| 64 | virtual void PopRegister(int register_index); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 65 | virtual void PushRegister(int register_index, |
| 66 | StackCheckFlag check_stack_limit); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 67 | virtual void AdvanceRegister(int reg, int by); // r[reg] += by. |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 68 | virtual void SetCurrentPositionFromEnd(int by); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 69 | virtual void SetRegister(int register_index, int to); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 70 | virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 71 | virtual void ClearRegisters(int reg_from, int reg_to); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 72 | virtual void ReadCurrentPositionFromRegister(int reg); |
| 73 | virtual void WriteStackPointerToRegister(int reg); |
| 74 | virtual void ReadStackPointerFromRegister(int reg); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 75 | virtual void LoadCurrentCharacter(int cp_offset, |
| 76 | Label* on_end_of_input, |
| 77 | bool check_bounds = true, |
| 78 | int characters = 1); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 79 | virtual void CheckCharacter(unsigned c, Label* on_equal); |
| 80 | virtual void CheckCharacterAfterAnd(unsigned c, |
| 81 | unsigned mask, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 82 | Label* on_equal); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 83 | virtual void CheckCharacterGT(uc16 limit, Label* on_greater); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 84 | virtual void CheckCharacterLT(uc16 limit, Label* on_less); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 85 | virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 86 | virtual void CheckAtStart(Label* on_at_start); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 87 | virtual void CheckNotAtStart(Label* on_not_at_start); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 88 | virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); |
| 89 | virtual void CheckNotCharacterAfterAnd(unsigned c, |
| 90 | unsigned mask, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 91 | Label* on_not_equal); |
| 92 | virtual void CheckNotCharacterAfterMinusAnd(uc16 c, |
| 93 | uc16 minus, |
| 94 | uc16 mask, |
| 95 | Label* on_not_equal); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 96 | virtual void CheckCharacterInRange(uc16 from, |
| 97 | uc16 to, |
| 98 | Label* on_in_range); |
| 99 | virtual void CheckCharacterNotInRange(uc16 from, |
| 100 | uc16 to, |
| 101 | Label* on_not_in_range); |
| 102 | virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 103 | virtual void CheckNotBackReference(int start_reg, Label* on_no_match); |
| 104 | virtual void CheckNotBackReferenceIgnoreCase(int start_reg, |
| 105 | Label* on_no_match); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 106 | virtual void IfRegisterLT(int register_index, int comparand, Label* if_lt); |
| 107 | virtual void IfRegisterGE(int register_index, int comparand, Label* if_ge); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 108 | virtual void IfRegisterEqPos(int register_index, Label* if_eq); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 109 | |
| 110 | virtual IrregexpImplementation Implementation(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 111 | virtual Handle<HeapObject> GetCode(Handle<String> source); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 112 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 113 | private: |
| 114 | void Expand(); |
| 115 | // Code and bitmap emission. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 116 | inline void EmitOrLink(Label* label); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 117 | inline void Emit32(uint32_t x); |
| 118 | inline void Emit16(uint32_t x); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 119 | inline void Emit8(uint32_t x); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 120 | inline void Emit(uint32_t bc, uint32_t arg); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 121 | // Bytecode buffer. |
| 122 | int length(); |
| 123 | void Copy(Address a); |
| 124 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 125 | // The buffer into which code and relocation info are generated. |
| 126 | Vector<byte> buffer_; |
| 127 | // The program counter. |
| 128 | int pc_; |
| 129 | // True if the assembler owns the buffer, false if buffer is external. |
| 130 | bool own_buffer_; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 131 | Label backtrack_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 132 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 133 | int advance_current_start_; |
| 134 | int advance_current_offset_; |
| 135 | int advance_current_end_; |
| 136 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 137 | Isolate* isolate_; |
| 138 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 139 | static const int kInvalidPC = -1; |
| 140 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 141 | DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMacroAssemblerIrregexp); |
| 142 | }; |
| 143 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 144 | #endif // V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 145 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 146 | } } // namespace v8::internal |
| 147 | |
| 148 | #endif // V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ |