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 #include "opcode_ids.h"
12
13 #define MAX_REAL_OPCODE 254
14
15 #define IS_WITHIN_OPCODE_RANGE(opcode) \
16 (((opcode) >= 0 && (opcode) <= MAX_REAL_OPCODE) || \
17 IS_PSEUDO_INSTR(opcode))
18
19 #define IS_BLOCK_PUSH_OPCODE(opcode) \
20 ((opcode) == SETUP_FINALLY || \
21 (opcode) == SETUP_WITH || \
22 (opcode) == SETUP_CLEANUP)
23
24 #define HAS_TARGET(opcode) \
25 (OPCODE_HAS_JUMP(opcode) || IS_BLOCK_PUSH_OPCODE(opcode))
26
27 /* opcodes that must be last in the basicblock */
28 #define IS_TERMINATOR_OPCODE(opcode) \
29 (OPCODE_HAS_JUMP(opcode) || IS_SCOPE_EXIT_OPCODE(opcode))
30
31 /* opcodes which are not emitted in codegen stage, only by the assembler */
32 #define IS_ASSEMBLER_OPCODE(opcode) \
33 ((opcode) == JUMP_FORWARD || \
34 (opcode) == JUMP_BACKWARD || \
35 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
36
37 #define IS_BACKWARDS_JUMP_OPCODE(opcode) \
38 ((opcode) == JUMP_BACKWARD || \
39 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
40
41 #define IS_UNCONDITIONAL_JUMP_OPCODE(opcode) \
42 ((opcode) == JUMP || \
43 (opcode) == JUMP_NO_INTERRUPT || \
44 (opcode) == JUMP_FORWARD || \
45 (opcode) == JUMP_BACKWARD || \
46 (opcode) == JUMP_BACKWARD_NO_INTERRUPT)
47
48 #define IS_SCOPE_EXIT_OPCODE(opcode) \
49 ((opcode) == RETURN_VALUE || \
50 (opcode) == RETURN_CONST || \
51 (opcode) == RAISE_VARARGS || \
52 (opcode) == RERAISE)
53
54
55 /* Flags used in the oparg for MAKE_FUNCTION */
56 #define MAKE_FUNCTION_DEFAULTS 0x01
57 #define MAKE_FUNCTION_KWDEFAULTS 0x02
58 #define MAKE_FUNCTION_ANNOTATIONS 0x04
59 #define MAKE_FUNCTION_CLOSURE 0x08
60
61 /* Values used in the oparg for RESUME */
62 #define RESUME_AT_FUNC_START 0
63 #define RESUME_AFTER_YIELD 1
64 #define RESUME_AFTER_YIELD_FROM 2
65 #define RESUME_AFTER_AWAIT 3
66
67 #define RESUME_OPARG_LOCATION_MASK 0x3
68 #define RESUME_OPARG_DEPTH1_MASK 0x4
69
70 #ifdef __cplusplus
71 }
72 #endif
73 #endif /* !Py_INTERNAL_OPCODE_UTILS_H */