summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-08-23 08:01:17 (GMT)
committerGitHub <noreply@github.com>2023-08-23 08:01:17 (GMT)
commit2dfbd4f36dd83f88f5df64c33612dd34eff256bb (patch)
treefca70758a85ee8f31122ec1f9cd882b425d5cf6b /Python/compile.c
parent79fdacc0059a3959074d2d9d054653eae1dcfe06 (diff)
downloadcpython-2dfbd4f36dd83f88f5df64c33612dd34eff256bb.zip
cpython-2dfbd4f36dd83f88f5df64c33612dd34eff256bb.tar.gz
cpython-2dfbd4f36dd83f88f5df64c33612dd34eff256bb.tar.bz2
gh-108113: Make it possible to optimize an AST (#108282)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 3260dba..4b2f70a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -557,6 +557,24 @@ _PyAST_Compile(mod_ty mod, PyObject *filename, PyCompilerFlags *pflags,
return co;
}
+int
+_PyCompile_AstOptimize(mod_ty mod, PyObject *filename, PyCompilerFlags *cf,
+ int optimize, PyArena *arena)
+{
+ PyFutureFeatures future;
+ if (!_PyFuture_FromAST(mod, filename, &future)) {
+ return -1;
+ }
+ int flags = future.ff_features | cf->cf_flags;
+ if (optimize == -1) {
+ optimize = _Py_GetConfig()->optimization_level;
+ }
+ if (!_PyAST_Optimize(mod, arena, optimize, flags)) {
+ return -1;
+ }
+ return 0;
+}
+
static void
compiler_free(struct compiler *c)
{