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