OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_JS_OPERATOR_H_ | 5 #ifndef V8_COMPILER_JS_OPERATOR_H_ |
6 #define V8_COMPILER_JS_OPERATOR_H_ | 6 #define V8_COMPILER_JS_OPERATOR_H_ |
7 | 7 |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/opcodes.h" | 9 #include "src/compiler/opcodes.h" |
10 #include "src/compiler/operator.h" | 10 #include "src/compiler/operator.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 #define OP1(name, ptype, pname, properties, inputs, outputs) \ | 75 #define OP1(name, ptype, pname, properties, inputs, outputs) \ |
76 return new (zone_) Operator1<ptype>(IrOpcode::k##name, properties, inputs, \ | 76 return new (zone_) Operator1<ptype>(IrOpcode::k##name, properties, inputs, \ |
77 outputs, #name, pname) | 77 outputs, #name, pname) |
78 | 78 |
79 #define BINOP(name) NOPROPS(name, 2, 1) | 79 #define BINOP(name) NOPROPS(name, 2, 1) |
80 #define UNOP(name) NOPROPS(name, 1, 1) | 80 #define UNOP(name) NOPROPS(name, 1, 1) |
81 | 81 |
82 #define PURE_BINOP(name) SIMPLE(name, Operator::kPure, 2, 1) | 82 #define PURE_BINOP(name) SIMPLE(name, Operator::kPure, 2, 1) |
83 | 83 |
84 Operator* Equal() { BINOP(JSEqual); } | 84 const Operator* Equal() { BINOP(JSEqual); } |
85 Operator* NotEqual() { BINOP(JSNotEqual); } | 85 const Operator* NotEqual() { BINOP(JSNotEqual); } |
86 Operator* StrictEqual() { PURE_BINOP(JSStrictEqual); } | 86 const Operator* StrictEqual() { PURE_BINOP(JSStrictEqual); } |
87 Operator* StrictNotEqual() { PURE_BINOP(JSStrictNotEqual); } | 87 const Operator* StrictNotEqual() { PURE_BINOP(JSStrictNotEqual); } |
88 Operator* LessThan() { BINOP(JSLessThan); } | 88 const Operator* LessThan() { BINOP(JSLessThan); } |
89 Operator* GreaterThan() { BINOP(JSGreaterThan); } | 89 const Operator* GreaterThan() { BINOP(JSGreaterThan); } |
90 Operator* LessThanOrEqual() { BINOP(JSLessThanOrEqual); } | 90 const Operator* LessThanOrEqual() { BINOP(JSLessThanOrEqual); } |
91 Operator* GreaterThanOrEqual() { BINOP(JSGreaterThanOrEqual); } | 91 const Operator* GreaterThanOrEqual() { BINOP(JSGreaterThanOrEqual); } |
92 Operator* BitwiseOr() { BINOP(JSBitwiseOr); } | 92 const Operator* BitwiseOr() { BINOP(JSBitwiseOr); } |
93 Operator* BitwiseXor() { BINOP(JSBitwiseXor); } | 93 const Operator* BitwiseXor() { BINOP(JSBitwiseXor); } |
94 Operator* BitwiseAnd() { BINOP(JSBitwiseAnd); } | 94 const Operator* BitwiseAnd() { BINOP(JSBitwiseAnd); } |
95 Operator* ShiftLeft() { BINOP(JSShiftLeft); } | 95 const Operator* ShiftLeft() { BINOP(JSShiftLeft); } |
96 Operator* ShiftRight() { BINOP(JSShiftRight); } | 96 const Operator* ShiftRight() { BINOP(JSShiftRight); } |
97 Operator* ShiftRightLogical() { BINOP(JSShiftRightLogical); } | 97 const Operator* ShiftRightLogical() { BINOP(JSShiftRightLogical); } |
98 Operator* Add() { BINOP(JSAdd); } | 98 const Operator* Add() { BINOP(JSAdd); } |
99 Operator* Subtract() { BINOP(JSSubtract); } | 99 const Operator* Subtract() { BINOP(JSSubtract); } |
100 Operator* Multiply() { BINOP(JSMultiply); } | 100 const Operator* Multiply() { BINOP(JSMultiply); } |
101 Operator* Divide() { BINOP(JSDivide); } | 101 const Operator* Divide() { BINOP(JSDivide); } |
102 Operator* Modulus() { BINOP(JSModulus); } | 102 const Operator* Modulus() { BINOP(JSModulus); } |
103 | 103 |
104 Operator* UnaryNot() { UNOP(JSUnaryNot); } | 104 const Operator* UnaryNot() { UNOP(JSUnaryNot); } |
105 Operator* ToBoolean() { UNOP(JSToBoolean); } | 105 const Operator* ToBoolean() { UNOP(JSToBoolean); } |
106 Operator* ToNumber() { UNOP(JSToNumber); } | 106 const Operator* ToNumber() { UNOP(JSToNumber); } |
107 Operator* ToString() { UNOP(JSToString); } | 107 const Operator* ToString() { UNOP(JSToString); } |
108 Operator* ToName() { UNOP(JSToName); } | 108 const Operator* ToName() { UNOP(JSToName); } |
109 Operator* ToObject() { UNOP(JSToObject); } | 109 const Operator* ToObject() { UNOP(JSToObject); } |
110 Operator* Yield() { UNOP(JSYield); } | 110 const Operator* Yield() { UNOP(JSYield); } |
111 | 111 |
112 Operator* Create() { SIMPLE(JSCreate, Operator::kEliminatable, 0, 1); } | 112 const Operator* Create() { SIMPLE(JSCreate, Operator::kEliminatable, 0, 1); } |
113 | 113 |
114 Operator* Call(int arguments, CallFunctionFlags flags) { | 114 const Operator* Call(int arguments, CallFunctionFlags flags) { |
115 CallParameters parameters = {arguments, flags}; | 115 CallParameters parameters = {arguments, flags}; |
116 OP1(JSCallFunction, CallParameters, parameters, Operator::kNoProperties, | 116 OP1(JSCallFunction, CallParameters, parameters, Operator::kNoProperties, |
117 arguments, 1); | 117 arguments, 1); |
118 } | 118 } |
119 | 119 |
120 Operator* CallNew(int arguments) { | 120 const Operator* CallNew(int arguments) { |
121 return new (zone_) | 121 return new (zone_) |
122 Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties, | 122 Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties, |
123 arguments, 1, "JSCallConstruct", arguments); | 123 arguments, 1, "JSCallConstruct", arguments); |
124 } | 124 } |
125 | 125 |
126 Operator* LoadProperty() { BINOP(JSLoadProperty); } | 126 const Operator* LoadProperty() { BINOP(JSLoadProperty); } |
127 Operator* LoadNamed(Unique<Name> name, | 127 const Operator* LoadNamed(Unique<Name> name, |
128 ContextualMode contextual_mode = NOT_CONTEXTUAL) { | 128 ContextualMode contextual_mode = NOT_CONTEXTUAL) { |
129 LoadNamedParameters parameters = {name, contextual_mode}; | 129 LoadNamedParameters parameters = {name, contextual_mode}; |
130 OP1(JSLoadNamed, LoadNamedParameters, parameters, Operator::kNoProperties, | 130 OP1(JSLoadNamed, LoadNamedParameters, parameters, Operator::kNoProperties, |
131 1, 1); | 131 1, 1); |
132 } | 132 } |
133 | 133 |
134 Operator* StoreProperty(StrictMode strict_mode) { | 134 const Operator* StoreProperty(StrictMode strict_mode) { |
135 OP1(JSStoreProperty, StrictMode, strict_mode, Operator::kNoProperties, 3, | 135 OP1(JSStoreProperty, StrictMode, strict_mode, Operator::kNoProperties, 3, |
136 0); | 136 0); |
137 } | 137 } |
138 | 138 |
139 Operator* StoreNamed(StrictMode strict_mode, Unique<Name> name) { | 139 const Operator* StoreNamed(StrictMode strict_mode, Unique<Name> name) { |
140 StoreNamedParameters parameters = {strict_mode, name}; | 140 StoreNamedParameters parameters = {strict_mode, name}; |
141 OP1(JSStoreNamed, StoreNamedParameters, parameters, Operator::kNoProperties, | 141 OP1(JSStoreNamed, StoreNamedParameters, parameters, Operator::kNoProperties, |
142 2, 0); | 142 2, 0); |
143 } | 143 } |
144 | 144 |
145 Operator* DeleteProperty(StrictMode strict_mode) { | 145 const Operator* DeleteProperty(StrictMode strict_mode) { |
146 OP1(JSDeleteProperty, StrictMode, strict_mode, Operator::kNoProperties, 2, | 146 OP1(JSDeleteProperty, StrictMode, strict_mode, Operator::kNoProperties, 2, |
147 1); | 147 1); |
148 } | 148 } |
149 | 149 |
150 Operator* HasProperty() { NOPROPS(JSHasProperty, 2, 1); } | 150 const Operator* HasProperty() { NOPROPS(JSHasProperty, 2, 1); } |
151 | 151 |
152 Operator* LoadContext(uint16_t depth, uint32_t index, bool immutable) { | 152 const Operator* LoadContext(uint16_t depth, uint32_t index, bool immutable) { |
153 ContextAccess access(depth, index, immutable); | 153 ContextAccess access(depth, index, immutable); |
154 OP1(JSLoadContext, ContextAccess, access, | 154 OP1(JSLoadContext, ContextAccess, access, |
155 Operator::kEliminatable | Operator::kNoWrite, 1, 1); | 155 Operator::kEliminatable | Operator::kNoWrite, 1, 1); |
156 } | 156 } |
157 Operator* StoreContext(uint16_t depth, uint32_t index) { | 157 const Operator* StoreContext(uint16_t depth, uint32_t index) { |
158 ContextAccess access(depth, index, false); | 158 ContextAccess access(depth, index, false); |
159 OP1(JSStoreContext, ContextAccess, access, Operator::kNoProperties, 2, 0); | 159 OP1(JSStoreContext, ContextAccess, access, Operator::kNoProperties, 2, 0); |
160 } | 160 } |
161 | 161 |
162 Operator* TypeOf() { SIMPLE(JSTypeOf, Operator::kPure, 1, 1); } | 162 const Operator* TypeOf() { SIMPLE(JSTypeOf, Operator::kPure, 1, 1); } |
163 Operator* InstanceOf() { NOPROPS(JSInstanceOf, 2, 1); } | 163 const Operator* InstanceOf() { NOPROPS(JSInstanceOf, 2, 1); } |
164 Operator* Debugger() { NOPROPS(JSDebugger, 0, 0); } | 164 const Operator* Debugger() { NOPROPS(JSDebugger, 0, 0); } |
165 | 165 |
166 // TODO(titzer): nail down the static parts of each of these context flavors. | 166 // TODO(titzer): nail down the static parts of each of these context flavors. |
167 Operator* CreateFunctionContext() { NOPROPS(JSCreateFunctionContext, 1, 1); } | 167 const Operator* CreateFunctionContext() { |
168 Operator* CreateCatchContext(Unique<String> name) { | 168 NOPROPS(JSCreateFunctionContext, 1, 1); |
| 169 } |
| 170 const Operator* CreateCatchContext(Unique<String> name) { |
169 OP1(JSCreateCatchContext, Unique<String>, name, Operator::kNoProperties, 1, | 171 OP1(JSCreateCatchContext, Unique<String>, name, Operator::kNoProperties, 1, |
170 1); | 172 1); |
171 } | 173 } |
172 Operator* CreateWithContext() { NOPROPS(JSCreateWithContext, 2, 1); } | 174 const Operator* CreateWithContext() { NOPROPS(JSCreateWithContext, 2, 1); } |
173 Operator* CreateBlockContext() { NOPROPS(JSCreateBlockContext, 2, 1); } | 175 const Operator* CreateBlockContext() { NOPROPS(JSCreateBlockContext, 2, 1); } |
174 Operator* CreateModuleContext() { NOPROPS(JSCreateModuleContext, 2, 1); } | 176 const Operator* CreateModuleContext() { |
175 Operator* CreateGlobalContext() { NOPROPS(JSCreateGlobalContext, 2, 1); } | 177 NOPROPS(JSCreateModuleContext, 2, 1); |
| 178 } |
| 179 const Operator* CreateGlobalContext() { |
| 180 NOPROPS(JSCreateGlobalContext, 2, 1); |
| 181 } |
176 | 182 |
177 Operator* Runtime(Runtime::FunctionId function, int arguments) { | 183 const Operator* Runtime(Runtime::FunctionId function, int arguments) { |
178 const Runtime::Function* f = Runtime::FunctionForId(function); | 184 const Runtime::Function* f = Runtime::FunctionForId(function); |
179 DCHECK(f->nargs == -1 || f->nargs == arguments); | 185 DCHECK(f->nargs == -1 || f->nargs == arguments); |
180 OP1(JSCallRuntime, Runtime::FunctionId, function, Operator::kNoProperties, | 186 OP1(JSCallRuntime, Runtime::FunctionId, function, Operator::kNoProperties, |
181 arguments, f->result_size); | 187 arguments, f->result_size); |
182 } | 188 } |
183 | 189 |
184 #undef SIMPLE | 190 #undef SIMPLE |
185 #undef NOPROPS | 191 #undef NOPROPS |
186 #undef OP1 | 192 #undef OP1 |
187 #undef BINOP | 193 #undef BINOP |
(...skipping 24 matching lines...) Expand all Loading... |
212 struct StaticParameterTraits<Runtime::FunctionId> { | 218 struct StaticParameterTraits<Runtime::FunctionId> { |
213 static OStream& PrintTo(OStream& os, Runtime::FunctionId val) { // NOLINT | 219 static OStream& PrintTo(OStream& os, Runtime::FunctionId val) { // NOLINT |
214 const Runtime::Function* f = Runtime::FunctionForId(val); | 220 const Runtime::Function* f = Runtime::FunctionForId(val); |
215 return os << (f->name ? f->name : "?Runtime?"); | 221 return os << (f->name ? f->name : "?Runtime?"); |
216 } | 222 } |
217 static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); } | 223 static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); } |
218 static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) { | 224 static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) { |
219 return a == b; | 225 return a == b; |
220 } | 226 } |
221 }; | 227 }; |
222 } | 228 |
223 } | 229 } // namespace compiler |
224 } // namespace v8::internal::compiler | 230 } // namespace internal |
| 231 } // namespace v8 |
225 | 232 |
226 #endif // V8_COMPILER_JS_OPERATOR_H_ | 233 #endif // V8_COMPILER_JS_OPERATOR_H_ |
OLD | NEW |