Ahmed Elmi
This project implements a MiniC compiler in four stages:
frontend/: lexing, parsing, AST construction, and semantic analysisir_builder/: AST to LLVM IRoptimizations/: LLVM IR optimization passesbackend/: LLVM IR to x86 32-bit assembly
g++flexbison- LLVM development tools for
ir_builder,optimizations, andbackend clang- Linux with
clang -m32for the full backend runtime tests
The LLVM-based Makefiles try these automatically:
/opt/homebrew/opt/llvm/bin/llvm-configllvm-configllvm-config-18llvm-config-17
From the project root:
makeThis builds:
frontend/parserir_builder/ir_builderoptimizations/optimizerbackend/backend
From the project root:
make testsor:
make test-allto run the full suite, or run the stage tests individually:
make test-parser
make test-semantic
make test-builder
make test-optimizations
make test-backendNotes:
test-backendruns full runtime comparisons only on Linux withclang -m32- On unsupported systems such as macOS,
test-backendprints a skip message instead of failing
./frontend/parser path/to/program.c./ir_builder/ir_builder ./tests/builder_tests/p1.c /tmp/p1.ll./optimizations/optimizer /tmp/p1.ll /tmp/p1_opt.llLocal-only optimization mode:
./optimizations/optimizer --local ./tests/optimizations/cfold_add.ll /tmp/cfold_add_opt.ll./backend/backend /tmp/p1_opt.ll /tmp/p1.sThe backend input is LLVM IR (.ll). The output is AT&T-style x86 32-bit assembly (.s).
./ir_builder/ir_builder ./tests/assembly_gen_tests/square.c /tmp/square.ll
./optimizations/optimizer /tmp/square.ll /tmp/square_opt.ll
./backend/backend /tmp/square_opt.ll /tmp/square.sOn Linux, you can assemble and run it with:
clang -m32 /tmp/square.s ./tests/assembly_gen_tests/main.c
./a.outfrontend/: lexer, parser, AST library, semantic analysisir_builder/: LLVM IR generation from the MiniC ASToptimizations/: local and global LLVM IR optimization passesbackend/: handwritten x86 code generation with local register allocationtests/: parser, semantic, builder, optimization, and assembly-generation tests
Each stage folder has its own README with:
- what that stage does
- how to build it directly
- how to run it manually
- how to test it with
make