OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/opcodes.h" | 5 #include "src/compiler/opcodes.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest-support.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace compiler { | 10 namespace compiler { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 bool IsCommonOpcode(IrOpcode::Value opcode) { | 14 bool IsCommonOpcode(IrOpcode::Value opcode) { |
15 switch (opcode) { | 15 switch (opcode) { |
16 #define OPCODE(Opcode) \ | 16 #define OPCODE(Opcode) \ |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 MACHINE_COMPARE_BINOP_LIST(OPCODE) | 74 MACHINE_COMPARE_BINOP_LIST(OPCODE) |
75 #undef OPCODE | 75 #undef OPCODE |
76 default: | 76 default: |
77 return false; | 77 return false; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789); | 82 const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789); |
83 | 83 |
| 84 char const* const kMnemonics[] = { |
| 85 #define OPCODE(Opcode) #Opcode, |
| 86 ALL_OP_LIST(OPCODE) |
| 87 #undef OPCODE |
| 88 }; |
| 89 |
| 90 const IrOpcode::Value kOpcodes[] = { |
| 91 #define OPCODE(Opcode) IrOpcode::k##Opcode, |
| 92 ALL_OP_LIST(OPCODE) |
| 93 #undef OPCODE |
| 94 }; |
| 95 |
84 } // namespace | 96 } // namespace |
85 | 97 |
86 | |
87 TEST(IrOpcodeTest, IsCommonOpcode) { | 98 TEST(IrOpcodeTest, IsCommonOpcode) { |
88 EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode)); | 99 EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode)); |
89 #define OPCODE(Opcode) \ | 100 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
90 EXPECT_EQ(IsCommonOpcode(IrOpcode::k##Opcode), \ | 101 EXPECT_EQ(IsCommonOpcode(opcode), IrOpcode::IsCommonOpcode(opcode)); |
91 IrOpcode::IsCommonOpcode(IrOpcode::k##Opcode)); | 102 } |
92 ALL_OP_LIST(OPCODE) | |
93 #undef OPCODE | |
94 } | 103 } |
95 | 104 |
96 | |
97 TEST(IrOpcodeTest, IsControlOpcode) { | 105 TEST(IrOpcodeTest, IsControlOpcode) { |
98 EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode)); | 106 EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode)); |
99 #define OPCODE(Opcode) \ | 107 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
100 EXPECT_EQ(IsControlOpcode(IrOpcode::k##Opcode), \ | 108 EXPECT_EQ(IsControlOpcode(opcode), IrOpcode::IsControlOpcode(opcode)); |
101 IrOpcode::IsControlOpcode(IrOpcode::k##Opcode)); | 109 } |
102 ALL_OP_LIST(OPCODE) | |
103 #undef OPCODE | |
104 } | 110 } |
105 | 111 |
106 | |
107 TEST(IrOpcodeTest, IsJsOpcode) { | 112 TEST(IrOpcodeTest, IsJsOpcode) { |
108 EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode)); | 113 EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode)); |
109 #define OPCODE(Opcode) \ | 114 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
110 EXPECT_EQ(IsJsOpcode(IrOpcode::k##Opcode), \ | 115 EXPECT_EQ(IsJsOpcode(opcode), IrOpcode::IsJsOpcode(opcode)); |
111 IrOpcode::IsJsOpcode(IrOpcode::k##Opcode)); | 116 } |
112 ALL_OP_LIST(OPCODE) | |
113 #undef OPCODE | |
114 } | 117 } |
115 | 118 |
116 | |
117 TEST(IrOpcodeTest, IsConstantOpcode) { | 119 TEST(IrOpcodeTest, IsConstantOpcode) { |
118 EXPECT_FALSE(IrOpcode::IsConstantOpcode(kInvalidOpcode)); | 120 EXPECT_FALSE(IrOpcode::IsConstantOpcode(kInvalidOpcode)); |
119 #define OPCODE(Opcode) \ | 121 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
120 EXPECT_EQ(IsConstantOpcode(IrOpcode::k##Opcode), \ | 122 EXPECT_EQ(IsConstantOpcode(opcode), IrOpcode::IsConstantOpcode(opcode)); |
121 IrOpcode::IsConstantOpcode(IrOpcode::k##Opcode)); | 123 } |
122 ALL_OP_LIST(OPCODE) | |
123 #undef OPCODE | |
124 } | 124 } |
125 | 125 |
126 | |
127 TEST(IrOpcodeTest, IsComparisonOpcode) { | 126 TEST(IrOpcodeTest, IsComparisonOpcode) { |
128 EXPECT_FALSE(IrOpcode::IsComparisonOpcode(kInvalidOpcode)); | 127 EXPECT_FALSE(IrOpcode::IsComparisonOpcode(kInvalidOpcode)); |
129 #define OPCODE(Opcode) \ | 128 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
130 EXPECT_EQ(IsComparisonOpcode(IrOpcode::k##Opcode), \ | 129 EXPECT_EQ(IsComparisonOpcode(opcode), IrOpcode::IsComparisonOpcode(opcode)); |
131 IrOpcode::IsComparisonOpcode(IrOpcode::k##Opcode)); | 130 } |
132 ALL_OP_LIST(OPCODE) | |
133 #undef OPCODE | |
134 } | 131 } |
135 | 132 |
136 | |
137 TEST(IrOpcodeTest, Mnemonic) { | 133 TEST(IrOpcodeTest, Mnemonic) { |
138 EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode)); | 134 EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode)); |
139 #define OPCODE(Opcode) \ | 135 TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { |
140 EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode)); | 136 EXPECT_STREQ(kMnemonics[opcode], IrOpcode::Mnemonic(opcode)); |
141 ALL_OP_LIST(OPCODE) | 137 } |
142 #undef OPCODE | |
143 } | 138 } |
144 | 139 |
145 } // namespace compiler | 140 } // namespace compiler |
146 } // namespace internal | 141 } // namespace internal |
147 } // namespace v8 | 142 } // namespace v8 |
OLD | NEW |