https://github.com/i3abghany/rustyc
A C compiler in Rust and LLVM.
https://github.com/i3abghany/rustyc
c compiler llvm x86-64
Last synced: 7 months ago
JSON representation
A C compiler in Rust and LLVM.
- Host: GitHub
- URL: https://github.com/i3abghany/rustyc
- Owner: i3abghany
- Created: 2023-09-02T23:55:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-02T23:48:46.000Z (almost 2 years ago)
- Last Synced: 2025-01-31T23:51:51.073Z (8 months ago)
- Topics: c, compiler, llvm, x86-64
- Language: Rust
- Homepage:
- Size: 93.8 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RustyC
RustyC is a compiler written in Rust that supports a subset of the
C programming language. It is capable of producing x86_64 native
assembly and LLVM IR.## Example Usage
An example of what RustyC can compile is shown below.
```c
// fib.cint fib_recursive(int n) {
if (n <= 1) return n;
return fib_recursive(n - 1) + fib_recursive(n - 2);
}int fib_iterative(int n) {
int a = 0;
int b = 1;
for (int i = 0; i < n; i = i + 1) {
int c = a;
a = b;
b = c + b;
}
return a;
}int main() {
return !(fib_recursive(10) == fib_iterative(10));
}
``````bash
$ cargo b --release
$ ./target/release/rustyc --helpUsage: rustyc.exe [OPTIONS] [INPUT_SOURCE_FILES]...
Arguments:
[INPUT_SOURCE_FILES]...Options:
-l, --emit-llvm
-c, --emit-object
-s, --emit-asm
-o, --exe-filename
-h, --help$ ./target/release/rustyc fib.c -o fib
$ ./fib; echo $?
0
```## Pre-requisites
- Rust 1.70.0 or later
- LLVM 15.0.x or later