Home | History | Annotate | Download | only in src
      1 // Copyright 2012 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_CODE_FACTORY_H_
      6 #define V8_CODE_FACTORY_H_
      7 
      8 #include "src/allocation.h"
      9 #include "src/assembler.h"
     10 #include "src/codegen.h"
     11 #include "src/globals.h"
     12 #include "src/interface-descriptors.h"
     13 
     14 namespace v8 {
     15 namespace internal {
     16 
     17 // Associates a body of code with an interface descriptor.
     18 class Callable final BASE_EMBEDDED {
     19  public:
     20   Callable(Handle<Code> code, CallInterfaceDescriptor descriptor)
     21       : code_(code), descriptor_(descriptor) {}
     22 
     23   Handle<Code> code() const { return code_; }
     24   CallInterfaceDescriptor descriptor() const { return descriptor_; }
     25 
     26  private:
     27   const Handle<Code> code_;
     28   const CallInterfaceDescriptor descriptor_;
     29 };
     30 
     31 
     32 class CodeFactory final {
     33  public:
     34   // Initial states for ICs.
     35   static Callable LoadIC(Isolate* isolate, TypeofMode typeof_mode,
     36                          LanguageMode language_mode);
     37   static Callable LoadICInOptimizedCode(Isolate* isolate,
     38                                         TypeofMode typeof_mode,
     39                                         LanguageMode language_mode,
     40                                         InlineCacheState initialization_state);
     41   static Callable KeyedLoadIC(Isolate* isolate, LanguageMode language_mode);
     42   static Callable KeyedLoadICInOptimizedCode(
     43       Isolate* isolate, LanguageMode language_mode,
     44       InlineCacheState initialization_state);
     45   static Callable CallIC(Isolate* isolate, int argc,
     46                          ConvertReceiverMode mode = ConvertReceiverMode::kAny);
     47   static Callable CallICInOptimizedCode(
     48       Isolate* isolate, int argc,
     49       ConvertReceiverMode mode = ConvertReceiverMode::kAny);
     50   static Callable StoreIC(Isolate* isolate, LanguageMode mode);
     51   static Callable StoreICInOptimizedCode(Isolate* isolate, LanguageMode mode,
     52                                          InlineCacheState initialization_state);
     53   static Callable KeyedStoreIC(Isolate* isolate, LanguageMode mode);
     54   static Callable KeyedStoreICInOptimizedCode(
     55       Isolate* isolate, LanguageMode mode,
     56       InlineCacheState initialization_state);
     57 
     58   static Callable CompareIC(Isolate* isolate, Token::Value op,
     59                             Strength strength);
     60   static Callable CompareNilIC(Isolate* isolate, NilValue nil_value);
     61 
     62   static Callable BinaryOpIC(Isolate* isolate, Token::Value op,
     63                              Strength strength);
     64 
     65   // Code stubs. Add methods here as needed to reduce dependency on
     66   // code-stubs.h.
     67   static Callable InstanceOf(Isolate* isolate);
     68 
     69   static Callable ToBoolean(Isolate* isolate);
     70 
     71   static Callable ToNumber(Isolate* isolate);
     72   static Callable ToString(Isolate* isolate);
     73   static Callable ToLength(Isolate* isolate);
     74   static Callable ToObject(Isolate* isolate);
     75   static Callable NumberToString(Isolate* isolate);
     76 
     77   static Callable RegExpConstructResult(Isolate* isolate);
     78   static Callable RegExpExec(Isolate* isolate);
     79 
     80   static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
     81                             PretenureFlag pretenure_flag);
     82   static Callable StringCompare(Isolate* isolate);
     83   static Callable SubString(Isolate* isolate);
     84 
     85   static Callable Typeof(Isolate* isolate);
     86 
     87   static Callable FastCloneRegExp(Isolate* isolate);
     88   static Callable FastCloneShallowArray(Isolate* isolate);
     89   static Callable FastCloneShallowObject(Isolate* isolate, int length);
     90 
     91   static Callable FastNewContext(Isolate* isolate, int slot_count);
     92   static Callable FastNewClosure(Isolate* isolate, LanguageMode language_mode,
     93                                  FunctionKind kind);
     94 
     95   static Callable ArgumentsAccess(Isolate* isolate, bool is_unmapped_arguments,
     96                                   bool has_duplicate_parameters);
     97   static Callable RestArgumentsAccess(Isolate* isolate);
     98 
     99   static Callable AllocateHeapNumber(Isolate* isolate);
    100   static Callable AllocateMutableHeapNumber(Isolate* isolate);
    101   static Callable AllocateInNewSpace(Isolate* isolate);
    102 
    103   static Callable ArgumentAdaptor(Isolate* isolate);
    104   static Callable Call(Isolate* isolate,
    105                        ConvertReceiverMode mode = ConvertReceiverMode::kAny);
    106   static Callable CallFunction(
    107       Isolate* isolate, ConvertReceiverMode mode = ConvertReceiverMode::kAny);
    108   static Callable Construct(Isolate* isolate);
    109   static Callable ConstructFunction(Isolate* isolate);
    110 
    111   static Callable InterpreterPushArgsAndCall(Isolate* isolate);
    112   static Callable InterpreterPushArgsAndConstruct(Isolate* isolate);
    113   static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1);
    114 };
    115 
    116 }  // namespace internal
    117 }  // namespace v8
    118 
    119 #endif  // V8_CODE_FACTORY_H_
    120