Debian Codegraph @

Include/internal/pycore_opcode_utils.h

raw
1 #ifndef Py_INTERNAL_OPCODE_UTILS_H
2 #define Py_INTERNAL_OPCODE_UTILS_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #ifndef Py_BUILD_CORE
8 # error "this header requires Py_BUILD_CORE define"
9 #endif
10
11 #define MAX_REAL_OPCODE 254
12
13 #define IS_WITHIN_OPCODE_RANGE(opcode) \
14 (((opcode) >= 0 && (opcode) <= MAX_REAL_OPCODE) || \
15 IS_PSEUDO_INSTR(opcode))
16
17 #define IS_BLOCK_PUSH_OPCODE(opcode) \
18 ((opcode) == SETUP_FINALLY || \
19 (opcode) == SETUP_WITH || \
20 (opcode) == SETUP_CLEANUP)
21
22 #define HAS_TARGET(opcode) \
23 (OPCODE_HAS_JUMP(opcode) || IS_BLOCK_PUSH_OPCODE(opcode))
24
25 /* opcodes that must be last in the basicblock */
26 #define IS_TERMINATOR_OPCODE(opcode) \
27 (OPCODE_HAS_JUMP(opcode) || IS_SCOPE_EXIT_OPCODE(opcode))
28
29 /* opcodes which are not emitted in codegen stage, only by the assembler */
30 #define IS_ASSEMBLER_OPCODE(opcode) \
31 ((opcode) == JUMP_FORWARD || \
32 (opcode) == JUMP_BACKWARD || \
33 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
34
35 #define IS_BACKWARDS_JUMP_OPCODE(opcode) \
36 ((opcode) == JUMP_BACKWARD || \
37 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
38
39 #define IS_UNCONDITIONAL_JUMP_OPCODE(opcode) \
40 ((opcode) == JUMP || \
41 (opcode) == JUMP_NO_INTERRUPT || \
42 (opcode) == JUMP_FORWARD || \
43 (opcode) == JUMP_BACKWARD || \
44 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
45
46 #define IS_CONDITIONAL_JUMP_OPCODE(opcode) \
47 ((opcode) == POP_JUMP_IF_FALSE || \
48 (opcode) == POP_JUMP_IF_TRUE || \
49 (opcode) == POP_JUMP_IF_NONE || \
50 (opcode) == POP_JUMP_IF_NOT_NONE)
51
52 #define IS_SCOPE_EXIT_OPCODE(opcode) \
53 ((opcode) == RETURN_VALUE || \
54 (opcode) == RAISE_VARARGS || \
55 (opcode) == RERAISE)
56
57 #define IS_RETURN_OPCODE(opcode) \
58 (opcode == RETURN_VALUE)
59 #define IS_RAISE_OPCODE(opcode) \
60 (opcode == RAISE_VARARGS || opcode == RERAISE)
61
62
63 /* Flags used in the oparg for MAKE_FUNCTION */
64 #define MAKE_FUNCTION_DEFAULTS 0x01
65 #define MAKE_FUNCTION_KWDEFAULTS 0x02
66 #define MAKE_FUNCTION_ANNOTATIONS 0x04
67 #define MAKE_FUNCTION_CLOSURE 0x08
68 #define MAKE_FUNCTION_ANNOTATE 0x10
69
70 /* Values used as the oparg for LOAD_COMMON_CONSTANT */
71 #define CONSTANT_ASSERTIONERROR 0
72 #define CONSTANT_NOTIMPLEMENTEDERROR 1
73 #define CONSTANT_BUILTIN_TUPLE 2
74 #define CONSTANT_BUILTIN_ALL 3
75 #define CONSTANT_BUILTIN_ANY 4
76 #define NUM_COMMON_CONSTANTS 5
77
78 /* Values used in the oparg for RESUME */
79 #define RESUME_AT_FUNC_START 0
80 #define RESUME_AFTER_YIELD 1
81 #define RESUME_AFTER_YIELD_FROM 2
82 #define RESUME_AFTER_AWAIT 3
83
84 #define RESUME_OPARG_LOCATION_MASK 0x3
85 #define RESUME_OPARG_DEPTH1_MASK 0x4
86
87 #ifdef __cplusplus
88 }
89 #endif
90 #endif /* !Py_INTERNAL_OPCODE_UTILS_H */