vnmakarov/mir logo

vnmakarov/mir

Free

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR

FreeFree tier
Type
Open Source

About vnmakarov/mir

MIR (Medium Internal Representation) is an open-source, lightweight JIT compiler framework developed by Vladimir Makarov. It provides a strongly typed intermediate representation that can represent machine instructions for 32-bit and 64-bit architectures. The project includes a C11 JIT compiler and interpreter, a C-to-MIR compiler (c2mir), an LLVM-to-MIR converter (llvm2mir), and a MIR-to-C converter (mir2c). MIR is designed to be a basis for implementing fast and lightweight JIT compilers, with initial plans to target CRuby and MRuby. It currently supports x86_64, aarch64, ppc64le, s390x, and riscv64 platforms on Linux and macOS. The code is written in C and is available under the MIT license.

Key Features

Lightweight JIT compiler framework based on MIR (Medium Internal Representation)
Includes a C11 JIT compiler and interpreter
C2MIR compiler to convert C source code to MIR
LLVM2MIR converter to translate LLVM IR to MIR
MIR2C converter to output C code from MIR
Strongly typed IR supporting 32-bit and 64-bit machine instructions
Supports multiple architectures: x86_64, aarch64, ppc64le, s390x, riscv64
Planned integration with CRuby and MRuby for dynamic language JITs

Pros & Cons

Pros
  • Lightweight and fast JIT framework suitable for embedding
  • Open source under permissive MIT license
  • Supports multiple modern CPU architectures
  • Includes both an interpreter and a JIT compiler for flexibility
  • Well-documented with detailed MIR specification and API guides
  • Provides converters from C and LLVM IR, easing adoption
Cons
  • Limited platform support: only tested on x86_64, aarch64, ppc64le, s390x, riscv64 Linux/macOS
  • Early-stage project with disclaimer of no warranty and limited testing
  • Not widely adopted yet; community and ecosystem are small
  • Requires understanding of low-level IR and JIT concepts to use effectively

Best For

Building lightweight JIT compilers for dynamic programming languagesConverting C or LLVM IR to a portable intermediate representation for analysis or optimizationExperimental JIT implementation for Ruby implementations (CRuby, MRuby)Educational purposes for understanding JIT compilation and intermediate representations

FAQ

What is MIR?
MIR stands for Medium Internal Representation. It is a strongly typed intermediate representation designed to represent machine instructions for 32-bit and 64-bit architectures, providing a basis for implementing lightweight JIT compilers.
What architectures does MIR support?
MIR currently supports x86_64, aarch64 (including Apple M1), ppc64le, s390x, and riscv64 platforms, primarily on Linux and macOS.
Is MIR production-ready?
The project comes with a disclaimer that there is absolutely no warranty that the code will work for any tests except ones given, and only on the tested platforms. It is considered experimental and early-stage.
Can MIR be used with LLVM?
Yes, MIR includes an LLVM2MIR converter that translates LLVM intermediate representation into MIR, allowing interoperability with LLVM-based tools.