Overview
The MCC compiler pipeline can be stopped at any intermediate stage using stage-specific flags. This is useful for:- Debugging compiler issues
- Inspecting intermediate representations
- Testing individual pipeline stages
- Understanding the compilation process
Stage Flags
All stage flags are mutually exclusive - you can only specify one at a time.—lex
- Preprocess the input file
- Tokenize the source into a stream of tokens
- Stop and exit
- Debugging lexer issues
- Verifying token recognition
- Testing preprocessor integration
—parse
- Preprocess and tokenize
- Parse tokens into an Abstract Syntax Tree (AST)
- Stop and exit
- Debugging parser issues
- Verifying syntax correctness
- Inspecting AST structure (with tracing enabled)
—tacky
- Preprocess, tokenize, and parse
- Perform semantic analysis and type checking
- Lower the AST to Three Address Code intermediate representation
- Stop and exit
- Debugging semantic analysis
- Inspecting the intermediate representation
- Verifying lowering correctness
- Testing optimization passes (if implemented)
—codegen
- Complete all stages up through TACKY
- Generate assembly instructions from TACKY IR
- Stop before rendering assembly text
- Exit
- Debugging code generation
- Inspecting assembly instruction structure
- Testing register allocation
- Verifying instruction selection
-S flag instead (see Assembly Output).
Assembly Output
-S
-S runs the full pipeline but preserves the assembly file.
Behavior:
- Runs complete compilation pipeline
- Generates assembly text file (
.sextension) - Keeps the assembly file instead of deleting it
- Continues to assemble and link to produce executable
input.s alongside the executable
Example:
Combining Stage Flags with Other Options
Stage flags can be combined with other options:With Output Specification
With Color Control
With Target Specification
--codegen is meaningful.
Debugging with Stages
Narrow Down Compilation Errors
If compilation fails, use stage flags to identify which stage is problematic:Inspect Intermediate Output
Combine stage flags with tracing to see internal state:Compare Assembly Output
Stage Progression
The complete stage pipeline:Exit Behavior
When using stage flags:- Success: Exit code 0 if the stage completes without errors
- Failure: Non-zero exit code with diagnostics if the stage fails
- No output files: Stage flags typically don’t produce output files (except
-S)
Related Commands
- Basic Compilation - Standard compilation workflow
- Command Options - Complete flag reference