• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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.
4 
5 #ifndef V8_COMMON_OPERATION_H_
6 #define V8_COMMON_OPERATION_H_
7 
8 #include <ostream>
9 
10 #define ARITHMETIC_OPERATION_LIST(V) \
11   V(Add)                             \
12   V(Subtract)                        \
13   V(Multiply)                        \
14   V(Divide)                          \
15   V(Modulus)                         \
16   V(Exponentiate)                    \
17   V(BitwiseAnd)                      \
18   V(BitwiseOr)                       \
19   V(BitwiseXor)                      \
20   V(ShiftLeft)                       \
21   V(ShiftRight)                      \
22   V(ShiftRightLogical)
23 
24 #define UNARY_OPERATION_LIST(V) \
25   V(BitwiseNot)                 \
26   V(Negate)                     \
27   V(Increment)                  \
28   V(Decrement)
29 
30 #define COMPARISON_OPERATION_LIST(V) \
31   V(Equal)                           \
32   V(StrictEqual)                     \
33   V(LessThan)                        \
34   V(LessThanOrEqual)                 \
35   V(GreaterThan)                     \
36   V(GreaterThanOrEqual)
37 
38 #define OPERATION_LIST(V)      \
39   ARITHMETIC_OPERATION_LIST(V) \
40   UNARY_OPERATION_LIST(V)      \
41   COMPARISON_OPERATION_LIST(V)
42 
43 enum class Operation {
44 #define DEFINE_OP(name) k##name,
45   OPERATION_LIST(DEFINE_OP)
46 #undef DEFINE_OP
47 };
48 
49 inline std::ostream& operator<<(std::ostream& os, const Operation& operation) {
50   switch (operation) {
51 #define CASE(name)         \
52   case Operation::k##name: \
53     return os << #name;
54     OPERATION_LIST(CASE)
55 #undef CASE
56   }
57 }
58 
59 #endif  // V8_COMMON_OPERATION_H_
60