OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/compiler/operator.h" | 5 #include "src/compiler/operator.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace compiler { | 11 namespace compiler { |
12 | 12 |
| 13 namespace { |
13 | 14 |
14 template <typename N> | 15 template <typename N> |
15 static inline N CheckRange(size_t val) { | 16 V8_INLINE N CheckRange(size_t val) { |
16 CHECK(val <= std::numeric_limits<N>::max()); | 17 CHECK_LE(val, std::numeric_limits<N>::max()); |
17 return static_cast<N>(val); | 18 return static_cast<N>(val); |
18 } | 19 } |
19 | 20 |
| 21 } // namespace |
| 22 |
20 | 23 |
21 Operator::Operator(Opcode opcode, Properties properties, const char* mnemonic, | 24 Operator::Operator(Opcode opcode, Properties properties, const char* mnemonic, |
22 size_t value_in, size_t effect_in, size_t control_in, | 25 size_t value_in, size_t effect_in, size_t control_in, |
23 size_t value_out, size_t effect_out, size_t control_out) | 26 size_t value_out, size_t effect_out, size_t control_out) |
24 : opcode_(opcode), | 27 : opcode_(opcode), |
25 properties_(properties), | 28 properties_(properties), |
26 mnemonic_(mnemonic), | 29 mnemonic_(mnemonic), |
27 value_in_(CheckRange<uint32_t>(value_in)), | 30 value_in_(CheckRange<uint32_t>(value_in)), |
28 effect_in_(CheckRange<uint16_t>(effect_in)), | 31 effect_in_(CheckRange<uint16_t>(effect_in)), |
29 control_in_(CheckRange<uint16_t>(control_in)), | 32 control_in_(CheckRange<uint16_t>(control_in)), |
30 value_out_(CheckRange<uint16_t>(value_out)), | 33 value_out_(CheckRange<uint16_t>(value_out)), |
31 effect_out_(CheckRange<uint8_t>(effect_out)), | 34 effect_out_(CheckRange<uint8_t>(effect_out)), |
32 control_out_(CheckRange<uint8_t>(control_out)) {} | 35 control_out_(CheckRange<uint8_t>(control_out)) {} |
33 | 36 |
34 | 37 |
35 std::ostream& operator<<(std::ostream& os, const Operator& op) { | 38 std::ostream& operator<<(std::ostream& os, const Operator& op) { |
36 op.PrintTo(os); | 39 op.PrintTo(os); |
37 return os; | 40 return os; |
38 } | 41 } |
39 | 42 |
40 | 43 |
41 void Operator::PrintTo(std::ostream& os) const { os << mnemonic(); } | 44 void Operator::PrintTo(std::ostream& os) const { os << mnemonic(); } |
42 | 45 |
43 } // namespace compiler | 46 } // namespace compiler |
44 } // namespace internal | 47 } // namespace internal |
45 } // namespace v8 | 48 } // namespace v8 |
OLD | NEW |