Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/unittests/compiler/opcodes-unittest.cc

Issue 807573004: [turbofan] Turn IrOpcode::IsXXX() into range checks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/opcodes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cstring>
6
7 #include "src/compiler/opcodes.h" 5 #include "src/compiler/opcodes.h"
8 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
9 7
10 namespace v8 { 8 namespace v8 {
11 namespace internal { 9 namespace internal {
12 namespace compiler { 10 namespace compiler {
13 11
12 namespace {
13
14 bool IsCommonOpcode(IrOpcode::Value opcode) {
15 switch (opcode) {
16 #define OPCODE(Opcode) \
17 case IrOpcode::k##Opcode: \
18 return true;
19 COMMON_OP_LIST(OPCODE)
20 CONTROL_OP_LIST(OPCODE)
21 #undef OPCODE
22 default:
23 return false;
24 }
25 }
26
27
28 bool IsControlOpcode(IrOpcode::Value opcode) {
29 switch (opcode) {
30 #define OPCODE(Opcode) \
31 case IrOpcode::k##Opcode: \
32 return true;
33 CONTROL_OP_LIST(OPCODE)
34 #undef OPCODE
35 default:
36 return false;
37 }
38 }
39
40
41 bool IsJsOpcode(IrOpcode::Value opcode) {
42 switch (opcode) {
43 #define OPCODE(Opcode) \
44 case IrOpcode::k##Opcode: \
45 return true;
46 JS_OP_LIST(OPCODE)
47 #undef OPCODE
48 default:
49 return false;
50 }
51 }
52
53
54 bool IsLeafOpcode(IrOpcode::Value opcode) {
55 switch (opcode) {
56 #define OPCODE(Opcode) \
57 case IrOpcode::k##Opcode: \
58 return true;
59 LEAF_OP_LIST(OPCODE)
60 #undef OPCODE
61 default:
62 return false;
63 }
64 }
65
66
67 const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789);
68
69 } // namespace
70
71
72 TEST(IrOpcodeTest, IsCommonOpcode) {
73 EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode));
74 #define OPCODE(Opcode) \
75 EXPECT_EQ(IsCommonOpcode(IrOpcode::k##Opcode), \
76 IrOpcode::IsCommonOpcode(IrOpcode::k##Opcode));
77 ALL_OP_LIST(OPCODE)
78 #undef OPCODE
79 }
80
81
82 TEST(IrOpcodeTest, IsControlOpcode) {
83 EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode));
84 #define OPCODE(Opcode) \
85 EXPECT_EQ(IsControlOpcode(IrOpcode::k##Opcode), \
86 IrOpcode::IsControlOpcode(IrOpcode::k##Opcode));
87 ALL_OP_LIST(OPCODE)
88 #undef OPCODE
89 }
90
91
92 TEST(IrOpcodeTest, IsJsOpcode) {
93 EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode));
94 #define OPCODE(Opcode) \
95 EXPECT_EQ(IsJsOpcode(IrOpcode::k##Opcode), \
96 IrOpcode::IsJsOpcode(IrOpcode::k##Opcode));
97 ALL_OP_LIST(OPCODE)
98 #undef OPCODE
99 }
100
101
102 TEST(IrOpcodeTest, IsLeafOpcode) {
103 EXPECT_FALSE(IrOpcode::IsLeafOpcode(kInvalidOpcode));
104 #define OPCODE(Opcode) \
105 EXPECT_EQ(IsLeafOpcode(IrOpcode::k##Opcode), \
106 IrOpcode::IsLeafOpcode(IrOpcode::k##Opcode));
107 ALL_OP_LIST(OPCODE)
108 #undef OPCODE
109 }
110
111
14 TEST(IrOpcodeTest, Mnemonic) { 112 TEST(IrOpcodeTest, Mnemonic) {
15 EXPECT_STREQ("UnknownOpcode", 113 EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode));
16 IrOpcode::Mnemonic(static_cast<IrOpcode::Value>(123456789)));
17 #define OPCODE(Opcode) \ 114 #define OPCODE(Opcode) \
18 EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode)); 115 EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode));
19 ALL_OP_LIST(OPCODE) 116 ALL_OP_LIST(OPCODE)
20 #undef OPCODE 117 #undef OPCODE
21 } 118 }
22 119
23 } // namespace compiler 120 } // namespace compiler
24 } // namespace internal 121 } // namespace internal
25 } // namespace v8 122 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/opcodes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698