CIL to WebAssembly compiler
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
WasmSExprEmitter Update to build against latest JSIL Oct 26, 2015
third_party Add ml-proto submodule Oct 26, 2015
.gitignore Make puzzle test match original better. Add missing file. Sep 21, 2015
.gitmodules Add ml-proto submodule Oct 26, 2015
LICENSE Initial commit Sep 1, 2015 Implement enough for a hacked-up pointer version of the NBody test to… Sep 19, 2015
WasmSExprEmitter.sln Initial commit Sep 1, 2015
ilwasm.jsilconfig TravisCI compatibility Oct 26, 2015 TravisCI compatibility Oct 26, 2015 Add ml-proto submodule Oct 26, 2015
windows-build.bat All tests pass on windows except Strings Sep 8, 2015


Maps a subset of .NET CIL to WebAssembly S-expressions. Implemented as a custom code generator backend for the JSIL CIL -> JS compiler.

Building on Windows

Make sure you have Visual Studio 2015 (the free Community edition is fine). Build JSIL (third_party/JSIL/JSIL.sln), then build WasmSExprEmitter & WasmMeta (WasmSExprEmitter.sln).

Building on Linux

A recent version of Mono is required for C#6 support and NuGet compatibility. If you don't have a recent version of Mono installed, run third_party/JSIL/ once to download & build from source, then do source third_party/JSIL/ to load it into your current environment.

Build JSIL (third_party/JSIL/, then build WasmSExprEmitter & WasmMeta (

Writing tests

Tests are placed in the third_party/tests directory as .cs files. A test has a single entry point (typically Program.Main) that accepts no arguments and has no return value.

The entry point's body must contain only calls to APIs from Wasm.Test, like SetHeapSize or AssertEq. Constants are fine but locals, branching or other behavior are not allowed in the entry point, as it is converted into top-level wasm assertions.

For more sophisticated tests, AssertHeapEq and AssertHeapEqFile can be used to assert against the contents of the wasm heap. AssertHeapEqFile will produce the actual contents of the heap as a file in the output directory during test runs, for debugging.


A test can export static methods with the Wasm.Module.Export attribute, like so:

public static void Exported () {}
public static void AlsoExported () {}

Exported methods can be invoked by name in the entry point by using the Test.AssertEq and Test.Invoke APIs.


Tests requiring access to the heap must first reserve it using the Test.SetHeapSize API. To read/write the heap use the fields of the Wasm.Heap class, like so:

Wasm.Heap.I32[offset] = value;
value = Wasm.Heap.U8[@base, offset];

The heap is not accessible externally (i.e. in the entry point) so to perform assertions against heap data, you must expose the heap via an exported function.

You can get the base of the heap as a pointer using the Base property of the heap fields, i.e. Wasm.Heap.I32.Base.

Fields and properties

Static fields of supported types work. To access a field's value from outside, export accessor methods, or simply define it as an exported property:

public static int Property { get; set; }


Currently only integral and floating-point types are supported. Functions and variables of other types will be ignored (or outright rejected) by ilwasm.

Future features

  • Struct fields
  • Struct locals
  • ref/out parameters