Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 | 2 |
| 3 // A light-weight assembler for the Regexp2000 byte code. | 3 // A light-weight assembler for the Regexp2000 byte code. |
| 4 | 4 |
| 5 #ifndef V8_ASSEMBLER_RE2K_H_ | 5 #ifndef V8_ASSEMBLER_RE2K_H_ |
| 6 #define V8_ASSEMBLER_RE2K_H_ | 6 #define V8_ASSEMBLER_RE2K_H_ |
| 7 | 7 |
| 8 namespace v8 { namespace internal { | 8 namespace v8 { namespace internal { |
| 9 | 9 |
| 10 | 10 |
| 11 class Re2kAssembler { | 11 class Re2kAssembler { |
| 12 public: | 12 public: |
| 13 // Create an assembler. Instructions and relocation information are emitted | 13 // Create an assembler. Instructions and relocation information are emitted |
| 14 // into a buffer, with the instructions starting from the beginning and the | 14 // into a buffer, with the instructions starting from the beginning and the |
| 15 // relocation information starting from the end of the buffer. See CodeDesc | 15 // relocation information starting from the end of the buffer. See CodeDesc |
| 16 // for a detailed comment on the layout (globals.h). | 16 // for a detailed comment on the layout (globals.h). |
| 17 // | 17 // |
| 18 // If the provided buffer is NULL, the assembler allocates and grows its own | 18 // If the provided buffer is NULL, the assembler allocates and grows its own |
| 19 // buffer, and buffer_size determines the initial buffer size. The buffer is | 19 // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 20 // owned by the assembler and deallocated upon destruction of the assembler. | 20 // owned by the assembler and deallocated upon destruction of the assembler. |
| 21 // | 21 // |
| 22 // If the provided buffer is not NULL, the assembler uses the provided buffer | 22 // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 23 // for code generation and assumes its size to be buffer_size. If the buffer | 23 // for code generation and assumes its size to be buffer_size. If the buffer |
| 24 // is too small, a fatal error occurs. No deallocation of the buffer is done | 24 // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 25 // upon destruction of the assembler. | 25 // upon destruction of the assembler. |
| 26 Re2kAssembler(Vector<byte>); | 26 explicit Re2kAssembler(Vector<byte>); |
| 27 ~Re2kAssembler(); | 27 ~Re2kAssembler(); |
| 28 | 28 |
| 29 // CP = current position in source. | 29 // CP = current position in source. |
| 30 // BT = backtrack label. | 30 // BT = backtrack label. |
| 31 | 31 |
| 32 // Stack. | 32 // Stack. |
| 33 void PushCurrentPosition(int cp_offset = 0); | 33 void PushCurrentPosition(int cp_offset = 0); |
| 34 void PushBacktrack(Label* l); | 34 void PushBacktrack(Label* l); |
| 35 void PushCapture(int index); | 35 void PushRegister(int index); |
| 36 void SetCapture(int index, int cp_offset = 0); | 36 void SetRegister(int index, int cp_offset = 0); |
| 37 | 37 |
| 38 void PopCurrentPosition(); | 38 void PopCurrentPosition(); |
| 39 void PopBacktrack(); | 39 void PopBacktrack(); |
| 40 void PopCapture(int index); | 40 void PopRegister(int index); |
| 41 | 41 |
| 42 void Fail(); | 42 void Fail(); |
| 43 void FailIfWithin(int distance_from_end); | 43 void FailIfWithin(int distance_from_end); |
| 44 void Succeed(); | 44 void Succeed(); |
| 45 | 45 |
| 46 void Bind(Label* l); // binds an unbound label L to the current code position | 46 void Bind(Label* l); // binds an unbound label L to the current code position |
| 47 | 47 |
| 48 void AdvanceCP(int cp_offset = 1); | 48 void AdvanceCP(int cp_offset = 1); |
| 49 | 49 |
| 50 void GoTo(Label* l); | 50 void GoTo(Label* l); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 61 void CheckNotRange(uc16 start, uc16 end, Label* on_match); | 61 void CheckNotRange(uc16 start, uc16 end, Label* on_match); |
| 62 | 62 |
| 63 | 63 |
| 64 // Checks that the current char is in the range and that the corresponding bit | 64 // Checks that the current char is in the range and that the corresponding bit |
| 65 // is set in the bitmap. | 65 // is set in the bitmap. |
| 66 void CheckBitmap(uc16 start, uc16 end, const byte* bits, Label* on_mismatch); | 66 void CheckBitmap(uc16 start, uc16 end, const byte* bits, Label* on_mismatch); |
| 67 void CheckNotBitmap(uc16 start, uc16 end, const byte* bits, Label* on_match); | 67 void CheckNotBitmap(uc16 start, uc16 end, const byte* bits, Label* on_match); |
| 68 | 68 |
| 69 // Checks current position (plus optional offset) for a match against a | 69 // Checks current position (plus optional offset) for a match against a |
| 70 // previous capture. Advances current position by the length of the capture | 70 // previous capture. Advances current position by the length of the capture |
| 71 // iff it matches. | 71 // iff it matches. The capture is stored in a given register and the |
| 72 // the register after. | |
| 72 void CheckBackref(int capture_index, Label* on_mismatch, int cp_offset = 0); | 73 void CheckBackref(int capture_index, Label* on_mismatch, int cp_offset = 0); |
| 73 void CheckNotBackref(int capture_index, Label* on_match, int cp_offset = 0); | 74 void CheckNotBackref(int capture_index, Label* on_match, int cp_offset = 0); |
| 74 | 75 |
| 76 // Checks a register for equal, less than or equal, less than, greater than | |
|
Christian Plesner Hansen
2008/11/06 15:42:58
We only need two of these, LT and GEQ.
| |
| 77 // or equal, greater than, not equal. | |
| 78 void CheckRegisterEq(int reg_index, uint16_t vs, Label* on_equal); | |
| 79 void CheckRegisterLe(int reg_index, uint16_t vs, Label* on_less_equal); | |
| 80 void CheckRegisterLt(int reg_index, uint16_t vs, Label* on_less_than); | |
| 81 void CheckRegisterGe(int reg_index, uint16_t vs, Label* on_greater_equal); | |
| 82 void CheckRegisterGt(int reg_index, uint16_t vs, Label* on_greater_than); | |
| 83 void CheckRegisterNe(int reg_index, uint16_t vs, Label* on_not_equal); | |
| 84 | |
| 75 // Code and bitmap emission. | 85 // Code and bitmap emission. |
| 76 inline void Emit32(uint32_t x); | 86 inline void Emit32(uint32_t x); |
| 77 inline void Emit16(uint32_t x); | 87 inline void Emit16(uint32_t x); |
| 78 inline void Emit(uint32_t x); | 88 inline void Emit(uint32_t x); |
| 79 | 89 |
| 80 // Bytecode buffer. | 90 // Bytecode buffer. |
| 81 int length(); | 91 int length(); |
| 82 void Copy(Address a); | 92 void Copy(Address a); |
| 83 | 93 |
| 84 private: | 94 private: |
| 85 // Don't use this. | 95 // Don't use this. |
| 86 Re2kAssembler() { UNREACHABLE(); } | 96 Re2kAssembler() { UNREACHABLE(); } |
| 87 // The buffer into which code and relocation info are generated. | 97 // The buffer into which code and relocation info are generated. |
| 88 Vector<byte> buffer_; | 98 Vector<byte> buffer_; |
| 89 | 99 |
| 100 inline void CheckRegister(int byte_code, | |
| 101 int reg_index, | |
| 102 uint16_t vs, | |
| 103 Label* on_true); | |
| 90 // Code generation. | 104 // Code generation. |
| 91 int pc_; // The program counter; moves forward. | 105 int pc_; // The program counter; moves forward. |
| 92 | 106 |
| 93 // True if the assembler owns the buffer, false if buffer is external. | 107 // True if the assembler owns the buffer, false if buffer is external. |
| 94 bool own_buffer_; | 108 bool own_buffer_; |
| 95 | 109 |
| 96 inline void EmitOrLink(Label* l); | 110 inline void EmitOrLink(Label* l); |
| 97 }; | 111 }; |
| 98 | 112 |
| 99 | 113 |
| 100 } } // namespace v8::internal | 114 } } // namespace v8::internal |
| 101 | 115 |
| 102 #endif // V8_ASSEMBLER_RE2K_H_ | 116 #endif // V8_ASSEMBLER_RE2K_H_ |
| OLD | NEW |