Development

  • Full source code can be available at download.
  • The compiler is structured in a fairly traditional way and consist of the following pahses:
    • lexer lexical analysis, tokenization
    • parser LALR(1) parser, generating abstract syntax trees (AST)
    • elaborator perform type reconstruction and generation of annotated abstracted syntax (Absyn)
    • translate generate index-passing code (Lambda)
    • anf-convert convert Lambda into A-normal form (ANF)
    • flatten flatten arguments, eliminating most record- and tuple arguments by passing fields separately (i.e., in individual registers)
    • uncurry eliminate of most curried functions
    • anf-optimize constant folding, simple constant- and value propagation, elimination of useless bindings, short-circuit selection from known tuples, inline tiny functions, some arithmetic expression simplification (execution of this pass is repeated and interleaved with other phases such as flatten and uncurry)
    • closure convert to first-order code (Closed) by closure conversion
    • clusters separate closure-converted blocks into clusters of blocks (Cluster); each cluster roughly corresponds to a single C function but may have multiple entry points
    • treeify re-grow larger expression trees (BBTree) to make tree-tiling instruction selection more useful
    • traceschedule arrange basic blocks (TraceTree) to minimize unconditional jumps
    • cg instruction selection by tree-tiling (maximum-munch algorithm)
    • regalloc graph-coloring register allocation
    • emit generate assembly code