My implementation of of the compiler described in Writing a C Compiler by Nora Sandler.
This is a C compiler targeting the cpu I designed in Digital. At some point I'll make a repository with the cpu schematics. This repository also has an emulator for the cpu written in Rust.
I wrote the assembler in Python a few years ago. It works, but the code is a mess. Soon I'll write a better version in Haskell.
Run
source scripts/bcc.shfrom the c-compiler directory to be able to use the following commands.
Compile with
bcc source.c -flagsCompiler flags: tokens, ast, semantics, tac, or asm.
You can specify as many of these flags as you want, and the compiler will print
the output of the corresponding stage.
Assembler flags: -emu if you want to target the emulator. The Digital simulation is targeted by default, and the output is written to the folder with the cpu simulation.
Other flags:
-runif you want to immediately run the emulator after compiling-sif you want to keep the generated assembly code (it is removed by default)-outif you want to keep the generated.outfile-binif you want to keep the generated.binfile
You can also run
basm source.sto assemble an assembly file. basm accepts the -emu, -run, -s, -out, and -bin flags.
Run the emulator with
bemu source.bin