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/callable.h" 10 #include "src/code-stubs.h" 11 #include "src/globals.h" 12 #include "src/interface-descriptors.h" 13 14 namespace v8 { 15 namespace internal { 16 17 // For ArrayNoArgumentConstructor and ArraySingleArgumentConstructor. 18 enum AllocationSiteOverrideMode { 19 DONT_OVERRIDE, 20 DISABLE_ALLOCATION_SITES, 21 }; 22 23 class V8_EXPORT_PRIVATE CodeFactory final { 24 public: 25 // CEntry has var-args semantics (all the arguments are passed on the 26 // stack and the arguments count is passed via register) which currently 27 // can't be expressed in CallInterfaceDescriptor. Therefore only the code 28 // is exported here. 29 static Handle<Code> RuntimeCEntry(Isolate* isolate, int result_size = 1); 30 31 static Handle<Code> CEntry(Isolate* isolate, int result_size = 1, 32 SaveFPRegsMode save_doubles = kDontSaveFPRegs, 33 ArgvMode argv_mode = kArgvOnStack, 34 bool builtin_exit_frame = false); 35 36 // Initial states for ICs. 37 static Callable LoadGlobalIC(Isolate* isolate, TypeofMode typeof_mode); 38 static Callable LoadGlobalICInOptimizedCode(Isolate* isolate, 39 TypeofMode typeof_mode); 40 static Callable StoreOwnIC(Isolate* isolate); 41 static Callable StoreOwnICInOptimizedCode(Isolate* isolate); 42 43 static Callable ResumeGenerator(Isolate* isolate); 44 45 static Callable FrameDropperTrampoline(Isolate* isolate); 46 static Callable HandleDebuggerStatement(Isolate* isolate); 47 48 static Callable BinaryOperation(Isolate* isolate, Operation op); 49 50 static Callable ApiGetter(Isolate* isolate); 51 static Callable CallApiCallback(Isolate* isolate, int argc); 52 53 // Code stubs. Add methods here as needed to reduce dependency on 54 // code-stubs.h. 55 56 static Callable NonPrimitiveToPrimitive( 57 Isolate* isolate, ToPrimitiveHint hint = ToPrimitiveHint::kDefault); 58 static Callable OrdinaryToPrimitive(Isolate* isolate, 59 OrdinaryToPrimitiveHint hint); 60 61 static Callable StringAdd(Isolate* isolate, 62 StringAddFlags flags = STRING_ADD_CHECK_NONE, 63 PretenureFlag pretenure_flag = NOT_TENURED); 64 65 static Callable FastNewFunctionContext(Isolate* isolate, 66 ScopeType scope_type); 67 68 static Callable ArgumentAdaptor(Isolate* isolate); 69 static Callable Call(Isolate* isolate, 70 ConvertReceiverMode mode = ConvertReceiverMode::kAny); 71 static Callable CallWithArrayLike(Isolate* isolate); 72 static Callable CallWithSpread(Isolate* isolate); 73 static Callable CallFunction( 74 Isolate* isolate, ConvertReceiverMode mode = ConvertReceiverMode::kAny); 75 static Callable CallVarargs(Isolate* isolate); 76 static Callable CallForwardVarargs(Isolate* isolate); 77 static Callable CallFunctionForwardVarargs(Isolate* isolate); 78 static Callable Construct(Isolate* isolate); 79 static Callable ConstructWithSpread(Isolate* isolate); 80 static Callable ConstructFunction(Isolate* isolate); 81 static Callable ConstructVarargs(Isolate* isolate); 82 static Callable ConstructForwardVarargs(Isolate* isolate); 83 static Callable ConstructFunctionForwardVarargs(Isolate* isolate); 84 85 static Callable InterpreterPushArgsThenCall(Isolate* isolate, 86 ConvertReceiverMode receiver_mode, 87 InterpreterPushArgsMode mode); 88 static Callable InterpreterPushArgsThenConstruct( 89 Isolate* isolate, InterpreterPushArgsMode mode); 90 static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1); 91 static Callable InterpreterOnStackReplacement(Isolate* isolate); 92 93 static Callable ArrayNoArgumentConstructor( 94 Isolate* isolate, ElementsKind kind, 95 AllocationSiteOverrideMode override_mode); 96 static Callable ArraySingleArgumentConstructor( 97 Isolate* isolate, ElementsKind kind, 98 AllocationSiteOverrideMode override_mode); 99 100 static Callable InternalArrayNoArgumentConstructor(Isolate* isolate, 101 ElementsKind kind); 102 static Callable InternalArraySingleArgumentConstructor(Isolate* isolate, 103 ElementsKind kind); 104 }; 105 106 } // namespace internal 107 } // namespace v8 108 109 #endif // V8_CODE_FACTORY_H_ 110