Note: this is an old repository from my senior year of college "Programming Languages" course. As a final project, I built a (very simple) compiler to turn MiniC
code into web assembly.
Goal: compile MiniC
assembly code into Web Assembly wasm
.
Proposed Solution: all web assembly code can be represented in a more readble, .wat
text format. The proposed solution will involve compiling MIPS
code generated from the MiniC
compiler, into S-Expressions
. The fundamental units of WASM are modules, and can be thought of as a "tree of nodes that describe the modules structure and code" (source). We can build a compiler that will compile the list of assembly instructions into a list of S-Expressions
. This .wat
file can then be converted to .wasm
using existing toolchains. Once complete a user would be able to run the code below and have an outputted program.asm
, program.dbg
, and program.wat
:
./mc program.mc
Resources: see the Resources.md folder for a collection of notes on web assembly - Resources.md
Proposed Goals:
- Explore Fundamentals of WebAssembly - Fundamentals.md
- Configure local environment for running WebAseembly -LocalEnviromnent.md
- Break down
MiniC -
MiniCEval.md- Step 1 - Setup
- Step 2 - System Args
- Step 3 - Debugging Setup
- Step 4 - Enviromnent Creation
- Step 5 - Parsing/Lexing
- Step 6 - Debugging File
- Step 7 - Static Type Checking
- Step 8 - Checking for Main Function
- Step 9 - Naming
- Step 10 - Lifting
- Step 11 - Copying
- Step 12 - Control Phase & Quads
- Step 13 - MIPS Codestream
- Step 13W - WASM Codestream
- Write Basic Function
.wat
- Breakdown syntax of
S-Expressions
- Competently write by hand
.wat
functions
- Breakdown syntax of
- Convert functions from
C
to.wat
by hand - Map out corresponding types between
Quads
andS-Expressions
- Compile
MiniC
assembly into.wat
- Understand and implement
OCaml
processes for reading in files (.asm
) - Understand and implement
OCaml
processes for writing out files (.wat
) - Compile
.asm
into.wat
- Compile
.wat
into .wasm
(in any tool chain) - Compile
.wat
into.wasm
(in OCaml toolchain)
- Understand and implement