Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 33822d0

Browse filesBrowse files
authored
gh-87092: move assembler related code from compile.c to assemble.c (#103277)
1 parent 78b763f commit 33822d0
Copy full SHA for 33822d0

10 files changed

+851
-749
lines changed

‎Include/internal/pycore_compile.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_compile.h
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,45 @@ extern int _PyAST_Optimize(
3333
struct _arena *arena,
3434
_PyASTOptimizeState *state);
3535

36+
37+
typedef struct {
38+
int i_opcode;
39+
int i_oparg;
40+
_PyCompilerSrcLocation i_loc;
41+
} _PyCompilerInstruction;
42+
43+
typedef struct {
44+
_PyCompilerInstruction *s_instrs;
45+
int s_allocated;
46+
int s_used;
47+
48+
int *s_labelmap; /* label id --> instr offset */
49+
int s_labelmap_size;
50+
int s_next_free_label; /* next free label id */
51+
} _PyCompile_InstructionSequence;
52+
53+
typedef struct {
54+
PyObject *u_name;
55+
PyObject *u_qualname; /* dot-separated qualified name (lazy) */
56+
57+
/* The following fields are dicts that map objects to
58+
the index of them in co_XXX. The index is used as
59+
the argument for opcodes that refer to those collections.
60+
*/
61+
PyObject *u_consts; /* all constants */
62+
PyObject *u_names; /* all names */
63+
PyObject *u_varnames; /* local variables */
64+
PyObject *u_cellvars; /* cell variables */
65+
PyObject *u_freevars; /* free variables */
66+
67+
Py_ssize_t u_argcount; /* number of arguments for block */
68+
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */
69+
Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */
70+
71+
int u_firstlineno; /* the first lineno of the block */
72+
} _PyCompile_CodeUnitMetadata;
73+
74+
3675
/* Utility for a number of growing arrays used in the compiler */
3776
int _PyCompile_EnsureArrayLargeEnough(
3877
int idx,

‎Include/internal/pycore_flowgraph.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_flowgraph.h
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern "C" {
99
#endif
1010

1111
#include "pycore_opcode_utils.h"
12+
#include "pycore_compile.h"
1213

1314
static const _PyCompilerSrcLocation NO_LOCATION = {-1, -1, -1, -1};
1415

@@ -33,7 +34,8 @@ typedef struct {
3334
typedef struct _PyCfgBasicblock_ {
3435
/* Each basicblock in a compilation unit is linked via b_list in the
3536
reverse order that the block are allocated. b_list points to the next
36-
block, not to be confused with b_next, which is next by control flow. */
37+
block in this list, not to be confused with b_next, which is next by
38+
control flow. */
3739
struct _PyCfgBasicblock_ *b_list;
3840
/* The label of this block if it is a jump target, -1 otherwise */
3941
_PyCfgJumpTargetLabel b_label;
@@ -91,10 +93,9 @@ void _PyCfgBuilder_Fini(_PyCfgBuilder *g);
9193

9294
_PyCfgInstruction* _PyCfg_BasicblockLastInstr(const _PyCfgBasicblock *b);
9395
int _PyCfg_OptimizeCodeUnit(_PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
94-
int code_flags, int nlocals, int nparams);
96+
int code_flags, int nlocals, int nparams, int firstlineno);
9597
int _PyCfg_Stackdepth(_PyCfgBasicblock *entryblock, int code_flags);
9698
void _PyCfg_ConvertExceptionHandlersToNops(_PyCfgBasicblock *entryblock);
97-
int _PyCfg_ResolveLineNumbers(_PyCfgBuilder *g, int firstlineno);
9899
int _PyCfg_ResolveJumps(_PyCfgBuilder *g);
99100
int _PyCfg_InstrSize(_PyCfgInstruction *instruction);
100101

@@ -110,6 +111,10 @@ basicblock_nofallthrough(const _PyCfgBasicblock *b) {
110111
#define BB_NO_FALLTHROUGH(B) (basicblock_nofallthrough(B))
111112
#define BB_HAS_FALLTHROUGH(B) (!basicblock_nofallthrough(B))
112113

114+
PyCodeObject *
115+
_PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *u, PyObject *const_cache,
116+
PyObject *consts, int maxdepth, _PyCfgBasicblock *entryblock,
117+
int nlocalsplus, int code_flags, PyObject *filename);
113118

114119
#ifdef __cplusplus
115120
}

‎Makefile.pre.in

Copy file name to clipboardExpand all lines: Makefile.pre.in
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,18 @@ PYTHON_OBJS= \
369369
Python/Python-ast.o \
370370
Python/Python-tokenize.o \
371371
Python/asdl.o \
372+
Python/assemble.o \
372373
Python/ast.o \
373374
Python/ast_opt.o \
374375
Python/ast_unparse.o \
375376
Python/bltinmodule.o \
376377
Python/ceval.o \
377-
Python/flowgraph.o \
378378
Python/codecs.o \
379379
Python/compile.o \
380380
Python/context.o \
381381
Python/dynamic_annotations.o \
382382
Python/errors.o \
383+
Python/flowgraph.o \
383384
Python/frame.o \
384385
Python/frozenmain.o \
385386
Python/future.o \

‎PCbuild/_freeze_module.vcxproj

Copy file name to clipboardExpand all lines: PCbuild/_freeze_module.vcxproj
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@
177177
<ClCompile Include="..\PC\winreg.c" />
178178
<ClCompile Include="..\Python\_warnings.c" />
179179
<ClCompile Include="..\Python\asdl.c" />
180+
<ClCompile Include="..\Python\assemble.c" />
180181
<ClCompile Include="..\Python\ast.c" />
181182
<ClCompile Include="..\Python\ast_opt.c" />
182183
<ClCompile Include="..\Python\ast_unparse.c" />
183184
<ClCompile Include="..\Python\bltinmodule.c" />
184185
<ClCompile Include="..\Python\bootstrap_hash.c" />
185186
<ClCompile Include="..\Python\ceval.c" />
186-
<ClCompile Include="..\Python\flowgraph.c" />
187187
<ClCompile Include="..\Python\codecs.c" />
188188
<ClCompile Include="..\Python\compile.c" />
189189
<ClCompile Include="..\Python\context.c" />
@@ -192,6 +192,7 @@
192192
<ClCompile Include="..\Python\dynload_win.c" />
193193
<ClCompile Include="..\Python\errors.c" />
194194
<ClCompile Include="..\Python\fileutils.c" />
195+
<ClCompile Include="..\Python\flowgraph.c" />
195196
<ClCompile Include="..\Python\formatter_unicode.c" />
196197
<ClCompile Include="..\Python\frame.c" />
197198
<ClCompile Include="..\Python\future.c" />

‎PCbuild/_freeze_module.vcxproj.filters

Copy file name to clipboardExpand all lines: PCbuild/_freeze_module.vcxproj.filters
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<ClCompile Include="..\Python\asdl.c">
2929
<Filter>Source Files</Filter>
3030
</ClCompile>
31+
<ClCompile Include="..\Python\assemble.c">
32+
<Filter>Source Files</Filter>
33+
</ClCompile>
3134
<ClCompile Include="..\Python\ast.c">
3235
<Filter>Source Files</Filter>
3336
</ClCompile>
@@ -76,9 +79,6 @@
7679
<ClCompile Include="..\Python\ceval.c">
7780
<Filter>Source Files</Filter>
7881
</ClCompile>
79-
<ClCompile Include="..\Python\flowgraph.c">
80-
<Filter>Source Files</Filter>
81-
</ClCompile>
8282
<ClCompile Include="..\Objects\classobject.c">
8383
<Filter>Source Files</Filter>
8484
</ClCompile>
@@ -142,6 +142,9 @@
142142
<ClCompile Include="..\Objects\floatobject.c">
143143
<Filter>Source Files</Filter>
144144
</ClCompile>
145+
<ClCompile Include="..\Python\flowgraph.c">
146+
<Filter>Source Files</Filter>
147+
</ClCompile>
145148
<ClCompile Include="..\Python\formatter_unicode.c">
146149
<Filter>Source Files</Filter>
147150
</ClCompile>

‎PCbuild/pythoncore.vcxproj

Copy file name to clipboardExpand all lines: PCbuild/pythoncore.vcxproj
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,20 +500,21 @@
500500
<ClCompile Include="..\Python\pyhash.c" />
501501
<ClCompile Include="..\Python\_warnings.c" />
502502
<ClCompile Include="..\Python\asdl.c" />
503+
<ClCompile Include="..\Python\assemble.c" />
503504
<ClCompile Include="..\Python\ast.c" />
504505
<ClCompile Include="..\Python\ast_opt.c" />
505506
<ClCompile Include="..\Python\ast_unparse.c" />
506507
<ClCompile Include="..\Python\bltinmodule.c" />
507508
<ClCompile Include="..\Python\bootstrap_hash.c" />
508509
<ClCompile Include="..\Python\ceval.c" />
509-
<ClCompile Include="..\Python\flowgraph.c" />
510510
<ClCompile Include="..\Python\codecs.c" />
511511
<ClCompile Include="..\Python\compile.c" />
512512
<ClCompile Include="..\Python\context.c" />
513513
<ClCompile Include="..\Python\dynamic_annotations.c" />
514514
<ClCompile Include="..\Python\dynload_win.c" />
515515
<ClCompile Include="..\Python\errors.c" />
516516
<ClCompile Include="..\Python\fileutils.c" />
517+
<ClCompile Include="..\Python\flowgraph.c" />
517518
<ClCompile Include="..\Python\formatter_unicode.c" />
518519
<ClCompile Include="..\Python\frame.c" />
519520
<ClCompile Include="..\Python\frozen.c" />

‎PCbuild/pythoncore.vcxproj.filters

Copy file name to clipboardExpand all lines: PCbuild/pythoncore.vcxproj.filters
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,9 @@
10941094
<ClCompile Include="..\Python\asdl.c">
10951095
<Filter>Python</Filter>
10961096
</ClCompile>
1097+
<ClCompile Include="..\Python\assemble.c">
1098+
<Filter>Python</Filter>
1099+
</ClCompile>
10971100
<ClCompile Include="..\Python\ast.c">
10981101
<Filter>Python</Filter>
10991102
</ClCompile>
@@ -1109,9 +1112,6 @@
11091112
<ClCompile Include="..\Python\ceval.c">
11101113
<Filter>Python</Filter>
11111114
</ClCompile>
1112-
<ClCompile Include="..\Python\flowgraph.c">
1113-
<Filter>Python</Filter>
1114-
</ClCompile>
11151115
<ClCompile Include="..\Python\codecs.c">
11161116
<Filter>Python</Filter>
11171117
</ClCompile>
@@ -1130,6 +1130,9 @@
11301130
<ClCompile Include="..\Python\fileutils.c">
11311131
<Filter>Python</Filter>
11321132
</ClCompile>
1133+
<ClCompile Include="..\Python\flowgraph.c">
1134+
<Filter>Python</Filter>
1135+
</ClCompile>
11331136
<ClCompile Include="..\Python\formatter_unicode.c">
11341137
<Filter>Python</Filter>
11351138
</ClCompile>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.