Overview
Themcc command compiles C source files through a complete compilation pipeline: preprocessing, parsing, lowering to Three Address Code (TACKY), code generation, and assembly/linking.
Basic Usage
Arguments
The C source file to compile
Options
The output file path for the compiled binary. If not specified, defaults to the input filename without extension.Short form:
-oExample:The target triple for cross-compilation (e.g.,
x86_64-unknown-linux-gnu). Defaults to the host system’s target.Default: Host system targetExample:Control colored output for diagnostics.Choices:
auto, always, neverDefault: autoExample:Examples
Compile a Simple Program
hello.c and produces an executable named hello in the current directory.
Input: hello.c
Specify Output File
main.c and writes the executable to myprogram.
Cross-Compilation
Disable Colored Output
Compilation Pipeline
Themcc compiler executes the following stages:
- Preprocessing - Expands macros and includes (delegates to system C preprocessor)
- Lexing - Tokenizes the preprocessed source
- Parsing - Builds an Abstract Syntax Tree (AST)
- Validation - Type checking and semantic analysis
- Lowering - Converts AST to Three Address Code (TACKY IR)
- Code Generation - Generates assembly instructions
- Assembly - Produces object files and links into executable
Diagnostics
The compiler emits diagnostics with severity levels:- Error - Compilation cannot continue
- Warning - Potential issues that don’t prevent compilation
- Note - Additional context for other diagnostics
Exit Codes
- 0 - Compilation succeeded
- Non-zero - Compilation failed (syntax error, type error, or system error)
Environment Variables
The C compiler to use for preprocessing and linking. Defaults to
cc.Default: ccExample:Controls tracing output for debugging the compiler itself.Default:
warn,mcc=debug,mcc-syntax=debug,mcc-driver=debugExample:Related Commands
- Stage Control - Stop compilation at specific stages
- Command Options - Complete reference of all flags