OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef VM_REGEXP_ASSEMBLER_BYTECODE_H_ |
| 6 #define VM_REGEXP_ASSEMBLER_BYTECODE_H_ |
| 7 |
| 8 #include "vm/object.h" |
| 9 #include "vm/regexp_assembler.h" |
| 10 |
| 11 namespace dart { |
| 12 |
| 13 class BytecodeRegExpMacroAssembler: public RegExpMacroAssembler { |
| 14 public: |
| 15 // Create an assembler. Instructions and relocation information are emitted |
| 16 // into a buffer, with the instructions starting from the beginning and the |
| 17 // relocation information starting from the end of the buffer. See CodeDesc |
| 18 // for a detailed comment on the layout (globals.h). |
| 19 // |
| 20 // If the provided buffer is NULL, the assembler allocates and grows its own |
| 21 // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 22 // owned by the assembler and deallocated upon destruction of the assembler. |
| 23 // |
| 24 // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 25 // for code generation and assumes its size to be buffer_size. If the buffer |
| 26 // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 27 // upon destruction of the assembler. |
| 28 BytecodeRegExpMacroAssembler(ZoneGrowableArray<uint8_t>* buffer, |
| 29 Zone* zone); |
| 30 virtual ~BytecodeRegExpMacroAssembler(); |
| 31 |
| 32 // The byte-code interpreter checks on each push anyway. |
| 33 virtual intptr_t stack_limit_slack() { return 1; } |
| 34 virtual bool CanReadUnaligned() { return false; } |
| 35 virtual void BindBlock(BlockLabel* label); |
| 36 virtual void AdvanceCurrentPosition(intptr_t by); // Signed cp change. |
| 37 virtual void PopCurrentPosition(); |
| 38 virtual void PushCurrentPosition(); |
| 39 virtual void Backtrack(); |
| 40 virtual void GoTo(BlockLabel* label); |
| 41 virtual void PushBacktrack(BlockLabel* label); |
| 42 virtual bool Succeed(); |
| 43 virtual void Fail(); |
| 44 virtual void PopRegister(intptr_t register_index); |
| 45 virtual void PushRegister(intptr_t register_index); |
| 46 virtual void AdvanceRegister(intptr_t reg, intptr_t by); // r[reg] += by. |
| 47 virtual void SetCurrentPositionFromEnd(intptr_t by); |
| 48 virtual void SetRegister(intptr_t register_index, intptr_t to); |
| 49 virtual void WriteCurrentPositionToRegister(intptr_t reg, intptr_t cp_offset); |
| 50 virtual void ClearRegisters(intptr_t reg_from, intptr_t reg_to); |
| 51 virtual void ReadCurrentPositionFromRegister(intptr_t reg); |
| 52 virtual void WriteStackPointerToRegister(intptr_t reg); |
| 53 virtual void ReadStackPointerFromRegister(intptr_t reg); |
| 54 virtual void LoadCurrentCharacter(intptr_t cp_offset, |
| 55 BlockLabel* on_end_of_input, |
| 56 bool check_bounds = true, |
| 57 intptr_t characters = 1); |
| 58 virtual void CheckCharacter(unsigned c, BlockLabel* on_equal); |
| 59 virtual void CheckCharacterAfterAnd(unsigned c, |
| 60 unsigned mask, |
| 61 BlockLabel* on_equal); |
| 62 virtual void CheckCharacterGT(uint16_t limit, BlockLabel* on_greater); |
| 63 virtual void CheckCharacterLT(uint16_t limit, BlockLabel* on_less); |
| 64 virtual void CheckGreedyLoop(BlockLabel* on_tos_equals_current_position); |
| 65 virtual void CheckAtStart(BlockLabel* on_at_start); |
| 66 virtual void CheckNotAtStart(BlockLabel* on_not_at_start); |
| 67 virtual void CheckNotCharacter(unsigned c, BlockLabel* on_not_equal); |
| 68 virtual void CheckNotCharacterAfterAnd(unsigned c, |
| 69 unsigned mask, |
| 70 BlockLabel* on_not_equal); |
| 71 virtual void CheckNotCharacterAfterMinusAnd(uint16_t c, |
| 72 uint16_t minus, |
| 73 uint16_t mask, |
| 74 BlockLabel* on_not_equal); |
| 75 virtual void CheckCharacterInRange(uint16_t from, |
| 76 uint16_t to, |
| 77 BlockLabel* on_in_range); |
| 78 virtual void CheckCharacterNotInRange(uint16_t from, |
| 79 uint16_t to, |
| 80 BlockLabel* on_not_in_range); |
| 81 virtual void CheckBitInTable(const TypedData& table, BlockLabel* on_bit_set); |
| 82 virtual void CheckNotBackReference(intptr_t start_reg, |
| 83 BlockLabel* on_no_match); |
| 84 virtual void CheckNotBackReferenceIgnoreCase(intptr_t start_reg, |
| 85 BlockLabel* on_no_match); |
| 86 virtual void IfRegisterLT(intptr_t register_index, |
| 87 intptr_t comparand, |
| 88 BlockLabel* if_lt); |
| 89 virtual void IfRegisterGE(intptr_t register_index, |
| 90 intptr_t comparand, |
| 91 BlockLabel* if_ge); |
| 92 virtual void IfRegisterEqPos(intptr_t register_index, BlockLabel* if_eq); |
| 93 |
| 94 virtual IrregexpImplementation Implementation(); |
| 95 // virtual Handle<HeapObject> GetCode(Handle<String> source); |
| 96 RawTypedData* GetBytecode(); |
| 97 |
| 98 // New |
| 99 virtual bool IsClosed() const { |
| 100 // Added by Dart for the IR version. Bytecode version should never need an |
| 101 // extra goto. |
| 102 return true; |
| 103 } |
| 104 virtual void Print(const char* str) { UNIMPLEMENTED(); } |
| 105 virtual void PrintBlocks() { UNIMPLEMENTED(); } |
| 106 ///// |
| 107 |
| 108 static RawInstance* Interpret(const JSRegExp& regexp, |
| 109 const String& str, |
| 110 const Smi& start_index, |
| 111 Zone* zone); |
| 112 |
| 113 private: |
| 114 void Expand(); |
| 115 // Code and bitmap emission. |
| 116 inline void EmitOrLink(BlockLabel* label); |
| 117 inline void Emit32(uint32_t x); |
| 118 inline void Emit16(uint32_t x); |
| 119 inline void Emit8(uint32_t x); |
| 120 inline void Emit(uint32_t bc, uint32_t arg); |
| 121 // Bytecode buffer. |
| 122 intptr_t length(); |
| 123 |
| 124 // The buffer into which code and relocation info are generated. |
| 125 ZoneGrowableArray<uint8_t>* buffer_; |
| 126 |
| 127 // The program counter. |
| 128 intptr_t pc_; |
| 129 |
| 130 BlockLabel backtrack_; |
| 131 |
| 132 intptr_t advance_current_start_; |
| 133 intptr_t advance_current_offset_; |
| 134 intptr_t advance_current_end_; |
| 135 |
| 136 static const int kInvalidPC = -1; |
| 137 |
| 138 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeRegExpMacroAssembler); |
| 139 }; |
| 140 |
| 141 |
| 142 } // namespace dart |
| 143 |
| 144 #endif // VM_REGEXP_ASSEMBLER_BYTECODE_H_ |
OLD | NEW |