Skip to content

luc-wallace/cluck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cluck

A compiler for a subset of C written in Haskell.

Inspired by MicroC

Generates LLVM IR, uses Clang as a backend.

Features

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

Resources used

C89 Draft

Writing a C Compiler - Nora Sandler

Functional Parsing - Computerphile

Megaparsec tutorial

Compiling a functional language to LLVM - Daniel J. Harvey

Micro C - Joseph Morag

Usage

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.

Options

-o - Specify output file

-A - Output AST

-H - Generate header file

-S - Output LLVM IR

Examples

Look in the examples folder for some supported programs.

About

A compiler for a subset of C made in Haskell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published