| 
									
										
										
										
											2023-03-31 18:17:59 +01:00
										 |  |  | #ifndef Py_INTERNAL_OPCODE_UTILS_H
 | 
					
						
							|  |  |  | #define Py_INTERNAL_OPCODE_UTILS_H
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef Py_BUILD_CORE
 | 
					
						
							|  |  |  | #  error "this header requires Py_BUILD_CORE define"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-11 11:20:39 +01:00
										 |  |  | #include "pycore_opcode.h"        // _PyOpcode_Jump
 | 
					
						
							| 
									
										
										
										
											2023-03-31 18:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAX_REAL_OPCODE 254
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_WITHIN_OPCODE_RANGE(opcode) \
 | 
					
						
							|  |  |  |         (((opcode) >= 0 && (opcode) <= MAX_REAL_OPCODE) || \ | 
					
						
							|  |  |  |          IS_PSEUDO_OPCODE(opcode)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_JUMP_OPCODE(opcode) \
 | 
					
						
							|  |  |  |          is_bit_set_in_table(_PyOpcode_Jump, opcode) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_BLOCK_PUSH_OPCODE(opcode) \
 | 
					
						
							|  |  |  |         ((opcode) == SETUP_FINALLY || \ | 
					
						
							|  |  |  |          (opcode) == SETUP_WITH || \ | 
					
						
							|  |  |  |          (opcode) == SETUP_CLEANUP) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define HAS_TARGET(opcode) \
 | 
					
						
							| 
									
										
										
										
											2023-06-15 00:14:22 +01:00
										 |  |  |         (OPCODE_HAS_JUMP(opcode) || IS_BLOCK_PUSH_OPCODE(opcode)) | 
					
						
							| 
									
										
										
										
											2023-03-31 18:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* opcodes that must be last in the basicblock */ | 
					
						
							|  |  |  | #define IS_TERMINATOR_OPCODE(opcode) \
 | 
					
						
							| 
									
										
										
										
											2023-06-15 00:14:22 +01:00
										 |  |  |         (OPCODE_HAS_JUMP(opcode) || IS_SCOPE_EXIT_OPCODE(opcode)) | 
					
						
							| 
									
										
										
										
											2023-03-31 18:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* opcodes which are not emitted in codegen stage, only by the assembler */ | 
					
						
							|  |  |  | #define IS_ASSEMBLER_OPCODE(opcode) \
 | 
					
						
							|  |  |  |         ((opcode) == JUMP_FORWARD || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_BACKWARD || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_BACKWARD_NO_INTERRUPT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_BACKWARDS_JUMP_OPCODE(opcode) \
 | 
					
						
							|  |  |  |         ((opcode) == JUMP_BACKWARD || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_BACKWARD_NO_INTERRUPT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_UNCONDITIONAL_JUMP_OPCODE(opcode) \
 | 
					
						
							|  |  |  |         ((opcode) == JUMP || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_NO_INTERRUPT || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_FORWARD || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_BACKWARD || \ | 
					
						
							|  |  |  |          (opcode) == JUMP_BACKWARD_NO_INTERRUPT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_SCOPE_EXIT_OPCODE(opcode) \
 | 
					
						
							|  |  |  |         ((opcode) == RETURN_VALUE || \ | 
					
						
							|  |  |  |          (opcode) == RETURN_CONST || \ | 
					
						
							|  |  |  |          (opcode) == RAISE_VARARGS || \ | 
					
						
							|  |  |  |          (opcode) == RERAISE) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define LOG_BITS_PER_INT 5
 | 
					
						
							|  |  |  | #define MASK_LOW_LOG_BITS 31
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int | 
					
						
							|  |  |  | is_bit_set_in_table(const uint32_t *table, int bitindex) { | 
					
						
							|  |  |  |     /* Is the relevant bit set in the relevant word? */ | 
					
						
							|  |  |  |     /* 512 bits fit into 9 32-bits words.
 | 
					
						
							|  |  |  |      * Word is indexed by (bitindex>>ln(size of int in bits)). | 
					
						
							|  |  |  |      * Bit within word is the low bits of bitindex. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (bitindex >= 0 && bitindex < 512) { | 
					
						
							|  |  |  |         uint32_t word = table[bitindex >> LOG_BITS_PER_INT]; | 
					
						
							|  |  |  |         return (word >> (bitindex & MASK_LOW_LOG_BITS)) & 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef LOG_BITS_PER_INT
 | 
					
						
							|  |  |  | #undef MASK_LOW_LOG_BITS
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 07:10:45 -07:00
										 |  |  | /* Flags used in the oparg for MAKE_FUNCTION */ | 
					
						
							|  |  |  | #define MAKE_FUNCTION_DEFAULTS    0x01
 | 
					
						
							|  |  |  | #define MAKE_FUNCTION_KWDEFAULTS  0x02
 | 
					
						
							|  |  |  | #define MAKE_FUNCTION_ANNOTATIONS 0x04
 | 
					
						
							|  |  |  | #define MAKE_FUNCTION_CLOSURE     0x08
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 18:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif /* !Py_INTERNAL_OPCODE_UTILS_H */
 |