7 ms·
Chibicc: A Small C Compiler
- saagarjha 6y agoAnother small C compiler by the same author: https://github.com/rui314/8cc https://github.com/rui314/8cc
- cogburnd02 6y agoELVM uses a modified version of 8cc to compile C into some utterly weird targets. Brainfuck, sed, TeX, whitespace... https://github.com/shinh/elvm https://github.com/shinh/elvm
- garrypettet 6y agoWhat a great resource. I will certainly pick up the book when it’s out.
- tarruda 6y agoLooking forward to the release, and will definitely get a copy!
- jart 6y agoOutstanding. 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?
- glouwbug 6y agoDo it and I'll use it
- sdfjkl 6y agoI quite like the learn-by-commit style. Look at a diff and see what changes it took to add a feature. Very good way of showing things in a format everyone is already familiar with.
- barumi 6y agoIt 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.
- gus_massa 6y agoSend an email to the mods hn@ycombinator.com They sometimes makes these changes.
- redtexture 6y agoThis is a totally lame response, compared to reposting the suggested title, and providing a link to the new post.
- dang 6y agoAdded. Thanks!
- niek_pas 6y agoWhere will we be able to buy a copy? Is there a mailing list? I will certainly forget about this book in n months time.
- wffurr 6y agoYou could write to the author or follow their social media: https://www.sigbus.info/ https://www.sigbus.info/
- rui314 6y agoAuthor here. No publishing date has been set yet. At least a half-written Japanese version of the book is available online for free (https://www.sigbus.info/compilerbook https://www.sigbus.info/compilerbook), and I'll probably translate this to English and share at least a few chapters for free. But nothing is set in stone yet. There's no mailing list for notifications yet.
- rui314 6y agoRelated discussions on Reddit: https://www.reddit.com/r/programming/comments/j35w0i/im_writing_a_c_compiler_called_chibicc_and_a_book/ https://www.reddit.com/r/programming/comments/j35w0i/im_writ... https://www.reddit.com/r/C_Programming/comments/j2wjyp/chibicc_a_small_c_compiler/ https://www.reddit.com/r/C_Programming/comments/j2wjyp/chibi... https://www.reddit.com/r/Compilers/comments/j2py9x/im_writing_a_c_compiler_called_chibicc_and_a_book/ https://www.reddit.com/r/Compilers/comments/j2py9x/im_writin...
- forgotmypw77 6y ago>Each commit of this project corresponds to a section of the book. For this purpose, not only the final state of the project but each commit was carefully written with readability in mind. Readers should be able to learn how a C language feature can be implemented just by reading one or a few commits of this project. For example, this is how while, [], ?:, and thread-local variable are implemented. If you have plenty of spare time, it might be fun to read it from the first commit. nice
- IncRnd 6y agoWhen 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. Somehow I can't imagine Brian Kernighan or Dennis Ritchie making those sorts of commits.
- protomyth 6y agoI would imagine it is done to avoid having a chapter at the end showing all the patches and why they were needed. A compiler course shouldn't have a bunch of errors if they can be avoided. I doubt Brian Kernighan or Dennis Ritchie put all the errata at the end of their books on subsequent printings. They fixed the main text.
- dibyendu 6y agoFor a different optimizing C compiler that is also small, and usable as a JIT see MIR project by Vladimir Makarov - https://github.com/vnmakarov/mir/tree/master/c2mir https://github.com/vnmakarov/mir/tree/master/c2mir
- emmanueloga_ 6y agomaybe the author can verify, from what I could see it generates assembler files that one should save to a .S file and then can be run with gcc's `cc -o executable file.S`.
- rui314 6y agoIt produces a .S file if `-S` flag was given. By default, it produces a .S file in a temporary and assemble it with `as` and write its output object file (an .o) file is produced as an output from the compiler.
- ykevinator 6y agoThe cat is excellent
- stiray 6y agohttps://bellard.org/tcc/ https://bellard.org/tcc/ Probably best know and with loooong beard...
- bear8642 6y agoMy immediate thought given title
- wang_li 6y agohttps://en.m.wikipedia.org/wiki/Small-C https://en.m.wikipedia.org/wiki/Small-C This is what I think of when I see Small C as a proper noun.
- hartzell 6y agoMe too. Taught myself C with that! This generation, CPM support and everything: https://archive.org/details/dr_dobbs_journal_vol_09/page/n333/mode/2up https://archive.org/details/dr_dobbs_journal_vol_09/page/n33...
- pjmlp 6y agoMe as well, that was my introduction to C, before I eventually had access to Turbo C 2.0 for MS-DOS.
- gilmi 6y agoI love 'the incremental approach to compiler construction'. Here are a few other courses that use this approach to teach compiler construction: * http://www.ccs.neu.edu/course/cs4410/ http://www.ccs.neu.edu/course/cs4410/ * https://ucsd-cse131-f19.github.io/ https://ucsd-cse131-f19.github.io/ * https://jeapostrophe.github.io/courses/2017/spring/406/notes/book.pdf https://jeapostrophe.github.io/courses/2017/spring/406/notes...
- philips4350 6y agoOh man I used to be a die hard fan of the author's 'turing complete fm[1]' podcast. It seems like he has stopped publishing new episodes, wonder what happened. [1] https://turingcomplete.fm/ https://turingcomplete.fm/
- triyambakam 6y agoLooks like it's a Japanese podcast? Or is there an English version?
- philips4350 6y agoOh, yes the podcast is only in Japanese.
- xcudfg89du8fg90 6y agoHard to tell. Maybe some die hard fan could shed some light
- philips4350 6y agoI follow him on Twitter and I haven't seen any 'official' info reading the podcast. But Mr.Rui did confirm in this thread that he would be continuing the podcast so seems like it will continue :)
- rui314 6y agoNothing in particular has happened to me, but producing a high quality podcast episodes takes time, and I didn't have enough time for doing that.
- philips4350 6y agoOh I see, thank you for your response. I'm glad that you intend to continue the podcast, can't wait for the next episode :)
- ruslan 6y agoCan it compile itself ?
- rui314 6y agoYes, it is.
- ruslan 6y agoThant'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.
- DethNinja 6y agoThis 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.
- poidos 6y agoI used LLVM for a small compiler; not for C, but for a Java-like language: https://github.com/LucianoLaratelli/dj2ll-public https://github.com/LucianoLaratelli/dj2ll-public All the API calls are contained within codegen.cpp.
- ndesaulniers 6y agoThe Kaleidoscope LLVM tutorial!
- mhh__ 6y agoI 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.
- pfdietz 6y agoI wonder how it does with Csmith.
- deleted 6y ago[deleted]
- carapace 6y agoAwesome 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.