Skip to content

Commit

Permalink
Add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefmoazzam committed Dec 10, 2024
1 parent 70ce2f4 commit 3e75565
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
I didn't figure out how to get started on this topic alone, this is all
following the great information provided by Nora Sandler on the topic of writing
a C compiler, I'd highly recommend checking out her [blog
series](https://norasandler.com/2017/11/29/Write-a-Compiler.html) and
[book](https://nostarch.com/writing-c-compiler)!

# How to run

For a C source code file `prog.c`, this can be compiled by running `cargo run
prog.c`:
```
> cat prog.c
int main() {
return 2;
}
> cargo run prog.c
> cat prog.s
.globl main
main:
pushq %rbp
movq %rsp, %rbp
subq $0, %rsp
movl $2, %eax
movq %rbp, %rsp
popq %rbp
ret
```

The output file stem (filename without extension) will be the same as the input
file. Ie, `test.c` would be compiled to `test.s`.

# What is supported

## Target architecture

This is only targeting x86-64.

## C language features

Currently, this only supports compiling C programs that use a *very* limited
subset of the C programing language features:
- a single (main) function
- a single return statement
- the return statement can contain nested applications of unary operators, but
the innermost operand must be a numerical literal

0 comments on commit 3e75565

Please sign in to comment.