Home | History | Annotate | Download | only in mips
      1 // Copyright 2006-2010 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 
     29 #ifndef V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
     30 #define V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
     31 
     32 namespace v8 {
     33 namespace internal {
     34 
     35 #ifdef V8_INTERPRETED_REGEXP
     36 class RegExpMacroAssemblerMIPS: public RegExpMacroAssembler {
     37  public:
     38   RegExpMacroAssemblerMIPS();
     39   virtual ~RegExpMacroAssemblerMIPS();
     40 };
     41 #else  // V8_INTERPRETED_REGEXP
     42 class RegExpMacroAssemblerMIPS: public NativeRegExpMacroAssembler {
     43  public:
     44   RegExpMacroAssemblerMIPS(Mode mode, int registers_to_save);
     45   virtual ~RegExpMacroAssemblerMIPS();
     46   virtual int stack_limit_slack();
     47   virtual void AdvanceCurrentPosition(int by);
     48   virtual void AdvanceRegister(int reg, int by);
     49   virtual void Backtrack();
     50   virtual void Bind(Label* label);
     51   virtual void CheckAtStart(Label* on_at_start);
     52   virtual void CheckCharacter(uint32_t c, Label* on_equal);
     53   virtual void CheckCharacterAfterAnd(uint32_t c,
     54                                       uint32_t mask,
     55                                       Label* on_equal);
     56   virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
     57   virtual void CheckCharacterLT(uc16 limit, Label* on_less);
     58   virtual void CheckCharacters(Vector<const uc16> str,
     59                                int cp_offset,
     60                                Label* on_failure,
     61                                bool check_end_of_string);
     62   // A "greedy loop" is a loop that is both greedy and with a simple
     63   // body. It has a particularly simple implementation.
     64   virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
     65   virtual void CheckNotAtStart(Label* on_not_at_start);
     66   virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
     67   virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
     68                                                Label* on_no_match);
     69   virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal);
     70   virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
     71   virtual void CheckNotCharacterAfterAnd(uint32_t c,
     72                                          uint32_t mask,
     73                                          Label* on_not_equal);
     74   virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
     75                                               uc16 minus,
     76                                               uc16 mask,
     77                                               Label* on_not_equal);
     78   // Checks whether the given offset from the current position is before
     79   // the end of the string.
     80   virtual void CheckPosition(int cp_offset, Label* on_outside_input);
     81   virtual bool CheckSpecialCharacterClass(uc16 type,
     82                                           Label* on_no_match);
     83   virtual void Fail();
     84   virtual Handle<HeapObject> GetCode(Handle<String> source);
     85   virtual void GoTo(Label* label);
     86   virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
     87   virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
     88   virtual void IfRegisterEqPos(int reg, Label* if_eq);
     89   virtual IrregexpImplementation Implementation();
     90   virtual void LoadCurrentCharacter(int cp_offset,
     91                                     Label* on_end_of_input,
     92                                     bool check_bounds = true,
     93                                     int characters = 1);
     94   virtual void PopCurrentPosition();
     95   virtual void PopRegister(int register_index);
     96   virtual void PushBacktrack(Label* label);
     97   virtual void PushCurrentPosition();
     98   virtual void PushRegister(int register_index,
     99                             StackCheckFlag check_stack_limit);
    100   virtual void ReadCurrentPositionFromRegister(int reg);
    101   virtual void ReadStackPointerFromRegister(int reg);
    102   virtual void SetCurrentPositionFromEnd(int by);
    103   virtual void SetRegister(int register_index, int to);
    104   virtual void Succeed();
    105   virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
    106   virtual void ClearRegisters(int reg_from, int reg_to);
    107   virtual void WriteStackPointerToRegister(int reg);
    108 
    109   // Called from RegExp if the stack-guard is triggered.
    110   // If the code object is relocated, the return address is fixed before
    111   // returning.
    112   static int CheckStackGuardState(Address* return_address,
    113                                   Code* re_code,
    114                                   Address re_frame);
    115  private:
    116   // Offsets from frame_pointer() of function parameters and stored registers.
    117   static const int kFramePointer = 0;
    118 
    119   // Above the frame pointer - Stored registers and stack passed parameters.
    120   // Registers s0 to s7, fp, and ra.
    121   static const int kStoredRegisters = kFramePointer;
    122   // Return address (stored from link register, read into pc on return).
    123   static const int kReturnAddress = kStoredRegisters + 9 * kPointerSize;
    124   // Stack frame header.
    125   static const int kStackFrameHeader = kReturnAddress + kPointerSize;
    126   // Stack parameters placed by caller.
    127   static const int kRegisterOutput = kStackFrameHeader + 16;
    128   static const int kStackHighEnd = kRegisterOutput + kPointerSize;
    129   static const int kDirectCall = kStackHighEnd + kPointerSize;
    130   static const int kIsolate = kDirectCall + kPointerSize;
    131 
    132   // Below the frame pointer.
    133   // Register parameters stored by setup code.
    134   static const int kInputEnd = kFramePointer - kPointerSize;
    135   static const int kInputStart = kInputEnd - kPointerSize;
    136   static const int kStartIndex = kInputStart - kPointerSize;
    137   static const int kInputString = kStartIndex - kPointerSize;
    138   // When adding local variables remember to push space for them in
    139   // the frame in GetCode.
    140   static const int kInputStartMinusOne = kInputString - kPointerSize;
    141   static const int kAtStart = kInputStartMinusOne - kPointerSize;
    142   // First register address. Following registers are below it on the stack.
    143   static const int kRegisterZero = kAtStart - kPointerSize;
    144 
    145   // Initial size of code buffer.
    146   static const size_t kRegExpCodeSize = 1024;
    147 
    148   // Load a number of characters at the given offset from the
    149   // current position, into the current-character register.
    150   void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
    151 
    152   // Check whether preemption has been requested.
    153   void CheckPreemption();
    154 
    155   // Check whether we are exceeding the stack limit on the backtrack stack.
    156   void CheckStackLimit();
    157 
    158 
    159   // Generate a call to CheckStackGuardState.
    160   void CallCheckStackGuardState(Register scratch);
    161 
    162   // The ebp-relative location of a regexp register.
    163   MemOperand register_location(int register_index);
    164 
    165   // Register holding the current input position as negative offset from
    166   // the end of the string.
    167   inline Register current_input_offset() { return t2; }
    168 
    169   // The register containing the current character after LoadCurrentCharacter.
    170   inline Register current_character() { return t3; }
    171 
    172   // Register holding address of the end of the input string.
    173   inline Register end_of_input_address() { return t6; }
    174 
    175   // Register holding the frame address. Local variables, parameters and
    176   // regexp registers are addressed relative to this.
    177   inline Register frame_pointer() { return fp; }
    178 
    179   // The register containing the backtrack stack top. Provides a meaningful
    180   // name to the register.
    181   inline Register backtrack_stackpointer() { return t4; }
    182 
    183   // Register holding pointer to the current code object.
    184   inline Register code_pointer() { return t1; }
    185 
    186   // Byte size of chars in the string to match (decided by the Mode argument)
    187   inline int char_size() { return static_cast<int>(mode_); }
    188 
    189   // Equivalent to a conditional branch to the label, unless the label
    190   // is NULL, in which case it is a conditional Backtrack.
    191   void BranchOrBacktrack(Label* to,
    192                          Condition condition,
    193                          Register rs,
    194                          const Operand& rt);
    195 
    196   // Call and return internally in the generated code in a way that
    197   // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
    198   inline void SafeCall(Label* to,
    199                        Condition cond,
    200                        Register rs,
    201                        const Operand& rt);
    202   inline void SafeReturn();
    203   inline void SafeCallTarget(Label* name);
    204 
    205   // Pushes the value of a register on the backtrack stack. Decrements the
    206   // stack pointer by a word size and stores the register's value there.
    207   inline void Push(Register source);
    208 
    209   // Pops a value from the backtrack stack. Reads the word at the stack pointer
    210   // and increments it by a word size.
    211   inline void Pop(Register target);
    212 
    213   // Calls a C function and cleans up the frame alignment done by
    214   // by FrameAlign. The called function *is* allowed to trigger a garbage
    215   // collection, but may not take more than four arguments (no arguments
    216   // passed on the stack), and the first argument will be a pointer to the
    217   // return address.
    218   inline void CallCFunctionUsingStub(ExternalReference function,
    219                                      int num_arguments);
    220 
    221 
    222   MacroAssembler* masm_;
    223 
    224   // Which mode to generate code for (ASCII or UC16).
    225   Mode mode_;
    226 
    227   // One greater than maximal register index actually used.
    228   int num_registers_;
    229 
    230   // Number of registers to output at the end (the saved registers
    231   // are always 0..num_saved_registers_-1)
    232   int num_saved_registers_;
    233 
    234   // Labels used internally.
    235   Label entry_label_;
    236   Label start_label_;
    237   Label success_label_;
    238   Label backtrack_label_;
    239   Label exit_label_;
    240   Label check_preempt_label_;
    241   Label stack_overflow_label_;
    242 };
    243 
    244 #endif  // V8_INTERPRETED_REGEXP
    245 
    246 
    247 }}  // namespace v8::internal
    248 
    249 #endif  // V8_MIPS_REGEXP_MACRO_ASSEMBLER_MIPS_H_
    250 
    251