Zirium
Zirium is a Rust library and command-line tool for reading, inspecting, editing, and writing textual MLIR, with typed Python bindings. It works without linking LLVM. The parser preserves the original bytes, including comments, whitespace, malformed syntax, and invalid UTF-8. A separate semantic representation supports verification and structural edits.
Version 0.0.12 is experimental. It targets MLIR 22.1 textual syntax and supports selected custom dialect forms. The API may change without a migration path; bytecode and ODS/TableGen loading are unsupported.
Installation
Install the Python package with:
Published wheels cover CPython 3.11 through 3.14 on Linux x86_64 and macOS arm64. Wheels are specific to each CPython version. Other platforms require a local source build and are unsupported.
Rust builds require Rust 1.88 or newer. From a source checkout, install the CLI with:
The Python wheel does not include the CLI. The getting-started guide covers Rust usage and building the Python extension locally.
Command-line utility
The zirium binary queries and edits textual MLIR. Pass the query first,
followed by any input files. With no input files, it reads from standard input.
For example, this selects every arith.addi operation in input.mlir:
The query language reference lists every predicate and pipeline stage. The CLI examples show complete queries, dependency slices, and edits.
You can also run the binary from a source checkout with Cargo:
Python example
=
=
assert ==
=
=
=
A File owns the original bytes, tokens, concrete syntax tree (CST), and syntax
diagnostics. A Document owns resolved semantic data. Keeping them separate lets
you inspect malformed source without requiring a valid semantic model, and edit
semantic structure without manipulating syntax nodes.
Output modes
Zirium has three output paths, each with a different contract:
| Output | Source object | Contract |
|---|---|---|
| Original | Parsed file | Reproduces the input bytes exactly. |
| Canonical | Semantic document | Emits deterministic generic MLIR from semantic storage. |
| Preserving | Hybrid semantic document | Copies unchanged source and regenerates edited operations or blocks. |
Canonical output normalizes formatting and SSA names and does not preserve comments or aliases. Use original output to reproduce the input, or hybrid retention when edits should preserve unrelated source text.
Dialect support
Generic quoted operations are handled without a dialect registry. Unknown dialect types and attributes keep their balanced bodies as opaque values.
The baseline registry covers a small set of Builtin, Func, Arith, and CF operations. Bundled presets expose selected custom forms from other dialects for structural queries. Unsupported forms use best-effort recovery; presets do not implement full dialect verification or execution.
The custom-format guide explains registry configuration, operation shapes, and use from Rust, Python, and the CLI. The preset reference groups the available dialects and links to their exact registry definitions.
The corpus notes
describe how syntax compatibility is checked against llvmorg-22.1.0.
Repository layout
crates/zirium/ Core Rust library
crates/zirium-python/ PyO3 extension module
python/zirium/ Python package and type declarations
python/tests/ Python API tests
tests/corpus/ Versioned MLIR compatibility corpus
docs/ Usage, compatibility, and architecture notes
fuzz/ Lexer and parser fuzz targets
The architecture notes include the syntax representation baseline and processing benchmarks.
Development
Run the Rust workspace tests from the repository root:
The compatibility guide lists the full CI checks, supported toolchains, and wheel checks. The getting-started guide covers Python development, and the release guide describes packaging and publication.
License
Zirium's original code is available under the MIT or Apache 2.0 license. Some MLIR-derived or adapted test material carries the source attribution and license notices recorded in the corpus manifest.
Release notes are recorded in the changelog.