Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / js-operator.h
1 // Copyright 2013 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_COMPILER_JS_OPERATOR_H_
6 #define V8_COMPILER_JS_OPERATOR_H_
7
8 #include "src/runtime/runtime.h"
9 #include "src/unique.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14
15 // Forward declarations.
16 class Operator;
17 struct JSOperatorGlobalCache;
18
19
20 // Defines the arity and the call flags for a JavaScript function call. This is
21 // used as a parameter by JSCallFunction operators.
22 class CallFunctionParameters FINAL {
23  public:
24   CallFunctionParameters(size_t arity, CallFunctionFlags flags)
25       : arity_(arity), flags_(flags) {}
26
27   size_t arity() const { return arity_; }
28   CallFunctionFlags flags() const { return flags_; }
29
30  private:
31   const size_t arity_;
32   const CallFunctionFlags flags_;
33 };
34
35 bool operator==(CallFunctionParameters const&, CallFunctionParameters const&);
36 bool operator!=(CallFunctionParameters const&, CallFunctionParameters const&);
37
38 size_t hash_value(CallFunctionParameters const&);
39
40 std::ostream& operator<<(std::ostream&, CallFunctionParameters const&);
41
42 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op);
43
44
45 // Defines the arity and the ID for a runtime function call. This is used as a
46 // parameter by JSCallRuntime operators.
47 class CallRuntimeParameters FINAL {
48  public:
49   CallRuntimeParameters(Runtime::FunctionId id, size_t arity)
50       : id_(id), arity_(arity) {}
51
52   Runtime::FunctionId id() const { return id_; }
53   size_t arity() const { return arity_; }
54
55  private:
56   const Runtime::FunctionId id_;
57   const size_t arity_;
58 };
59
60 bool operator==(CallRuntimeParameters const&, CallRuntimeParameters const&);
61 bool operator!=(CallRuntimeParameters const&, CallRuntimeParameters const&);
62
63 size_t hash_value(CallRuntimeParameters const&);
64
65 std::ostream& operator<<(std::ostream&, CallRuntimeParameters const&);
66
67 const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op);
68
69
70 // Defines the location of a context slot relative to a specific scope. This is
71 // used as a parameter by JSLoadContext and JSStoreContext operators and allows
72 // accessing a context-allocated variable without keeping track of the scope.
73 class ContextAccess FINAL {
74  public:
75   ContextAccess(size_t depth, size_t index, bool immutable);
76
77   size_t depth() const { return depth_; }
78   size_t index() const { return index_; }
79   bool immutable() const { return immutable_; }
80
81  private:
82   // For space reasons, we keep this tightly packed, otherwise we could just use
83   // a simple int/int/bool POD.
84   const bool immutable_;
85   const uint16_t depth_;
86   const uint32_t index_;
87 };
88
89 bool operator==(ContextAccess const&, ContextAccess const&);
90 bool operator!=(ContextAccess const&, ContextAccess const&);
91
92 size_t hash_value(ContextAccess const&);
93
94 std::ostream& operator<<(std::ostream&, ContextAccess const&);
95
96 ContextAccess const& ContextAccessOf(Operator const*);
97
98
99 class VectorSlotPair {
100  public:
101   VectorSlotPair(Handle<TypeFeedbackVector> vector, FeedbackVectorICSlot slot)
102       : vector_(vector), slot_(slot) {}
103
104   Handle<TypeFeedbackVector> vector() const { return vector_; }
105   FeedbackVectorICSlot slot() const { return slot_; }
106
107   int index() const { return vector_->GetIndex(slot_); }
108
109  private:
110   const Handle<TypeFeedbackVector> vector_;
111   const FeedbackVectorICSlot slot_;
112 };
113
114
115 bool operator==(VectorSlotPair const& lhs, VectorSlotPair const& rhs);
116
117
118 // Defines the property being loaded from an object by a named load. This is
119 // used as a parameter by JSLoadNamed operators.
120 class LoadNamedParameters FINAL {
121  public:
122   LoadNamedParameters(const Unique<Name>& name, const VectorSlotPair& feedback,
123                       ContextualMode contextual_mode)
124       : name_(name), contextual_mode_(contextual_mode), feedback_(feedback) {}
125
126   const Unique<Name>& name() const { return name_; }
127   ContextualMode contextual_mode() const { return contextual_mode_; }
128
129   const VectorSlotPair& feedback() const { return feedback_; }
130
131  private:
132   const Unique<Name> name_;
133   const ContextualMode contextual_mode_;
134   const VectorSlotPair feedback_;
135 };
136
137 bool operator==(LoadNamedParameters const&, LoadNamedParameters const&);
138 bool operator!=(LoadNamedParameters const&, LoadNamedParameters const&);
139
140 size_t hash_value(LoadNamedParameters const&);
141
142 std::ostream& operator<<(std::ostream&, LoadNamedParameters const&);
143
144 const LoadNamedParameters& LoadNamedParametersOf(const Operator* op);
145
146
147 // Defines the property being loaded from an object. This is
148 // used as a parameter by JSLoadProperty operators.
149 class LoadPropertyParameters FINAL {
150  public:
151   explicit LoadPropertyParameters(const VectorSlotPair& feedback)
152       : feedback_(feedback) {}
153
154   const VectorSlotPair& feedback() const { return feedback_; }
155
156  private:
157   const VectorSlotPair feedback_;
158 };
159
160 bool operator==(LoadPropertyParameters const&, LoadPropertyParameters const&);
161 bool operator!=(LoadPropertyParameters const&, LoadPropertyParameters const&);
162
163 size_t hash_value(LoadPropertyParameters const&);
164
165 std::ostream& operator<<(std::ostream&, LoadPropertyParameters const&);
166
167 const LoadPropertyParameters& LoadPropertyParametersOf(const Operator* op);
168
169
170 // Defines the property being stored to an object by a named store. This is
171 // used as a parameter by JSStoreNamed operators.
172 class StoreNamedParameters FINAL {
173  public:
174   StoreNamedParameters(StrictMode strict_mode, const Unique<Name>& name)
175       : strict_mode_(strict_mode), name_(name) {}
176
177   StrictMode strict_mode() const { return strict_mode_; }
178   const Unique<Name>& name() const { return name_; }
179
180  private:
181   const StrictMode strict_mode_;
182   const Unique<Name> name_;
183 };
184
185 bool operator==(StoreNamedParameters const&, StoreNamedParameters const&);
186 bool operator!=(StoreNamedParameters const&, StoreNamedParameters const&);
187
188 size_t hash_value(StoreNamedParameters const&);
189
190 std::ostream& operator<<(std::ostream&, StoreNamedParameters const&);
191
192 const StoreNamedParameters& StoreNamedParametersOf(const Operator* op);
193
194
195 // Interface for building JavaScript-level operators, e.g. directly from the
196 // AST. Most operators have no parameters, thus can be globally shared for all
197 // graphs.
198 class JSOperatorBuilder FINAL : public ZoneObject {
199  public:
200   explicit JSOperatorBuilder(Zone* zone);
201
202   const Operator* Equal();
203   const Operator* NotEqual();
204   const Operator* StrictEqual();
205   const Operator* StrictNotEqual();
206   const Operator* LessThan();
207   const Operator* GreaterThan();
208   const Operator* LessThanOrEqual();
209   const Operator* GreaterThanOrEqual();
210   const Operator* BitwiseOr();
211   const Operator* BitwiseXor();
212   const Operator* BitwiseAnd();
213   const Operator* ShiftLeft();
214   const Operator* ShiftRight();
215   const Operator* ShiftRightLogical();
216   const Operator* Add();
217   const Operator* Subtract();
218   const Operator* Multiply();
219   const Operator* Divide();
220   const Operator* Modulus();
221
222   const Operator* UnaryNot();
223   const Operator* ToBoolean();
224   const Operator* ToNumber();
225   const Operator* ToString();
226   const Operator* ToName();
227   const Operator* ToObject();
228   const Operator* Yield();
229
230   const Operator* Create();
231
232   const Operator* CallFunction(size_t arity, CallFunctionFlags flags);
233   const Operator* CallRuntime(Runtime::FunctionId id, size_t arity);
234
235   const Operator* CallConstruct(int arguments);
236
237   const Operator* LoadProperty(const VectorSlotPair& feedback);
238   const Operator* LoadNamed(const Unique<Name>& name,
239                             const VectorSlotPair& feedback,
240                             ContextualMode contextual_mode = NOT_CONTEXTUAL);
241
242   const Operator* StoreProperty(StrictMode strict_mode);
243   const Operator* StoreNamed(StrictMode strict_mode, const Unique<Name>& name);
244
245   const Operator* DeleteProperty(StrictMode strict_mode);
246
247   const Operator* HasProperty();
248
249   const Operator* LoadContext(size_t depth, size_t index, bool immutable);
250   const Operator* StoreContext(size_t depth, size_t index);
251
252   const Operator* TypeOf();
253   const Operator* InstanceOf();
254   const Operator* Debugger();
255
256   // TODO(titzer): nail down the static parts of each of these context flavors.
257   const Operator* CreateFunctionContext();
258   const Operator* CreateCatchContext(const Unique<String>& name);
259   const Operator* CreateWithContext();
260   const Operator* CreateBlockContext();
261   const Operator* CreateModuleContext();
262   const Operator* CreateGlobalContext();
263
264  private:
265   Zone* zone() const { return zone_; }
266
267   const JSOperatorGlobalCache& cache_;
268   Zone* const zone_;
269
270   DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder);
271 };
272
273 }  // namespace compiler
274 }  // namespace internal
275 }  // namespace v8
276
277 #endif  // V8_COMPILER_JS_OPERATOR_H_