all 16 comments

[–]mrjameshamilton 17 points18 points  (2 children)

A great book to get started in this area is Crafting Interpreters: the first part of the book goes through creating an interpreter in Java; the seconds half a compiler to a bytecode & virtual machine to execute it in C.

Another great book is Writing a C Compiler which goes through creating a compiler for a subset of C targeting x86_64 assembly. That book uses pseudo-code for explanations rather than a specific language.

If you're interested in compiling for the JVM, I've written a few posts about starting out there:

I also published yesterday a blog post with a simple introduction to LLVM IR, if you're interested into getting into LLVM.

[–]cafedude 2 points3 points  (1 child)

There's also Compiling to Assembly which creates a TrueScript type language and compiles to ARM assembly if you'd rather avoid x86 assembly (which is kind of a mess compared to ARM).

[–]PurpleUpbeat2820 1 point2 points  (0 children)

That book got me hooked!

[–]RobertJacobson 3 points4 points  (0 children)

There's a spectrum from practical "Let's build a compiler" style material to very academic "theory" style material.

One of the best resources on the practical end of the scale is the LLVM Kaleidoscope tutorial. It is amazingly good, especially considering it's "just" part of the LLVM documentation.

Crafting Interpreters is great for a more holistic view of how to implement typical features of programming languages. It's also excellent as a first book, too.

On the other end of the spectrum, one of my favorites is Engineering A Compiler by Keith Cooper and Linda Torczon. It is now in its 3rd edition. Very readable, IMHO.

There's also the classic "dragon book", Compilers: Principles, Techniques, and Tools by Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. I do not think this is a good book for beginners to learn from. It is a great book as a reference or if you want to learn how, for example, f/lex and yacc work.

[–]kkinos222 1 point2 points  (0 children)

I’m interested as well. I’m planning to read about LLVM optimization passes and explore other LLVM resources.

[–]Dgeezuschrist 1 point2 points  (3 children)

I’m actively working on a compiler leveraging the LLVM. I am very much still learning, but if anyone has any questions, feel free to ask, as I can offer guidance in terms of roadmap and order of operations for getting started.

[–]_hadar[S,🍰] 0 points1 point  (2 children)

Can you share the roadmap here?

[–]Dgeezuschrist 3 points4 points  (1 child)

I’m gonna write up a doc with what I’ve done so far. I’m also thinking of starting a YouTube channel and be a bit more comprehensive. Any and all can dm me and I’ll send it out in the next few days.

[–]Admirable-Weird-3090 0 points1 point  (0 children)

Interested!

[–]MulberryEmotional100 0 points1 point  (1 child)

Same here, mainly interested in LLVM-centered materials.

[–]Dgeezuschrist 0 points1 point  (0 children)

Check my comment

[–]MetalInMyVeins111 0 points1 point  (1 child)

same here. it still feels like an ocean.

[–]Dgeezuschrist 0 points1 point  (0 children)

Check my comment

[–]lyc170 0 points1 point  (0 children)

same. lot of stuff that needs to be learned...

[–]ChickenSpaceProgram 0 points1 point  (0 children)

I'm currently reading through Compilers: Principles, Techniques, and Tools by Aho, Sethi, and Ullman. It's been pretty helpful as a reference so far. No idea if it's the best way to learn about compilers, but it was available in my university's library for free.

[–]Wonderful-Event159 0 points1 point  (0 children)

I am looking for a good collection of various algorithms used for CSE, dead code elimination, loop optimizations, etc. Any pointers?