mirror of
https://github.com/python/cpython
synced 2026-09-29 09:40:29 +03:00
gh-117494: extract the Instruction Sequence data structure into a separate file (#117496)
This commit is contained in:
parent
060a96f1a9
commit
04697bcfaf
13 changed files with 283 additions and 224 deletions
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "pycore_symtable.h" // _Py_SourceLocation
|
||||
#include "pycore_instruction_sequence.h"
|
||||
|
||||
struct _arena; // Type defined in pycore_pyarena.h
|
||||
struct _mod; // Type defined in pycore_ast.h
|
||||
|
|
@ -37,38 +38,6 @@ extern int _PyAST_Optimize(
|
|||
int optimize,
|
||||
int ff_features);
|
||||
|
||||
typedef struct {
|
||||
int h_label;
|
||||
int h_startdepth;
|
||||
int h_preserve_lasti;
|
||||
} _PyCompile_ExceptHandlerInfo;
|
||||
|
||||
typedef struct {
|
||||
int i_opcode;
|
||||
int i_oparg;
|
||||
_Py_SourceLocation i_loc;
|
||||
_PyCompile_ExceptHandlerInfo i_except_handler_info;
|
||||
|
||||
/* Used by the assembler */
|
||||
int i_target;
|
||||
int i_offset;
|
||||
} _PyCompile_Instruction;
|
||||
|
||||
typedef struct {
|
||||
_PyCompile_Instruction *s_instrs;
|
||||
int s_allocated;
|
||||
int s_used;
|
||||
|
||||
int *s_labelmap; /* label id --> instr offset */
|
||||
int s_labelmap_size;
|
||||
int s_next_free_label; /* next free label id */
|
||||
} _PyCompile_InstructionSequence;
|
||||
|
||||
int _PyCompile_InstructionSequence_UseLabel(_PyCompile_InstructionSequence *seq, int lbl);
|
||||
int _PyCompile_InstructionSequence_Addop(_PyCompile_InstructionSequence *seq,
|
||||
int opcode, int oparg,
|
||||
_Py_SourceLocation loc);
|
||||
int _PyCompile_InstructionSequence_ApplyLabelMap(_PyCompile_InstructionSequence *seq);
|
||||
|
||||
typedef struct {
|
||||
PyObject *u_name;
|
||||
|
|
|
|||
|
|
@ -8,16 +8,13 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "pycore_opcode_utils.h"
|
||||
#include "pycore_compile.h"
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
} _PyCfgJumpTargetLabel;
|
||||
#include "pycore_instruction_sequence.h"
|
||||
#include "pycore_opcode_utils.h"
|
||||
|
||||
struct _PyCfgBuilder;
|
||||
|
||||
int _PyCfgBuilder_UseLabel(struct _PyCfgBuilder *g, _PyCfgJumpTargetLabel lbl);
|
||||
int _PyCfgBuilder_UseLabel(struct _PyCfgBuilder *g, _PyJumpTargetLabel lbl);
|
||||
int _PyCfgBuilder_Addop(struct _PyCfgBuilder *g, int opcode, int oparg, _Py_SourceLocation loc);
|
||||
|
||||
struct _PyCfgBuilder* _PyCfgBuilder_New(void);
|
||||
|
|
@ -27,14 +24,14 @@ int _PyCfgBuilder_CheckSize(struct _PyCfgBuilder* g);
|
|||
int _PyCfg_OptimizeCodeUnit(struct _PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
|
||||
int nlocals, int nparams, int firstlineno);
|
||||
|
||||
int _PyCfg_ToInstructionSequence(struct _PyCfgBuilder *g, _PyCompile_InstructionSequence *seq);
|
||||
int _PyCfg_ToInstructionSequence(struct _PyCfgBuilder *g, _PyInstructionSequence *seq);
|
||||
int _PyCfg_OptimizedCfgToInstructionSequence(struct _PyCfgBuilder *g, _PyCompile_CodeUnitMetadata *umd,
|
||||
int code_flags, int *stackdepth, int *nlocalsplus,
|
||||
_PyCompile_InstructionSequence *seq);
|
||||
_PyInstructionSequence *seq);
|
||||
|
||||
PyCodeObject *
|
||||
_PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *u, PyObject *const_cache,
|
||||
PyObject *consts, int maxdepth, _PyCompile_InstructionSequence *instrs,
|
||||
PyObject *consts, int maxdepth, _PyInstructionSequence *instrs,
|
||||
int nlocalsplus, int code_flags, PyObject *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
60
Include/internal/pycore_instruction_sequence.h
Normal file
60
Include/internal/pycore_instruction_sequence.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef Py_INTERNAL_INSTRUCTION_SEQUENCE_H
|
||||
#define Py_INTERNAL_INSTRUCTION_SEQUENCE_H
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int h_label;
|
||||
int h_startdepth;
|
||||
int h_preserve_lasti;
|
||||
} _PyExceptHandlerInfo;
|
||||
|
||||
typedef struct {
|
||||
int i_opcode;
|
||||
int i_oparg;
|
||||
_Py_SourceLocation i_loc;
|
||||
_PyExceptHandlerInfo i_except_handler_info;
|
||||
|
||||
/* Temporary fields, used by the assembler and in instr_sequence_to_cfg */
|
||||
int i_target;
|
||||
int i_offset;
|
||||
} _PyInstruction;
|
||||
|
||||
typedef struct {
|
||||
_PyInstruction *s_instrs;
|
||||
int s_allocated;
|
||||
int s_used;
|
||||
|
||||
int s_next_free_label; /* next free label id */
|
||||
/* Map of a label id to instruction offset (index into s_instrs).
|
||||
* If s_labelmap is NULL, then each label id is the offset itself.
|
||||
*/
|
||||
int *s_labelmap; /* label id --> instr offset */
|
||||
int s_labelmap_size;
|
||||
} _PyInstructionSequence;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
} _PyJumpTargetLabel;
|
||||
|
||||
int _PyInstructionSequence_UseLabel(_PyInstructionSequence *seq, int lbl);
|
||||
int _PyInstructionSequence_Addop(_PyInstructionSequence *seq,
|
||||
int opcode, int oparg,
|
||||
_Py_SourceLocation loc);
|
||||
_PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq);
|
||||
int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq);
|
||||
int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos,
|
||||
int opcode, int oparg, _Py_SourceLocation loc);
|
||||
void PyInstructionSequence_Fini(_PyInstructionSequence *seq);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_INTERNAL_INSTRUCTION_SEQUENCE_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue