MCPcopy Index your code
hub / github.com/0xMiden/compiler

github.com/0xMiden/compiler @v0.9.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.0 ↗ · + Follow
10,755 symbols 43,879 edges 842 files 3,181 documented · 30%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Miden Compiler

[!IMPORTANT] This project is a work-in-progress, so if you encounter bugs or other things which are not covered in the issue tracker, there is a good chance we know about them, but please do report them anyway so we can ensure they are tracked publically as well.

This repository contains the Miden compiler, which can be used both as a compiler backend for existing languages that wish to target Miden Assembly using a standard SSA-based IR; or as means of compiling WebAssembly (Wasm) produced by another compiler to Miden Assembly.

This repo is broken into the following high-level components:

  • Miden HIR (high-level intermediate representation) and it's supporting crates; providing everything needed to build and compile IR for a program you want to emit Miden Assembly for.
  • The Wasm frontend; a library which can be used to convert a program compiled to .wasm to HIR
  • The midenc executable, which provides a command-line tool that provides a convenient way to compile Wasm or HIR modules/programs to Miden Assembly and test them.

[!TIP] We've published initial documentation in mdBook format for easier reading, also accessible in the docs directory. This documentation covers how to get started with the compiler, provides a couple guides for currently supported use cases, and contains appendices that go into detail about various design aspects of the toolchain.

Building

You'll need to have Rust installed. This repository pins the toolchain in rust-toolchain.toml at the repo root (currently a nightly channel); use rustup to install that exact channel after cloning so local builds match CI.

Additionally, you'll want to have cargo-make installed:

$ cargo install cargo-make

From there, you can build all of the tooling used for the compiler, including the compiler itself with:

$ cargo make

To build just the compiler:

$ cargo make midenc

Testing

To run the compiler test suite:

$ cargo make test

This will run all of the unit tests in the workspace, as well as all of our lit tests.

Debugging

Emitting internal sources/artifacts

  • MIDENC_EMIT: Environment-variable equivalent of --emit. Accepts the same KIND[=PATH] syntax (comma-delimited), where PATH is treated either as folder e.g. MIDENC_EMIT=ir=target/emit or file MIDENC_EMIT=hir=my_name.hir.
  • MIDENC_EMIT_MACRO_EXPAND[=<dir>]: When set, integration tests dump cargo expand output for Rust fixtures to <fixture>.expanded.rs files in <dir> (or the CWD if empty/1).

Docs

The documentation in the docs/external folder is built using Docusaurus and is automatically absorbed into the main miden-docs repository for the main documentation website. Changes to the next branch trigger an automated deployment workflow. The docs folder requires npm packages to be installed before building.

The docs/internal folder corresponds to internal docs, which are hosted using mdbook and Github Pages here: The Miden compiler. These md files are not exported to the main docs.

Packaging

TBD

Extension points exported contracts — how you extend this code

Eval (Interface)
This trait is intended to be implemented by any [midenc_hir::Op] that we wish to be able to evaluate via the [HirEvaluat [81 …
eval/src/eval.rs
WordValue (Interface)
A type that can be stored in (or loaded from) account storage. Storage slots and map items store a single [`Word`]. Imp [8 …
sdk/base/src/types/storage.rs
FromFeltRepr (Interface)
Trait for deserialization from felt memory representation. [7 implementers]
sdk/field-repr/repr/src/lib.rs
Stage (Interface)
This trait is implemented by a stage in the compiler [17 implementers]
midenc-compile/src/stage.rs
Tactic (Interface)
A [Tactic] implements an algorithm for solving operand movement constraints that adhere to a specific pattern or pattern [7 …
codegen/masm/src/opt/operands/tactics/mod.rs
LatticeAnchor (Interface)
An abstraction over lattice anchors. In classical data-flow analysis, lattice anchors represent positions in a program [14 …
hir-analysis/src/anchor.rs
Analysis (Interface)
The [Analysis] trait is used to define an analysis over some operation. Analyses must be default-constructible, and `Si [7 …
hir/src/pass/analysis.rs
Emitter (Interface)
The [Emitter] trait is used for controlling how diagnostics are displayed. An [Emitter] must produce a [Buffer] for use [5 …
midenc-session/src/emitter.rs

Core symbols most depended-on inside this repo

unwrap
called by 1922
midenc-session/src/flags/arg_matches.rs
borrow
called by 1342
hir/src/ir/entity.rs
expect
called by 951
hir/src/ir/parse/lexer.rs
map
called by 936
hir/src/ir/entity.rs
clone
called by 923
hir/src/ir/entity.rs
iter
called by 581
hir/src/constants.rs
span
called by 493
hir/src/ir/parse/operation.rs
as_value_ref
called by 489
hir/src/ir/value.rs

Shape

Method 6,032
Function 3,210
Class 1,080
Interface 225
Enum 208

Languages

Rust100%
TypeScript1%
Python1%

Modules by API surface

frontend/masm/src/tests.rs192 symbols
hir/src/adt/smalldeque.rs159 symbols
frontend/masm/src/lift.rs156 symbols
frontend/wasm/src/component/types/mod.rs133 symbols
hir/src/ir/operation.rs123 symbols
tests/integration/src/end_to_end/arithmetic.rs114 symbols
codegen/masm/src/emit/mod.rs101 symbols
hir/src/ir/block.rs96 symbols
frontend/wasm/src/code_translator/tests.rs92 symbols
hir/src/ir/parse/operation.rs90 symbols
hir/src/ir/entity.rs87 symbols
hir/src/ir/loops.rs84 symbols

For agents

$ claude mcp add compiler \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact