Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-87092: move assembler related code from compile.c to assemble.c #103277

Merged
merged 10 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,45 @@ extern int _PyAST_Optimize(
struct _arena *arena,
_PyASTOptimizeState *state);


typedef struct {
int i_opcode;
int i_oparg;
_PyCompilerSrcLocation i_loc;
} _PyCompilerInstruction;

typedef struct {
_PyCompilerInstruction *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;

typedef struct {
PyObject *u_name;
PyObject *u_qualname; /* dot-separated qualified name (lazy) */

/* The following fields are dicts that map objects to
the index of them in co_XXX. The index is used as
the argument for opcodes that refer to those collections.
*/
PyObject *u_consts; /* all constants */
PyObject *u_names; /* all names */
PyObject *u_varnames; /* local variables */
PyObject *u_cellvars; /* cell variables */
PyObject *u_freevars; /* free variables */

Py_ssize_t u_argcount; /* number of arguments for block */
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */
Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */

int u_firstlineno; /* the first lineno of the block */
} _PyCompile_CodeUnitMetadata;


/* Utility for a number of growing arrays used in the compiler */
int _PyCompile_EnsureArrayLargeEnough(
int idx,
Expand Down
8 changes: 6 additions & 2 deletions Include/internal/pycore_flowgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
#endif

#include "pycore_opcode_utils.h"
#include "pycore_compile.h"

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

Expand Down Expand Up @@ -91,10 +92,9 @@ void _PyCfgBuilder_Fini(_PyCfgBuilder *g);

_PyCfgInstruction* _PyCfg_BasicblockLastInstr(const _PyCfgBasicblock *b);
int _PyCfg_OptimizeCodeUnit(_PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
int code_flags, int nlocals, int nparams);
int code_flags, int nlocals, int nparams, int firstlineno);
int _PyCfg_Stackdepth(_PyCfgBasicblock *entryblock, int code_flags);
void _PyCfg_ConvertExceptionHandlersToNops(_PyCfgBasicblock *entryblock);
int _PyCfg_ResolveLineNumbers(_PyCfgBuilder *g, int firstlineno);
int _PyCfg_ResolveJumps(_PyCfgBuilder *g);
int _PyCfg_InstrSize(_PyCfgInstruction *instruction);

Expand All @@ -110,6 +110,10 @@ basicblock_nofallthrough(const _PyCfgBasicblock *b) {
#define BB_NO_FALLTHROUGH(B) (basicblock_nofallthrough(B))
#define BB_HAS_FALLTHROUGH(B) (!basicblock_nofallthrough(B))

PyCodeObject *
_PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *u, PyObject *const_cache,
PyObject *consts, int maxdepth, _PyCfgBasicblock *entryblock,
int nlocalsplus, int code_flags, PyObject *filename);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,18 @@ PYTHON_OBJS= \
Python/Python-ast.o \
Python/Python-tokenize.o \
Python/asdl.o \
Python/assemble.o \
Python/ast.o \
Python/ast_opt.o \
Python/ast_unparse.o \
Python/bltinmodule.o \
Python/ceval.o \
Python/flowgraph.o \
Python/codecs.o \
Python/compile.o \
Python/context.o \
Python/dynamic_annotations.o \
Python/errors.o \
Python/flowgraph.o \
Python/frame.o \
Python/frozenmain.o \
Python/future.o \
Expand Down
3 changes: 2 additions & 1 deletion PCbuild/_freeze_module.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@
<ClCompile Include="..\PC\winreg.c" />
<ClCompile Include="..\Python\_warnings.c" />
<ClCompile Include="..\Python\asdl.c" />
<ClCompile Include="..\Python\assemble.c" />
<ClCompile Include="..\Python\ast.c" />
<ClCompile Include="..\Python\ast_opt.c" />
<ClCompile Include="..\Python\ast_unparse.c" />
<ClCompile Include="..\Python\bltinmodule.c" />
<ClCompile Include="..\Python\bootstrap_hash.c" />
<ClCompile Include="..\Python\ceval.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\codecs.c" />
<ClCompile Include="..\Python\compile.c" />
<ClCompile Include="..\Python\context.c" />
Expand All @@ -192,6 +192,7 @@
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
<ClCompile Include="..\Python\frame.c" />
<ClCompile Include="..\Python\future.c" />
Expand Down
9 changes: 6 additions & 3 deletions PCbuild/_freeze_module.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<ClCompile Include="..\Python\asdl.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\assemble.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\ast.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -76,9 +79,6 @@
<ClCompile Include="..\Python\ceval.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\flowgraph.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Objects\classobject.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -142,6 +142,9 @@
<ClCompile Include="..\Objects\floatobject.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\flowgraph.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\formatter_unicode.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
3 changes: 2 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -499,20 +499,21 @@
<ClCompile Include="..\Python\pyhash.c" />
<ClCompile Include="..\Python\_warnings.c" />
<ClCompile Include="..\Python\asdl.c" />
<ClCompile Include="..\Python\assemble.c" />
<ClCompile Include="..\Python\ast.c" />
<ClCompile Include="..\Python\ast_opt.c" />
<ClCompile Include="..\Python\ast_unparse.c" />
<ClCompile Include="..\Python\bltinmodule.c" />
<ClCompile Include="..\Python\bootstrap_hash.c" />
<ClCompile Include="..\Python\ceval.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\codecs.c" />
<ClCompile Include="..\Python\compile.c" />
<ClCompile Include="..\Python\context.c" />
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
<ClCompile Include="..\Python\frame.c" />
<ClCompile Include="..\Python\frozen.c" />
Expand Down
9 changes: 6 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@
<ClCompile Include="..\Python\asdl.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\assemble.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\ast.c">
<Filter>Python</Filter>
</ClCompile>
Expand All @@ -1106,9 +1109,6 @@
<ClCompile Include="..\Python\ceval.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\flowgraph.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\codecs.c">
<Filter>Python</Filter>
</ClCompile>
Expand All @@ -1127,6 +1127,9 @@
<ClCompile Include="..\Python\fileutils.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\flowgraph.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\formatter_unicode.c">
<Filter>Python</Filter>
</ClCompile>
Expand Down
Loading