Skip to content

About

A Web Assembly Assembler and Compiler that follows the evolution of Computer languages from x86 assembly to modern C

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

45 Commits

Folders and files

Repository files navigation

Web Assembly Compiler

This project is talked about on my youtube channel JBrosDevelopment and my blog.

  1. Part 1: The Assembler: Youtube and Blog

Original Goal:

This Project is to follow the evolution of the Computers from opcode to programming languages. First is to learn the opcodes and how to run programs in web assembly binary. After I do this, I will create my own Assembly language for the web assembly binary. Once I have that, I can create my own C type programming language that will compile into my Assembly language and then into the web assembly binary.

This project has expanded it's goals:

  1. Full assembler and assembly language (wal: Web Assembly Language)
  2. Full Compiler that compiles a C type programming language (cweb: C Web Assembly) into wal and then into web assembly binary.
  3. For cweb to be able to be compiled by the gcc compiler into an executable as well as by this project into web assembly binary. (Make cweb a superset of C but with less features)
  4. A linker that can link multiple wal and cweb files into a single web assembly binary, allowing for easier programming with modularity and multiple files.
  5. A build system written in cweb that compiles into a library using gcc that ports to other languages for use in other projects. This is to eventually make other programming languages that compile using my cweb build system. (Basically my own custom LLVM)

Updates

I will update the DEVLOG as I progress through the project. Treat this almost as a blog of my progress.

I also do have a youtube channel and a blog, where I will be posting progress videos and blog posts about this project.

LICENSE

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Community

Please feel free to clone and fork this project! Any pull requests are welcome and will be looked at and may be merged if it alilgns with the goals of this project. It also may be included in the next video.

Building

After cloning this repository, to run the assembler you will need the following:

  1. Node.js - for Assembler.0.0 - Assembler.0.8
  2. Wasmtime - for Assembler.1.0 and above (recommended)

Assembling

Using Node.js, you can run the assembler using the following command:

node Assembler/assemble.js <version (ie. 0.7)> <input file (wal)> <output file (wasm)>

Note when running the assembler with Node.js, versions 1.0+ of the assembler use WASI functions so Node.js will not work and Wasmtime is required.

Using Wasmtime, you can run the assembler using the following command:

wasmtime run --dir . Assembler/bin/assembler.<version (ie. 1.2)>.wal.wasm <input file (wal)> <output file (wasm)>

Note when running the assembler with Wasmtime, versions 1.0+ of the assembler use WASI functions so Wasmtime is required and Node.js will not work.

Running

Once you have a wasm file, follow these steps to run it

With Node.js, you can run the wasm file using the following command:

node Assembler/run.js <input file (wasm)>

Note when running a wasm file with Node.js, any import functions defined in the WAL file will need to be defined in the JavaScript file used to run the wasm file. If you want to use specific WASI functions, you can import the @wasmer/wasi package and use it to run the wasm file, or you can use Wasmtime if you're not using any custom import functions.

With Wasmtime, you can run the wasm file using the following command:

wasmtime run <input file (wasm)>

Note when running a wasm file with Wasmtime, any import functions will need to be specific WASI functions. If you want to use your own import functions, you will need to use Node.js to run the wasm file.

Example

Open up the example directory after cloning this repository. The fibonacci.wal file is a simple program that calculates the fibonacci sequence. It uses Assembler.1.2. You can assemble it and run it with the following commands:

wasmtime run --dir . Assembler/bin/assembler.1.2.wal.wasm Example/fibonacci.wal fibonacci.wasm
node Example/run-fibonacci.js

This program uses the console.log function to print the fibonacci sequence to the console. You can change the input number in the run-fibonacci.js file to calculate a different fibonacci number.

About

A Web Assembly Assembler and Compiler that follows the evolution of Computer languages from x86 assembly to modern C

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages