1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2008-2009 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_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 { 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#ifdef V8_INTERPRETED_REGEXP 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass RegExpMacroAssemblerIrregexp: public RegExpMacroAssembler { 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Create an assembler. Instructions and relocation information are emitted 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // into a buffer, with the instructions starting from the beginning and the 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // relocation information starting from the end of the buffer. See CodeDesc 41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // for a detailed comment on the layout (globals.h). 42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // 43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If the provided buffer is NULL, the assembler allocates and grows its own 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // buffer, and buffer_size determines the initial buffer size. The buffer is 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // owned by the assembler and deallocated upon destruction of the assembler. 46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If the provided buffer is not NULL, the assembler uses the provided buffer 48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // for code generation and assumes its size to be buffer_size. If the buffer 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // is too small, a fatal error occurs. No deallocation of the buffer is done 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // upon destruction of the assembler. 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit RegExpMacroAssemblerIrregexp(Vector<byte>); 52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual ~RegExpMacroAssemblerIrregexp(); 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The byte-code interpreter checks on each push anyway. 54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual int stack_limit_slack() { return 1; } 55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void Bind(Label* label); 56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void AdvanceCurrentPosition(int by); // Signed cp change. 57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void PopCurrentPosition(); 58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void PushCurrentPosition(); 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void Backtrack(); 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void GoTo(Label* label); 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void PushBacktrack(Label* label); 62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void Succeed(); 63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void Fail(); 64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void PopRegister(int register_index); 65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void PushRegister(int register_index, 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block StackCheckFlag check_stack_limit); 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void AdvanceRegister(int reg, int by); // r[reg] += by. 68f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch virtual void SetCurrentPositionFromEnd(int by); 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void SetRegister(int register_index, int to); 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void ClearRegisters(int reg_from, int reg_to); 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void ReadCurrentPositionFromRegister(int reg); 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void WriteStackPointerToRegister(int reg); 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void ReadStackPointerFromRegister(int reg); 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void LoadCurrentCharacter(int cp_offset, 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_end_of_input, 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool check_bounds = true, 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int characters = 1); 79b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch virtual void CheckCharacter(unsigned c, Label* on_equal); 80b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch virtual void CheckCharacterAfterAnd(unsigned c, 81b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch unsigned mask, 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_equal); 83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckCharacterGT(uc16 limit, Label* on_greater); 84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckCharacterLT(uc16 limit, Label* on_less); 85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); 86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckAtStart(Label* on_at_start); 87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckNotAtStart(Label* on_not_at_start); 88b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); 89b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch virtual void CheckNotCharacterAfterAnd(unsigned c, 90b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch unsigned mask, 91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_not_equal); 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckNotCharacterAfterMinusAnd(uc16 c, 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uc16 minus, 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uc16 mask, 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_not_equal); 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckNotBackReference(int start_reg, Label* on_no_match); 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckNotBackReferenceIgnoreCase(int start_reg, 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_no_match); 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal); 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void CheckCharacters(Vector<const uc16> str, 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int cp_offset, 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label* on_failure, 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool check_end_of_string); 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void IfRegisterLT(int register_index, int comparand, Label* if_lt); 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void IfRegisterGE(int register_index, int comparand, Label* if_ge); 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual void IfRegisterEqPos(int register_index, Label* if_eq); 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual IrregexpImplementation Implementation(); 109053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block virtual Handle<HeapObject> GetCode(Handle<String> source); 110589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Expand(); 113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code and bitmap emission. 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void EmitOrLink(Label* label); 115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Emit32(uint32_t x); 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Emit16(uint32_t x); 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Emit(uint32_t bc, uint32_t arg); 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Bytecode buffer. 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length(); 120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Copy(Address a); 121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The buffer into which code and relocation info are generated. 123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Vector<byte> buffer_; 124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The program counter. 125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int pc_; 126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // True if the assembler owns the buffer, false if buffer is external. 127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool own_buffer_; 128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Label backtrack_; 129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int advance_current_start_; 131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int advance_current_offset_; 132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int advance_current_end_; 133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kInvalidPC = -1; 135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMacroAssemblerIrregexp); 137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#endif // V8_INTERPRETED_REGEXP 140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} } // namespace v8::internal 142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // V8_REGEXP_MACRO_ASSEMBLER_IRREGEXP_H_ 144