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 |
(...skipping 17 matching lines...) Expand all Loading... |
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 PushRegister(int index); | 35 void PushRegister(int index); |
36 void SetRegisterToCurrentPosition(int index, int cp_offset = 0); | 36 void SetRegisterToCurrentPosition(int index, int cp_offset = 0); |
37 void SetRegister(int index, int value); | 37 void SetRegister(int index, int value); |
| 38 void AdvanceRegister(int index, int by); |
38 | 39 |
39 void PopCurrentPosition(); | 40 void PopCurrentPosition(); |
40 void PopBacktrack(); | 41 void PopBacktrack(); |
41 void PopRegister(int index); | 42 void PopRegister(int index); |
42 | 43 |
43 void Fail(); | 44 void Fail(); |
44 void FailIfWithin(int distance_from_end); | |
45 void Succeed(); | 45 void Succeed(); |
46 | 46 |
47 void Break(); // This instruction will cause a fatal VM error if hit. | 47 void Break(); // This instruction will cause a fatal VM error if hit. |
48 | 48 |
49 void Bind(Label* l); // binds an unbound label L to the current code position | 49 void Bind(Label* l); // Binds an unbound label L to the current code posn. |
50 | 50 |
51 void AdvanceCP(int cp_offset = 1); | 51 void AdvanceCP(int by); |
52 | 52 |
53 void GoTo(Label* l); | 53 void GoTo(Label* l); |
54 | 54 |
55 // Loads current char into a register. | 55 // Loads current char into a machine register. Jumps to the label if we |
56 void LoadCurrentChar(int cp_offset = 0); | 56 // reached the end of the subject string. Fall through otherwise. |
| 57 void LoadCurrentChar(int cp_offset, Label* on_end); |
57 | 58 |
58 // Checks current char register against a singleton. | 59 // Checks current char register against a singleton. |
59 void CheckChar(uc16 c, Label* on_mismatch); | 60 void CheckChar(uc16 c, Label* on_mismatch); |
60 void CheckNotChar(uc16 c, Label* on_match); | 61 void CheckNotChar(uc16 c, Label* on_match); |
61 | 62 |
62 // Checks current char register against the magic end-of-input symbol. | |
63 void CheckEnd(Label* on_not_end); | |
64 void CheckNotEnd(Label* on_end); | |
65 | |
66 // Checks current char register against a range. | 63 // Checks current char register against a range. |
67 void CheckRange(uc16 start, uc16 end, Label* on_mismatch); | 64 void CheckRange(uc16 start, uc16 end, Label* on_mismatch); |
68 void CheckNotRange(uc16 start, uc16 end, Label* on_match); | 65 void CheckNotRange(uc16 start, uc16 end, Label* on_match); |
69 | 66 |
70 // Checks that the current char is in the range and that the corresponding bit | |
71 // is set in the bitmap. | |
72 void CheckBitmap(uc16 start, uc16 end, const byte* bits, Label* on_mismatch); | |
73 void CheckNotBitmap(uc16 start, uc16 end, const byte* bits, Label* on_match); | |
74 | |
75 // Checks current position (plus optional offset) for a match against a | 67 // Checks current position (plus optional offset) for a match against a |
76 // previous capture. Advances current position by the length of the capture | 68 // previous capture. Advances current position by the length of the capture |
77 // iff it matches. The capture is stored in a given register and the | 69 // iff it matches. The capture is stored in a given register and the |
78 // the register after. | 70 // the register after. If a register contains -1 then the other register |
79 void CheckBackref(int capture_index, Label* on_mismatch, int cp_offset = 0); | 71 // mush always contain -1 and the on_mismatch label will never be called. |
80 void CheckNotBackref(int capture_index, Label* on_match, int cp_offset = 0); | 72 void CheckBackref(int capture_index, Label* on_mismatch); |
81 | 73 |
82 // Checks a register for equal, less than or equal, less than, greater than | 74 // Checks a register for strictly-less-than or greater-than-or-equal. |
83 // or equal, greater than, not equal. | 75 void CheckRegisterLT(int reg_index, uint16_t vs, Label* on_less_than); |
84 void CheckRegisterLt(int reg_index, uint16_t vs, Label* on_less_than); | 76 void CheckRegisterGE(int reg_index, uint16_t vs, Label* on_greater_equal); |
85 void CheckRegisterGe(int reg_index, uint16_t vs, Label* on_greater_equal); | 77 |
| 78 // Subtracts a 16 bit value from the current character, uses the result to |
| 79 // look up in a bit array, uses the result of that decide whether to fall |
| 80 // though (on 1) or jump to the on_zero label (on 0). |
| 81 void LookupMap1(uc16 start, Label* bit_map, Label* on_zero); |
| 82 |
| 83 // Subtracts a 16 bit value from the current character, uses the result to |
| 84 // look up in a 2-bit array, uses the result of that to look up in a label |
| 85 // table and jumps to the label. |
| 86 void LookupMap2(uc16 start, |
| 87 Label* half_nibble_map, |
| 88 const Vector<Label*>& table); |
| 89 |
| 90 // Subtracts a 16 bit value from the current character, uses the result to |
| 91 // look up in a byte array, uses the result of that to look up in a label |
| 92 // array and jumps to the label. |
| 93 void LookupMap8(uc16 start, Label* byte_map, const Vector<Label*>& table); |
| 94 |
| 95 // Takes the high byte of the current character, uses the result to |
| 96 // look up in a byte array, uses the result of that to look up in a label |
| 97 // array and jumps to the label. |
| 98 void LookupHighMap8(byte start, Label* byte_map, const Vector<Label*>& table); |
86 | 99 |
87 // Code and bitmap emission. | 100 // Code and bitmap emission. |
88 inline void Emit32(uint32_t x); | 101 inline void Emit32(uint32_t x); |
89 inline void Emit16(uint32_t x); | 102 inline void Emit16(uint32_t x); |
90 inline void Emit(uint32_t x); | 103 inline void Emit(uint32_t x); |
91 | 104 |
92 // Bytecode buffer. | 105 // Bytecode buffer. |
93 int length(); | 106 int length(); |
94 void Copy(Address a); | 107 void Copy(Address a); |
95 | 108 |
| 109 inline void EmitOrLink(Label* l); |
96 private: | 110 private: |
97 // Don't use this. | 111 // Don't use this. |
98 Re2kAssembler() { UNREACHABLE(); } | 112 Re2kAssembler() { UNREACHABLE(); } |
99 // The buffer into which code and relocation info are generated. | 113 // The buffer into which code and relocation info are generated. |
100 Vector<byte> buffer_; | 114 Vector<byte> buffer_; |
101 | 115 |
102 inline void CheckRegister(int byte_code, | 116 inline void CheckRegister(int byte_code, |
103 int reg_index, | 117 int reg_index, |
104 uint16_t vs, | 118 uint16_t vs, |
105 Label* on_true); | 119 Label* on_true); |
106 // Code generation. | 120 // Code generation. |
107 int pc_; // The program counter; moves forward. | 121 int pc_; // The program counter; moves forward. |
108 | 122 |
109 // True if the assembler owns the buffer, false if buffer is external. | 123 // True if the assembler owns the buffer, false if buffer is external. |
110 bool own_buffer_; | 124 bool own_buffer_; |
111 | |
112 inline void EmitOrLink(Label* l); | |
113 }; | 125 }; |
114 | 126 |
115 | 127 |
116 } } // namespace v8::internal | 128 } } // namespace v8::internal |
117 | 129 |
118 #endif // V8_ASSEMBLER_RE2K_H_ | 130 #endif // V8_ASSEMBLER_RE2K_H_ |
OLD | NEW |