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/globals.h"
11#include "src/interface-descriptors.h"
12#include "src/type-hints.h"
13
14namespace v8 {
15namespace internal {
16
17// For ArrayNoArgumentConstructor and ArraySingleArgumentConstructor.
18enum AllocationSiteOverrideMode {
19 DONT_OVERRIDE,
20 DISABLE_ALLOCATION_SITES,
21};
22
23class 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 KeyedStoreIC_SloppyArguments(Isolate* isolate,
44 KeyedAccessStoreMode mode);
45 static Callable KeyedStoreIC_Slow(Isolate* isolate,
46 KeyedAccessStoreMode mode);
47 static Callable StoreInArrayLiteralIC_Slow(Isolate* isolate,
48 KeyedAccessStoreMode mode);
49 static Callable ElementsTransitionAndStore(Isolate* isolate,
50 KeyedAccessStoreMode mode);
51 static Callable StoreFastElementIC(Isolate* isolate,
52 KeyedAccessStoreMode mode);
53
54 static Callable ResumeGenerator(Isolate* isolate);
55
56 static Callable FrameDropperTrampoline(Isolate* isolate);
57 static Callable HandleDebuggerStatement(Isolate* isolate);
58
59 static Callable BinaryOperation(Isolate* isolate, Operation op);
60
61 static Callable ApiGetter(Isolate* isolate);
62 static Callable CallApiCallback(Isolate* isolate);
63
64 static Callable NonPrimitiveToPrimitive(
65 Isolate* isolate, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
66 static Callable OrdinaryToPrimitive(Isolate* isolate,
67 OrdinaryToPrimitiveHint hint);
68
69 static Callable StringAdd(Isolate* isolate,
70 StringAddFlags flags = STRING_ADD_CHECK_NONE);
71
72 static Callable FastNewFunctionContext(Isolate* isolate,
73 ScopeType scope_type);
74
75 static Callable ArgumentAdaptor(Isolate* isolate);
76 static Callable Call(Isolate* isolate,
77 ConvertReceiverMode mode = ConvertReceiverMode::kAny);
78 static Callable CallWithArrayLike(Isolate* isolate);
79 static Callable CallWithSpread(Isolate* isolate);
80 static Callable CallFunction(
81 Isolate* isolate, ConvertReceiverMode mode = ConvertReceiverMode::kAny);
82 static Callable CallVarargs(Isolate* isolate);
83 static Callable CallForwardVarargs(Isolate* isolate);
84 static Callable CallFunctionForwardVarargs(Isolate* isolate);
85 static Callable Construct(Isolate* isolate);
86 static Callable ConstructWithSpread(Isolate* isolate);
87 static Callable ConstructFunction(Isolate* isolate);
88 static Callable ConstructVarargs(Isolate* isolate);
89 static Callable ConstructForwardVarargs(Isolate* isolate);
90 static Callable ConstructFunctionForwardVarargs(Isolate* isolate);
91
92 static Callable InterpreterPushArgsThenCall(Isolate* isolate,
93 ConvertReceiverMode receiver_mode,
94 InterpreterPushArgsMode mode);
95 static Callable InterpreterPushArgsThenConstruct(
96 Isolate* isolate, InterpreterPushArgsMode mode);
97 static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1);
98 static Callable InterpreterOnStackReplacement(Isolate* isolate);
99
100 static Callable ArrayNoArgumentConstructor(
101 Isolate* isolate, ElementsKind kind,
102 AllocationSiteOverrideMode override_mode);
103 static Callable ArraySingleArgumentConstructor(
104 Isolate* isolate, ElementsKind kind,
105 AllocationSiteOverrideMode override_mode);
106};
107
108} // namespace internal
109} // namespace v8
110
111#endif // V8_CODE_FACTORY_H_
112