// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_BUILTINS_BUILTINS_REGEXP_GEN_H_ #define V8_BUILTINS_BUILTINS_REGEXP_GEN_H_ #include "src/base/optional.h" #include "src/codegen/code-stub-assembler.h" #include "src/common/message-template.h" namespace v8 { namespace internal { class RegExpBuiltinsAssembler : public CodeStubAssembler { public: explicit RegExpBuiltinsAssembler(compiler::CodeAssemblerState* state) : CodeStubAssembler(state) {} void BranchIfFastRegExp( Node* const context, Node* const object, Node* const map, base::Optional additional_property_to_check, Label* const if_isunmodified, Label* const if_ismodified); // Create and initialize a RegExp object. TNode RegExpCreate(TNode context, TNode native_context, TNode regexp_string, TNode flags); TNode RegExpCreate(TNode context, TNode initial_map, TNode regexp_string, TNode flags); TNode IsRegExp(TNode context, TNode maybe_receiver); TNode SmiZero(); TNode IntPtrZero(); // Allocate a RegExpResult with the given length (the number of captures, // including the match itself), index (the index where the match starts), // and input string. TNode AllocateRegExpResult( TNode context, TNode length, TNode index, TNode input, TNode* elements_out = nullptr); TNode FastLoadLastIndexBeforeSmiCheck(TNode regexp); TNode FastLoadLastIndex(TNode regexp) { return CAST(FastLoadLastIndexBeforeSmiCheck(regexp)); } TNode SlowLoadLastIndex(TNode context, TNode regexp); TNode LoadLastIndex(TNode context, TNode regexp, bool is_fastpath); void FastStoreLastIndex(TNode regexp, TNode value); void SlowStoreLastIndex(SloppyTNode context, SloppyTNode regexp, SloppyTNode value); void StoreLastIndex(TNode context, TNode regexp, TNode value, bool is_fastpath); // Loads {var_string_start} and {var_string_end} with the corresponding // offsets into the given {string_data}. void GetStringPointers(Node* const string_data, Node* const offset, Node* const last_index, Node* const string_length, String::Encoding encoding, Variable* var_string_start, Variable* var_string_end); // Low level logic around the actual call into pattern matching code. TNode RegExpExecInternal(TNode context, TNode regexp, TNode string, TNode last_index, TNode match_info); TNode ConstructNewResultFromMatchInfo( TNode context, TNode maybe_regexp, TNode match_info, TNode string); TNode RegExpPrototypeExecBodyWithoutResult( TNode context, TNode maybe_regexp, TNode string, Label* if_didnotmatch, const bool is_fastpath); TNode RegExpPrototypeExecBodyWithoutResultFast( TNode context, TNode maybe_regexp, TNode string, Label* if_didnotmatch); TNode RegExpPrototypeExecBody(TNode context, TNode maybe_regexp, TNode string, const bool is_fastpath); Node* ThrowIfNotJSReceiver(Node* context, Node* maybe_receiver, MessageTemplate msg_template, char const* method_name); // Analogous to BranchIfFastRegExp, for use in asserts. TNode IsFastRegExp(SloppyTNode context, SloppyTNode object); void BranchIfFastRegExp(Node* const context, Node* const object, Label* const if_isunmodified, Label* const if_ismodified); // Performs fast path checks on the given object itself, but omits prototype // checks. Node* IsFastRegExpNoPrototype(Node* const context, Node* const object); TNode IsFastRegExpWithOriginalExec(TNode context, TNode object); Node* IsFastRegExpNoPrototype(Node* const context, Node* const object, Node* const map); void BranchIfFastRegExpResult(Node* const context, Node* const object, Label* if_isunmodified, Label* if_ismodified); Node* FlagsGetter(Node* const context, Node* const regexp, bool is_fastpath); TNode FastFlagGetter(TNode regexp, JSRegExp::Flag flag); TNode FastFlagGetterGlobal(TNode regexp) { return ReinterpretCast(FastFlagGetter(regexp, JSRegExp::kGlobal)); } TNode FastFlagGetterUnicode(TNode regexp) { return ReinterpretCast(FastFlagGetter(regexp, JSRegExp::kUnicode)); } TNode SlowFlagGetter(TNode context, TNode regexp, JSRegExp::Flag flag); TNode FlagGetter(TNode context, TNode regexp, JSRegExp::Flag flag, bool is_fastpath); void FlagGetter(Node* context, Node* receiver, JSRegExp::Flag flag, int counter, const char* method_name); Node* RegExpInitialize(Node* const context, Node* const regexp, Node* const maybe_pattern, Node* const maybe_flags); Node* RegExpExec(Node* context, Node* regexp, Node* string); TNode AdvanceStringIndex(SloppyTNode string, SloppyTNode index, SloppyTNode is_unicode, bool is_fastpath); TNode AdvanceStringIndexFast(TNode string, TNode index, TNode is_unicode) { return CAST(AdvanceStringIndex(string, index, is_unicode, true)); } void RegExpPrototypeMatchBody(TNode context, TNode regexp, TNode const string, const bool is_fastpath); void RegExpPrototypeSearchBodyFast(TNode context, TNode regexp, TNode string); void RegExpPrototypeSearchBodySlow(Node* const context, Node* const regexp, Node* const string); void RegExpPrototypeSplitBody(Node* const context, Node* const regexp, TNode const string, TNode const limit); }; class RegExpMatchAllAssembler : public RegExpBuiltinsAssembler { public: explicit RegExpMatchAllAssembler(compiler::CodeAssemblerState* state) : RegExpBuiltinsAssembler(state) {} TNode CreateRegExpStringIterator(TNode native_context, TNode regexp, TNode string, TNode global, TNode full_unicode); void Generate(TNode context, TNode native_context, TNode receiver, TNode maybe_string); }; } // namespace internal } // namespace v8 #endif // V8_BUILTINS_BUILTINS_REGEXP_GEN_H_