blob: fb1a1650538d43189b43d79c0e6e974a03772cab [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
14namespace v8 {
15namespace internal {
16
17// Associates a body of code with an interface descriptor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018class Callable final BASE_EMBEDDED {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032class CodeFactory final {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000033 public:
34 // Initial states for ICs.
Ben Murdoch097c5b22016-05-18 11:27:45 +010035 static Callable LoadIC(Isolate* isolate, TypeofMode typeof_mode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 static Callable LoadICInOptimizedCode(Isolate* isolate,
37 TypeofMode typeof_mode,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 InlineCacheState initialization_state);
Ben Murdoch097c5b22016-05-18 11:27:45 +010039 static Callable KeyedLoadIC(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040 static Callable KeyedLoadICInOptimizedCode(
Ben Murdoch097c5b22016-05-18 11:27:45 +010041 Isolate* isolate, InlineCacheState initialization_state);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042 static Callable CallIC(Isolate* isolate, int argc,
Ben Murdoch097c5b22016-05-18 11:27:45 +010043 ConvertReceiverMode mode = ConvertReceiverMode::kAny,
44 TailCallMode tail_call_mode = TailCallMode::kDisallow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 static Callable CallICInOptimizedCode(
46 Isolate* isolate, int argc,
Ben Murdoch097c5b22016-05-18 11:27:45 +010047 ConvertReceiverMode mode = ConvertReceiverMode::kAny,
48 TailCallMode tail_call_mode = TailCallMode::kDisallow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 static Callable StoreIC(Isolate* isolate, LanguageMode mode);
50 static Callable StoreICInOptimizedCode(Isolate* isolate, LanguageMode mode,
51 InlineCacheState initialization_state);
52 static Callable KeyedStoreIC(Isolate* isolate, LanguageMode mode);
53 static Callable KeyedStoreICInOptimizedCode(
54 Isolate* isolate, LanguageMode mode,
55 InlineCacheState initialization_state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056
Ben Murdoch097c5b22016-05-18 11:27:45 +010057 static Callable CompareIC(Isolate* isolate, Token::Value op);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 static Callable CompareNilIC(Isolate* isolate, NilValue nil_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059
Ben Murdoch097c5b22016-05-18 11:27:45 +010060 static Callable BinaryOpIC(Isolate* isolate, Token::Value op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061
62 // Code stubs. Add methods here as needed to reduce dependency on
63 // code-stubs.h.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064 static Callable InstanceOf(Isolate* isolate);
65
66 static Callable ToBoolean(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067
68 static Callable ToNumber(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069 static Callable ToString(Isolate* isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +010070 static Callable ToName(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 static Callable ToLength(Isolate* isolate);
72 static Callable ToObject(Isolate* isolate);
73 static Callable NumberToString(Isolate* isolate);
74
75 static Callable RegExpConstructResult(Isolate* isolate);
76 static Callable RegExpExec(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077
78 static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
79 PretenureFlag pretenure_flag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000080 static Callable StringCompare(Isolate* isolate);
81 static Callable SubString(Isolate* isolate);
82
83 static Callable Typeof(Isolate* isolate);
84
85 static Callable FastCloneRegExp(Isolate* isolate);
86 static Callable FastCloneShallowArray(Isolate* isolate);
87 static Callable FastCloneShallowObject(Isolate* isolate, int length);
88
89 static Callable FastNewContext(Isolate* isolate, int slot_count);
90 static Callable FastNewClosure(Isolate* isolate, LanguageMode language_mode,
91 FunctionKind kind);
Ben Murdoch097c5b22016-05-18 11:27:45 +010092 static Callable FastNewObject(Isolate* isolate);
93 static Callable FastNewRestParameter(Isolate* isolate);
94 static Callable FastNewSloppyArguments(Isolate* isolate);
95 static Callable FastNewStrictArguments(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096
Emily Bernierd0a1eb72015-03-24 16:35:39 -040097 static Callable AllocateHeapNumber(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098 static Callable AllocateMutableHeapNumber(Isolate* isolate);
99 static Callable AllocateInNewSpace(Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101 static Callable ArgumentAdaptor(Isolate* isolate);
102 static Callable Call(Isolate* isolate,
103 ConvertReceiverMode mode = ConvertReceiverMode::kAny);
104 static Callable CallFunction(
105 Isolate* isolate, ConvertReceiverMode mode = ConvertReceiverMode::kAny);
106 static Callable Construct(Isolate* isolate);
107 static Callable ConstructFunction(Isolate* isolate);
108
Ben Murdoch097c5b22016-05-18 11:27:45 +0100109 static Callable InterpreterPushArgsAndCall(Isolate* isolate,
110 TailCallMode tail_call_mode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 static Callable InterpreterPushArgsAndConstruct(Isolate* isolate);
112 static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113};
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400114
115} // namespace internal
116} // namespace v8
117
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118#endif // V8_CODE_FACTORY_H_