1e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch// Copyright 2010 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_X64_REGEXP_MACRO_ASSEMBLER_X64_H_
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_X64_REGEXP_MACRO_ASSEMBLER_X64_H_
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#include "x64/assembler-x64.h"
323fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#include "x64/assembler-x64-inl.h"
333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#include "macro-assembler.h"
343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#include "code.h"
353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#include "x64/macro-assembler-x64.h"
363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#ifndef V8_INTERPRETED_REGEXP
41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass RegExpMacroAssemblerX64: public NativeRegExpMacroAssembler {
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  RegExpMacroAssemblerX64(Mode mode, int registers_to_save);
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~RegExpMacroAssemblerX64();
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual int stack_limit_slack();
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void AdvanceCurrentPosition(int by);
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void AdvanceRegister(int reg, int by);
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Backtrack();
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Bind(Label* label);
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckAtStart(Label* on_at_start);
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckCharacter(uint32_t c, Label* on_equal);
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckCharacterAfterAnd(uint32_t c,
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      uint32_t mask,
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Label* on_equal);
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckCharacters(Vector<const uc16> str,
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               int cp_offset,
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               Label* on_failure,
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               bool check_end_of_string);
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // A "greedy loop" is a loop that is both greedy and with a simple
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // body. It has a particularly simple implementation.
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotAtStart(Label* on_not_at_start);
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               Label* on_no_match);
69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal);
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotCharacterAfterAnd(uint32_t c,
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         uint32_t mask,
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         Label* on_not_equal);
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                              uc16 minus,
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                              uc16 mask,
77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                              Label* on_not_equal);
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Checks whether the given offset from the current position is before
79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the end of the string.
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual bool CheckSpecialCharacterClass(uc16 type,
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          Label* on_no_match);
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Fail();
84053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  virtual Handle<HeapObject> GetCode(Handle<String> source);
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void GoTo(Label* label);
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void IfRegisterEqPos(int reg, Label* if_eq);
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual IrregexpImplementation Implementation();
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void LoadCurrentCharacter(int cp_offset,
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    Label* on_end_of_input,
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    bool check_bounds = true,
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    int characters = 1);
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PopCurrentPosition();
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PopRegister(int register_index);
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PushBacktrack(Label* label);
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PushCurrentPosition();
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PushRegister(int register_index,
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                            StackCheckFlag check_stack_limit);
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void ReadCurrentPositionFromRegister(int reg);
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void ReadStackPointerFromRegister(int reg);
102f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  virtual void SetCurrentPositionFromEnd(int by);
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void SetRegister(int register_index, int to);
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Succeed();
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void ClearRegisters(int reg_from, int reg_to);
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void WriteStackPointerToRegister(int reg);
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Result Match(Handle<Code> regexp,
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      Handle<String> subject,
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      int* offsets_vector,
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      int offsets_vector_length,
11344f0eee88ff00398ff7f715fab053374d808c90dSteve Block                      int previous_index,
11444f0eee88ff00398ff7f715fab053374d808c90dSteve Block                      Isolate* isolate);
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Result Execute(Code* code,
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        String* input,
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        int start_offset,
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        const byte* input_start,
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        const byte* input_end,
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        int* output,
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        bool at_start);
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Called from RegExp if the stack-guard is triggered.
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If the code object is relocated, the return address is fixed before
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // returning.
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int CheckStackGuardState(Address* return_address,
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Code* re_code,
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Address re_frame);
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Offsets from rbp of function parameters and stored registers.
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFramePointer = 0;
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Above the frame pointer - function parameters and return address.
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kReturn_eip = kFramePointer + kPointerSize;
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFrameAlign = kReturn_eip + kPointerSize;
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN64
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Parameters (first four passed as registers, but with room on stack).
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // In Microsoft 64-bit Calling Convention, there is room on the callers
141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // stack (before the return address) to spill parameter registers. We
142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // use this space to store the register passed parameters.
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputString = kFrameAlign;
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // StartIndex is passed as 32 bit int.
145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStartIndex = kInputString + kPointerSize;
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputStart = kStartIndex + kPointerSize;
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputEnd = kInputStart + kPointerSize;
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kRegisterOutput = kInputEnd + kPointerSize;
149d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  static const int kStackHighEnd = kRegisterOutput + kPointerSize;
150e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // DirectCall is passed as 32 bit int (values 0 or 1).
151e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kDirectCall = kStackHighEnd + kPointerSize;
15244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kIsolate = kDirectCall + kPointerSize;
153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // In AMD64 ABI Calling Convention, the first six integer parameters
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // are passed as registers, and caller must allocate space on the stack
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // if it wants them stored. We push the parameters after the frame pointer.
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputString = kFramePointer - kPointerSize;
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStartIndex = kInputString - kPointerSize;
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputStart = kStartIndex - kPointerSize;
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputEnd = kInputStart - kPointerSize;
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kRegisterOutput = kInputEnd - kPointerSize;
162d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  static const int kStackHighEnd = kRegisterOutput - kPointerSize;
163d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  static const int kDirectCall = kFrameAlign;
16444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kIsolate = kDirectCall + kPointerSize;
165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN64
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Microsoft calling convention has three callee-saved registers
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // (that we are using). We push these after the frame pointer.
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBackup_rsi = kFramePointer - kPointerSize;
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBackup_rdi = kBackup_rsi - kPointerSize;
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBackup_rbx = kBackup_rdi - kPointerSize;
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLastCalleeSaveRegister = kBackup_rbx;
174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // AMD64 Calling Convention has only one callee-save register that
176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // we use. We push this after the frame pointer (and after the
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // parameters).
178d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  static const int kBackup_rbx = kStackHighEnd - kPointerSize;
179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLastCalleeSaveRegister = kBackup_rbx;
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // When adding local variables remember to push space for them in
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the frame in GetCode.
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInputStartMinusOne =
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kLastCalleeSaveRegister - kPointerSize;
186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // First register address. Following registers are below it on the stack.
18825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Initial size of code buffer.
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const size_t kRegExpCodeSize = 1024;
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Load a number of characters at the given offset from the
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // current position, into the current-character register.
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check whether preemption has been requested.
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CheckPreemption();
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check whether we are exceeding the stack limit on the backtrack stack.
201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CheckStackLimit();
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Generate a call to CheckStackGuardState.
204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CallCheckStackGuardState();
205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The rbp-relative location of a regexp register.
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Operand register_location(int register_index);
208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The register containing the current character after LoadCurrentCharacter.
210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Register current_character() { return rdx; }
211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The register containing the backtrack stack top. Provides a meaningful
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // name to the register.
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Register backtrack_stackpointer() { return rcx; }
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The registers containing a self pointer to this code's Code object.
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Register code_object_pointer() { return r8; }
218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Byte size of chars in the string to match (decided by the Mode argument)
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int char_size() { return static_cast<int>(mode_); }
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Equivalent to a conditional branch to the label, unless the label
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // is NULL, in which case it is a conditional Backtrack.
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void BranchOrBacktrack(Condition condition, Label* to);
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void MarkPositionForCodeRelativeFixup() {
22744f0eee88ff00398ff7f715fab053374d808c90dSteve Block    code_relative_fixup_positions_.Add(masm_.pc_offset());
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void FixupCodeRelativePositions();
231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Call and return internally in the generated code in a way that
233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SafeCall(Label* to);
235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SafeCallTarget(Label* label);
236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SafeReturn();
237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Pushes the value of a register on the backtrack stack. Decrements the
239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // stack pointer (rcx) by a word size and stores the register's value there.
240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Push(Register source);
241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Pushes a value on the backtrack stack. Decrements the stack pointer (rcx)
243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // by a word size and stores the value there.
244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Push(Immediate value);
245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Pushes the Code object relative offset of a label on the backtrack stack
247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // (i.e., a backtrack target). Decrements the stack pointer (rcx)
248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // by a word size and stores the value there.
249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Push(Label* label);
250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Pops a value from the backtrack stack. Reads the word at the stack pointer
252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // (rcx) and increments it by a word size.
253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Pop(Register target);
254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Drops the top value from the backtrack stack without reading it.
256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Increments the stack pointer (rcx) by a word size.
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Drop();
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
25944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  MacroAssembler masm_;
26044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  MacroAssembler::NoRootArrayScope no_root_array_scope_;
261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ZoneList<int> code_relative_fixup_positions_;
263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Which mode to generate code for (ASCII or UC16).
265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Mode mode_;
266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // One greater than maximal register index actually used.
268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int num_registers_;
269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Number of registers to output at the end (the saved registers
271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // are always 0..num_saved_registers_-1)
272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int num_saved_registers_;
273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Labels used internally.
275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label entry_label_;
276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label start_label_;
277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label success_label_;
278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label backtrack_label_;
279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label exit_label_;
280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label check_preempt_label_;
281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Label stack_overflow_label_;
282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#endif  // V8_INTERPRETED_REGEXP
285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}}  // namespace v8::internal
287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_X64_REGEXP_MACRO_ASSEMBLER_X64_H_
289