9 ms·
Compiler Class
- mrkeen 6y agoCool! Any plans for emitting assembly, c or llvm? There seem to be an awful lot of resources on compiler frontends, and not so much on the backend.
- mhh__ 6y agoThere are a lot of resources on compiler backends, just that GCC and LLVM don't follow them. The GCC and LLVM machine models for example are very sophisticated and I've never seen anything like them documented in a textbook because they all basically assume a early 2000s RISC machine rather than a CISC with a very bulky decoder.
- myk9001 6y agoYou might find [CS 6120: Advanced Compilers: The Self-Guided Online Course][1] interesting. I'm slowly working through it, but basically its focus is intermediate representations, optimizations, etc. A link to the course was on the first page of HN some time ago. If you want to know more about LLVM IR specifically, check this [talk from 2019 EuroLLVM Developers’ Meeting][2] Also -- and you knew it was coming -- I've written [a toy-compiler of a Scala subset][3] myself :) I'm new to F# and writing compilers, so I'm sure the code is full of rookie mistakes. Still, it works and does generate assembly and executables for Linux and Windows. [1]: https://www.cs.cornell.edu/courses/cs6120/2020fa/self-guided/ https://www.cs.cornell.edu/courses/cs6120/2020fa/self-guided... [2]: https://www.youtube.com/watch?v=m8G_S5LwlTo https://www.youtube.com/watch?v=m8G_S5LwlTo [3]: https://github.com/mykolav/coollang-2020-fs https://github.com/mykolav/coollang-2020-fs
- norswap 6y agoI plan to show how to emit Java bytecode - the advantage being that you don't have to write your own GC, and you benefit from the JVM JIT compiler. I think in general the backend is much easier (especially if you don't have to do your own optimizations) - you mostly need to know a couple of patterns for working with tree-like structures.
- artemonster 6y agoI really hope this wouldn't end up like 95% of other "compiler" classes that usually just focus on parsing, rather than on emitting code, cpu architectures & optimizing
- mhh__ 6y agoUnlikely. Although if I ever get round to it I'd like to start an open source compiler textbook to try and centralise knowledge in this area since the field is simply too advanced to summarise in a single book these days.
- jcranmer 6y agoThere's definitely a lack of advanced compiler textbooks, and the venerable Dragon book definitely shows its age nowadays. I've gone so far as to write an outline for what I'd want to cover, and came to the conclusion that it needs several books to adequately cover the material. And there's a lot of topics that I am personally too ignorant of to do any justice to.
- mhh__ 6y agoThe latter point is why I think it has to be open source rather than a single man or woman's work
- pwdisswordfish6 6y agoThis is the same path that led to The Art Of Computer Programming.
- m12k 6y agoSounds like you're looking for a "Compilers 201" class.
- hvidgaard 6y agoGoing from a grammar to an AST is the first and one of the hardest step IMO. And there is plenty of open source tools for exactly that and in general it is uninteresting and boring. Transforming the AST to something that can be used to emit instructions is the major thing to focus on IMO. Getting to an AST that only use very simple primitives that enables general optimizations and emitting code is hard and a different task every time.
- theXspidy 6y agoGet daily informative news from noisy news straight to your inbox with https://CutThroughTheNoise.co https://CutThroughTheNoise.co For free
- jstanley 6y agoThanks, this is serendipitous timing. I definitely plan to watch the YouTube playlist. I'm designing a simple CPU at the moment[1] and one of the things that keeps me awake at night is thinking about how to make a compiler for it. It only supports 64K words of RAM (and I'm not planning to implement bank switching), and I definitely want the compiler to be self-hosting on my CPU, so retargeting LLVM or similar won't be applicable. I've looked at Small-C[2], Cowgol[3], and PL/0[4] which all target related goals, from different directions. [1] https://github.com/jes/scamp-cpu https://github.com/jes/scamp-cpu [2] https://en.wikipedia.org/wiki/Small-C https://en.wikipedia.org/wiki/Small-C [3] http://cowlark.com/cowgol/ http://cowlark.com/cowgol/ [4] https://en.wikipedia.org/wiki/PL/0 https://en.wikipedia.org/wiki/PL/0
- lenkite 6y agoHave you taken a look at Ferret ? https://ferret-lang.org/ https://ferret-lang.org/ ? Ferret is a free software lisp implementation designed to be used in real time embedded control systems. Ferret lisp compiles down to self contained C++11. Generated code is portable between any Operating System and/or Microcontroller that supports a C++11 compliant compiler. It has been verified to run on architectures ranging from embedded systems with as little as 2KB of RAM to general purpose computers running Linux/Mac OS X/Windows.
- jstanley 6y agoI hadn't seen it, and it looks cool, thanks. I'm really keen to be able to run the compiler end-to-end on the CPU itself, so I think getting C++11 working would be the stumbling block there.
- read_if_gay_ 6y agoMaybe this is interesting to you as well? https://github.com/cksystemsteaching/selfie https://github.com/cksystemsteaching/selfie
- yudlejoza 6y ago> ... real time ... embedded ... microcontroller ... > ... that supports ... C++11 ... Makes perfect sense.
- kuter 6y agoGCC has a book recommendation page [0] I had been using some of these books to self study. [0] https://gcc.gnu.org/wiki/ListOfCompilerBooks https://gcc.gnu.org/wiki/ListOfCompilerBooks
- mhh__ 6y agoBe warned that some of the books are ancient now
- chrisseaton 6y agoSome of these books are so incredibly out of date that you will end up with almost no understanding of how actual compilers work. Use with care.
- anta40 6y agoCould you specifically point those outdated books? Perhaps the "Dragon Book" is among them?
- justicezyx 6y agoThe hidden surge of demand on compiler engineers is well below the radar of most people and online channels. But I am betting this will soon happen. As ASICs especially IoT development will require more and more investment in compiler tool chains and other programming related tools.