OLD | NEW |
| (Empty) |
1 // Copyright 2012 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ | |
6 #define V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ | |
7 | |
8 #include "src/regexp-macro-assembler.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 | |
13 #ifdef V8_INTERPRETED_REGEXP | |
14 | |
15 // A light-weight assembler for the Irregexp byte code. | |
16 class RegExpMacroAssemblerIrregexp: public RegExpMacroAssembler { | |
17 public: | |
18 // Create an assembler. Instructions and relocation information are emitted | |
19 // into a buffer, with the instructions starting from the beginning and the | |
20 // relocation information starting from the end of the buffer. See CodeDesc | |
21 // for a detailed comment on the layout (globals.h). | |
22 // | |
23 // If the provided buffer is NULL, the assembler allocates and grows its own | |
24 // buffer, and buffer_size determines the initial buffer size. The buffer is | |
25 // owned by the assembler and deallocated upon destruction of the assembler. | |
26 // | |
27 // If the provided buffer is not NULL, the assembler uses the provided buffer | |
28 // for code generation and assumes its size to be buffer_size. If the buffer | |
29 // is too small, a fatal error occurs. No deallocation of the buffer is done | |
30 // upon destruction of the assembler. | |
31 RegExpMacroAssemblerIrregexp(Isolate* isolate, Vector<byte> buffer, | |
32 Zone* zone); | |
33 virtual ~RegExpMacroAssemblerIrregexp(); | |
34 // The byte-code interpreter checks on each push anyway. | |
35 virtual int stack_limit_slack() { return 1; } | |
36 virtual bool CanReadUnaligned() { return false; } | |
37 virtual void Bind(Label* label); | |
38 virtual void AdvanceCurrentPosition(int by); // Signed cp change. | |
39 virtual void PopCurrentPosition(); | |
40 virtual void PushCurrentPosition(); | |
41 virtual void Backtrack(); | |
42 virtual void GoTo(Label* label); | |
43 virtual void PushBacktrack(Label* label); | |
44 virtual bool Succeed(); | |
45 virtual void Fail(); | |
46 virtual void PopRegister(int register_index); | |
47 virtual void PushRegister(int register_index, | |
48 StackCheckFlag check_stack_limit); | |
49 virtual void AdvanceRegister(int reg, int by); // r[reg] += by. | |
50 virtual void SetCurrentPositionFromEnd(int by); | |
51 virtual void SetRegister(int register_index, int to); | |
52 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); | |
53 virtual void ClearRegisters(int reg_from, int reg_to); | |
54 virtual void ReadCurrentPositionFromRegister(int reg); | |
55 virtual void WriteStackPointerToRegister(int reg); | |
56 virtual void ReadStackPointerFromRegister(int reg); | |
57 virtual void LoadCurrentCharacter(int cp_offset, | |
58 Label* on_end_of_input, | |
59 bool check_bounds = true, | |
60 int characters = 1); | |
61 virtual void CheckCharacter(unsigned c, Label* on_equal); | |
62 virtual void CheckCharacterAfterAnd(unsigned c, | |
63 unsigned mask, | |
64 Label* on_equal); | |
65 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); | |
66 virtual void CheckCharacterLT(uc16 limit, Label* on_less); | |
67 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); | |
68 virtual void CheckAtStart(Label* on_at_start); | |
69 virtual void CheckNotAtStart(Label* on_not_at_start); | |
70 virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); | |
71 virtual void CheckNotCharacterAfterAnd(unsigned c, | |
72 unsigned mask, | |
73 Label* on_not_equal); | |
74 virtual void CheckNotCharacterAfterMinusAnd(uc16 c, | |
75 uc16 minus, | |
76 uc16 mask, | |
77 Label* on_not_equal); | |
78 virtual void CheckCharacterInRange(uc16 from, | |
79 uc16 to, | |
80 Label* on_in_range); | |
81 virtual void CheckCharacterNotInRange(uc16 from, | |
82 uc16 to, | |
83 Label* on_not_in_range); | |
84 virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set); | |
85 virtual void CheckNotBackReference(int start_reg, Label* on_no_match); | |
86 virtual void CheckNotBackReferenceIgnoreCase(int start_reg, | |
87 Label* on_no_match); | |
88 virtual void IfRegisterLT(int register_index, int comparand, Label* if_lt); | |
89 virtual void IfRegisterGE(int register_index, int comparand, Label* if_ge); | |
90 virtual void IfRegisterEqPos(int register_index, Label* if_eq); | |
91 | |
92 virtual IrregexpImplementation Implementation(); | |
93 virtual Handle<HeapObject> GetCode(Handle<String> source); | |
94 | |
95 private: | |
96 void Expand(); | |
97 // Code and bitmap emission. | |
98 inline void EmitOrLink(Label* label); | |
99 inline void Emit32(uint32_t x); | |
100 inline void Emit16(uint32_t x); | |
101 inline void Emit8(uint32_t x); | |
102 inline void Emit(uint32_t bc, uint32_t arg); | |
103 // Bytecode buffer. | |
104 int length(); | |
105 void Copy(Address a); | |
106 | |
107 // The buffer into which code and relocation info are generated. | |
108 Vector<byte> buffer_; | |
109 // The program counter. | |
110 int pc_; | |
111 // True if the assembler owns the buffer, false if buffer is external. | |
112 bool own_buffer_; | |
113 Label backtrack_; | |
114 | |
115 int advance_current_start_; | |
116 int advance_current_offset_; | |
117 int advance_current_end_; | |
118 | |
119 Isolate* isolate_; | |
120 | |
121 static const int kInvalidPC = -1; | |
122 | |
123 DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMacroAssemblerIrregexp); | |
124 }; | |
125 | |
126 #endif // V8_INTERPRETED_REGEXP | |
127 | |
128 } } // namespace v8::internal | |
129 | |
130 #endif // V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ | |
OLD | NEW |