How kkorel/wacc-compiler works
WACC-Compiler is a command-line compiler: a user supplies a WACC file, which is parsed, scope-renamed, type-checked, translated through two intermediate representations, formatted as x86-64 assembly, and written as a .s file. The README also documents language features including arrays, pairs, functions, I/O and runtime safety checks; these are represented at their compiler stages. Some subsystem links reflect the documented pipeline because their implementations were not sampled.
Main entry points: Main.scala CLI driver · parser.scala Parser · renamer.scala Scope renamer · stackMachine.scala Stack IR lowering
Components 18
Frontend
- CLI driver
src/main/wacc/Main.scala - Lexer
src/main/wacc/lexer.scala - Parser
src/main/wacc/parser.scala - Program AST
src/main/wacc/ast.scala - Diagnostics
src/main/wacc/errors.scala
Semantic Analysis
- Scope renamer
src/main/wacc/renamer.scala - Type checker
src/main/wacc/typeChecker.scala
Code Generation
- Stack IR lowering
src/main/wacc/backend/stackMachine.scala - Stack IR
src/main/wacc/backend/stackCode.scala - x86 lowering
src/main/wacc/backend/x86Lowerer.scala - x86 IR
src/main/wacc/backend/x86IR.scala
Output
- Assembly formatter
src/main/wacc/backend/x86Formatter.scala
Other components
- Compiler user
- WACC source
- Assembly file
- GNU assembler and linker
- Generated program
- Linux libc
Connections 19
- Compiler user → WACC source: provides source
- Compiler user → CLI driver: invokes
- CLI driver → WACC source: reads file
- CLI driver → Parser: parses via
- Parser → Lexer: tokenizes with
- Parser → Program AST: produces AST
- CLI driver → Diagnostics: formats failures
- CLI driver → Scope renamer: resolves names
- Scope renamer → Type checker: returns renamed AST
- CLI driver → Type checker: checks types
- CLI driver → Stack IR lowering: lowers typed AST
- Stack IR lowering → Stack IR: emits instructions
- CLI driver → x86 lowering: lowers stack IR
- x86 lowering → x86 IR: emits instructions
- CLI driver → Assembly formatter: formats x86 IR
- Assembly formatter → Assembly file: writes assembly
- Compiler user → GNU assembler and linker: assembles output
- GNU assembler and linker → Generated program: builds executable
- Generated program → Linux libc: calls routines