How kylemontg/comp5210-compiler works
This repository is a compiler for a subset of C99. Its user workflow is to pass C source to the command-line compiler and receive three-address code, optionally optimized and/or emitted as 64-bit Windows x86 assembly. The graph preserves the front-end, semantic checks, intermediate representation, optimization passes, and output capabilities documented in the README. Some wiring is based on the SOURCE INDEX and README rather than complete excerpts; uncertain runtime orchestration is therefore not expanded.
Main entry points: main.py CLI Driver · tac.py TAC Generator · ast_nodes.py AST Nodes · copy_and_constant_propagation.py Copy Propagation
Components 18
C Front End
- Lexer
src/lexer.py - Token Model
src/tokens.py - Parser
src/parser.py - AST Nodes
src/ast_nodes.py
Semantic Analysis
- Semantic Checks
src/semantic_analyzer.py - Symbol Scopes
src/symbol_table.py - Compiler Errors
src/errors.py
Intermediate Code
- TAC Generator
src/tac.py
Optimization
- Control-Flow Graph
src/optimizations/cfg.py - Constant Folding
src/optimizations/constant_fold.py - Copy Propagation
src/optimizations/copy_and_constant_propagation.py - Dead-Code Elimination
src/optimizations/dead_code_elimination.py - Register Allocation
src/optimizations/register_optimization.py
Compiler Outputs
- x64 Assembly
src/asm.py - Structure Printer
src/print_structures.py - TAC Comparison
src/tac_diff.py
Other components
- Compiler User
- CLI Driver
main.py
Connections 28
- Compiler User → CLI Driver: provides source
README.md - CLI Driver → Lexer: starts compilation
- Lexer → Token Model: produces tokens
src/lexer.py - Parser → Token Model: consumes tokens
src/parser.py - Parser → AST Nodes: builds AST
src/parser.py - Semantic Checks → AST Nodes: checks AST
src/semantic_analyzer.py - Semantic Checks → Symbol Scopes: uses scopes
src/semantic_analyzer.py - TAC Generator → AST Nodes: lowers AST
src/tac.py - TAC Generator → Symbol Scopes: uses symbols
src/tac.py - CLI Driver → Semantic Checks: runs checks
- CLI Driver → TAC Generator: generates TAC
- CLI Driver → Structure Printer: prints structures
- CLI Driver → TAC Comparison: compares TAC
- CLI Driver → x64 Assembly: requests assembly
README.md - CLI Driver → Constant Folding: selects optimizations
- CLI Driver → Copy Propagation: selects optimizations
- CLI Driver → Dead-Code Elimination: selects optimizations
- CLI Driver → Register Allocation: selects optimizations
- Constant Folding → TAC Generator: rewrites TAC
src/optimizations/constant_fold.py - Copy Propagation → TAC Generator: rewrites TAC
src/optimizations/copy_and_constant_propagation.py - Copy Propagation → Control-Flow Graph: builds graph
src/optimizations/copy_and_constant_propagation.py - Dead-Code Elimination → TAC Generator: rewrites TAC
src/optimizations/dead_code_elimination.py - Dead-Code Elimination → Control-Flow Graph: traverses graph
src/optimizations/dead_code_elimination.py - Register Allocation → TAC Generator: analyzes TAC
src/optimizations/register_optimization.py - Register Allocation → Control-Flow Graph: builds graph
src/optimizations/register_optimization.py - x64 Assembly → TAC Generator: translates TAC
src/asm.py - Structure Printer → AST Nodes: formats nodes
src/print_structures.py - TAC Comparison → TAC Generator: compares instructions
src/tac_diff.py