Optimix is a high-performance, handcrafted compiler implementing modern optimization techniques found in industrial compilers like LLVM and GCC. It is built from scratch in C++17, featuring a custom 3-Address Code IR and Static Single Assignment (SSA) form.
- 3-Stage Architecture: Separation of Frontend (AST), Mid-end (IR), and Backend (Interpreter).
- Static Single Assignment (SSA): Implements variable versioning and dominance analysis for optimization.
- Memory Management: Supports Stack Allocation (
int arr[10]) and Heap Simulation for array storage. - Intrinsic I/O: Built-in
print()statement for runtime output and debugging. - Control Flow Graph (CFG): Lowers structured code (
while,if) into flat basic blocks with jump transitions. - Operator Precedence Parsing: Hand-written recursive descent parser handling complex mathematical expressions.
- Zero Dependencies: Built with pure C++ Standard Library (no Flex/Bison/LLVM deps).
- Lexer: Tokenizes source code (ignoring comments/whitespace).
- Parser: Builds an Abstract Syntax Tree (AST) using Operator Precedence.
- IR Builder: Lowers AST to Linear IR (3-Address Code).
- Optimizer:
- SSA Pass: Renames variables (
x->x_1,x_2) to enable data-flow analysis.
- SSA Pass: Renames variables (
- Interpreter: Virtual Machine execution of the generated IR.
You don't need to build from source! Download the latest binary for your OS:
- 🐧 Linux: Download
optimix - 🪟 Windows: Download
optimix.exe - 🍎 macOS: Download
optimix
- Download the compiler file above.
- Move it to a folder (e.g.,
Downloadsor your project folder). - Run it with your source code.
On Linux/Mac: Open Terminal:
# Give permission (only needed once)
chmod +x optimix
# Run it
./optimix compile examples/factorial.optxOn Windows: Open Command Prompt (cmd) or PowerShell:
# Run it
.\optimix.exe compile examples\factorial.optxIf you want to compile the compiler yourself (for development), you will need:
- C++ Compiler:
clang++org++(supporting C++17) - Git: To clone the repository
# Clone the repo
git clone https://github.com/AdityaPandey-DEV/Optimix-Compiler.git
cd optimix
# Compile the compiler
clang++ -std=c++17 -I include src/main.cpp src/lexer/Lexer.cpp src/parser/Parser.cpp src/codegen/Interpreter.cpp src/ir/IR.cpp src/ir/IRBuilder.cpp src/ir/SSA.cpp -o optimix
# Run an example
./optimix compile examples/factorial.optxint main() {
int n = 5;
int result = 1;
int i = 1;
// Complex loop with math
while (i < n + 1) {
result = result * i; // Multiplication binds tighter
i = i + 1;
}
return result;
}**Output**: `120`
## 📊 Comprehensive Example (`comprehensive.optx`)
```c
int main() {
int arr[10]; // Array Declaration
int i = 0;
// Fill array loop
while (i < 5) {
arr[i] = i * 10;
i = i + 1;
}
// Print loop
int j = 0;
while (j < 5) {
print(arr[j]); // Array Access & I/O
j = j + 1;
}
return 0;
}
Output:
0
10
20
30
40
Aditya Pandey Passionate about Systems Engineering and Compiler Design.