r/Compilers • u/milcsu09 • Jul 10 '26
My first big compiler project; without a backend!
o7 everybody! This is my first post on Reddit, so sorry for technical issues :)
I'm a self-taught high school student. Last year's October I got motivated to create a compiler in C99.
Here's the link: https://github.com/milcsu09/compiler-x86_64
I highly recommend looking into examples/ and euler/ to see the language in use. The README is extremely sparse, but I think the project is simple enough to be undestood by anyone :)
The motivation mostly came from the GitHub repository "A Compiler Writing Journey" ( https://github.com/DoctorWkt/acwj ). It also was a nice guide to see what features I might want to tackle next.
The compiler compiles a modified Rust-like language with C semantics to x86_64 assembly for Linux. It's around 6.6k lines of code. The assembly generated can be viewed in the GitHub repository.
I tried to preserve the semantics of C as much as I could, like implicit integer conversion, array to pointer decay, function pointer semantics, etc..., and I think I did a good job. But I don't doubt my code doesn't have bugs :P
The language is not complete, and I doubt it'll ever be finished. The purpose of the project was learning.
So, I would really appreciate your opinion, and I'm happy to answer questions you have!
NOTE: (I'm sad that I have to explicitly say this) I didn't use AI. Again, the project was for learning purposes, and in my opinion generating a project with AI won't make you learn anything :P
11
u/il_dude Jul 10 '26
It looks like you committed project Euler solutions to your compiler repo!
5
u/Small_Ad3541 Jul 11 '26 edited Jul 11 '26
How do you represent strings? I’m not talking about encoding, I’m more curious about how your compiler transforms "Called ‘f()’" into assembly code and what IRs are under the hood
Good job btw!
2
u/Sssean6 Jul 11 '26
Do you implement optimization before and after code generation? Like loop unrolling
-1
u/Gingrspacecadet Jul 10 '26
im doing the other way around! C syntax, rust semantics. it's going pretty well atm
0
u/[deleted] Jul 10 '26
[deleted] — view deleted comment