A compiler for a subset of C written in Haskell.
Inspired by MicroC
Generates LLVM IR, uses Clang as a backend.
Current:
- Variable and function declarations
- Return, if, for, while and do-while statements
- Expressions and precedence
- Number, char and float literals
- Binary and unary operators (most implemented)
- Detailed syntax errors
- Static analysis for bindings and types
- Code generation for expressions and functions
- Pointer types
- Type casts
Future:
- Arrays
- Structs
Writing a C Compiler - Nora Sandler
Functional Parsing - Computerphile
Compiling a functional language to LLVM - Daniel J. Harvey
Only compatible with GHC 8.8.
Requires LLVM 14 to be installed including Clang 14.
On Ubuntu:
sudo apt install llvm-14
ghcup install cabal
cabal build
Binary is located in ./dist-newstyle/build
./cluck <input file>.c
If no input file is provided, code can be entered directly via standard input.
Use Ctrl + D to submit once typed.
-o
- Specify output file
-A
- Output AST
-H
- Generate header file
-S
- Output LLVM IR
Look in the examples folder for some supported programs.