File indexing completed on 2025-01-30 10:18:09
0001 #ifndef Py_INTERNAL_OPCODE_UTILS_H
0002 #define Py_INTERNAL_OPCODE_UTILS_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "pycore_opcode.h" // _PyOpcode_Jump
0012
0013
0014 #define MAX_REAL_OPCODE 254
0015
0016 #define IS_WITHIN_OPCODE_RANGE(opcode) \
0017 (((opcode) >= 0 && (opcode) <= MAX_REAL_OPCODE) || \
0018 IS_PSEUDO_OPCODE(opcode))
0019
0020 #define IS_JUMP_OPCODE(opcode) \
0021 is_bit_set_in_table(_PyOpcode_Jump, opcode)
0022
0023 #define IS_BLOCK_PUSH_OPCODE(opcode) \
0024 ((opcode) == SETUP_FINALLY || \
0025 (opcode) == SETUP_WITH || \
0026 (opcode) == SETUP_CLEANUP)
0027
0028 #define HAS_TARGET(opcode) \
0029 (IS_JUMP_OPCODE(opcode) || IS_BLOCK_PUSH_OPCODE(opcode))
0030
0031
0032 #define IS_TERMINATOR_OPCODE(opcode) \
0033 (IS_JUMP_OPCODE(opcode) || IS_SCOPE_EXIT_OPCODE(opcode))
0034
0035
0036 #define IS_ASSEMBLER_OPCODE(opcode) \
0037 ((opcode) == JUMP_FORWARD || \
0038 (opcode) == JUMP_BACKWARD || \
0039 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
0040
0041 #define IS_BACKWARDS_JUMP_OPCODE(opcode) \
0042 ((opcode) == JUMP_BACKWARD || \
0043 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
0044
0045 #define IS_UNCONDITIONAL_JUMP_OPCODE(opcode) \
0046 ((opcode) == JUMP || \
0047 (opcode) == JUMP_NO_INTERRUPT || \
0048 (opcode) == JUMP_FORWARD || \
0049 (opcode) == JUMP_BACKWARD || \
0050 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
0051
0052 #define IS_SCOPE_EXIT_OPCODE(opcode) \
0053 ((opcode) == RETURN_VALUE || \
0054 (opcode) == RETURN_CONST || \
0055 (opcode) == RAISE_VARARGS || \
0056 (opcode) == RERAISE)
0057
0058 #define IS_SUPERINSTRUCTION_OPCODE(opcode) \
0059 ((opcode) == LOAD_FAST__LOAD_FAST || \
0060 (opcode) == LOAD_FAST__LOAD_CONST || \
0061 (opcode) == LOAD_CONST__LOAD_FAST || \
0062 (opcode) == STORE_FAST__LOAD_FAST || \
0063 (opcode) == STORE_FAST__STORE_FAST)
0064
0065
0066 #define LOG_BITS_PER_INT 5
0067 #define MASK_LOW_LOG_BITS 31
0068
0069 static inline int
0070 is_bit_set_in_table(const uint32_t *table, int bitindex) {
0071
0072
0073
0074
0075
0076 if (bitindex >= 0 && bitindex < 512) {
0077 uint32_t word = table[bitindex >> LOG_BITS_PER_INT];
0078 return (word >> (bitindex & MASK_LOW_LOG_BITS)) & 1;
0079 }
0080 else {
0081 return 0;
0082 }
0083 }
0084
0085 #undef LOG_BITS_PER_INT
0086 #undef MASK_LOW_LOG_BITS
0087
0088
0089 #ifdef __cplusplus
0090 }
0091 #endif
0092 #endif