Compiler stages

I have a curiosity question. I always use the -p argument when I compile a program because I like to visually see that the compiler is doing something, so I always see it go through 13 stages (or suddenly jump to 14 at the very end). My question is, what exactly are these stages doing? Most of them are too fast to read, and I while can guess some of them, I’m a bit unsure on most of them. I especially don’t understand what “Codegen (bc+obj)” is doing, yet that’s the stage that takes the longest by far. Something with LLVM bytecode? IR → Bytecode? Secret Battlechess easter egg port?

1 Like

With the --stats flag you get the stages information in a list view so it doesn’t run away under your eyes because the compiler blasts through most of them quickly.

The codegen phase consists of three stages:

  • crystal: the compiler builds the LLVM IR
  • bc+obj: LLVM compiles the IR into byte/object code
  • linking: the linker links the generated code with libraries into the final executable