blob: 2126790359c5303b00669bb29a632daf52c59676 [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 Murdoch4a90d5f2016-03-22 12:00:34 +000035 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 static Callable CompareIC(Isolate* isolate, Token::Value op,
59 Strength strength);
60 static Callable CompareNilIC(Isolate* isolate, NilValue nil_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061
62 static Callable BinaryOpIC(Isolate* isolate, Token::Value op,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063 Strength strength);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064
65 // Code stubs. Add methods here as needed to reduce dependency on
66 // code-stubs.h.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067 static Callable InstanceOf(Isolate* isolate);
68
69 static Callable ToBoolean(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070
71 static Callable ToNumber(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079
80 static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
81 PretenureFlag pretenure_flag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000082 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099 static Callable AllocateHeapNumber(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000100 static Callable AllocateMutableHeapNumber(Isolate* isolate);
101 static Callable AllocateInNewSpace(Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114};
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400115
116} // namespace internal
117} // namespace v8
118
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000119#endif // V8_CODE_FACTORY_H_