From Quasi Paragon
Revision as of 15:10, 9 March 2018 by Nathan (talk | contribs) (Middle end)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

For many the compiler, bestowing animation upon lifeless source code,[1] is a magic box. To me it's just another program. So, let's share the goodness with some writings on the subject. I'll add items to this as the fancy strikes me.[2] While GCC is the compiler I know intimately, what's here is applicable to most compilers.

If you'd like to know about a bit of the compiler, email wiki.

Big picture

Random discussion of compilers in general — they're not magic, but they have some rather magical properties.

Front end

This is the bit of the compiler that slurps in your source code and turns it into some kind of internal representation. It's concerned with lexing and parsing, semantic analysis, template instantiation and giving you good diagnostics on why what you wrote is bad. The output of this is an Abstract Syntax Tree (AST)[3]

Middle end

This is the bit that's responsible for optimizing your code. Taking the FE stuff and making it go. Generally converting the AST to some lower-level internal representation (IR) in the process. There can be some fairly high level transforms here backed up by non-trivial maths. All of this is optional — your program will work without optimizing, just perform suckily.

Back end

And this is the bit that turns the IR into machine code the target CPU can actually execute. Some optimizations occur here too.

  • FIXME

Other pieces

  • FIXME

  1. Mary Shelley: Frankenstein
  2. It is trueish — there may be arbitrary hand-waving. Some errors may have crept in :(
  3. It's not a tree and it's not syntax. It's not particularly abstract either.