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
3 // found in the LICENSE file.
5 #include "src/compiler/opcodes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
14 bool IsCommonOpcode(IrOpcode::Value opcode) {
16 #define OPCODE(Opcode) \
17 case IrOpcode::k##Opcode: \
19 COMMON_OP_LIST(OPCODE)
20 CONTROL_OP_LIST(OPCODE)
28 bool IsControlOpcode(IrOpcode::Value opcode) {
30 #define OPCODE(Opcode) \
31 case IrOpcode::k##Opcode: \
33 CONTROL_OP_LIST(OPCODE)
41 bool IsJsOpcode(IrOpcode::Value opcode) {
43 #define OPCODE(Opcode) \
44 case IrOpcode::k##Opcode: \
54 bool IsConstantOpcode(IrOpcode::Value opcode) {
56 #define OPCODE(Opcode) \
57 case IrOpcode::k##Opcode: \
59 CONSTANT_OP_LIST(OPCODE)
67 bool IsComparisonOpcode(IrOpcode::Value opcode) {
69 #define OPCODE(Opcode) \
70 case IrOpcode::k##Opcode: \
72 JS_COMPARE_BINOP_LIST(OPCODE)
73 SIMPLIFIED_COMPARE_BINOP_LIST(OPCODE)
74 MACHINE_COMPARE_BINOP_LIST(OPCODE)
82 const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789);
87 TEST(IrOpcodeTest, IsCommonOpcode) {
88 EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode));
89 #define OPCODE(Opcode) \
90 EXPECT_EQ(IsCommonOpcode(IrOpcode::k##Opcode), \
91 IrOpcode::IsCommonOpcode(IrOpcode::k##Opcode));
97 TEST(IrOpcodeTest, IsControlOpcode) {
98 EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode));
99 #define OPCODE(Opcode) \
100 EXPECT_EQ(IsControlOpcode(IrOpcode::k##Opcode), \
101 IrOpcode::IsControlOpcode(IrOpcode::k##Opcode));
107 TEST(IrOpcodeTest, IsJsOpcode) {
108 EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode));
109 #define OPCODE(Opcode) \
110 EXPECT_EQ(IsJsOpcode(IrOpcode::k##Opcode), \
111 IrOpcode::IsJsOpcode(IrOpcode::k##Opcode));
117 TEST(IrOpcodeTest, IsConstantOpcode) {
118 EXPECT_FALSE(IrOpcode::IsConstantOpcode(kInvalidOpcode));
119 #define OPCODE(Opcode) \
120 EXPECT_EQ(IsConstantOpcode(IrOpcode::k##Opcode), \
121 IrOpcode::IsConstantOpcode(IrOpcode::k##Opcode));
127 TEST(IrOpcodeTest, IsComparisonOpcode) {
128 EXPECT_FALSE(IrOpcode::IsComparisonOpcode(kInvalidOpcode));
129 #define OPCODE(Opcode) \
130 EXPECT_EQ(IsComparisonOpcode(IrOpcode::k##Opcode), \
131 IrOpcode::IsComparisonOpcode(IrOpcode::k##Opcode));
137 TEST(IrOpcodeTest, Mnemonic) {
138 EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode));
139 #define OPCODE(Opcode) \
140 EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode));
145 } // namespace compiler
146 } // namespace internal