Index: runtime/vm/regexp_assembler.h |
diff --git a/runtime/vm/regexp_assembler.h b/runtime/vm/regexp_assembler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e1d5b3788f81d5bb8a52a10abc4da57e8c4ed7b3 |
--- /dev/null |
+++ b/runtime/vm/regexp_assembler.h |
@@ -0,0 +1,626 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#ifndef VM_REGEXP_ASSEMBLER_H_ |
+#define VM_REGEXP_ASSEMBLER_H_ |
+ |
+#include "vm/assembler.h" |
+#include "vm/intermediate_language.h" |
+#include "vm/object.h" |
+ |
+namespace dart { |
+ |
+/// Convenience wrapper around a BlockEntryInstr pointer. |
+class BlockLabel : public ValueObject { |
+ public: |
+ BlockLabel() |
+ : block_(new JoinEntryInstr(-1, -1)), |
+ is_bound_(false), |
+ is_linked_(false) { } |
+ |
+ BlockLabel(const BlockLabel& that) |
+ : ValueObject(), |
+ block_(that.block_), |
+ is_bound_(that.is_bound_), |
+ is_linked_(that.is_linked_) { } |
+ |
+ BlockLabel& operator=(const BlockLabel& that) { |
+ block_ = that.block_; |
+ is_bound_ = that.is_bound_; |
+ is_linked_ = that.is_linked_; |
+ return *this; |
+ } |
+ |
+ JoinEntryInstr* block() const { return block_; } |
+ |
+ bool IsBound() const { return is_bound_; } |
+ void SetBound(intptr_t block_id) { |
+ ASSERT(!is_bound_); |
+ block_->set_block_id(block_id); |
+ is_bound_ = true; |
+ } |
+ |
+ bool IsLinked() const { return !is_bound_ && is_linked_; } |
+ void SetLinked() { |
+ is_linked_ = true; |
+ } |
+ |
+ intptr_t Position() const { |
+ ASSERT(IsBound()); |
+ return block_->block_id(); |
+ } |
+ |
+ private: |
+ JoinEntryInstr* block_; |
+ |
+ bool is_bound_; |
+ bool is_linked_; |
+}; |
+ |
+ |
+class RegExpMacroAssembler { |
+ public: |
+ // The implementation must be able to handle at least: |
+ static const intptr_t kMaxRegister = (1 << 16) - 1; |
+ static const intptr_t kMaxCPOffset = (1 << 15) - 1; |
+ static const intptr_t kMinCPOffset = -(1 << 15); |
+ |
+ static const intptr_t kTableSizeBits = 7; |
+ static const intptr_t kTableSize = 1 << kTableSizeBits; |
+ static const intptr_t kTableMask = kTableSize - 1; |
+ |
+ enum IrregexpImplementation { |
+ kIRImplementation |
+ }; |
+ |
+ enum StackCheckFlag { |
+ kNoStackLimitCheck = false, |
+ kCheckStackLimit = true |
+ }; |
+ |
+ explicit RegExpMacroAssembler(Isolate* isolate); |
+ virtual ~RegExpMacroAssembler(); |
+ // The maximal number of pushes between stack checks. Users must supply |
+ // kCheckStackLimit flag to push operations (instead of kNoStackLimitCheck) |
+ // at least once for every stack_limit() pushes that are executed. |
+ virtual intptr_t stack_limit_slack() = 0; |
+ virtual bool CanReadUnaligned() = 0; |
+ virtual void AdvanceCurrentPosition(intptr_t by) = 0; // Signed cp change. |
+ virtual void AdvanceRegister(intptr_t reg, intptr_t by) = 0; // r[reg] += by. |
+ // Continues execution from the position pushed on the top of the backtrack |
+ // stack by an earlier PushBacktrack(BlockLabel*). |
+ virtual void Backtrack() = 0; |
+ virtual void BindBlock(BlockLabel* label) = 0; |
+ virtual void CheckAtStart(BlockLabel* on_at_start) = 0; |
+ // Dispatch after looking the current character up in a 2-bits-per-entry |
+ // map. The destinations vector has up to 4 labels. |
+ virtual void CheckCharacter(unsigned c, BlockLabel* on_equal) = 0; |
+ // Bitwise and the current character with the given constant and then |
+ // check for a match with c. |
+ virtual void CheckCharacterAfterAnd(unsigned c, |
+ unsigned and_with, |
+ BlockLabel* on_equal) = 0; |
+ virtual void CheckCharacterGT(uint16_t limit, BlockLabel* on_greater) = 0; |
+ virtual void CheckCharacterLT(uint16_t limit, BlockLabel* on_less) = 0; |
+ virtual void CheckGreedyLoop(BlockLabel* on_tos_equals_current_position) = 0; |
+ virtual void CheckNotAtStart(BlockLabel* on_not_at_start) = 0; |
+ virtual void CheckNotBackReference( |
+ intptr_t start_reg, BlockLabel* on_no_match) = 0; |
+ virtual void CheckNotBackReferenceIgnoreCase(intptr_t start_reg, |
+ BlockLabel* on_no_match) = 0; |
+ // Check the current character for a match with a literal character. If we |
+ // fail to match then goto the on_failure label. End of input always |
+ // matches. If the label is NULL then we should pop a backtrack address off |
+ // the stack and go to that. |
+ virtual void CheckNotCharacter(unsigned c, BlockLabel* on_not_equal) = 0; |
+ virtual void CheckNotCharacterAfterAnd(unsigned c, |
+ unsigned and_with, |
+ BlockLabel* on_not_equal) = 0; |
+ // Subtract a constant from the current character, then and with the given |
+ // constant and then check for a match with c. |
+ virtual void CheckNotCharacterAfterMinusAnd(uint16_t c, |
+ uint16_t minus, |
+ uint16_t and_with, |
+ BlockLabel* on_not_equal) = 0; |
+ virtual void CheckCharacterInRange(uint16_t from, |
+ uint16_t to, // Both inclusive. |
+ BlockLabel* on_in_range) = 0; |
+ virtual void CheckCharacterNotInRange(uint16_t from, |
+ uint16_t to, // Both inclusive. |
+ BlockLabel* on_not_in_range) = 0; |
+ |
+ // The current character (modulus the kTableSize) is looked up in the byte |
+ // array, and if the found byte is non-zero, we jump to the on_bit_set label. |
+ virtual void CheckBitInTable(const TypedData& table, |
+ BlockLabel* on_bit_set) = 0; |
+ |
+ // Checks whether the given offset from the current position is before |
+ // the end of the string. May overwrite the current character. |
+ virtual void CheckPosition(intptr_t cp_offset, BlockLabel* on_outside_input) { |
+ LoadCurrentCharacter(cp_offset, on_outside_input, true); |
+ } |
+ // Check whether a standard/default character class matches the current |
+ // character. Returns false if the type of special character class does |
+ // not have custom support. |
+ // May clobber the current loaded character. |
+ virtual bool CheckSpecialCharacterClass(uint16_t type, |
+ BlockLabel* on_no_match) { |
+ return false; |
+ } |
+ virtual void Fail() = 0; |
+ virtual Function& GetCode(const String& source) = 0; |
+ // Jump to the target label, and continue emission there. |
+ virtual void GoTo(BlockLabel* to) = 0; |
+ // Check whether a register is >= a given constant and go to a label if it |
+ // is. Backtracks instead if the label is NULL. |
+ virtual void IfRegisterGE( |
+ intptr_t reg, intptr_t comparand, BlockLabel* if_ge) = 0; |
+ // Check whether a register is < a given constant and go to a label if it is. |
+ // Backtracks instead if the label is NULL. |
+ virtual void IfRegisterLT( |
+ intptr_t reg, intptr_t comparand, BlockLabel* if_lt) = 0; |
+ // Check whether a register is == to the current position and go to a |
+ // label if it is. |
+ virtual void IfRegisterEqPos(intptr_t reg, BlockLabel* if_eq) = 0; |
+ virtual IrregexpImplementation Implementation() = 0; |
+ // The assembler is closed, iff there is no current instruction assigned. |
+ virtual bool IsClosed() const = 0; |
+ // Jump to the target label without setting it as the current instruction. |
+ virtual void Jump(BlockLabel* to) = 0; |
+ virtual void LoadCurrentCharacter(intptr_t cp_offset, |
+ BlockLabel* on_end_of_input, |
+ bool check_bounds = true, |
+ intptr_t characters = 1) = 0; |
+ virtual void PopCurrentPosition() = 0; |
+ virtual void PopRegister(intptr_t register_index) = 0; |
+ // Prints string within the generated code. Used for debugging. |
+ virtual void Print(const char* str) = 0; |
+ // Prints all emitted blocks. |
+ virtual void PrintBlocks() = 0; |
+ // Pushes the label on the backtrack stack, so that a following Backtrack |
+ // will go to this label. Always checks the backtrack stack limit. |
+ virtual void PushBacktrack(BlockLabel* label) = 0; |
+ virtual void PushCurrentPosition() = 0; |
+ virtual void PushRegister(intptr_t register_index, |
+ StackCheckFlag check_stack_limit) = 0; |
+ virtual void ReadCurrentPositionFromRegister(intptr_t reg) = 0; |
+ virtual void ReadStackPointerFromRegister(intptr_t reg) = 0; |
+ virtual void SetCurrentPositionFromEnd(intptr_t by) = 0; |
+ virtual void SetRegister(intptr_t register_index, intptr_t to) = 0; |
+ // Return whether the matching (with a global regexp) will be restarted. |
+ virtual bool Succeed() = 0; |
+ virtual void WriteCurrentPositionToRegister( |
+ intptr_t reg, intptr_t cp_offset) = 0; |
+ virtual void ClearRegisters(intptr_t reg_from, intptr_t reg_to) = 0; |
+ virtual void WriteStackPointerToRegister(intptr_t reg) = 0; |
+ |
+ // Controls the generation of large inlined constants in the code. |
+ void set_slow_safe(bool ssc) { slow_safe_compiler_ = ssc; } |
+ bool slow_safe() { return slow_safe_compiler_; } |
+ |
+ enum GlobalMode { NOT_GLOBAL, GLOBAL, GLOBAL_NO_ZERO_LENGTH_CHECK }; |
+ // Set whether the regular expression has the global flag. Exiting due to |
+ // a failure in a global regexp may still mean success overall. |
+ inline void set_global_mode(GlobalMode mode) { global_mode_ = mode; } |
+ inline bool global() { return global_mode_ != NOT_GLOBAL; } |
+ inline bool global_with_zero_length_check() { |
+ return global_mode_ == GLOBAL; |
+ } |
+ |
+ Isolate* isolate() const { return isolate_; } |
+ |
+ private: |
+ bool slow_safe_compiler_; |
+ bool global_mode_; |
+ Isolate* isolate_; |
+}; |
+ |
+ |
+class IRRegExpMacroAssembler: public RegExpMacroAssembler { |
+ public: |
+ // Type of input string to generate code for. |
+ enum Mode { ASCII = 1, UC16 = 2 }; |
+ |
+ // Result of calling generated native RegExp code. |
+ // RETRY: Something significant changed during execution, and the matching |
+ // should be retried from scratch. |
+ // EXCEPTION: Something failed during execution. If no exception has been |
+ // thrown, it's an internal out-of-memory, and the caller should |
+ // throw the exception. |
+ // FAILURE: Matching failed. |
+ // SUCCESS: Matching succeeded, and the output array has been filled with |
+ // capture positions. |
+ enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 }; |
+ |
+ IRRegExpMacroAssembler(Mode mode, intptr_t capture_count, Isolate* isolate); |
+ virtual ~IRRegExpMacroAssembler(); |
+ |
+ virtual bool CanReadUnaligned(); |
+ |
+ // Compares two-byte strings case insensitively. |
+ // Called from generated RegExp code. |
+ static intptr_t CaseInsensitiveCompareUC16( |
+ uint8_t* byte_offset1, uint8_t* byte_offset2, size_t byte_length); |
+ |
+ static Result Execute(const Function& function, |
+ const String& input, |
+ const Smi& start_offset, |
+ Array* output, |
+ Isolate* isolate); |
+ |
+ virtual bool IsClosed() const { return (current_instruction_ == NULL); } |
+ |
+ virtual intptr_t stack_limit_slack(); |
+ virtual void AdvanceCurrentPosition(intptr_t by); |
+ virtual void AdvanceRegister(intptr_t reg, intptr_t by); |
+ virtual void Backtrack(); |
+ virtual void BindBlock(BlockLabel* label); |
+ virtual void CheckAtStart(BlockLabel* on_at_start); |
+ virtual void CheckCharacter(uint32_t c, BlockLabel* on_equal); |
+ virtual void CheckCharacterAfterAnd(uint32_t c, |
+ uint32_t mask, |
+ BlockLabel* on_equal); |
+ virtual void CheckCharacterGT(uint16_t limit, BlockLabel* on_greater); |
+ virtual void CheckCharacterLT(uint16_t limit, BlockLabel* on_less); |
+ // A "greedy loop" is a loop that is both greedy and with a simple |
+ // body. It has a particularly simple implementation. |
+ virtual void CheckGreedyLoop(BlockLabel* on_tos_equals_current_position); |
+ virtual void CheckNotAtStart(BlockLabel* on_not_at_start); |
+ virtual void CheckNotBackReference(intptr_t start_reg, |
+ BlockLabel* on_no_match); |
+ virtual void CheckNotBackReferenceIgnoreCase(intptr_t start_reg, |
+ BlockLabel* on_no_match); |
+ virtual void CheckNotCharacter(uint32_t c, BlockLabel* on_not_equal); |
+ virtual void CheckNotCharacterAfterAnd(uint32_t c, |
+ uint32_t mask, |
+ BlockLabel* on_not_equal); |
+ virtual void CheckNotCharacterAfterMinusAnd(uint16_t c, |
+ uint16_t minus, |
+ uint16_t mask, |
+ BlockLabel* on_not_equal); |
+ virtual void CheckCharacterInRange(uint16_t from, |
+ uint16_t to, |
+ BlockLabel* on_in_range); |
+ virtual void CheckCharacterNotInRange(uint16_t from, |
+ uint16_t to, |
+ BlockLabel* on_not_in_range); |
+ virtual void CheckBitInTable(const TypedData& table, BlockLabel* on_bit_set); |
+ |
+ // Checks whether the given offset from the current position is before |
+ // the end of the string. |
+ virtual void CheckPosition(intptr_t cp_offset, BlockLabel* on_outside_input); |
+ virtual bool CheckSpecialCharacterClass( |
+ uint16_t type, BlockLabel* on_no_match); |
+ virtual void Fail(); |
+ virtual Function& GetCode(const String& source); |
+ virtual void GoTo(BlockLabel* to); |
+ virtual void IfRegisterGE(intptr_t reg, |
+ intptr_t comparand, BlockLabel* if_ge); |
+ virtual void IfRegisterLT(intptr_t reg, |
+ intptr_t comparand, BlockLabel* if_lt); |
+ virtual void IfRegisterEqPos(intptr_t reg, BlockLabel* if_eq); |
+ virtual IrregexpImplementation Implementation(); |
+ virtual void Jump(BlockLabel* to); |
+ virtual void LoadCurrentCharacter(intptr_t cp_offset, |
+ BlockLabel* on_end_of_input, |
+ bool check_bounds = true, |
+ intptr_t characters = 1); |
+ virtual void PopCurrentPosition(); |
+ virtual void PopRegister(intptr_t register_index); |
+ virtual void Print(const char* str); |
+ virtual void PushBacktrack(BlockLabel* label); |
+ virtual void PushCurrentPosition(); |
+ virtual void PushRegister(intptr_t register_index, |
+ StackCheckFlag check_stack_limit); |
+ virtual void ReadCurrentPositionFromRegister(intptr_t reg); |
+ virtual void ReadStackPointerFromRegister(intptr_t reg); |
+ virtual void SetCurrentPositionFromEnd(intptr_t by); |
+ virtual void SetRegister(intptr_t register_index, intptr_t to); |
+ virtual bool Succeed(); |
+ virtual void WriteCurrentPositionToRegister(intptr_t reg, intptr_t cp_offset); |
+ virtual void ClearRegisters(intptr_t reg_from, intptr_t reg_to); |
+ virtual void WriteStackPointerToRegister(intptr_t reg); |
+ |
+ virtual void PrintBlocks(); |
+ |
+ // Called from RegExp if the stack-guard is triggered. |
+ // If the code object is relocated, the return address is fixed before |
+ // returning. |
+ static intptr_t CheckStackGuardState(Address* return_address, |
+ Code* re_code, |
+ Address re_frame); |
+ |
+ private: |
+ static const intptr_t kPointerSize = sizeof(void*); |
+ |
+ // Offsets from ebp of function parameters and stored registers. |
+ static const intptr_t kFramePointer = 0; |
+ // Above the frame pointer - function parameters and return address. |
+ static const intptr_t kReturn_eip = kFramePointer + kPointerSize; |
+ static const intptr_t kFrameAlign = kReturn_eip + kPointerSize; |
+ // Parameters. |
+ static const intptr_t kInputString = kFrameAlign; |
+ static const intptr_t kStartIndex = kInputString + kPointerSize; |
+ static const intptr_t kInputStart = kStartIndex + kPointerSize; |
+ static const intptr_t kInputEnd = kInputStart + kPointerSize; |
+ static const intptr_t kRegisterOutput = kInputEnd + kPointerSize; |
+ // For the case of global regular expression, we have room to store at least |
+ // one set of capture results. For the case of non-global regexp, we ignore |
+ // this value. |
+ static const intptr_t kNumOutputRegisters = kRegisterOutput + kPointerSize; |
+ static const intptr_t kStackHighEnd = kNumOutputRegisters + kPointerSize; |
+ static const intptr_t kDirectCall = kStackHighEnd + kPointerSize; |
+ static const intptr_t kIsolate = kDirectCall + kPointerSize; |
+ // Below the frame pointer - local stack variables. |
+ // When adding local variables remember to push space for them in |
+ // the frame in GetCode. |
+ static const intptr_t kBackup_esi = kFramePointer - kPointerSize; |
+ static const intptr_t kBackup_edi = kBackup_esi - kPointerSize; |
+ static const intptr_t kBackup_ebx = kBackup_edi - kPointerSize; |
+ static const intptr_t kSuccessfulCaptures = kBackup_ebx - kPointerSize; |
+ static const intptr_t kInputStartMinusOne = |
+ kSuccessfulCaptures - kPointerSize; |
+ // First register address. Following registers are below it on the stack. |
+ static const intptr_t kRegisterZero = kInputStartMinusOne - kPointerSize; |
+ |
+ // Initial size of code buffer. |
+ static const size_t kRegExpCodeSize = 1024; |
+ |
+ // Generate the contents of preset blocks. The entry block is the entry point |
+ // of the generated code. |
+ void GenerateEntryBlock(); |
+ // Performs backtracking, i.e. popping an offset from the stack and doing |
+ // an indirect goto. |
+ void GenerateBacktrackBlock(); |
+ // Copies capture indices into the result area and returns true. |
+ void GenerateSuccessBlock(); |
+ // Returns false. |
+ void GenerateExitBlock(); |
+ |
+ enum ComparisonKind { |
+ kEQ, |
+ kNE, |
+ kLT, |
+ kGT, |
+ kLTE, |
+ kGTE, |
+ }; |
+ |
+ LocalVariable* Local(const char* name); |
+ LocalVariable* Parameter(const char* name, intptr_t index) const; |
+ |
+ ConstantInstr* Int64Constant(int64_t value) const; |
+ ConstantInstr* Uint64Constant(uint64_t value) const; |
+ ConstantInstr* BoolConstant(bool value) const; |
+ ConstantInstr* StringConstant(const char* value) const; |
+ |
+ ComparisonInstr* Comparison(ComparisonKind kind, |
+ Definition* lhs, Definition* rhs); |
+ |
+ InstanceCallInstr* InstanceCall(const char *name, |
+ PushArgumentInstr* arg1) const; |
+ InstanceCallInstr* InstanceCall(const char *name, |
+ PushArgumentInstr* arg1, |
+ PushArgumentInstr* arg2) const; |
+ InstanceCallInstr* InstanceCall(const char *name, |
+ PushArgumentInstr* arg1, |
+ PushArgumentInstr* arg2, |
+ PushArgumentInstr* arg3) const; |
+ InstanceCallInstr* InstanceCall( |
+ const char* name, |
+ ZoneGrowableArray<PushArgumentInstr*>* arguments) const; |
+ |
+ StaticCallInstr* StaticCall(const Function& function) const; |
+ StaticCallInstr* StaticCall(const Function& function, |
+ PushArgumentInstr* arg1) const; |
+ StaticCallInstr* StaticCall( |
+ const Function& function, |
+ ZoneGrowableArray<PushArgumentInstr*>* arguments) const; |
+ |
+ // Creates a new block consisting simply of a goto to dst. |
+ TargetEntryInstr* TargetWithJoinGoto(JoinEntryInstr* dst); |
+ |
+ // Adds, respectively subtracts lhs and rhs and returns the result. |
+ Value* Add(PushArgumentInstr* lhs, PushArgumentInstr* rhs); |
+ Value* Sub(PushArgumentInstr* lhs, PushArgumentInstr* rhs); |
+ |
+ LoadLocalInstr* LoadLocal(LocalVariable* local) const; |
+ void StoreLocal(LocalVariable* local, Value* value); |
+ |
+ PushArgumentInstr* PushArgument(Value* value); |
+ |
+ // Returns the character within the passed string at the specified index. |
+ Value* CharacterAt(Definition* index); |
+ |
+ // Load a number of characters at the given offset from the |
+ // current position, into the current-character register. |
+ void LoadCurrentCharacterUnchecked(intptr_t cp_offset, |
+ intptr_t character_count); |
+ |
+ // Check whether preemption has been requested. |
+ void CheckPreemption(); |
+ |
+ // Generate a call to CheckStackGuardState. |
+ void CallCheckStackGuardState(Register scratch); |
+ |
+ // Byte size of chars in the string to match (decided by the Mode argument) |
+ inline intptr_t char_size() { return static_cast<int>(mode_); } |
+ |
+ // Equivalent to a conditional branch to the label, unless the label |
+ // is NULL, in which case it is a conditional Backtrack. |
+ void BranchOrBacktrack(ComparisonInstr* comparison, |
+ BlockLabel* true_successor); |
+ |
+ // Set up all local variables and parameters. |
+ void InitializeLocals(); |
+ |
+ // A table mapping block ids to block offsets, used to look up offsets |
+ // for indirect goto instructions. |
+ void FinalizeBlockOffsetTable(const GrowableArray<BlockEntryInstr*>& blocks); |
+ |
+ // When backtrack blocks are pushed, they are not necessarily bound and thus |
+ // do not have a block id yet. When we are done generating the IR, insert |
+ // final block ids into all such places. |
+ void RewriteBacktrackPushes(); |
+ |
+ // All blocks that are the target of indirect gotos must be added as an |
+ // explicit edge to the graph entry in order for flow analysis to succeed |
+ // (similar to catch blocks). |
+ void AttachIndirectTargets(); |
+ |
+ // Bookkeeping for block ids. |
+ intptr_t AllocateBlockId() { return next_block_id_++; } |
+ |
+ // Bookkeeping for temp local ids. |
+ intptr_t temp_count() const { return temp_count_; } |
+ intptr_t AllocateTemp() { return temp_count_++; } |
+ void DeallocateTemps(intptr_t count) { |
+ ASSERT(temp_count_ >= count); |
+ temp_count_ -= count; |
+ } |
+ |
+ // Bookkeeping for the number of pushed arguments. |
+ intptr_t args_pushed() const { return args_pushed_; } |
+ void add_args_pushed(intptr_t n) { args_pushed_ += n; } |
+ |
+ // Bookkeeping for the number of stack locals. |
+ intptr_t GetNextLocalIndex(); |
+ intptr_t AllocateStackLocal() { return num_stack_locals_++; } |
+ intptr_t num_stack_locals() const { |
+ return num_stack_locals_; |
+ } |
+ |
+ // We never have any copied parameters. |
+ intptr_t num_copied_params() const { |
+ return 0; |
+ } |
+ |
+ // Return the position register at the specified index, creating it if |
+ // necessary. Note that the number of such registers can exceed the amount |
+ // required by the number of output captures. |
+ LocalVariable* position_register(intptr_t index); |
+ |
+ void set_current_instruction(Instruction* instruction); |
+ |
+ // The following functions are responsible for appending instructions |
+ // to the current instruction in various ways. The most simple one |
+ // is AppendInstruction, which simply appends an instruction and performs |
+ // bookkeeping. |
+ void AppendInstruction(Instruction* instruction); |
+ // Similar to AppendInstruction, but closes the current block by |
+ // setting current_instruction_ to NULL. |
+ void CloseBlockWith(Instruction* instruction); |
+ // Appends definition and allocates a temp index for the result. |
+ Value* Bind(Definition* definition); |
+ // Appends the definition. |
+ void Do(Definition* definition); |
+ // Closes the current block with a jump to the specified block. |
+ void Jump(JoinEntryInstr* to); |
+ |
+ // Accessors for our local stack_. |
+ void PushStack(Definition* definition); |
+ Value* PopStack(); |
+ |
+ // Prints the specified argument. Used for debugging. |
+ void Print(PushArgumentInstr* argument); |
+ |
+ // Used to keep track of each (block, block reference) pair created |
+ // during pushes to the backtracking stack. These are required since |
+ // such pushes must be rewritten to contain correct block ids once they |
+ // are available. |
+ struct BacktrackReference : public ValueObject { |
+ BacktrackReference(JoinEntryInstr* block, ConstantInstr* reference) |
+ : block(block), |
+ reference(reference) { } |
+ |
+ BacktrackReference(const BacktrackReference& that) |
+ : ValueObject(), |
+ block(that.block), |
+ reference(that.reference) { } |
+ |
+ BacktrackReference& operator=(const BacktrackReference& that) { |
+ block = that.block; |
+ reference = that.reference; |
+ return *this; |
+ } |
+ |
+ JoinEntryInstr* block; |
+ ConstantInstr* reference; |
+ }; |
+ |
+ // Which mode to generate code for (ASCII or UC16). |
+ Mode mode_; |
+ |
+ // Counters keeping track of the number of blocks, temps, pushed arguments, |
+ // and stack locals. |
+ intptr_t next_block_id_; |
+ intptr_t temp_count_; |
+ intptr_t args_pushed_; |
+ intptr_t num_stack_locals_; |
+ |
+ // Block entries used internally. |
+ GraphEntryInstr* entry_block_; |
+ JoinEntryInstr* start_block_; |
+ JoinEntryInstr* success_block_; |
+ JoinEntryInstr* backtrack_block_; |
+ JoinEntryInstr* exit_block_; |
+ |
+ // All created blocks are contained within this set. Used for printing |
+ // the generated code. |
+ GrowableArray<BlockEntryInstr*> blocks_; |
+ |
+ // The current instruction to link to when new code is emitted. |
+ Instruction* current_instruction_; |
+ |
+ // A list, acting as the runtime stack for both backtrack locations and |
+ // stored positions within the string. |
+ LocalVariable* stack_; |
+ |
+ // Stores the current character within the string. |
+ LocalVariable* current_character_; |
+ |
+ // Stores the current location within the string as a negative offset |
+ // from the end of the string. |
+ LocalVariable* current_position_; |
+ |
+ // The string being processed, passed as a function parameter. |
+ LocalVariable* string_param_; |
+ |
+ // Stores the length of string_param_. |
+ LocalVariable* string_param_length_; |
+ |
+ // The start index within the string, passed as a function parameter. |
+ LocalVariable* start_index_param_; |
+ |
+ // The array of matches to be filled in, passed as a function parameter. |
+ LocalVariable* matches_param_; |
+ |
+ // The word character map static member of the RegExp class. |
+ // Byte map of one byte characters with a 0xff if the character is a word |
+ // character (digit, letter or underscore) and 0x00 otherwise. |
+ // Used by generated RegExp code. |
+ LocalVariable* word_character_map_; |
+ |
+ // An assortment of utility variables. |
+ LocalVariable* capture_length_; |
+ LocalVariable* stack_ptr_; |
+ LocalVariable* match_start_index_; |
+ LocalVariable* capture_start_index_; |
+ LocalVariable* match_end_index_; |
+ LocalVariable* char_in_capture_; |
+ LocalVariable* char_in_match_; |
+ |
+ // Stored positions containing group bounds. Generated as needed. |
+ const intptr_t position_registers_count_; |
+ GrowableArray<LocalVariable*> position_registers_; |
+ |
+ // Stores code offsets for all blocks. |
+ // Used to implement backtracking. |
+ GrowableObjectArray& block_offsets_; |
+ GrowableArray<BacktrackReference> backtrack_references_; |
+}; |
+ |
+} // namespace dart |
+ |
+#endif // VM_REGEXP_ASSEMBLER_H_ |