Home | History | Annotate | Download | only in builtins
      1 // Copyright 2017 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_BUILTINS_BUILTINS_REGEXP_H_
      6 #define V8_BUILTINS_BUILTINS_REGEXP_H_
      7 
      8 #include "src/code-stub-assembler.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 typedef compiler::Node Node;
     14 typedef compiler::CodeAssemblerState CodeAssemblerState;
     15 typedef compiler::CodeAssemblerLabel CodeAssemblerLabel;
     16 
     17 class RegExpBuiltinsAssembler : public CodeStubAssembler {
     18  public:
     19   explicit RegExpBuiltinsAssembler(CodeAssemblerState* state)
     20       : CodeStubAssembler(state) {}
     21 
     22   void BranchIfFastRegExp(Node* const context, Node* const object,
     23                           Node* const map, Label* const if_isunmodified,
     24                           Label* const if_ismodified);
     25 
     26  protected:
     27   Node* FastLoadLastIndex(Node* regexp);
     28   Node* SlowLoadLastIndex(Node* context, Node* regexp);
     29   Node* LoadLastIndex(Node* context, Node* regexp, bool is_fastpath);
     30 
     31   void FastStoreLastIndex(Node* regexp, Node* value);
     32   void SlowStoreLastIndex(Node* context, Node* regexp, Node* value);
     33   void StoreLastIndex(Node* context, Node* regexp, Node* value,
     34                       bool is_fastpath);
     35 
     36   Node* ConstructNewResultFromMatchInfo(Node* const context, Node* const regexp,
     37                                         Node* const match_info,
     38                                         Node* const string);
     39 
     40   Node* RegExpPrototypeExecBodyWithoutResult(Node* const context,
     41                                              Node* const regexp,
     42                                              Node* const string,
     43                                              Label* if_didnotmatch,
     44                                              const bool is_fastpath);
     45   Node* RegExpPrototypeExecBody(Node* const context, Node* const regexp,
     46                                 Node* const string, const bool is_fastpath);
     47 
     48   Node* ThrowIfNotJSReceiver(Node* context, Node* maybe_receiver,
     49                              MessageTemplate::Template msg_template,
     50                              char const* method_name);
     51 
     52   // Analogous to BranchIfFastRegExp, for use in asserts.
     53   Node* IsFastRegExpMap(Node* const context, Node* const object,
     54                         Node* const map);
     55 
     56   Node* IsInitialRegExpMap(Node* context, Node* object, Node* map);
     57   void BranchIfFastRegExpResult(Node* context, Node* map,
     58                                 Label* if_isunmodified, Label* if_ismodified);
     59 
     60   Node* FlagsGetter(Node* const context, Node* const regexp, bool is_fastpath);
     61 
     62   Node* FastFlagGetter(Node* const regexp, JSRegExp::Flag flag);
     63   Node* SlowFlagGetter(Node* const context, Node* const regexp,
     64                        JSRegExp::Flag flag);
     65   Node* FlagGetter(Node* const context, Node* const regexp, JSRegExp::Flag flag,
     66                    bool is_fastpath);
     67   void FlagGetter(JSRegExp::Flag flag, v8::Isolate::UseCounterFeature counter,
     68                   const char* method_name);
     69 
     70   Node* IsRegExp(Node* const context, Node* const maybe_receiver);
     71   Node* RegExpInitialize(Node* const context, Node* const regexp,
     72                          Node* const maybe_pattern, Node* const maybe_flags);
     73 
     74   Node* RegExpExec(Node* context, Node* regexp, Node* string);
     75 
     76   Node* AdvanceStringIndex(Node* const string, Node* const index,
     77                            Node* const is_unicode, bool is_fastpath);
     78 
     79   void RegExpPrototypeMatchBody(Node* const context, Node* const regexp,
     80                                 Node* const string, const bool is_fastpath);
     81 
     82   void RegExpPrototypeSearchBodyFast(Node* const context, Node* const regexp,
     83                                      Node* const string);
     84   void RegExpPrototypeSearchBodySlow(Node* const context, Node* const regexp,
     85                                      Node* const string);
     86 
     87   void RegExpPrototypeSplitBody(Node* const context, Node* const regexp,
     88                                 Node* const string, Node* const limit);
     89 
     90   Node* ReplaceGlobalCallableFastPath(Node* context, Node* regexp, Node* string,
     91                                       Node* replace_callable);
     92   Node* ReplaceSimpleStringFastPath(Node* context, Node* regexp, Node* string,
     93                                     Node* replace_string);
     94 };
     95 
     96 }  // namespace internal
     97 }  // namespace v8
     98 
     99 #endif  // V8_BUILTINS_BUILTINS_REGEXP_H_
    100