Skip to content
/ jankcc Public

A WIP minimal C Compiler written in Rust 🦀

Notifications You must be signed in to change notification settings

Iquiji/jankcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

      _             _       ____ ____ 
     | | __ _ _ __ | | __  / ___/ ___|
  _  | |/ _` | '_ \| |/ / | |  | |    
 | |_| | (_| | | | |   <  | |__| |___ 
  \___/ \__,_|_| |_|_|\_\  \____\____|

A WIP minimal hobby C Compiler written in Rust :]


Usage:


Features:

  • Preproccessor? (Put on Halt for now) ❌
    • #include ❌
    • #ifndef ❌
    • #if ❌
    • ... ❌
  • Lexer ✔️
    • Allow Hex Numbers & Co. ⭕
    • Sensible Error Generation ⭕
    • Fix Column Number Generation ⭕
  • Parser ✔️
    • Expresions ✔️
    • Type Names ✔️
    • Declarations ✔️
    • Statements ✔️
    • Typedef Check -> Context dependent Part ✔️
    • Full Parse for subset? of C11 Standard ⚠️
    • Error Continuation ⭕
  • Enviroment Builder ⚠️
    • Symbol Table extraction ⚠️
    • Type Checking on AST ☢️ <- Needed to Continue on Translating Expressions ;)
    • Constant Expression Runner ⭕
    • MIR generation ⚠️
  • MIR to cranelift backend ⚠️
  • Custom MIR codegen backend ⭕
    • Conversion to SSA ⭕
    • SSA optimisier ⭕
    • Register Allocator ⭕
    • Code Generation from SSA ⭕

Implementation Details:

Lexer:

  • Only Integer/Float Numbers ([0-9+(.0-9*)?])

Parser:

  • Handwritten Recursive Descent Parser (Predictive: No Backtracking)
  • Only minimally tested, check src/parser/tests/ for tests

Enviroment Builder:

  • Early Work started, extremely unstable API and many features missing
  • no Tag completion for structs
  • no Type Checking, Number inherintly int, and no casting

MIR:

  • limited Instruction Pool
  • Block System still heavily WIP and needs to be reworked

MIR to Cranelift:

  • minimal example works :)
  • to see more working examples look at the integration test C-Files :)
  • only 1 kind of signature to a function like printf that has varargs is supported :/
  • more will come as MIR is developed further ;)
  • Current Limitations:

    • only if statement and recursion semi-working
    • no Arrays, Structs, Unions, Enums

About

A WIP minimal C Compiler written in Rust 🦀

Topics

Resources

Stars

Watchers

Forks