Skip to content

BhuvanB404/C-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boop Compiler

Boop is a small C-like compiler that tokenizes source code, builds an AST, and emits LLVM IR. The project is intentionally simple right now. The goal seems to be keeping the pipeline easy to read while still using LLVM for the backend.

Current functionality

  • Tokenizer, parser, and AST construction
  • LLVM IR code generation
  • Writes IR to a .ll file or prints it with -emit-llvm
  • Supported language pieces:
    • integer literals and identifiers
    • local declarations with auto
    • extern declarations for callable functions
    • assignment statements
    • function calls
    • return
    • control flow with if, else, and while
    • arithmetic, comparison, logical, and shift operators
    • builtin putnum support in the LLVM backend

Repository layout

  • include/ public headers for tokens, parser, AST, and codegen
  • src/ compiler implementation
  • tests/ small source files used for checking behavior
  • Clover/ a separate compiler project in the same repository

Build

Build with the provided Makefile:

make

This produces the compiler binary in the project root.

Usage

Compile a source file and write LLVM IR to a file:

./compiler tests/test_add.bcc

Print LLVM IR directly to stdout:

./compiler tests/test_add.bcc -emit-llvm

If you write to a .ll file, you can turn it into an executable with clang:

clang test_add.ll -o test_add

Example

main() {
    auto x, y;
    x = 10;
    y = 20;

    if (x < y) {
        putnum(x);
    }

    return(0);
}

Notes

  • All values are currently treated as i64 in the LLVM backend
  • Top-level globals are parsed, but they are currently lowered as per-function stack slots
  • The parser is still small and does not handle a full C-style language

License

MIT. See LICENCE.

About

a simple c++ compiler written with the goal of IR optimization testing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors