Live data from Hacker News

Chibicc: A Small C Compiler

github.com

31–40 of 48 posts

Re: Chibicc: A Small C Compiler

#31
Awesome project!

> When I find a bug in this compiler, I go back to the original commit that introduced the bug and rewrite the commit history as if there were no such bug from the beginning. This is an unusual way of fixing bugs, but as a a part of a book, it is important to keep every commit bug-free.

Ooo la la! "Chibicc Vol. II, The Bugs" !?

In all seriousness, a book about the bugs would be (IMO) even more fun to read than the compiler book.

Re: Chibicc: A Small C Compiler

#33
post #4

Outstanding. A professional C compiler with a hackable codebase that emits x86_64 code. I'm noticing it assumes glibc-based linux. What if I modified it to emit Actually Portable Executables without needing ld/as?

Do it and I'll use it

Re: Chibicc: A Small C Compiler

#34

This looks great, I’ll definitely use it. Is there any similar project like this where LLVM IR is used? I’ll start building a language just for fun during weekends and I plan to use LLVM but it is rather hard to understand clang on limited time, so a smaller scale project would be awesome.

I would look at the LLVM tutorials, and maybe the insides of your favourite languages compiler (other than clang)

When it comes to both parsing and emitting IR, keep it simple (stupid!) - the difficult bit (on a day to day basis) with the compiler is almost always the language semantics, the backend is more theory-dense but to just implement a language you can use LLVM as a black-box.

If you minimise mutable state and utilise lowering (you can implement foreach by lowering the AST to a for loop, for example) your compiler will be much easier to debug.

Re: Chibicc: A Small C Compiler

#35
post #27
post #23

Can it compile itself ?

Yes, it is.

Thant's great! Missing parts are assembler and linker, which of course are out of the scope of a C compiler per se, though make complete toolchain. I'm interested in this stuff because I'm toying with my own simple machine coined for tiny FPGAs and I concidered writing my own C compiler, but I need an assembler first.

Re: Chibicc: A Small C Compiler

#37
post #6

It would be helpful if the title was edited to feature the compiler's name: chibicc. It would make it easier to search and SEO-wise it would be helpful to disseminate the project.

Send an email to the mods hn@ycombinator.com They sometimes makes these changes.

This is a totally lame response, compared to reposting the suggested title, and providing a link to the new post.

Re: Chibicc: A Small C Compiler

#39
post #24
post #19

https://bellard.org/tcc/ Probably best know and with loooong beard...

https://en.m.wikipedia.org/wiki/Small-C This is what I think of when I see Small C as a proper noun.

Me too. Taught myself C with that!

This generation, CPM support and everything: https://archive.org/details/dr_dobbs_journal_vol_09/page/n33...

Post reply on HN