Cross-compiler cheatsheet

If you have worked on LLVM, GCC, rustc, or another production compiler and want to find the matching concept here, this table is the one-page index. Each row points to a file or symbol; the file is the place to start reading.

Front end

Production-compiler conceptThis compilerFile / function
Lexer / tokeniserInline tokeniserintercalc.sh:tokenize
ParserInline statement classifierintercalc.sh:classify_statement
ASTParallel arrays per statementstmt_type[], stmt_body[], stmt_label[], ...
Expression treeParallel arrays per expression nodeexpr_type[], expr_left[], expr_right[], ...
Diagnosticsdie_compile / print_warningintercalc.sh
Format-on-savetools/format_intercal.shexternal

Middle end

Production-compiler conceptThis compilerFile / function
GIMPLE / MIR / Cranelift CLIFThree-address IRbuild_ir, ir_ops[]
SSA constructionBlock-parameter SSAemit_ssa (read-only dump)
Pass managerSequential time_phase callsintercalc.sh:main
Constant propagationSCCP-WZ + chain-copy var-constemit_sccp_wz, compute_var_constants
Dead-code eliminationPer-statement abstain-flag DCEcompute_flag_checks, stmt_needs_flag[]
Register allocationLinear-scan (Poletto-Sarkar)emit_regalloc, compute_regalloc_decisions
Effect analysisPer-statement ICL-code reachabilityemit_effects, stmt_e275_safe[], ...
PeepholeSed-pass on emitted assemblyintercalc.sh:peephole_optimize
Optimisation bisect--opt-bisect-limit=NLLVM-style

Back end

Production-compiler conceptThis compilerFile / function
Instruction selectionPer-statement-type emit functionscodegen_*
Calling conventionINTERCAL has no functions; the convention is the syslib labelssrc/syslib/syslib.i
Linker drivercc -x assembler -inline in intercalc.sh
Per-platform targetsrc/runtime/{macos_arm64,linux_arm64,linux_x86_64}.shand-written runtime
Assembler post-processingsed (ARM64 macOS → Linux), separate codegen for x86_64inline in intercalc.sh

Tooling

Production-compiler conceptThis compilerFile / function
Compiler driverintercal wrappershell script
Build systemNone (single zsh script)n/a
LSPLSP v0.4.0src/lsp/intercal_lsp.sh
LinterStatic checkstools/lint_intercal.sh
FormatterIndent + uppercasetools/format_intercal.sh
CI matrix3 platforms.github/workflows/ci.yml
Differential testingcsmith-style program generatortools/csmith_intercal.sh + tests/run_csmith_diff.sh
Bytecode tierStack VMsrc/bytecode/intercalc_bc.sh + intercalc_vm.sh

Migration patterns

If you have done one of these in another compiler, this is where to start in ours:

You have doneStart reading
Added an LLVM IR opcodelower_ir_for_stmt and the case in codegen_statement (NEXT_FROM was added the same way)
Added a GCC tree-ssa passcompute_* analyses in intercalc.sh
Migrated a compiler from one IR to another (HIR → MIR; AST → GIMPLE)INTERCAL_NEW_IR=1 opt-in flag and lower_ir_for_stmt's per-type fallback
Implemented Wegman-Zadeck SCCPemit_sccp_wz — the algorithm in 200 lines
Built linear-scan regallocemit_regalloc (the algorithm) and compute_regalloc_decisions (the same algorithm without the trace, populating globals)
Wrote an LSP serversrc/lsp/intercal_lsp.sh is one zsh file; jsonrpc framing is hand-rolled

Reading order

Three suggestions depending on your goal:

  1. Adding a feature. Read learning-by-extending.md first. Then pick the smallest possible analogue from this cheatsheet and trace through it end to end.

  2. Understanding the codegen path. Read pipeline.md → code-generation.md → lower_ir_for_stmt and follow the feature-flag fork from codegen_statement.

  3. Bridging to a production compiler. Read the relevant Part VII chapter (LLVM, GCC, rustc, Go, GHC, ...) alongside the matching row in this cheatsheet. The shape of the change is the same; the diff size is two orders of magnitude larger but the steps map.