Skip to content

Inspect the Compilation Pipeline

How-to Guide2 min read
Edit page

This guide shows how to look inside the compiler while it processes a single source file: emitting intermediate representations, choosing backends, tuning codegen, and adjusting lint levels.

Every command below compiles a file named input.g. Add --with-stdlib when your file uses names such as println, Vec, Option, Result, String, or Box — the flag prepends the assembled standard library so those names resolve without explicit use statements:

Terminal
glyim input.g --with-stdlib --emit mir

The --emit flag selects the output artifact:

Terminal
glyim input.g --emit mir # MIR after lowering — useful for debugging lowering
glyim input.g --emit llvm-ir # LLVM IR from the LLVM backend
glyim input.g --emit asm # target assembly
glyim input.g --emit obj # native object file (default)
glyim input.g --emit exec -o hello # runnable executable
glyim input.g --emit cdylib # dynamic library, used for proc-macro crates

Write the artifact to a specific path with -o:

Terminal
glyim input.g --emit llvm-ir -o out.ll

The --backend flag selects between llvm (default) and bytecode. The bytecode backend emits compact stack-machine bytecode that the glyim-bytecode-vm crate executes — useful for testing and embedded execution:

Terminal
glyim input.g --backend bytecode --emit obj
Terminal
glyim input.g -O2 --lto thin # optimization level 2, thin LTO
glyim input.g --codegen-units 4 # partition into 4 codegen units
  • -O/--opt-level ranges from 0 (default) to 3.
  • --codegen-units defaults to the available parallelism capped at 16, mirroring rustc’s -C codegen-units policy.
  • --lto accepts off (default), fat, or thin. fat requires multi-CGU support, which is not yet implemented, and errors cleanly. thin requires the llvm-lto2 tool from the LLVM distribution the backend was built against.
Terminal
glyim input.g --target aarch64-unknown-linux-gnu

Override the system linker and pass extra flags when needed:

Terminal
glyim input.g --linker /path/to/ld --link-flags "-L/opt/lib -lmylib"

Editors and tooling consume diagnostics as JSON, one object per diagnostic:

Terminal
glyim input.g --error-format json

The default human format renders diagnostics with miette, including source snippets and labels.

Compile proc-macro dependency sources to host cdylibs first, then reference them with a comma-separated list:

Terminal
glyim proc_macro_dep.g --emit cdylib
glyim main.g --proc-macro-deps proc_macro_dep.g

The compiler currently ships two lints: unsafe_fn_call (alias unsafe) and unused_generic_params (alias unused_generics). Set their levels with repeatable flags:

Terminal
glyim input.g -D unsafe # promote to error
glyim input.g -A unsafe_fn_call # suppress
glyim input.g -W unused_generic_params # set back to warning (the default)
glyim -W help # list all available lints

-A allows (suppresses), -W warns (default), and -D denies, which aborts compilation at the pipeline’s error gate. See the lint reference for details.