minic

Minimalist compiler course, based on Essential of Compilation

Stars
11
Committers
2

Bot releases are visible (Hide)

minic - Arithmetic compilation Latest Release

Published by dannypsnl about 1 year ago

You will have your extremely first experience about compilation, the language we supported here is:

x        ; variable
i        ; integer
e ::=
  | x
  | i
  | (+ e1 e2)
  | (- e1 e2)
  | (let ((x e1)) e2)

There have 8 passes.

  1. uniquify
  2. remove complex operands
  3. explicate control
  4. select instruction
  5. liveness analysis
  6. conflict graph inference
  7. register allocation
  8. Due to AArch64 stack operations, we add patch stack operations

Run example

To run example, use the following command:

dune exec minic -- ./example/hello.ss

There have three examples in this stage.

  1. hello.ss
  2. rco_example.ss
  3. conflict_graph_sample.ss

Bonus: any length of input

This implementation can only take (+ e1 e2) and (- e1 e2), but in Racket(another scheme variant) we can have

  1. (+) which produces 0
  2. (+ e1 e2 e3 ...) which sums all
  3. (- e1 e2 e3 ...) which recursively subtract (- e1 e2) then put result as head of subtraction then again, e.g. (- 6 3 2) is 1, not 5

Can you implement them?

Note
For subtract, this bonus disallow (- e), which is valid in Racket.

Bonus: move biasing

Remove the instruction like mov a, a, this is completely useless but can occur after register allocation.