GitHub - xqb64/ucc: An optimizing compiler for a large subset of the C programming language

1 min read Original article ↗

ucc

This is a Rust implementation of the C compiler from Nora Sandler's book.

How it works

At the forefront is the compiler driver, which orchestrates the compilation process---from lexing and parsing, through several stages of semantic analysis, such as variable resolution, loop labeling, and type checking. After generating an intermediate representation (IR), the compiler passes it through an iterative optimization pipeline. This pipeline leverages forward and backward data-flow analysis, liveness analysis, and address-taken analysis to implement optimizations such as constant folding, unreachable code elimination, copy propagation, and dead store elimination. Finally, it generates and optimizes the x86_64 assembly code using a graph coloring-based register allocator with conservative coalescing, before emitting the optimized code.

architecture

Status

  • prefix/suffix inc/dec
  • compound assignment
  • bitwise ops
  • char (in both unsigned and signed variants)
  • short
  • int (in both unsigned and signed variants)
  • long (in both unsigned and signed variants)
  • float
  • double
  • void
  • if/else
  • switch
  • while
  • do while
  • for
  • break
  • continue
  • ConsideredHarmful
  • static
  • extern
  • arrays
  • structs
  • sizeof
  • enums
  • unions
  • typedef

License

Licensed under the MIT license.