```
██████╗██████╗ ██╗ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
██╔════╝██╔══██╗██║ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
██║ ██████╔╝██║ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██████╔╝
██║ ██╔═══╝ ██║ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██╔══██╗
╚██████╗██║ ███████╗ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║
╚═════╝╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝
```
CPL Compiler is a 6-stage cross compiler built with Python and Flask. It takes CPL source code and walks it through the complete compilation pipeline — right in your browser. It generates both x86-style Assembly and C99 from the same source.
Source Code
│
▼
┌──────────────┐
│ 1. Lexer │ → Tokenizes source into typed tokens
└──────┬───────┘
▼
┌──────────────┐
│ 2. Parser │ → Builds Abstract Syntax Tree (AST)
└──────┬───────┘
▼
┌──────────────┐
│ 3. Semantic │ → Type checking, scope & symbol resolution
└──────┬───────┘
▼
┌──────────────┐
│ 4. IR Gen │ → Generates Three-Address Code (TAC)
└──────┬───────┘
▼
┌──────────────┐
│ 5. Optimizer│ → Dead code elimination & instruction reduction
└──────┬───────┘
▼
┌──────────────┐
│ 6. Codegen │ → Outputs x86 Assembly + C99 code
└──────────────┘
- Python 3.8+ (Verify:
python --version)
git clone https://github.com/vikasjha11/Cross_Compiler_Project.git
cd Cross_Compiler_Project
pip install -r requirements.txtPath A - Web UI (recommended for full visual pipeline):
python app.pyOpen in browser:
http://localhost:5000
Then:
- Paste CPL code in the editor.
- Click Compile.
- Verify all pipeline stages appear: Tokens, AST, Semantic, TAC, Optimized TAC, Assembly, C output.
- Check generated files in project root: output.asm and output.c.
Path B - CLI mode (recommended for terminal demo):
python cplc.pyThen:
- Watch all 6 stages print in terminal.
- Verify final files generated in project root: output.asm and output.c.
- Use these outputs for verification on another machine.
The project also follows the idea of a T-diagram, where the compiler is shown as a translation tool from CPL source into target code.
In this project:
- The host machine runs the compiler.
- The compiler translates CPL into x86 Assembly and C99.
- The generated C file can be moved to another machine and compiled there.
- This shows the cross-compilation pipeline clearly in T-diagram form.
Bootstrapping a compiler means using a simpler version of the compiler (or a host compiler) to compile a more advanced version of itself. This is a classic technique in compiler development that demonstrates the compiler can compile its own kind of code.
Phase 0 — Host compilation:
- Run the Python-based CPL compiler on
bootstrap.cpl. - The compiler outputs
output.asm(x86 assembly) andoutput.c(C99 source). - Inspect the generated code to confirm it correctly represents the bootstrap seed logic.
Phase 1 — Native compilation:
- Compile the generated
output.cwith your system C compiler (gcc or clang). - This creates a native binary that can run independently.
- The C output is portable and can be moved to another machine.
Phase 2 — Self-hosting iteration:
- Use the native compiler from Phase 1 to compile future CPL programs.
- Eventually, compile a CPL-written version of the compiler itself.
- Once the CPL compiler can compile itself, the project is fully self-hosted.
Option A: Bootstrap mode (recommended for demo)
python cplc.py --bootstrapThis runs Phase 0 automatically on bootstrap.cpl, shows all compilation stages, and prints the bootstrap narrative.
Option B: Compile any CPL file directly
python cplc.py bootstrap.cpl --target bothThis also generates both target outputs but without the bootstrap narrative.
- Paste CPL code in the editor.
- Click Compile.
- Check all stage outputs in the right panel.
Each compile also overwrites:
output.asmoutput.c
python cplc.pyCLI prints all compilation stages and writes output.asm and output.c.
See both points:
- Your compiler generates target files (
output.asm,output.c) from CPL source. - Generated target code runs on another machine.
Demo steps:
- Run compiler on your machine (
python cplc.pyor web compile). - Show generated files in project root.
- Copy
output.cto another machine. - Compile and run on the other machine:
gcc output.c -o program
./program- Show matching output.
Notes:
output.cis the portable proof (works across CPU architectures when recompiled).output.asmis architecture-specific (x86).





