Giter Site home page Giter Site logo

vincaslt / wasm-jit-prototype Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webassembly/wasm-jit-prototype

0.0 2.0 0.0 8.18 MB

Standalone VM using LLVM JIT

License: Other

CMake 0.42% C++ 15.36% Assembly 0.71% C 3.51% WebAssembly 79.78% Shell 0.04% Python 0.18%

wasm-jit-prototype's Introduction

Linux/OSX Build Status

Primary repo: https://github.com/AndrewScheidecker/WAVM

Overview

This is a standalone VM for WebAssembly. It can load both the standard binary format, and the text format defined by the WebAssembly reference interpreter. For the text format, it can load both the standard stack machine syntax and the old-fashioned AST syntax used by the reference interpreter, and all of the testing commands.

Building and running it

To build it, you'll need CMake and LLVM 6.0. If CMake can't find your LLVM directory, you can manually give it the location in the LLVM_DIR CMake configuration variable. Note that on Windows, you must compile LLVM from source, and manually point the LLVM_DIR configuration variable at <LLVM build directory>\lib\cmake\llvm.

Building WAVM on Windows

1.) Install the Visual Studio C++ Build Tools for Visual Studio 2015 or 2017

Take note of which version you have installed:

  • If using Visual Studio 2015, use -G"Visual Studio 14 Win64" for the <VS Generator Directive> placeholder below
  • If using Visual Studio 2017, use -G"Visual Studio 15 Win64" for the <VS Generator Directive> placeholder below

2.) Build LLVM x64 on Windows with Visual Studio

Create an llvm_build directory, navigate to that directory and run:

cmake -Thost=x64 <VS Generator Directive> -DCMAKE_INSTALL_PREFIX=<desired install path for LLVM> <path to LLVM source>

Open the generated LLVM.sln locateed within the 'llvm_build' directory in Visual Studio and build the "INSTALL" Project

The output binaries should be located in <desired install path for LLVM>

3.) Build WAVM x64 on Windows with Visual Studio against LLVM x64

Create a wavm_build directory, navigate to that directory and run:

cmake -Thost=x64 <VS Generator Directive> -DLLVM_DIR=<LLVM build directory>\lib\cmake\llvm <path to WAVM source>

Open the generated WAVM.sln located within the 'wavm_build' directory in Visual Studio and build the "ALL_BUILD" Project

The output binaries should be located in wavm_build\bin

Usage

I've tested it on Windows with Visual C++ 2015/2017, Linux with GCC and clang, and MacOS with Xcode/clang. Travis CI is testing Linux/GCC, Linux/clang, and OSX/clang.

The primary executable is wavm:

Usage: wavm [switches] [programfile] [--] [arguments]
  in.wast|in.wasm		Specify program file (.wast/.wasm)
  -f|--function name		Specify function name to run in module rather than main
  -c|--check			Exit after checking that the program is valid
  -d|--debug			Write additional debug information to stdout
  --				Stop parsing arguments

wavm will load a WebAssembly file and call main (or a specified function). Example programs to try without changing any code include those found in the Test/wast and Test/spec directory such as the following:

wavm Test/wast/helloworld.wast
wavm Test/Benchmark/Benchmark.wast
wavm Test/zlib/zlib.wast

WebAssembly programs that export a main function with the standard parameters will be passed in the command line arguments. If the same main function returns a i32 type it will become the exit code. WAVM supports Emscripten's defined I/O functions so programs can read from stdin and write to stdout and stderr. See echo.wast for an example of a program that echos the command line arguments back out through stdout.

There are a few additional executables that can be used to assemble the WAST file into a binary:

Assemble in.wast out.wasm

Disassemble a binary into a WAST file:

Disassemble in.wasm out.wast

and to execute a test script defined by a WAST file (see the Test/spec directory for examples of the syntax):

Test in.wast

Architecture

IR

The IR (Intermediate Representation) is the glue that the WAST parser, the WASM serialization, and the Runtime communicate through. It closely mirrors the semantics of the WebAssembly binary format, but is easier to work with in memory.

Parsing

Parsing the WebAssembly text format uses a table-driven deterministic finite automaton to scan the input string for tokens. The tables are generated from a set of tokens that match literal strings, and a set of tokens that match regular expressions. The parser is a standard recursive descent parser.

Runtime

The Runtime is the primary consumer of the byte code. It provides an API for instantiating WebAssembly modules and calling functions exported from them. To instantiate a module, it initializes the module's runtime environment (globals, memory objects, and table objects), translates the byte code into LLVM IR, and uses LLVM to generate machine code for the module's functions.

License

WAVM is provided under the terms of LICENSE.

wasm-jit-prototype's People

Contributors

andrewscheidecker avatar icefox avatar avsm avatar toolboc avatar chicoxyzzy avatar vincaslt avatar orthographic-pedant 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.