[stubs] Refactor StringCompareStub and use it for HStringCompareAndBranch.
[platform/upstream/v8.git] / src / code-factory.h
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                          CallICState::CallType call_type);
47   static Callable CallICInOptimizedCode(Isolate* isolate, int argc,
48                                         CallICState::CallType call_type);
49   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);
56
57   static Callable CompareIC(Isolate* isolate, Token::Value op,
58                             Strength strength);
59
60   static Callable BinaryOpIC(Isolate* isolate, Token::Value op,
61                              Strength strength);
62
63   // Code stubs. Add methods here as needed to reduce dependency on
64   // code-stubs.h.
65   static Callable LoadGlobalViaContext(Isolate* isolate, int depth);
66   static Callable StoreGlobalViaContext(Isolate* isolate, int depth,
67                                         LanguageMode language_mode);
68
69   static Callable InstanceOf(Isolate* isolate);
70
71   static Callable ToBoolean(
72       Isolate* isolate, ToBooleanStub::ResultMode mode,
73       ToBooleanStub::Types types = ToBooleanStub::Types());
74
75   static Callable ToNumber(Isolate* isolate);
76   static Callable ToString(Isolate* isolate);
77   static Callable ToObject(Isolate* isolate);
78
79   static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
80                             PretenureFlag pretenure_flag);
81   static Callable StringCompare(Isolate* isolate);
82
83   static Callable Typeof(Isolate* isolate);
84
85   static Callable FastCloneShallowArray(Isolate* isolate);
86   static Callable FastCloneShallowObject(Isolate* isolate, int length);
87
88   static Callable FastNewClosure(Isolate* isolate, LanguageMode language_mode,
89                                  FunctionKind kind);
90
91   static Callable AllocateHeapNumber(Isolate* isolate);
92
93   static Callable CallFunction(Isolate* isolate, int argc,
94                                CallFunctionFlags flags);
95
96   static Callable PushArgsAndCall(Isolate* isolate);
97 };
98
99 }  // namespace internal
100 }  // namespace v8
101
102 #endif  // V8_CODE_FACTORY_H_