Chapter Progression
Tests are organized in the directory structure:Test Categories
Tests are organized by expected behavior:Valid Tests (valid/)
Programs that should:
- Compile successfully through all stages
- Execute and return the expected exit code
- Produce the expected standard output (if specified)
expected_results.json):
Invalid Tests
Programs that should fail at specific compilation stages:invalid_parse/- Lexical or syntactic errorsinvalid_tacky/- Errors during lowering to intermediate representationinvalid_semantics/- Semantic analysis errorsinvalid_codegen/- Code generation errorsinvalid_types/- Type checking errors (in later chapters)
Chapter Overview
Chapters 1-10: Core Language Features
These chapters introduce fundamental C language constructs: Chapter 1: A Minimal Compiler- Basic program structure
- Return statements
- Integer literals
- Tests: Simple programs that return integer constants
- Negation (
-) - Bitwise complement (
~) - Logical negation (
!) - Tests: Expressions with unary operators
- Addition and subtraction
- Multiplication and division
- Modulo
- Tests: Arithmetic expressions with operator precedence
- Comparison operators (
<,>,<=,>=,==,!=) - Logical operators (
&&,||) - Short-circuit evaluation
- Tests: Boolean expressions and comparisons
- Variable declarations
- Assignment statements
- Identifier resolution
- Tests: Programs using local variables
- If statements
- Conditional expressions (ternary operator)
- Block statements
- Tests: Control flow with conditionals
- Compound operators (
+=,-=,*=,/=,%=) - Tests: Assignment operators with side effects
- While loops
- Do-while loops
- For loops
- Break and continue statements
- Tests: Iterative control flow
- Function declarations
- Function definitions
- Function calls
- Parameter passing
- Tests: Multi-function programs
- Global variables
- Static variables
- Storage class specifiers
- Tests: Variable scoping and lifetime
Chapters 11-18: Advanced Features
These chapters introduce more complex language features: Chapter 11: Long Integerslongtype- Type conversions
- Tests: 64-bit integer arithmetic
unsignedtype specifier- Signed/unsigned conversions
- Tests: Unsigned arithmetic and wrap-around
doubletype- Floating-point arithmetic
- Type conversions with floating-point
- Tests: Floating-point expressions
- Pointer types
- Address-of operator (
&) - Indirection operator (
*) - Tests: Pointer arithmetic and dereferencing
- Array declarations
- Array subscripting
- Array/pointer relationship
- Tests: Array access and manipulation
- String literals
- Character arrays
- String manipulation
- Tests: String operations
- Structure types
- Member access (
.and->) - Structure assignment
- Tests: Complex data structures
- Function pointers
- Void pointers
- Pointer conversions
- Tests: Advanced pointer usage
Chapter 19: Optimizations
This chapter introduces compiler optimizations:- Constant folding
- Dead code elimination
- Copy propagation
- Common subexpression elimination
- Preserve program semantics
- Improve code quality
- Handle edge cases correctly
--fold-constants).
Chapter 20: Register Allocation
This chapter tests efficient register usage:- Register allocation strategies
- Spilling to memory
- Register coalescing
- Generates efficient code
- Handles register pressure
- Produces correct results with limited registers
Test Naming Convention
Test names follow the pattern:chapter_{n}::{kind}::{filename}
Examples:
chapter_1::valid::return_2chapter_3::invalid_parse::malformed_parenchapter_5::valid::multiple_varschapter_6::invalid_semantics::undeclared_var
- Easy filtering by chapter:
chapter_3 - Easy filtering by kind:
::valid:: - Easy filtering by feature:
return
Chapter Configuration
The test harness limits which chapters are tested viaMAX_CHAPTER:
- Progressive development (implement features chapter by chapter)
- CI to run only completed chapters
- Development testing of future chapters with
--ignored
Feature Dependencies
Later chapters depend on earlier ones:- Chapter 5 (variables) requires chapters 1-4 (expressions)
- Chapter 6 (conditionals) requires chapter 5 (variables)
- Chapter 8 (loops) requires chapter 6 (conditionals)
- Chapter 9 (functions) requires chapter 8 (loops)
- Chapter 14 (pointers) requires chapters 11-13 (type system)
Extra Credit Features
Some chapters include optional “extra credit” features:- Bitwise operators (
&,|,^,<<,>>) - Compound assignment with bitwise operators
- Increment/decrement operators (
++,--) - Goto statements and labels
- Switch statements
- NaN handling for floating-point
- Union types
Expected Results
All test expectations are defined inexpected_results.json: