@@ -8,19 +8,34 @@ The compiler currently handles C programs with unary operators and integer const
88
99``` c
1010int main (void) {
11- return ~ (-42);
11+ return -((42 * 10) / (2 + 3)); // Returns -84
1212}
1313```
1414
1515### Compilation Pipeline
1616
17- The compiler processes source code through the following stages :
17+ The compiler is organized into several major subsystems :
1818
19- 1. **Lexical Analysis**: Breaks source code into a sequence of tokens
20- 2. **Parsing**: Converts tokens into an Abstract Syntax Tree (AST)
21- 3. **TACKY Generation**: Transforms AST into TACKY intermediate representation
22- 4. **Code Generation**: Transforms AST into x86_64 assembly
23- 5. **Code Emission**: Outputs the assembly code to an executable
19+ - **Frontend** - Parsing and analysis
20+ - Lexical analysis (breaks source into tokens)
21+ - Parsing (converts tokens to AST)
22+ - Token definitions
23+
24+ - **Core** - Core data types and compiler infrastructure
25+ - AST, Assembly, and TACKY intermediate representations
26+ - Compiler monad and error handling
27+
28+ - **Backend** - Code generation
29+ - TACKY to assembly conversion
30+ - Register allocation
31+ - Assembly output
32+
33+ - **Driver** - Pipeline coordination
34+ - Command line interface
35+ - Compilation pipeline stages
36+ - External tool integration (GCC for preprocessing and linking)
37+
38+ Each subsystem is organized as a hierarchical module that provides a clean interface to its functionality while hiding implementation details.
2439
2540### Internal Representations
2641
@@ -85,20 +100,24 @@ Programs are represented internally using a series of increasingly lower-level d
85100 ├── lib/ # Main library code
86101 │ ├── Halcyon.hs # Library entry point
87102 │ └── Halcyon/ # Core modules
103+ │ ├── Backend.hs # Backend subsystem interface
88104 │ ├── Backend/ # Code generation and emission
89105 │ │ ├── Codegen.hs # TACKY to Assembly conversion
90106 │ │ ├── Emit.hs # Assembly to text output
91107 │ │ └── ReplacePseudos.hs # Register/stack allocation
108+ │ ├── Core.hs # Core subsystem interface
92109 │ ├── Core/ # Core data types and utilities
93110 │ │ ├── Assembly.hs # Assembly representation
94111 │ │ ├── Ast.hs # C language AST
95112 │ │ ├── Monad.hs # Compiler monad stack
96113 │ │ ├── Settings.hs # Compiler settings and types
97114 │ │ ├── Tacky.hs # TACKY IR definition
98115 │ │ └── TackyGen.hs # AST to TACKY transformation
116+ │ ├── Driver.hs # Driver subsystem interface
99117 │ ├── Driver/ # Compiler driver
100118 │ │ ├── Cli.hs # Command line interface
101119 │ │ └── Pipeline.hs # Compilation pipeline
120+ │ ├── Frontend.hs # Frontend subsystem interface
102121 │ └── Frontend/ # Parsing and analysis
103122 │ ├── Lexer.hs # Lexical analysis
104123 │ ├── Parse.hs # Parsing
0 commit comments