| 1 |
#ifndef Py_INTERNAL_COMPILE_H |
| 2 |
#define Py_INTERNAL_COMPILE_H |
| 3 |
#ifdef __cplusplus |
| 4 |
extern "C" { |
| 5 |
#endif |
| 6 |
|
| 7 |
#ifndef Py_BUILD_CORE |
| 8 |
# error "this header requires Py_BUILD_CORE define" |
| 9 |
#endif |
| 10 |
|
| 11 |
#include "pycore_symtable.h" // _Py_SourceLocation |
| 12 |
#include "pycore_instruction_sequence.h" |
| 13 |
|
| 14 |
struct _arena; // Type defined in pycore_pyarena.h |
| 15 |
struct _mod; // Type defined in pycore_ast.h |
| 16 |
|
| 17 |
// Export for 'test_peg_generator' shared extension |
| 18 |
PyAPI_FUNC(PyCodeObject*) _PyAST_Compile( |
| 19 |
struct _mod *mod, |
| 20 |
PyObject *filename, |
| 21 |
PyCompilerFlags *flags, |
| 22 |
int optimize, |
| 23 |
struct _arena *arena); |
| 24 |
|
| 25 |
/* AST optimizations */ |
| 26 |
extern int _PyCompile_AstOptimize( |
| 27 |
struct _mod *mod, |
| 28 |
PyObject *filename, |
| 29 |
PyCompilerFlags *flags, |
| 30 |
int optimize, |
| 31 |
struct _arena *arena); |
| 32 |
|
| 33 |
struct _Py_SourceLocation; |
| 34 |
|
| 35 |
extern int _PyAST_Optimize( |
| 36 |
struct _mod *, |
| 37 |
struct _arena *arena, |
| 38 |
int optimize, |
| 39 |
int ff_features); |
| 40 |
|
| 41 |
|
| 42 |
typedef struct { |
| 43 |
PyObject *u_name; |
| 44 |
PyObject *u_qualname; /* dot-separated qualified name (lazy) */ |
| 45 |
|
| 46 |
/* The following fields are dicts that map objects to |
| 47 |
the index of them in co_XXX. The index is used as |
| 48 |
the argument for opcodes that refer to those collections. |
| 49 |
*/ |
| 50 |
PyObject *u_consts; /* all constants */ |
| 51 |
PyObject *u_names; /* all names */ |
| 52 |
PyObject *u_varnames; /* local variables */ |
| 53 |
PyObject *u_cellvars; /* cell variables */ |
| 54 |
PyObject *u_freevars; /* free variables */ |
| 55 |
PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only |
| 56 |
temporarily within an inlined comprehension. When |
| 57 |
value is True, treat as fast-local. */ |
| 58 |
|
| 59 |
Py_ssize_t u_argcount; /* number of arguments for block */ |
| 60 |
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */ |
| 61 |
Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */ |
| 62 |
|
| 63 |
int u_firstlineno; /* the first lineno of the block */ |
| 64 |
} _PyCompile_CodeUnitMetadata; |
| 65 |
|
| 66 |
|
| 67 |
/* Utility for a number of growing arrays used in the compiler */ |
| 68 |
int _PyCompile_EnsureArrayLargeEnough( |
| 69 |
int idx, |
| 70 |
void **array, |
| 71 |
int *alloc, |
| 72 |
int default_alloc, |
| 73 |
size_t item_size); |
| 74 |
|
| 75 |
int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj); |
| 76 |
|
| 77 |
|
| 78 |
// Export for '_opcode' extension module |
| 79 |
PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); |
| 80 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); |
| 81 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); |
| 82 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode); |
| 83 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode); |
| 84 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode); |
| 85 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode); |
| 86 |
PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode); |
| 87 |
|
| 88 |
PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index); |
| 89 |
PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index); |
| 90 |
|
| 91 |
/* Access compiler internals for unit testing */ |
| 92 |
|
| 93 |
// Export for '_testinternalcapi' shared extension |
| 94 |
PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc); |
| 95 |
|
| 96 |
// Export for '_testinternalcapi' shared extension |
| 97 |
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen( |
| 98 |
PyObject *ast, |
| 99 |
PyObject *filename, |
| 100 |
PyCompilerFlags *flags, |
| 101 |
int optimize, |
| 102 |
int compile_mode); |
| 103 |
|
| 104 |
// Export for '_testinternalcapi' shared extension |
| 105 |
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg( |
| 106 |
PyObject *instructions, |
| 107 |
PyObject *consts, |
| 108 |
int nlocals); |
| 109 |
|
| 110 |
// Export for '_testinternalcapi' shared extension |
| 111 |
PyAPI_FUNC(PyCodeObject*) |
| 112 |
_PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename, |
| 113 |
PyObject *instructions); |
| 114 |
|
| 115 |
#ifdef __cplusplus |
| 116 |
} |
| 117 |
#endif |
| 118 |
#endif /* !Py_INTERNAL_COMPILE_H */ |