A WIP learning experiment in building a very simple C-like RiscV compiler in Typescript based around Adrian Sampson's open-learning compiler course with a react-based IDE.
- Chevrotain based simple C-like language parser with AST generation
- Basic UI for code editing, AST/IR/CFG visualisation
- C-like AST to Bril IR ("blang?")
- Bril IR
- Control Flow Graph (CFG) visualisation with dominance highlighting
- Conversion to Single Static Assignment (SSA) form
- Data flow analysis
- Defined variables
- Live variables
- Optimisations
- Dead-code elimination
- Local and global value numbering
- Common expression evaluation
- Constant folding
- Copy propogation
- Loop invariant code motion
- Loop unrolling
- Strength reduction
- Code generation
- Webassmebly
- RiscV
- Expand SimpleC
- if (cond) instead of if (cond == true) where cond is boolean identifier
- uf (cond) instead of if (cond == true) where cond is boolean function call
- arrays
- stdlib (print_int, print_string)
- add modulo operator to SimpleC and Bril
- add bitwise operators to SimpleC and Bril
- add assert to library functions
- move semicolon out of each statement to allow no semicolon in for (int i=0;i<10;i++)
- Improve UI
- CFG node selection shows DFA for that node
- Bril IR diffeditor - plain vs SSA and SSA vs optimisations
- Use ReactFlow and Elk.js instead of vis.js?
- Refactor
- Switch from redux-toolkit to zustand
- Move interp.ts into a webworker so ui doesn't stall
- Optimisations
- CFG optimisations
- Branch removal
- Unreachable code elimination
- CFG cleaning
- Tail merging
- Remove top label and any unnecessary terminator instructions
- Loop optimisation
- Unrolling
- Loop-invariant computation hoisting
- Strength reduction
- Peephole optimisations
- CFG optimisations
- Many more examples
- Mandelbrot
- Color Mandelbrot
- Game of Life
- Code generators
- IR to RiscV - WIP
- IR to WebAssembly
- Add LLVM mid-end?
- Chevrotain parser
- rc-dock
- rc-tree
- vis.js
- monaco-editor
- wabt.js
- Does not work with import wabt from "wabt". Use these steps instead
- Add <script src="https://unpkg.com/wabt/index.js"></script> to index.html
- Make file wabt.d.ts and move index.d.ts from wabt.js
- To use wabt:
- Wabt().then((wabtModule) => wabtModule.parseWat....)
- Does not work with import wabt from "wabt". Use these steps instead
- Adrian Sampson's self-guided CS6120 https://www.cs.cornell.edu/courses/cs6120/2020fa/
- WASM binary structure and code generation
- Register allocation adapted from https://github.com/johnflanigan/graph-coloring-via-register-allocation
- Refractor data ? all in zustore
- Simple C editor - on change => store.setCTxt(txt)
- Store setCTxt c to bril, optimise bril, compile to wasm, compile to riscv
- Store setBril => optimtise => brilOptim