1 #ifndef Py_INTERNAL_INSTRUCTION_SEQUENCE_H 2 #define Py_INTERNAL_INSTRUCTION_SEQUENCE_H 3 4 #ifndef Py_BUILD_CORE 5 # error "this header requires Py_BUILD_CORE define" 6 #endif 7 8 #include "pycore_symtable.h" 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 15 typedef struct { 16 int h_label; 17 int h_startdepth; 18 int h_preserve_lasti; 19 } _PyExceptHandlerInfo; 20 21 typedef struct { 22 int i_opcode; 23 int i_oparg; 24 _Py_SourceLocation i_loc; 25 _PyExceptHandlerInfo i_except_handler_info; 26 27 /* Temporary fields, used by the assembler and in instr_sequence_to_cfg */ 28 int i_target; 29 int i_offset; 30 } _PyInstruction; 31 32 typedef struct instruction_sequence { 33 PyObject_HEAD 34 _PyInstruction *s_instrs; 35 int s_allocated; 36 int s_used; 37 38 int s_next_free_label; /* next free label id */ 39 40 /* Map of a label id to instruction offset (index into s_instrs). 41 * If s_labelmap is NULL, then each label id is the offset itself. 42 */ 43 int *s_labelmap; 44 int s_labelmap_size; 45 46 /* PyList of instruction sequences of nested functions */ 47 PyObject *s_nested; 48 } _PyInstructionSequence; 49 50 typedef struct { 51 int id; 52 } _PyJumpTargetLabel; 53 54 PyAPI_FUNC(PyObject*)_PyInstructionSequence_New(void); 55 56 int _PyInstructionSequence_UseLabel(_PyInstructionSequence *seq, int lbl); 57 int _PyInstructionSequence_Addop(_PyInstructionSequence *seq, 58 int opcode, int oparg, 59 _Py_SourceLocation loc); 60 _PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq); 61 int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq); 62 int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos, 63 int opcode, int oparg, _Py_SourceLocation loc); 64 int _PyInstructionSequence_AddNested(_PyInstructionSequence *seq, _PyInstructionSequence *nested); 65 void PyInstructionSequence_Fini(_PyInstructionSequence *seq); 66 67 extern PyTypeObject _PyInstructionSequence_Type; 68 #define _PyInstructionSequence_Check(v) Py_IS_TYPE((v), &_PyInstructionSequence_Type) 69 70 #ifdef __cplusplus 71 } 72 #endif 73 #endif /* !Py_INTERNAL_INSTRUCTION_SEQUENCE_H */ 74