Compiler - Usage
Difficulty: 🟡 Intermediate
Time: 25 minutes
📚 What you’ll learn
- Basic usage of
cmcommand - Subcommands and options
- Debugging
- Output formats
Basic Usage
Interpreter Execution
# Basic
./build/bin/cm run program.cm
# Multiple files (Future)
./build/bin/cm run main.cm lib.cm
# From stdin
echo 'int main() { println("Hello"); return 0; }' | ./build/bin/cm run -
Compilation
# Generate executable
./build/bin/cm compile program.cm -o program
# Default output (a.out)
./build/bin/cm compile program.cm
# Run
./program
Subcommands
run - Interpreter
cm run program.cm
Pros/Cons:
- ✅ Instant execution
- ✅ Easy debugging
- ❌ Slow execution speed
compile - Compilation
cm compile program.cm -o output
Pros/Cons:
- ✅ Fast executable
- ✅ Optimization enabled
- ❌ Compilation time
check - Syntax & Type Checking
cm check program.cm
Pros/Cons:
- ✅ No compilation needed
- ✅ Detailed error location
- ✅ No LLVM required
Compiler Options
Optimization Levels
# No optimization (Debug)
cm compile program.cm -O0
# Basic optimization
cm compile program.cm -O1
# Standard optimization (Recommended)
cm compile program.cm -O2
# Maximum optimization
cm compile program.cm -O3
Target Specification
# Native code (Default)
cm compile program.cm -o program
# WebAssembly
cm compile program.cm --target=wasm -o program.wasm
# JavaScript
cm compile program.cm --target=js -o program.js
Output Formats
# Executable (Default)
cm compile program.cm -o program
# LLVM IR
cm compile program.cm --emit-llvm -o program.ll
# Assembly
cm compile program.cm --emit-asm -o program.s
Debugging Options
Debug Mode
# Show runtime debug info
cm run program.cm --debug
# Short option
cm run program.cm -d
Compile with Debug Info
# Include debug symbols
cm compile program.cm -g -o program_debug
# Debug with GDB
gdb ./program_debug
Next Steps
✅ Understood cm command basics
✅ Learned debugging methods
✅ Learned optimization options
✅ Understood targets (Native/WASM/JS)
⏭️ Next, learn about LLVM Backend
Related Links
- Environment Setup - Make command reference
- Linter - Static analysis
- Formatter - Code formatting
- JS Backend - JavaScript output
Previous: String Operations
Next: LLVM Backend
Last Updated: 2026-02-10