Git Product home page Git Product logo

ilwasm's Introduction

ilwasm

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/install-mono.sh once to download & build from source, then do source third_party/JSIL/activate-mono.sh to load it into your current environment.

Build JSIL (third_party/JSIL/linux-build.sh), then build WasmSExprEmitter & WasmMeta (linux-build.sh).

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.

Exports

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

[Export]
public static void Exported () {}
[Export("customName")]
public static void AlsoExported () {}

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

Heap

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:

[Export]
public static int Property { get; set; }

Types

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

ilwasm's People

Contributors

kg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.