The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / regexp-macro-assembler-irregexp.h @ 40c0f755

History | View | Annotate | Download (7 KB)

1
// Copyright 2008-2009 the V8 project authors. All rights reserved.
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

    
31
namespace v8 { namespace internal {
32

    
33

    
34
class RegExpMacroAssemblerIrregexp: public RegExpMacroAssembler {
35
 public:
36
  // Create an assembler. Instructions and relocation information are emitted
37
  // into a buffer, with the instructions starting from the beginning and the
38
  // relocation information starting from the end of the buffer. See CodeDesc
39
  // for a detailed comment on the layout (globals.h).
40
  //
41
  // If the provided buffer is NULL, the assembler allocates and grows its own
42
  // buffer, and buffer_size determines the initial buffer size. The buffer is
43
  // owned by the assembler and deallocated upon destruction of the assembler.
44
  //
45
  // If the provided buffer is not NULL, the assembler uses the provided buffer
46
  // for code generation and assumes its size to be buffer_size. If the buffer
47
  // is too small, a fatal error occurs. No deallocation of the buffer is done
48
  // upon destruction of the assembler.
49
  explicit RegExpMacroAssemblerIrregexp(Vector<byte>);
50
  virtual ~RegExpMacroAssemblerIrregexp();
51
  // The byte-code interpreter checks on each push anyway.
52
  virtual int stack_limit_slack() { return 1; }
53
  virtual void Bind(Label* label);
54
  virtual void EmitOrLink(Label* label);
55
  virtual void AdvanceCurrentPosition(int by);  // Signed cp change.
56
  virtual void PopCurrentPosition();
57
  virtual void PushCurrentPosition();
58
  virtual void Backtrack();
59
  virtual void GoTo(Label* label);
60
  virtual void PushBacktrack(Label* label);
61
  virtual void Succeed();
62
  virtual void Fail();
63
  virtual void PopRegister(int register_index);
64
  virtual void PushRegister(int register_index,
65
                            StackCheckFlag check_stack_limit);
66
  virtual void AdvanceRegister(int reg, int by);  // r[reg] += by.
67
  virtual void SetRegister(int register_index, int to);
68
  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
69
  virtual void ClearRegisters(int reg_from, int reg_to);
70
  virtual void ReadCurrentPositionFromRegister(int reg);
71
  virtual void WriteStackPointerToRegister(int reg);
72
  virtual void ReadStackPointerFromRegister(int reg);
73
  virtual void LoadCurrentCharacter(int cp_offset,
74
                                    Label* on_end_of_input,
75
                                    bool check_bounds = true,
76
                                    int characters = 1);
77
  virtual void CheckCharacter(uint32_t c, Label* on_equal);
78
  virtual void CheckCharacterAfterAnd(uint32_t c,
79
                                      uint32_t mask,
80
                                      Label* on_equal);
81
  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
82
  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
83
  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
84
  virtual void CheckAtStart(Label* on_at_start);
85
  virtual void CheckNotAtStart(Label* on_not_at_start);
86
  virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
87
  virtual void CheckNotCharacterAfterAnd(uint32_t c,
88
                                         uint32_t mask,
89
                                         Label* on_not_equal);
90
  virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
91
                                              uc16 minus,
92
                                              uc16 mask,
93
                                              Label* on_not_equal);
94
  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
95
  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
96
                                               Label* on_no_match);
97
  virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal);
98
  virtual void CheckCharacters(Vector<const uc16> str,
99
                               int cp_offset,
100
                               Label* on_failure,
101
                               bool check_end_of_string);
102
  virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero);
103
  virtual void DispatchHalfNibbleMap(uc16 start,
104
                                     Label* half_nibble_map,
105
                                     const Vector<Label*>& destinations);
106
  virtual void DispatchByteMap(uc16 start,
107
                               Label* byte_map,
108
                               const Vector<Label*>& destinations);
109
  virtual void DispatchHighByteMap(byte start,
110
                                   Label* byte_map,
111
                                   const Vector<Label*>& destinations);
112
  virtual void IfRegisterLT(int register_index, int comparand, Label* if_lt);
113
  virtual void IfRegisterGE(int register_index, int comparand, Label* if_ge);
114
  virtual void IfRegisterEqPos(int register_index, Label* if_eq);
115

    
116
  virtual IrregexpImplementation Implementation();
117
  virtual Handle<Object> GetCode(Handle<String> source);
118
 private:
119
  void Expand();
120
  // Code and bitmap emission.
121
  inline void Emit32(uint32_t x);
122
  inline void Emit16(uint32_t x);
123
  inline void Emit(uint32_t bc, uint32_t arg);
124
  // Bytecode buffer.
125
  int length();
126
  void Copy(Address a);
127

    
128
  // The buffer into which code and relocation info are generated.
129
  Vector<byte> buffer_;
130
  // The program counter.
131
  int pc_;
132
  // True if the assembler owns the buffer, false if buffer is external.
133
  bool own_buffer_;
134
  Label backtrack_;
135

    
136
  int advance_current_start_;
137
  int advance_current_offset_;
138
  int advance_current_end_;
139

    
140
  static const int kInvalidPC = -1;
141

    
142
  DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMacroAssemblerIrregexp);
143
};
144

    
145
} }  // namespace v8::internal
146

    
147
#endif  // V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_