Crates.io | air-mir |
lib.rs | air-mir |
version | 0.4.0 |
created_at | 2025-06-21 00:21:47.760243+00 |
updated_at | 2025-06-21 00:21:47.760243+00 |
description | Intermediate representation for the AirScript language |
homepage | |
repository | https://github.com/0xMiden/air-script |
max_upload_size | |
id | 1720399 |
size | 383,482 |
This crate contains the middle intermediate representation for AirScript, MIR
.
The purpose of the MIR
is to provide a representation of an AirScript program that allows for optimization and translation to AirIR
containing the AlgebraicGraph
.
Generate an MIR
from an AirScript AST (the output of the AirScript parser) using the new
method. The new
method will return a new MIR
or an Error
of type SemanticError
if it encounters any errors while processing the AST.
The new
method will first iterate through the source sections that contain declarations to build a symbol table with constants, trace columns, public inputs and periodic columns. It will return a SemanticError
if it encounters a duplicate, incorrect, or missing declaration. Once the symbol table is built, the constraints and intermediate variables in the boundary_constraints
and integrity_constraints
sections of the AST are processed. Finally, new
returns a Result containing the AirIR
or a SemanticError
.
Example usage:
// parse the source string to a Result containing the AST or an Error
let ast = parse(source.as_str()).expect("Parsing failed");
// Create the compilation pipeline needed to translate the AST to MIR
let pipeline = air_parser::transforms::ConstantPropagation::new(&diagnostics)
.chain(mir::passes::AstToMir::new(&diagnostics))
// process the AST to get a Result containing the MIR or a CompileError
let mir = pipeline.run(ast)
Although generation of an AirIR
uses a symbol table while processing the source AST, the internal representation only consists of the following:
AirIR
.main
).ConstraintRoot
for each trace segment (e.g. main), where ConstraintRoot
contains the node index in the graph where each of the constraint starts and the constraint domain which specifies the row(s) accessed by each of the constraints.This project is MIT licensed.