CLI reference¶
postpile is the command-line entry point of the POST Compiler (console script postpile = postpile.cli:main). It exposes four subcommands over the compilation pipeline:
| Command | Purpose |
|---|---|
check |
Report what a build would refuse, without building |
build |
Compile a POST Python file (and its POST imports) to native code |
backends |
List registered backends and their availability |
backend-info |
Show one backend's capabilities and tool status |
A subcommand is required. All subcommands accept -h / --help (ppc build --help prints the build flags below).
ppc check¶
Structurally checks each file against the POST Python subset (the same gate build runs first) and prints the violations with source context.
check accepts one or more FILE arguments. For each it reports the constructs the POST Python subset disqualifies and, for a file clean of those, what this compiler does not lower yet, which is what build would refuse. With --exe it checks each file as ppc build --exe would, as a whole script whose top-level statements are the entry point. It exits 0 when all files are clean and 1 otherwise (the total count is printed to stderr).
ppc build¶
Compiles the entry FILE and every POST module it imports through the selected backend, then links the objects into one native shared library (.so, or .dylib on macOS). A directory target builds its package entry: __post__.py if present, otherwise __init__.py.
Options¶
| Flag | Argument | Description |
|---|---|---|
--output, -o |
PATH |
Output artifact path. Defaults to <FILE> with the platform library suffix beside the source (or <name><EXT_SUFFIX> for --ext-module). |
--prefix |
DIR |
Install the libpp<name> layout under DIR: lib/lib<name>.so, include/<name>.h, share/postpile/<name>.json. Always emits the header and manifest. |
--ext-module |
(flag) | Build an importable CPython extension module (registers each public ufunc as a real numpy.ufunc, and exposes the other public functions as Python callables). Requires a backend with the ext_module capability; C only. |
--module-name |
NAME |
Artifact / importable module name. Defaults to the file stem, or the package directory's name when the entry is __init__.py / __post__.py. |
--emit-header |
(flag) | Also write the C ABI header next to the output as <output>.h. |
--emit-manifest |
(flag) | Also write the JSON export manifest next to the output as <output>.json. |
--search-path |
DIR |
Additional POST module source root for resolving imports. Repeatable. |
--backend |
{c,qbe,llvm} |
Code-generation backend. Default: c, or $POSTPILE_BACKEND (see precedence). |
--mode |
{debug,release,unchecked} |
Build mode (see Build modes). Default: debug, or $POSTPILE_MODE. |
--release / --debug |
(flag) | Shorthand for --mode release / --mode debug. |
--unchecked |
(flag) | With --release: drop the run-time checks too (--mode unchecked). |
--no-overflow-checks |
(flag) | Keep bounds checks and assertions but drop integer-overflow diagnosis (for code that relies on modular arithmetic). |
--grow-ints / --no-grow-ints |
(flag) | With --exe, int has CPython's width by default, growing past 64 bits in debug and release alike. --no-grow-ints keeps a 64-bit int, which a checked build stops on overflow and an --unchecked build wraps, and which costs less on integer loops over lists (about 1.7x in release, ADR 0075). A library or an extension is always 64 bits, since its caller would read a big value as a number; --grow-ints without --exe is refused. |
--cc |
CMD |
C compiler command. Default: cc. |
--cflags |
FLAG... |
Extra flags passed to both the compile and link steps. |
--keep-c |
(flag) | Keep the intermediate build directory (emitted .c / .ssa sources and objects), which is deleted by default. |
build prints the artifact path on stdout, followed by the header and/or manifest paths when those flags are set (--prefix prints all three). It exits 0 on success, 1 on a build error (subset violation, IR/ABI error, or toolchain failure), and 2 for a misused invocation: an unknown $POSTPILE_BACKEND, or combining --prefix with --ext-module.
--prefix and --ext-module are separate build targets
They cannot be combined. Build the extension with --output pointing into
the recipe's site-packages instead.
Examples¶
# Explicit output path
ppc build examples/gaussian.py -o build/gaussian.so
# Emit the stable C ABI header and JSON manifest alongside the library
ppc build src/lib.py --emit-header --emit-manifest
# Importable CPython extension module (C backend)
ppc build mypkg/ --ext-module --module-name mypkg
# Lower the scalar/array kernel subset through QBE
ppc build examples/blur.py --backend qbe
# Extra POST source root + a custom compiler and flags
ppc build src/app.py --search-path vendor/ --cc clang --cflags -O3 -march=native
# Packaging layout: lib/, include/, share/postpile/ under $PREFIX
ppc build src/lib.py --prefix "$PREFIX"
Build modes¶
ppc build defaults to a debug build, the mode that cannot silently disagree with CPython. --release (or --mode release) is python -O: assertions are not evaluated and every other check stays, so a release build stops wherever a debug build does. --release --unchecked (or --mode unchecked) drops the checks too: it continues where they would stop, so it computes CPython's answer only on the inputs a checked build has run to the end. The published benchmark numbers give both release builds. The mode also honours $POSTPILE_MODE, with --mode/--release/--debug taking precedence; --unchecked without --release is refused.
| Construct | Debug (default) | Release | Unchecked |
|---|---|---|---|
| Array subscript | per-axis bounds check on the normalized index | the same check | no check |
assert |
evaluated; a failure raises AssertionError |
not lowered, as python -O does |
not lowered |
Integer + - * ** // %, unary -, abs on a 64-bit int |
overflow diagnosed (the program aborts) | overflow diagnosed | wraps at the declared width |
range(a, b, step) with a runtime step |
traps if step is zero |
traps if step is zero |
no check |
Fixed-width cast (Int64(x)) of NaN or ±infinity |
reports and aborts | reports and aborts | returns 0 |
The build mode is a frontend parameter: no backend branches on it, so an unchecked artifact's IR is byte-identical to what it would have been without the modes existing. That invariant is what keeps a check from perturbing the QBE backend's loop optimizations in an unchecked build. Debug and release builds trap integer overflow; --unchecked builds let it wrap. That is postpile's answer to §4.1.1's requirement that a compiler document its overflow behaviour. See ADR-0002 for the full rationale and the measured cost (bounds checks are hoisted out of loops, so array code pays almost nothing).
ppc build kernels.py # debug: checked
ppc build kernels.py --release # release: python -O, still checked
ppc build kernels.py --release --unchecked # the checks dropped too
ppc build kernels.py --no-overflow-checks # debug, minus only the overflow diagnosis
ppc build --exe app.py # an int as wide as CPython's, every mode
ppc build --exe app.py --no-grow-ints # a 64-bit int: checked stops, unchecked wraps
ppc backends¶
Lists the registered backends with their availability on this machine, the source each emits, and their capabilities.
c available emits .c caps: complex, ext_module
llvm available emits .ll caps: (base)
qbe available emits .ssa caps: (base)
available means the backend's external tools are present: a C compiler for c; the qbe binary and a C compiler for qbe; llvmlite and a C compiler for llvm. Capabilities are drawn from complex, ext_module, and float16; (base) means none of those optional features (the scalar/array kernel subset the QBE and LLVM backends share).
ppc backend-info¶
Shows one backend's name, emitted source extension, availability, and the full capability triple.
Exits 2 if BACKEND is not a registered name.
Backend selection¶
The build backend is chosen at runtime with a fixed precedence:
- an explicit
--backend {c,qbe,llvm}on the command line; - otherwise the
POSTPILE_BACKENDenvironment variable; - otherwise the default,
c.
POSTPILE_BACKEND=qbe ppc build examples/gaussian.py # env selects qbe
ppc build examples/gaussian.py --backend c # flag overrides env
--backend is validated against the registered backends. An invalid POSTPILE_BACKEND is not caught by that validation, so build reports it explicitly and exits 2:
See the C, QBE, and LLVM backend pages for what each lowers, and the backend protocol for the registry.