If compilers fascinate you — how a page of text becomes a running program — this page is for you. Dragon is the name of the machinery that turns intermediate code into native binaries at Mica: control-flow analysis, an SSA middle end, storage placement, register allocation, and native emission for Linux x86_64 and AArch64 with DWARF debug information. It is the backend of the Mica compiler, written from the first line to the last without LLVM or GCC beneath it, and it is available to you as the Dragon SDK: a C header and a static archive, so that a compiler you write gets the same optimizer, the same native code and the same debugger support Mica’s own has.

The road, from a first parser to a language of your own

StepWhat you doWhere
1Build a complete compiler. Niklaus Wirth’s PL/0, the smallest complete compiler anyone has written down, taken apart a piece at a time: the scanner, the symbol table, the parser, the seam between a parser and a code emitter, Wirth’s stack machine as an oracle, and the Dragon road that hands the program to Dragon and gets optimized native code back. It is written twice, in C23 and in Mica, so you learn which parts of a compiler are essential and which are a language’s opinion. No prior compiler knowledge is needed, and you do not need to know Mica.Build a compiler with Mica
2Prove it. How two compilers are made to check each other, why a slow reference implementation is worth keeping, and what honest testing of a compiler looks like.Proving it
3Look inside a production compiler. One flag writes every stage of the Mica compiler’s work on your program to a folder: the tokens, the tree after analysis, the Spectra code, the control-flow graph, dominance, liveness, reaching definitions, SSA and the way out of it, placement, the assembly, every optimization pass’s ledger and the memory analysis. A real pipeline, readable, on a program you wrote.The compiler, exported
4Extend the language. Nine exercises, from a ten-minute warm-up to a genuine piece of compiler engineering, each with the hard part marked.Exercises
5Install the SDK. The header, the archive, the licence, the first check.Installing the Dragon SDK
6Write your own. Your parser builds Spectra; Dragon builds the binary, the optimization and the debug information. The runtime floor your programs link ships as its own package, and your compiler’s users install your compiler, not Mica.The Dragon SDK: our backend, as a deliverable · The Dragon SDK stands alone

Spectra, the intermediate language

Spectra is the flat three-address code the whole Dragon backend consumes: the language every frontend writes, whether it is the Mica compiler or the PL/0 of the course. A frontend builds Spectra units through the SDK’s C header, or through the dragon surface embedded in the Mica compiler, and Dragon does the rest. You can read Spectra for any program you compile — it is the fourth stage of the exported compiler, with the source lines riding as comments — and the course’s ninth chapter emits it by hand for PL/0, which is the moment a parser becomes a compiler.

What Dragon does with it

StageWhat it establishes
control-flow analysisthe graph of basic blocks and its dominance tree
dataflowliveness and reaching definitions
the middle endstatic single assignment, the optimizer’s passes on it, and the way back out
placementwhich value lives in which register or frame slot, on each architecture
emissionthe assembly for the GNU assembler and linker, with DWARF v5 so gdb steps your language’s source
the memory analysisevery allocation an obligation, followed through the intermediate code, so a frontend built on Dragon inherits the heap proofs

The whole of it is 217,653 lines of Go with no third-party dependency, and it is tested the way how we verify describes: the two PL/0 compilers are compiled and run on every change to the compiler, and their outputs, their p-code listings and the Spectra of every unit they build are compared byte for byte.

The licence

The Dragon SDK is a separate package from the compiler, under a licence written for toolchains: free for noncommercial use, commercial use by agreement, and nothing of it attaches to the programs your compiler produces. Licensing states the terms; the Mica compiler itself is free for any use.

What Dragon is not

Said plainly. Dragon is not an LLVM: there is no LLVM IR in or out, and the intermediate language is Spectra. It has two targets, Linux x86_64 and AArch64. It does not compile at run time: it emits assembly for the GNU assembler and linker. And the API is a preview: Dragon and Spectra may change between releases, and the SDK page says so in the same words.