Skip to content

Commit 52df037

Browse files
committed
chore: prepare v0.2.0 release
1 parent f6a7475 commit 52df037

File tree

3 files changed

+76
-24
lines changed

3 files changed

+76
-24
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,23 @@
1515
- Defined CompilerT monad transformer
1616
- x86_64 code generation
1717
- Basic compiler driver with preprocessing and assembly
18+
19+
## 0.2.0.0 -- 2024-11-22
20+
21+
### Added
22+
- Support for unary operators (negation and bitwise complement)
23+
- New TACKY intermediate representation between AST and Assembly
24+
- Stack frame management in generated assembly
25+
- Function prologue and epilogue handling
26+
- Pseudoregister allocation and replacement
27+
- Invalid instruction detection and fixing
28+
- New compiler passes in pipeline:
29+
- TACKY generation
30+
- Pseudoregister replacement
31+
- Stack allocation
32+
- Instruction fixing
33+
34+
### Changed
35+
- Compiler pipeline now includes TACKY transformation stage
36+
- Assembly generation now works from TACKY rather than directly from AST
37+
- Parser improved to handle nested expressions correctly

README.md

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Halcyon is a work-in-progress compiler for a large subset of C, written in Haske
44

55
## Current Status
66

7-
The compiler currently handles the simplest subset of C programs: functions that return integer constants. For example:
7+
The compiler currently handles C programs with unary operators and integer constants. For example:
88

99
```c
1010
int main(void) {
11-
return 42;
11+
return ~(-42);
1212
}
1313
```
1414
@@ -18,8 +18,9 @@ The compiler processes source code through the following stages:
1818
1919
1. **Lexical Analysis**: Breaks source code into a sequence of tokens
2020
2. **Parsing**: Converts tokens into an Abstract Syntax Tree (AST)
21-
3. **Code Generation**: Transforms AST into x86_64 assembly
22-
4. **Code Emission**: Outputs the assembly code to an executable
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
2324
2425
### Internal Representations
2526
@@ -33,10 +34,24 @@ Programs are represented internally using a series of increasingly lower-level d
3334
, body :: Statement
3435
}
3536
data Statement = Return Expr
36-
data Expr = Constant Int
37+
data Expr = Constant Int | Unary UnaryOp Expr
38+
data UnaryOp = Complement | Negate
3739
```
3840

39-
2. **Assembly AST**:
41+
2. **TACKY IR**:
42+
```haskell
43+
data Program = Program FunctionDef
44+
data FunctionDef = Function
45+
{ name :: Text
46+
, body :: [Instruction]
47+
}
48+
data Instruction
49+
= Return TackyVal
50+
| Unary UnaryOp TackyVal TackyVal
51+
data TackyVal = Constant Int | Var Text
52+
```
53+
54+
3. **Assembly AST**:
4055
```haskell
4156
data Program = Program FunctionDef
4257
data FunctionDef = Function
@@ -47,26 +62,42 @@ Programs are represented internally using a series of increasingly lower-level d
4762
data Operand = Imm Int | Register
4863
```
4964

65+
5066
## Project Structure
5167

5268
```
53-
lib/
54-
├── Halcyon/
55-
│ ├── Backend/ # Code generation and emission
56-
│ │ ├── Codegen.hs # AST to Assembly conversion
57-
│ │ └── Emit.hs # Assembly to text output
58-
│ ├── Core/ # Core data types and utilities
59-
│ │ ├── Assembly.hs # Assembly representation
60-
│ │ ├── Ast.hs # C language AST
61-
│ │ ├── Monad.hs # Compiler monad stack
62-
│ │ └── Settings.hs # Compiler settings and types
63-
│ ├── Driver/ # Compiler driver
64-
│ │ ├── Cli.hs # Command line interface
65-
│ │ └── Pipeline.hs # Compilation pipeline
66-
│ └── Frontend/ # Parsing and analysis
67-
│ ├── Lexer.hs # Lexical analysis
68-
│ ├── Parse.hs # Parsing
69-
│ └── Tokens.hs # Token definitions
69+
.
70+
├── app/ # Application entry point
71+
│ └── Main.hs
72+
├── bin/ # Binary outputs
73+
├── lib/ # Main library code
74+
│ ├── Halcyon.hs # Library entry point
75+
│ └── Halcyon/ # Core modules
76+
│ ├── Backend/ # Code generation and emission
77+
│ │ ├── Codegen.hs # TACKY to Assembly conversion
78+
│ │ ├── Emit.hs # Assembly to text output
79+
│ │ └── ReplacePseudos.hs # Register/stack allocation
80+
│ ├── Core/ # Core data types and utilities
81+
│ │ ├── Assembly.hs # Assembly representation
82+
│ │ ├── Ast.hs # C language AST
83+
│ │ ├── Monad.hs # Compiler monad stack
84+
│ │ ├── Settings.hs # Compiler settings and types
85+
│ │ ├── Tacky.hs # TACKY IR definition
86+
│ │ └── TackyGen.hs # AST to TACKY transformation
87+
│ ├── Driver/ # Compiler driver
88+
│ │ ├── Cli.hs # Command line interface
89+
│ │ └── Pipeline.hs # Compilation pipeline
90+
│ └── Frontend/ # Parsing and analysis
91+
│ ├── Lexer.hs # Lexical analysis
92+
│ ├── Parse.hs # Parsing
93+
│ └── Tokens.hs # Token definitions
94+
├── test/ # Test suite
95+
│ └── Main.hs
96+
├── CHANGELOG.md # Version history
97+
├── LICENSE # Project license
98+
├── README.md # Project documentation
99+
├── flake.nix # Nix build configuration
100+
└── halcyon.cabal # Cabal build configuration
70101
```
71102
72103
### Architecture
@@ -95,6 +126,7 @@ Options:
95126
--lex Run lexical analysis only
96127
--parse Run parsing only
97128
--codegen Run through code generation
129+
--tacky Run through TACKY generation
98130
-S Stop after assembly generation
99131
-h,--help Show help text
100132
```

halcyon.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: halcyon
3-
version: 0.1.0.0
3+
version: 0.2.0.0
44
-- synopsis:
55
-- description:
66
license: BSD-3-Clause

0 commit comments

Comments
 (0)