๐Ÿ“ฆ huangsam / virtuc

A piece of C with LLVM ๐Ÿฐ

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching โš–๏ธ MIT License
clangcompilerllvmparserrust
๐Ÿ“ฅ Clone https://github.com/huangsam/virtuc.git
HTTPS git clone https://github.com/huangsam/virtuc.git
SSH git clone git@github.com:huangsam/virtuc.git
CLI gh repo clone huangsam/virtuc
Samuel Huang Samuel Huang Update terms in CI flow and README f425943 1 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ src
๐Ÿ“ tests
๐Ÿ“„ .gitignore
๐Ÿ“„ AGENTS.md
๐Ÿ“„ Cargo.lock
๐Ÿ“„ Cargo.toml
๐Ÿ“„ LICENSE
๐Ÿ“„ README.md
๐Ÿ“„ README.md

VirtuC

GitHub Actions Workflow Status License

A compiler for a subset of the C programming language, implemented in Rust.

VirtuC supports the E2E compilation from C source code to [LLVM IR] for native execution. The IR artifact is then compiled and linked using clang to produce a final executable.

Features

  • Lexing & Parsing: Tokenizes and parses C subset into AST using logos and nom.
  • Semantic Analysis: Type checking and symbol resolution.
  • Code Generation: Emits LLVM IR via inkwell and links with system libraries via clang.
  • CLI: Compiles to native executables.
  • C Interop: Supports extern declarations and #include <...> headers.

Supported C subset

  • Primitive types: int (64-bit), float (64-bit)
  • Variables and assignments
  • Arithmetic and comparison operators
  • Control flow: if-else, for loops
  • Functions with parameters and return values
  • Function calls

Getting started

Ensure you have Rust and LLVM installed. Then:

cargo install --path .

Once compiled, you can use the tool to compile C source files:

# Compile the source file
virtuc compile hello.c

# Run the generated executable
./hello.out