Skip to content

irrio/semblance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Semblance

Semblance is an in-place WebAssembly interpreter written in C. The implementation is a rather direct translation of the WebAssembly Core Specification into C code. Everything is much easier to grok if you are familiar with the spec.

I wanted to understand the WebAssembly core specification in detail, and this project is the result of that. As such, this is not production quality software. There are many places where I've skipped input validation in an effort to move forward quickly. One should be careful to only evaluate trusted WebAssembly modules with this interpreter.

I'm still a far way off from implementing every opcode. I doubt it will ever get that far. But I've made enough progress that simple Hello, World programs will run without issue.

Build Instructions

Compile the interpreter by running make. The executable will be found at target/semblance.

make

Usage Instructions

semblance <MODULE.wasm>

Options:
    -h, --help              Print this help text
    -I, --invoke <NAME>     Invoke the function exported as $NAME

Currently, the runtime provides an implementation of void puts(char *str); that can be used to write to standard output.

extern void puts(char *str);

void hello() {
    puts("Hello, World!");
}

Compile this C code to WebAssembly with Clang:

clang \
    --target=wasm32 \
    -O3 \
    # Don't include the standard library
    -nostdlib \
    # Don't include an entry point
    -Wl,--no-entry \
    # Export all symbols in the resulting module
    -Wl,--export-all \
    # Allow any undefined symbols (like puts) to be
    # found in the environment, provided by the runtime
    -Wl,--allow-undefined \
    -o hello.wasm \
    hello.c

Run hello.wasm:

./target/semblance hello.wasm --invoke hello

This should output:

Hello, World!
Ok []

Contributing

Since this project is primarily for my personal learning purposes, I am currently not accepting any pull requests. However, I am pretty inexperienced writing C and would happily accept a code review from someone willing to provide feedback.

About

My little WebAssembly interpreter

Topics

Resources

Stars

Watchers

Forks

Languages