| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 060a96f commit 04697bc
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ extern "C" { | |||
| 9 | 9 | #endif | |
| 10 | 10 | ||
| 11 | 11 | #include "pycore_symtable.h" // _Py_SourceLocation | |
| 12 | + #include "pycore_instruction_sequence.h" | ||
| 12 | 13 | ||
| 13 | 14 | struct _arena; // Type defined in pycore_pyarena.h | |
| 14 | 15 | struct _mod; // Type defined in pycore_ast.h | |
@@ -37,38 +38,6 @@ extern int _PyAST_Optimize( | |||
| 37 | 38 | int optimize, | |
| 38 | 39 | int ff_features); | |
| 39 | 40 | ||
| 40 | - typedef struct { | ||
| 41 | - int h_label; | ||
| 42 | - int h_startdepth; | ||
| 43 | - int h_preserve_lasti; | ||
| 44 | - } _PyCompile_ExceptHandlerInfo; | ||
| 45 | - | ||
| 46 | - typedef struct { | ||
| 47 | - int i_opcode; | ||
| 48 | - int i_oparg; | ||
| 49 | - _Py_SourceLocation i_loc; | ||
| 50 | - _PyCompile_ExceptHandlerInfo i_except_handler_info; | ||
| 51 | - | ||
| 52 | - /* Used by the assembler */ | ||
| 53 | - int i_target; | ||
| 54 | - int i_offset; | ||
| 55 | - } _PyCompile_Instruction; | ||
| 56 | - | ||
| 57 | - typedef struct { | ||
| 58 | - _PyCompile_Instruction *s_instrs; | ||
| 59 | - int s_allocated; | ||
| 60 | - int s_used; | ||
| 61 | - | ||
| 62 | - int *s_labelmap; /* label id --> instr offset */ | ||
| 63 | - int s_labelmap_size; | ||
| 64 | - int s_next_free_label; /* next free label id */ | ||
| 65 | - } _PyCompile_InstructionSequence; | ||
| 66 | - | ||
| 67 | - int _PyCompile_InstructionSequence_UseLabel(_PyCompile_InstructionSequence *seq, int lbl); | ||
| 68 | - int _PyCompile_InstructionSequence_Addop(_PyCompile_InstructionSequence *seq, | ||
| 69 | - int opcode, int oparg, | ||
| 70 | - _Py_SourceLocation loc); | ||
| 71 | - int _PyCompile_InstructionSequence_ApplyLabelMap(_PyCompile_InstructionSequence *seq); | ||
| 72 | 41 | ||
| 73 | 42 | typedef struct { | |
| 74 | 43 | PyObject *u_name; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,16 +8,13 @@ extern "C" { | |||
| 8 | 8 | # error "this header requires Py_BUILD_CORE define" | |
| 9 | 9 | #endif | |
| 10 | 10 | ||
| 11 | - #include "pycore_opcode_utils.h" | ||
| 12 | 11 | #include "pycore_compile.h" | |
| 13 | - | ||
| 14 | - typedef struct { | ||
| 15 | - int id; | ||
| 16 | - } _PyCfgJumpTargetLabel; | ||
| 12 | + #include "pycore_instruction_sequence.h" | ||
| 13 | + #include "pycore_opcode_utils.h" | ||
| 17 | 14 | ||
| 18 | 15 | struct _PyCfgBuilder; | |
| 19 | 16 | ||
| 20 | - int _PyCfgBuilder_UseLabel(struct _PyCfgBuilder *g, _PyCfgJumpTargetLabel lbl); | ||
| 17 | + int _PyCfgBuilder_UseLabel(struct _PyCfgBuilder *g, _PyJumpTargetLabel lbl); | ||
| 21 | 18 | int _PyCfgBuilder_Addop(struct _PyCfgBuilder *g, int opcode, int oparg, _Py_SourceLocation loc); | |
| 22 | 19 | ||
| 23 | 20 | struct _PyCfgBuilder* _PyCfgBuilder_New(void); | |
@@ -27,14 +24,14 @@ int _PyCfgBuilder_CheckSize(struct _PyCfgBuilder* g); | |||
| 27 | 24 | int _PyCfg_OptimizeCodeUnit(struct _PyCfgBuilder *g, PyObject *consts, PyObject *const_cache, | |
| 28 | 25 | int nlocals, int nparams, int firstlineno); | |
| 29 | 26 | ||
| 30 | - int _PyCfg_ToInstructionSequence(struct _PyCfgBuilder *g, _PyCompile_InstructionSequence *seq); | ||
| 27 | + int _PyCfg_ToInstructionSequence(struct _PyCfgBuilder *g, _PyInstructionSequence *seq); | ||
| 31 | 28 | int _PyCfg_OptimizedCfgToInstructionSequence(struct _PyCfgBuilder *g, _PyCompile_CodeUnitMetadata *umd, | |
| 32 | 29 | int code_flags, int *stackdepth, int *nlocalsplus, | |
| 33 | - _PyCompile_InstructionSequence *seq); | ||
| 30 | + _PyInstructionSequence *seq); | ||
| 34 | 31 | ||
| 35 | 32 | PyCodeObject * | |
| 36 | 33 | _PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *u, PyObject *const_cache, | |
| 37 | - PyObject *consts, int maxdepth, _PyCompile_InstructionSequence *instrs, | ||
| 34 | + PyObject *consts, int maxdepth, _PyInstructionSequence *instrs, | ||
| 38 | 35 | int nlocalsplus, int code_flags, PyObject *filename); | |
| 39 | 36 | ||
| 40 | 37 | #ifdef __cplusplus | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 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 | + #ifdef __cplusplus | ||
| 9 | + extern "C" { | ||
| 10 | + #endif | ||
| 11 | + | ||
| 12 | + typedef struct { | ||
| 13 | + int h_label; | ||
| 14 | + int h_startdepth; | ||
| 15 | + int h_preserve_lasti; | ||
| 16 | + } _PyExceptHandlerInfo; | ||
| 17 | + | ||
| 18 | + typedef struct { | ||
| 19 | + int i_opcode; | ||
| 20 | + int i_oparg; | ||
| 21 | + _Py_SourceLocation i_loc; | ||
| 22 | + _PyExceptHandlerInfo i_except_handler_info; | ||
| 23 | + | ||
| 24 | + /* Temporary fields, used by the assembler and in instr_sequence_to_cfg */ | ||
| 25 | + int i_target; | ||
| 26 | + int i_offset; | ||
| 27 | + } _PyInstruction; | ||
| 28 | + | ||
| 29 | + typedef struct { | ||
| 30 | + _PyInstruction *s_instrs; | ||
| 31 | + int s_allocated; | ||
| 32 | + int s_used; | ||
| 33 | + | ||
| 34 | + int s_next_free_label; /* next free label id */ | ||
| 35 | + /* Map of a label id to instruction offset (index into s_instrs). | ||
| 36 | + * If s_labelmap is NULL, then each label id is the offset itself. | ||
| 37 | + */ | ||
| 38 | + int *s_labelmap; /* label id --> instr offset */ | ||
| 39 | + int s_labelmap_size; | ||
| 40 | + } _PyInstructionSequence; | ||
| 41 | + | ||
| 42 | + typedef struct { | ||
| 43 | + int id; | ||
| 44 | + } _PyJumpTargetLabel; | ||
| 45 | + | ||
| 46 | + int _PyInstructionSequence_UseLabel(_PyInstructionSequence *seq, int lbl); | ||
| 47 | + int _PyInstructionSequence_Addop(_PyInstructionSequence *seq, | ||
| 48 | + int opcode, int oparg, | ||
| 49 | + _Py_SourceLocation loc); | ||
| 50 | + _PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq); | ||
| 51 | + int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq); | ||
| 52 | + int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos, | ||
| 53 | + int opcode, int oparg, _Py_SourceLocation loc); | ||
| 54 | + void PyInstructionSequence_Fini(_PyInstructionSequence *seq); | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + #ifdef __cplusplus | ||
| 58 | + } | ||
| 59 | + #endif | ||
| 60 | + #endif /* !Py_INTERNAL_INSTRUCTION_SEQUENCE_H */ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -442,6 +442,7 @@ PYTHON_OBJS= \ | |||
| 442 | 442 | Python/initconfig.o \ | |
| 443 | 443 | Python/interpconfig.o \ | |
| 444 | 444 | Python/instrumentation.o \ | |
| 445 | + Python/instruction_sequence.o \ | ||
| 445 | 446 | Python/intrinsics.o \ | |
| 446 | 447 | Python/jit.o \ | |
| 447 | 448 | Python/legacy_tracing.o \ | |
@@ -1170,6 +1171,7 @@ PYTHON_HEADERS= \ | |||
| 1170 | 1171 | $(srcdir)/Include/internal/pycore_importdl.h \ | |
| 1171 | 1172 | $(srcdir)/Include/internal/pycore_initconfig.h \ | |
| 1172 | 1173 | $(srcdir)/Include/internal/pycore_instruments.h \ | |
| 1174 | + $(srcdir)/Include/internal/pycore_instruction_sequence.h \ | ||
| 1173 | 1175 | $(srcdir)/Include/internal/pycore_interp.h \ | |
| 1174 | 1176 | $(srcdir)/Include/internal/pycore_intrinsics.h \ | |
| 1175 | 1177 | $(srcdir)/Include/internal/pycore_jit.h \ | |
@@ -1800,7 +1802,7 @@ regen-sre: | |||
| 1800 | 1802 | $(srcdir)/Modules/_sre/sre_constants.h \ | |
| 1801 | 1803 | $(srcdir)/Modules/_sre/sre_targets.h | |
| 1802 | 1804 | ||
| 1803 | - Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/internal/pycore_ast.h | ||
| 1805 | + Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/internal/pycore_ast.h $(srcdir)/Include/internal/pycore_ast.h | ||
| 1804 | 1806 | ||
| 1805 | 1807 | Python/getplatform.o: $(srcdir)/Python/getplatform.c | |
| 1806 | 1808 | $(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c | |
@@ -1935,8 +1937,12 @@ regen-uop-metadata: | |||
| 1935 | 1937 | $(srcdir)/Include/internal/pycore_uop_metadata.h.new $(srcdir)/Python/bytecodes.c | |
| 1936 | 1938 | $(UPDATE_FILE) $(srcdir)/Include/internal/pycore_uop_metadata.h $(srcdir)/Include/internal/pycore_uop_metadata.h.new | |
| 1937 | 1939 | ||
| 1938 | - | ||
| 1939 | - Python/compile.o: $(srcdir)/Include/internal/pycore_opcode_metadata.h | ||
| 1940 | + Python/compile.o Python/assemble.o Python/flowgraph.o Python/instruction_sequence.o: \ | ||
| 1941 | + $(srcdir)/Include/internal/pycore_compile.h \ | ||
| 1942 | + $(srcdir)/Include/internal/pycore_flowgraph.h \ | ||
| 1943 | + $(srcdir)/Include/internal/pycore_instruction_sequence.h \ | ||
| 1944 | + $(srcdir)/Include/internal/pycore_opcode_metadata.h \ | ||
| 1945 | + $(srcdir)/Include/internal/pycore_opcode_utils.h | ||
| 1940 | 1946 | ||
| 1941 | 1947 | Python/ceval.o: \ | |
| 1942 | 1948 | $(srcdir)/Python/ceval_macros.h \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Refactored the instruction sequence data structure out of compile.c into instruction_sequence.c. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -222,6 +222,7 @@ | |||
| 222 | 222 | <ClCompile Include="..\Python\import.c" /> | |
| 223 | 223 | <ClCompile Include="..\Python\importdl.c" /> | |
| 224 | 224 | <ClCompile Include="..\Python\initconfig.c" /> | |
| 225 | + <ClCompile Include="..\Python\instruction_sequence.c" /> | ||
| 225 | 226 | <ClCompile Include="..\Python\interpconfig.c" /> | |
| 226 | 227 | <ClCompile Include="..\Python\intrinsics.c" /> | |
| 227 | 228 | <ClCompile Include="..\Python\instrumentation.c" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,6 +229,7 @@ | |||
| 229 | 229 | <ClCompile Include="..\Python\initconfig.c"> | |
| 230 | 230 | <Filter>Source Files</Filter> | |
| 231 | 231 | </ClCompile> | |
| 232 | + <ClCompile Include="..\Python\instruction_sequence.c"> | ||
| 232 | 233 | <ClCompile Include="..\Python\interpconfig.c"> | |
| 233 | 234 | <Filter>Source Files</Filter> | |
| 234 | 235 | </ClCompile> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -248,6 +248,7 @@ | |||
| 248 | 248 | <ClInclude Include="..\Include\internal\pycore_import.h" /> | |
| 249 | 249 | <ClInclude Include="..\Include\internal\pycore_importdl.h" /> | |
| 250 | 250 | <ClInclude Include="..\Include\internal\pycore_initconfig.h" /> | |
| 251 | + <ClInclude Include="..\Include\internal\pycore_instruction_sequence.h" /> | ||
| 251 | 252 | <ClInclude Include="..\Include\internal\pycore_interp.h" /> | |
| 252 | 253 | <ClInclude Include="..\Include\internal\pycore_intrinsics.h" /> | |
| 253 | 254 | <ClInclude Include="..\Include\internal\pycore_jit.h" /> | |
@@ -590,6 +591,7 @@ | |||
| 590 | 591 | <ClCompile Include="..\Python\initconfig.c" /> | |
| 591 | 592 | <ClCompile Include="..\Python\interpconfig.c" /> | |
| 592 | 593 | <ClCompile Include="..\Python\intrinsics.c" /> | |
| 594 | + <ClCompile Include="..\Python\instruction_sequence.c" /> | ||
| 593 | 595 | <ClCompile Include="..\Python\instrumentation.c" /> | |
| 594 | 596 | <ClCompile Include="..\Python\jit.c" /> | |
| 595 | 597 | <ClCompile Include="..\Python\legacy_tracing.c" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -663,6 +663,9 @@ | |||
| 663 | 663 | <ClInclude Include="..\Include\internal\pycore_initconfig.h"> | |
| 664 | 664 | <Filter>Include\internal</Filter> | |
| 665 | 665 | </ClInclude> | |
| 666 | + <ClInclude Include="..\Include\internal\pycore_instruction_sequence.h"> | ||
| 667 | + <Filter>Include\internal</Filter> | ||
| 668 | + </ClInclude> | ||
| 666 | 669 | <ClInclude Include="..\Include\internal\pycore_interp.h"> | |
| 667 | 670 | <Filter>Include\internal</Filter> | |
| 668 | 671 | </ClInclude> | |
@@ -1349,6 +1352,9 @@ | |||
| 1349 | 1352 | <ClCompile Include="..\Python\intrinsics.c"> | |
| 1350 | 1353 | <Filter>Source Files</Filter> | |
| 1351 | 1354 | </ClCompile> | |
| 1355 | + <ClCompile Include="..\Python\instruction_sequence.c"> | ||
| 1356 | + <Filter>Source Files</Filter> | ||
| 1357 | + </ClCompile> | ||
| 1352 | 1358 | <ClCompile Include="..\Python\instrumentation.c"> | |
| 1353 | 1359 | <Filter>Source Files</Filter> | |
| 1354 | 1360 | </ClCompile> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | #include "Python.h" | |
| 4 | 4 | #include "pycore_code.h" // write_location_entry_start() | |
| 5 | 5 | #include "pycore_compile.h" | |
| 6 | + #include "pycore_instruction_sequence.h" | ||
| 6 | 7 | #include "pycore_opcode_utils.h" // IS_BACKWARDS_JUMP_OPCODE | |
| 7 | 8 | #include "pycore_opcode_metadata.h" // is_pseudo_target, _PyOpcode_Caches | |
| 8 | 9 | #include "pycore_symtable.h" // _Py_SourceLocation | |
@@ -23,8 +24,8 @@ | |||
| 23 | 24 | } | |
| 24 | 25 | ||
| 25 | 26 | typedef _Py_SourceLocation location; | |
| 26 | - typedef _PyCompile_Instruction instruction; | ||
| 27 | - typedef _PyCompile_InstructionSequence instr_sequence; | ||
| 27 | + typedef _PyInstruction instruction; | ||
| 28 | + typedef _PyInstructionSequence instr_sequence; | ||
| 28 | 29 | ||
| 29 | 30 | static inline bool | |
| 30 | 31 | same_location(location a, location b) | |
@@ -132,7 +133,7 @@ assemble_emit_exception_table_item(struct assembler *a, int value, int msb) | |||
| 132 | 133 | static int | |
| 133 | 134 | assemble_emit_exception_table_entry(struct assembler *a, int start, int end, | |
| 134 | 135 | int handler_offset, | |
| 135 | - _PyCompile_ExceptHandlerInfo *handler) | ||
| 136 | + _PyExceptHandlerInfo *handler) | ||
| 136 | 137 | { | |
| 137 | 138 | Py_ssize_t len = PyBytes_GET_SIZE(a->a_except_table); | |
| 138 | 139 | if (a->a_except_table_off + MAX_SIZE_OF_ENTRY >= len) { | |
@@ -158,7 +159,7 @@ static int | |||
| 158 | 159 | assemble_exception_table(struct assembler *a, instr_sequence *instrs) | |
| 159 | 160 | { | |
| 160 | 161 | int ioffset = 0; | |
| 161 | - _PyCompile_ExceptHandlerInfo handler; | ||
| 162 | + _PyExceptHandlerInfo handler; | ||
| 162 | 163 | handler.h_label = -1; | |
| 163 | 164 | handler.h_startdepth = -1; | |
| 164 | 165 | handler.h_preserve_lasti = -1; | |
@@ -736,8 +737,7 @@ _PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *umd, PyObject *const_cac | |||
| 736 | 737 | PyObject *consts, int maxdepth, instr_sequence *instrs, | |
| 737 | 738 | int nlocalsplus, int code_flags, PyObject *filename) | |
| 738 | 739 | { | |
| 739 | - | ||
| 740 | - if (_PyCompile_InstructionSequence_ApplyLabelMap(instrs) < 0) { | ||
| 740 | + if (_PyInstructionSequence_ApplyLabelMap(instrs) < 0) { | ||
| 741 | 741 | return NULL; | |
| 742 | 742 | } | |
| 743 | 743 | if (resolve_unconditional_jumps(instrs) < 0) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments