| 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 |
|
| 49 |
/* Code for creating annotations, spliced into the main sequence later */ |
| 50 |
struct instruction_sequence *s_annotations_code; |
| 51 |
} _PyInstructionSequence; |
| 52 |
|
| 53 |
typedef struct { |
| 54 |
int id; |
| 55 |
} _PyJumpTargetLabel; |
| 56 |
|
| 57 |
#define NO_LABEL ((const _PyJumpTargetLabel){-1}) |
| 58 |
|
| 59 |
#define SAME_JUMP_TARGET_LABEL(L1, L2) ((L1).id == (L2).id) |
| 60 |
#define IS_JUMP_TARGET_LABEL(L) (!SAME_JUMP_TARGET_LABEL((L), (NO_LABEL))) |
| 61 |
|
| 62 |
PyAPI_FUNC(PyObject*)_PyInstructionSequence_New(void); |
| 63 |
|
| 64 |
int _PyInstructionSequence_UseLabel(_PyInstructionSequence *seq, int lbl); |
| 65 |
int _PyInstructionSequence_Addop(_PyInstructionSequence *seq, |
| 66 |
int opcode, int oparg, |
| 67 |
_Py_SourceLocation loc); |
| 68 |
_PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq); |
| 69 |
int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq); |
| 70 |
int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos, |
| 71 |
int opcode, int oparg, _Py_SourceLocation loc); |
| 72 |
int _PyInstructionSequence_SetAnnotationsCode(_PyInstructionSequence *seq, |
| 73 |
_PyInstructionSequence *annotations); |
| 74 |
int _PyInstructionSequence_AddNested(_PyInstructionSequence *seq, _PyInstructionSequence *nested); |
| 75 |
void PyInstructionSequence_Fini(_PyInstructionSequence *seq); |
| 76 |
|
| 77 |
extern PyTypeObject _PyInstructionSequence_Type; |
| 78 |
#define _PyInstructionSequence_Check(v) Py_IS_TYPE((v), &_PyInstructionSequence_Type) |
| 79 |
|
| 80 |
#ifdef __cplusplus |
| 81 |
} |
| 82 |
#endif |
| 83 |
#endif /* !Py_INTERNAL_INSTRUCTION_SEQUENCE_H */ |