MIR: a strongly typed IR for lightweight JITs, with a C11 front end on top
A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
At a glance
- What is it?
- vnmakarov/mir is a C project that defines a Medium Internal Representation, a code generator for it, an interpreter, and a C11 compiler built on the same pieces. This piece covers the IR's type rules, how MIR code is created, and where the project's own disclaimer limits what you can rely on.
- Who is it for?
- MIR fits a language implementer who wants a small, typed IR with ready code generators for x86_64, aarch64, ppc64le, s390x and riscv64, and who is willing to read MIR.md first. It does not fit anyone who needs a tested guarantee on Windows or on any platform and workload outside the listed ones, because the disclaimer withholds that.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 23 days ago.
- What is it written in?
- Mainly C, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- vnmakarov/mir2,676 ★ · +16
| Repository | 2026-09-29 | 2026-11-15 |
|---|---|---|
| vnmakarov/mir | 2.7k | 2.7k |
16 Stars in the last 47 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Locals have only four types, and memory types are widened on load
MIR is a strongly typed IR that can represent machine 32-bit and 64-bit instructions of different architectures. The type system is deliberately narrow. Each local variable has a type that can only be a 64-bit integer, float, double, or long double. A local can also be bound to a particular target machine register.
The narrow part is the integer side. There is no 8-bit or 16-bit local. Narrower integers exist only as memory types: 8-, 16-, 32- and 64-bit signed or unsigned integers, plus float, double and long double. When an integer memory value is used, it is first expanded with sign or zero promotion to a 64-bit integer value.
For a frontend author the consequence is direct. If your source language has small integer types, your translator has to decide where to widen and where to narrow, because the IR will always compute in 64 bits on locals. That keeps the instruction set compact, and it moves the burden of small-integer semantics into whatever generates the MIR.
A memory operand carries type, displacement, base, index and scale
Instructions have an opcode and operands. An operand can be a local variable (or a function argument), an immediate, a memory operand, a label, or a reference. Immediates can be a 64-bit integer, float, double, or long double. Labels carry a name and are used by control flow instructions. A reference points to functions and declarations in the current module, in other MIR modules, or to C external functions and declarations.
The memory operand is the most structured one. It has a type, a displacement, a base and an index (both integer local variables), and an integer constant as the scale for the index. In the textual form of the sieve example this shows up as `u8:(flags, i)`, an unsigned 8-bit access to the array `flags` at index `i`.
The head of that textual file looks like this:
m_sieve: module
export sieve
sieve: func i32, i32:NThe same example shows how functions are written. The `func` line declares results first, and results have types but no names. Parameters always have names and come after the results. In `sieve: func i32, i32:N`, the first `i32` is the return type and `N` is the argument. A function may have more than one result, which is a difference from C that a C front end has to account for.
MIR can be built through an API or loaded from binary and text files
There are three ways to get MIR into the system. You can call the API, which provides functions for creating modules, functions, instructions, operands and so on. You can also read it from a MIR binary file or from a MIR text file. The text form is described as the best way to get a feel for the IR.
Structurally, MIR consists of modules. A module can contain functions plus some declarations and data. Each function has a signature with parameter and return types, local variables that include the function arguments, and instructions. In the sieve example, a module named `m_sieve` exports `sieve`, declares locals such as `i64:iter` and `i64:flags`, and uses `alloca flags, 819000` to reserve the 819000 flag bytes that the C version declares as `char flags[Size]`.
The detailed description of the IR and its API lives in MIR.md in the repository, and the brief overview is only a starting point. If you plan to emit MIR programmatically, MIR.md is the document to read before the first line of code.
Instruction families include hooks for interpreter-to-JIT switching and lazy versioning
The instruction set is grouped by purpose. Conversion instructions move between 32- and 64-bit signed and unsigned values and the float, double and long double types. Arithmetic covers addition, subtraction, multiplication, division and modulo. Logical instructions cover and, or, xor and shifts, and they work on 32- and 64-bit signed and unsigned values only. Comparison instructions also take float, double and long double.
Control flow has unconditional jump, jump on zero or non-zero, combined comparison and branch instructions that take a label, and a switch that jumps to one of several labels by an index given as the first operand. There is a label address instruction and an unconditional indirect jump that uses a previously taken label address. Function and procedural calls, plus return instructions that optionally return 32- or 64-bit integers, float, double or long double, round out the set.
Two families point at the intended use. Specialized light-weight call and return instructions are for fast switching from a threaded interpreter to JITted code and back. Property instructions generate specialized machine code when lazy basic block versioning is used. Both are aimed at dynamic language implementations rather than at a general ahead-of-time compiler.
The disclaimer withholds any warranty beyond the shipped tests and listed platforms
The README carries an explicit disclaimer: there is absolutely no warranty that the code will work for any tests except the ones given in the repository and on platforms other than x86_64 Linux/OSX, aarch64 Linux/OSX (Apple M1), and ppc64le, s390x and riscv64 Linux.
Read that sentence for what it excludes. Windows is not in the list of platforms. A continuous integration workflow named AMD64-Linux-OSX-Windows-test is linked from the badges, but the disclaimer wording is what the author commits to. Any platform not named, and any program outside the repository's own tests, is untested territory by the author's own statement.
The source tree matches the list. There is one generator file per architecture: mir-gen-x86_64.c, mir-gen-aarch64.c, mir-gen-ppc64.c, mir-gen-s390x.c and mir-gen-riscv64.c, alongside mir-gen-stub.c, and a HOW-TO-PORT-MIR.md for new targets. For a user the consequence is that adopting MIR on another architecture means writing a port, and on a listed one it means validating your own workload rather than assuming the tests cover it.
The C front end, converters and fuzzing scripts share the repository
MIR is more than the IR. The repository description calls it a lightweight JIT compiler based on MIR plus a C11 JIT compiler and interpreter based on MIR. The C front end lives in the c2mir directory, and there are separate directories named llvm2mir and mir2c. The core files are mir.c and mir.h for the IR, mir-gen.c for code generation, and mir-interp.c for the interpreter.
Testing material is visible at the top level: c-tests, c-benchmarks, adt-tests, mir-tests, and two scripts named csmith-c2m.sh and csmith-c2m-gcc.sh. Supporting headers such as mir-hash.h, mir-htab.h, mir-bitmap.h and mir-varr.h suggest the project carries its own small data structures, and CUSTOM-ALLOCATORS.md plus mir-alloc.h and mir-code-alloc.h point to pluggable allocation.
This breadth has one practical consequence. Because the C compiler is built on the IR, the project eats its own cooking: a C11 program exercises the same instruction set, generators and interpreter that you would use from a language of your own. The README links three blog posts from developers.redhat.com covering the project's motivation, the C2MIR compiler, and code specialization for dynamic language JITs.
Releases are sparse and the CRuby and MRuby work is only a plan
The repository is not archived, and its last push was on 2026-10-23. Tagged releases are far sparser: v1.0.0 on 2024-05-27, v0.1.2 on 2023-01-13 and v0.1.1 on 2021-12-20. That gap means master carries changes after the latest tag, so pinning to a release gives you older code than a checkout of master, and pinning to master gives you code with no version number to cite.
The goal statement is that the project provides a basis to implement fast and lightweight JITs. The language integration is worded as intent only: the plan is to try the MIR light-weight JIT first for a CRuby or MRuby implementation. That is a stated plan, not a shipped integration, so nobody should assume a Ruby runtime with MIR exists on the strength of the README.
Building is handled by CMakeLists.txt and GNUmakefile at the top level, with INSTALL.md in the tree. The build commands belong to that file, so read it for the options that match your platform before wiring MIR into a larger project.
Editorial conclusion
MIR fits a language implementer who wants a small, typed IR with ready code generators for x86_64, aarch64, ppc64le, s390x and riscv64, and who is willing to read MIR.md first. It does not fit anyone who needs a tested guarantee on Windows or on any platform and workload outside the listed ones, because the disclaimer withholds that. Before adopting it, run your own workload on your own target, and read INSTALL.md for the build steps, since the latest tagged release is from May 2024 while master has moved since.
Frequently asked questions
What is the purpose of a JIT compiler like MIR?
The MIR project goal is to provide a basis to implement fast and lightweight JITs. It also ships a C11 compiler and interpreter built on the same IR.
What is the difference between an interpreter and a JIT compiler in MIR?
MIR includes both an interpreter (mir-interp.c) and machine code generators for several architectures. Specialized light-weight call and return instructions exist for fast switching from a threaded interpreter to JITted code and back.
How does JIT work in MIR?
MIR is created through an API or loaded from a MIR binary or text file. The code generator in mir-gen.c, with one file per architecture, then produces machine code from it.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/vnmakarov-mir)Star history chart for your README
[](https://hysenlabs.com/projects/vnmakarov-mir)Was this useful?