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_OPERATOR_H_ | 5 #ifndef V8_COMPILER_OPERATOR_H_ |
6 #define V8_COMPILER_OPERATOR_H_ | 6 #define V8_COMPILER_OPERATOR_H_ |
7 | 7 |
8 #include <ostream> // NOLINT(readability/streams) | 8 #include <ostream> // NOLINT(readability/streams) |
9 | 9 |
10 #include "src/base/flags.h" | 10 #include "src/base/flags.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 uint16_t control_out_; | 129 uint16_t control_out_; |
130 | 130 |
131 DISALLOW_COPY_AND_ASSIGN(Operator); | 131 DISALLOW_COPY_AND_ASSIGN(Operator); |
132 }; | 132 }; |
133 | 133 |
134 DEFINE_OPERATORS_FOR_FLAGS(Operator::Properties) | 134 DEFINE_OPERATORS_FOR_FLAGS(Operator::Properties) |
135 | 135 |
136 std::ostream& operator<<(std::ostream& os, const Operator& op); | 136 std::ostream& operator<<(std::ostream& os, const Operator& op); |
137 | 137 |
138 | 138 |
| 139 // Default equality function for below Operator1<*> class. |
| 140 template <typename T> |
| 141 struct OpEqualTo : public std::equal_to<T> {}; |
| 142 |
| 143 |
| 144 // Default hashing function for below Operator1<*> class. |
| 145 template <typename T> |
| 146 struct OpHash : public base::hash<T> {}; |
| 147 |
| 148 |
139 // A templatized implementation of Operator that has one static parameter of | 149 // A templatized implementation of Operator that has one static parameter of |
140 // type {T}. | 150 // type {T} with the proper default equality and hashing functions. |
141 template <typename T, typename Pred = std::equal_to<T>, | 151 template <typename T, typename Pred = OpEqualTo<T>, typename Hash = OpHash<T>> |
142 typename Hash = base::hash<T>> | |
143 class Operator1 : public Operator { | 152 class Operator1 : public Operator { |
144 public: | 153 public: |
145 Operator1(Opcode opcode, Properties properties, const char* mnemonic, | 154 Operator1(Opcode opcode, Properties properties, const char* mnemonic, |
146 size_t value_in, size_t effect_in, size_t control_in, | 155 size_t value_in, size_t effect_in, size_t control_in, |
147 size_t value_out, size_t effect_out, size_t control_out, | 156 size_t value_out, size_t effect_out, size_t control_out, |
148 T parameter, Pred const& pred = Pred(), Hash const& hash = Hash()) | 157 T parameter, Pred const& pred = Pred(), Hash const& hash = Hash()) |
149 : Operator(opcode, properties, mnemonic, value_in, effect_in, control_in, | 158 : Operator(opcode, properties, mnemonic, value_in, effect_in, control_in, |
150 value_out, effect_out, control_out), | 159 value_out, effect_out, control_out), |
151 parameter_(parameter), | 160 parameter_(parameter), |
152 pred_(pred), | 161 pred_(pred), |
(...skipping 23 matching lines...) Expand all Loading... |
176 private: | 185 private: |
177 T const parameter_; | 186 T const parameter_; |
178 Pred const pred_; | 187 Pred const pred_; |
179 Hash const hash_; | 188 Hash const hash_; |
180 }; | 189 }; |
181 | 190 |
182 | 191 |
183 // Helper to extract parameters from Operator1<*> operator. | 192 // Helper to extract parameters from Operator1<*> operator. |
184 template <typename T> | 193 template <typename T> |
185 inline T const& OpParameter(const Operator* op) { | 194 inline T const& OpParameter(const Operator* op) { |
186 return reinterpret_cast<const Operator1<T>*>(op)->parameter(); | 195 return reinterpret_cast<const Operator1<T, OpEqualTo<T>, OpHash<T>>*>(op) |
| 196 ->parameter(); |
187 } | 197 } |
188 | 198 |
| 199 |
189 // NOTE: We have to be careful to use the right equal/hash functions below, for | 200 // NOTE: We have to be careful to use the right equal/hash functions below, for |
190 // float/double we always use the ones operating on the bit level, for Handle<> | 201 // float/double we always use the ones operating on the bit level, for Handle<> |
191 // we always use the ones operating on the location level. | 202 // we always use the ones operating on the location level. |
192 template <> | 203 template <> |
193 inline float const& OpParameter(const Operator* op) { | 204 struct OpEqualTo<float> : public base::bit_equal_to<float> {}; |
194 return reinterpret_cast<const Operator1<float, base::bit_equal_to<float>, | 205 template <> |
195 base::bit_hash<float>>*>(op) | 206 struct OpHash<float> : public base::bit_hash<float> {}; |
196 ->parameter(); | |
197 } | |
198 | 207 |
199 template <> | 208 template <> |
200 inline double const& OpParameter(const Operator* op) { | 209 struct OpEqualTo<double> : public base::bit_equal_to<double> {}; |
201 return reinterpret_cast<const Operator1<double, base::bit_equal_to<double>, | 210 template <> |
202 base::bit_hash<double>>*>(op) | 211 struct OpHash<double> : public base::bit_hash<double> {}; |
203 ->parameter(); | |
204 } | |
205 | 212 |
206 template <> | 213 template <> |
207 inline Handle<HeapObject> const& OpParameter(const Operator* op) { | 214 struct OpEqualTo<Handle<HeapObject>> : public Handle<HeapObject>::equal_to {}; |
208 return reinterpret_cast< | 215 template <> |
209 const Operator1<Handle<HeapObject>, Handle<HeapObject>::equal_to, | 216 struct OpHash<Handle<HeapObject>> : public Handle<HeapObject>::hash {}; |
210 Handle<HeapObject>::hash>*>(op)->parameter(); | |
211 } | |
212 | 217 |
213 template <> | 218 template <> |
214 inline Handle<String> const& OpParameter(const Operator* op) { | 219 struct OpEqualTo<Handle<String>> : public Handle<String>::equal_to {}; |
215 return reinterpret_cast<const Operator1< | 220 template <> |
216 Handle<String>, Handle<String>::equal_to, Handle<String>::hash>*>(op) | 221 struct OpHash<Handle<String>> : public Handle<String>::hash {}; |
217 ->parameter(); | |
218 } | |
219 | 222 |
220 template <> | 223 template <> |
221 inline Handle<ScopeInfo> const& OpParameter(const Operator* op) { | 224 struct OpEqualTo<Handle<ScopeInfo>> : public Handle<ScopeInfo>::equal_to {}; |
222 return reinterpret_cast< | 225 template <> |
223 const Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to, | 226 struct OpHash<Handle<ScopeInfo>> : public Handle<ScopeInfo>::hash {}; |
224 Handle<ScopeInfo>::hash>*>(op)->parameter(); | |
225 } | |
226 | 227 |
227 } // namespace compiler | 228 } // namespace compiler |
228 } // namespace internal | 229 } // namespace internal |
229 } // namespace v8 | 230 } // namespace v8 |
230 | 231 |
231 #endif // V8_COMPILER_OPERATOR_H_ | 232 #endif // V8_COMPILER_OPERATOR_H_ |
OLD | NEW |