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.
5 #ifndef V8_COMPILER_JS_OPERATOR_H_
6 #define V8_COMPILER_JS_OPERATOR_H_
8 #include "src/runtime/runtime.h"
9 #include "src/unique.h"
15 // Forward declarations.
17 struct JSOperatorGlobalCache;
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 {
24 CallFunctionParameters(size_t arity, CallFunctionFlags flags)
25 : arity_(arity), flags_(flags) {}
27 size_t arity() const { return arity_; }
28 CallFunctionFlags flags() const { return flags_; }
32 const CallFunctionFlags flags_;
35 bool operator==(CallFunctionParameters const&, CallFunctionParameters const&);
36 bool operator!=(CallFunctionParameters const&, CallFunctionParameters const&);
38 size_t hash_value(CallFunctionParameters const&);
40 std::ostream& operator<<(std::ostream&, CallFunctionParameters const&);
42 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op);
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 {
49 CallRuntimeParameters(Runtime::FunctionId id, size_t arity)
50 : id_(id), arity_(arity) {}
52 Runtime::FunctionId id() const { return id_; }
53 size_t arity() const { return arity_; }
56 const Runtime::FunctionId id_;
60 bool operator==(CallRuntimeParameters const&, CallRuntimeParameters const&);
61 bool operator!=(CallRuntimeParameters const&, CallRuntimeParameters const&);
63 size_t hash_value(CallRuntimeParameters const&);
65 std::ostream& operator<<(std::ostream&, CallRuntimeParameters const&);
67 const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op);
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 {
75 ContextAccess(size_t depth, size_t index, bool immutable);
77 size_t depth() const { return depth_; }
78 size_t index() const { return index_; }
79 bool immutable() const { return immutable_; }
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_;
89 bool operator==(ContextAccess const&, ContextAccess const&);
90 bool operator!=(ContextAccess const&, ContextAccess const&);
92 size_t hash_value(ContextAccess const&);
94 std::ostream& operator<<(std::ostream&, ContextAccess const&);
96 ContextAccess const& ContextAccessOf(Operator const*);
99 class VectorSlotPair {
101 VectorSlotPair(Handle<TypeFeedbackVector> vector, FeedbackVectorICSlot slot)
102 : vector_(vector), slot_(slot) {}
104 Handle<TypeFeedbackVector> vector() const { return vector_; }
105 FeedbackVectorICSlot slot() const { return slot_; }
107 int index() const { return vector_->GetIndex(slot_); }
110 const Handle<TypeFeedbackVector> vector_;
111 const FeedbackVectorICSlot slot_;
115 bool operator==(VectorSlotPair const& lhs, VectorSlotPair const& rhs);
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 {
122 LoadNamedParameters(const Unique<Name>& name, const VectorSlotPair& feedback,
123 ContextualMode contextual_mode)
124 : name_(name), contextual_mode_(contextual_mode), feedback_(feedback) {}
126 const Unique<Name>& name() const { return name_; }
127 ContextualMode contextual_mode() const { return contextual_mode_; }
129 const VectorSlotPair& feedback() const { return feedback_; }
132 const Unique<Name> name_;
133 const ContextualMode contextual_mode_;
134 const VectorSlotPair feedback_;
137 bool operator==(LoadNamedParameters const&, LoadNamedParameters const&);
138 bool operator!=(LoadNamedParameters const&, LoadNamedParameters const&);
140 size_t hash_value(LoadNamedParameters const&);
142 std::ostream& operator<<(std::ostream&, LoadNamedParameters const&);
144 const LoadNamedParameters& LoadNamedParametersOf(const Operator* op);
147 // Defines the property being loaded from an object. This is
148 // used as a parameter by JSLoadProperty operators.
149 class LoadPropertyParameters FINAL {
151 explicit LoadPropertyParameters(const VectorSlotPair& feedback)
152 : feedback_(feedback) {}
154 const VectorSlotPair& feedback() const { return feedback_; }
157 const VectorSlotPair feedback_;
160 bool operator==(LoadPropertyParameters const&, LoadPropertyParameters const&);
161 bool operator!=(LoadPropertyParameters const&, LoadPropertyParameters const&);
163 size_t hash_value(LoadPropertyParameters const&);
165 std::ostream& operator<<(std::ostream&, LoadPropertyParameters const&);
167 const LoadPropertyParameters& LoadPropertyParametersOf(const Operator* op);
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 {
174 StoreNamedParameters(LanguageMode language_mode, const Unique<Name>& name)
175 : language_mode_(language_mode), name_(name) {}
177 LanguageMode language_mode() const { return language_mode_; }
178 const Unique<Name>& name() const { return name_; }
181 const LanguageMode language_mode_;
182 const Unique<Name> name_;
185 bool operator==(StoreNamedParameters const&, StoreNamedParameters const&);
186 bool operator!=(StoreNamedParameters const&, StoreNamedParameters const&);
188 size_t hash_value(StoreNamedParameters const&);
190 std::ostream& operator<<(std::ostream&, StoreNamedParameters const&);
192 const StoreNamedParameters& StoreNamedParametersOf(const Operator* op);
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
198 class JSOperatorBuilder FINAL : public ZoneObject {
200 explicit JSOperatorBuilder(Zone* zone);
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();
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();
230 const Operator* Create();
232 const Operator* CallFunction(size_t arity, CallFunctionFlags flags);
233 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity);
235 const Operator* CallConstruct(int arguments);
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);
242 const Operator* StoreProperty(LanguageMode language_mode);
243 const Operator* StoreNamed(LanguageMode language_mode,
244 const Unique<Name>& name);
246 const Operator* DeleteProperty(LanguageMode language_mode);
248 const Operator* HasProperty();
250 const Operator* LoadContext(size_t depth, size_t index, bool immutable);
251 const Operator* StoreContext(size_t depth, size_t index);
253 const Operator* TypeOf();
254 const Operator* InstanceOf();
255 const Operator* Debugger();
257 // TODO(titzer): nail down the static parts of each of these context flavors.
258 const Operator* CreateFunctionContext();
259 const Operator* CreateCatchContext(const Unique<String>& name);
260 const Operator* CreateWithContext();
261 const Operator* CreateBlockContext();
262 const Operator* CreateModuleContext();
263 const Operator* CreateScriptContext();
266 Zone* zone() const { return zone_; }
268 const JSOperatorGlobalCache& cache_;
271 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder);
274 } // namespace compiler
275 } // namespace internal
278 #endif // V8_COMPILER_JS_OPERATOR_H_