All Projects → andoma → Vmir

andoma / Vmir

Licence: mit
Virtual Machine for Intermediate Representation

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Vmir

Lam
🚀 a lightweight, universal actor-model vm for writing scalable and reliable applications that run natively and on WebAssembly
Stars: ✭ 176 (-65.76%)
Mutual labels:  webassembly, virtual-machine
Ring
Innovative and practical general-purpose multi-paradigm language
Stars: ✭ 716 (+39.3%)
Mutual labels:  webassembly, virtual-machine
Wasm3
🚀 The fastest WebAssembly interpreter, and the most universal runtime
Stars: ✭ 4,375 (+751.17%)
Mutual labels:  webassembly, virtual-machine
Wasmvm
An unofficial standalone WebAssembly process virtual machine
Stars: ✭ 164 (-68.09%)
Mutual labels:  webassembly, virtual-machine
Customasm
💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Stars: ✭ 211 (-58.95%)
Mutual labels:  webassembly, virtual-machine
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (-94.16%)
Mutual labels:  virtual-machine, webassembly
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (-4.67%)
Mutual labels:  webassembly, virtual-machine
Embiggen Disk
embiggden-disk live-resizes a filesystem after first live-resizing any necessary layers below it: an optional LVM LV and PV, and an MBR or GPT partition table
Stars: ✭ 440 (-14.4%)
Mutual labels:  virtual-machine
Llvm
Project moved to: https://github.com/llvm/llvm-project
Stars: ✭ 4,461 (+767.9%)
Mutual labels:  virtual-machine
Gasm
An Experimental Wasm Virtual Machine for Gophers
Stars: ✭ 437 (-14.98%)
Mutual labels:  virtual-machine
16bitjs
💻 A 16-bit virtual machine, including assembly language with 37 instructions, binary assembler, and a step through debugger
Stars: ✭ 427 (-16.93%)
Mutual labels:  virtual-machine
Wasm Imagemagick
Webassembly compilation of https://github.com/ImageMagick/ImageMagick & samples
Stars: ✭ 442 (-14.01%)
Mutual labels:  webassembly
Wasm And Rust
WebAssembly and Rust: A Web Love Story
Stars: ✭ 476 (-7.39%)
Mutual labels:  webassembly
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (-14.79%)
Mutual labels:  webassembly
Turboscript
Super charged typed JavaScript dialect for parallel programming which compiles to WebAssembly
Stars: ✭ 487 (-5.25%)
Mutual labels:  webassembly
Mako
A simple virtual game console
Stars: ✭ 435 (-15.37%)
Mutual labels:  virtual-machine
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+1072.96%)
Mutual labels:  webassembly
Walt
⚡ Walt is a JavaScript-like syntax for WebAssembly text format ⚡
Stars: ✭ 4,513 (+778.02%)
Mutual labels:  webassembly
Asmble
Compile WebAssembly to JVM and other WASM tools
Stars: ✭ 466 (-9.34%)
Mutual labels:  webassembly
Gluesql
GlueSQL is quite sticky, it attaches to anywhere.
Stars: ✭ 463 (-9.92%)
Mutual labels:  webassembly

VMIR - Virtual Machine for Intermediate Representation

Build status

VMIR is a standalone library written in C that can parse and execute:

  • WebAssembly .wasm files
  • LLVM Bitcode .bc files

Optionally it can generate machine code (JIT) to speed up execution significantly. JIT is currently only supported on 32 bit ARM.

VMIR is licensed under the MIT license. See LICENSE.

To build VMIR just type:

$ make

... and you will end up with a VMIR binary in very same directory. The library is compiled from a single file src/vmir.c which in turn include other files to keep the code somewhat separated.

Example

Let's create a small program and run it. Type the following well known snippet into a file called helloworld.c

int main(void)
{
  printf("Hello world\n");
  return 0;
}

Then compile it

clang -emit-llvm -target le32-unknown-nacl -c helloworld.c -o helloworld.bc

And finally, run it:

$ ./vmir helloworld.bc
Hello world

Compiling to WebAssembly requires a bit more work than a single line. However, there is a pre-built version of sha1sum included in the source repo.

$ echo hello | ./vmir examples/prebuilt/sha1sum.wasm
f572d396fae9206628714fb2ce00f72e94f2258f  -

If you're on Linux and want to go all crazy you can use VMIR to execute Bitcode and WebAssembly directly from the command line by installing a kernel binfmt pointing to the VMIR executable:

echo ":vmirwasm:M::\x00\x61\x73\x6d\x01::${PWD}/vmir:" | sudo tee /proc/sys/fs/binfmt_misc/register
echo ":vmirbc:M::\x42\x43\xc0\xde::${PWD}/vmir:" | sudo tee /proc/sys/fs/binfmt_misc/register

And then you just simply just do:

$ echo hello | examples/prebuilt/sha1sum.wasm
f572d396fae9206628714fb2ce00f72e94f2258f  -

Performance

Interpretation is about 10x slower (on x86) than the same binary compiled as native code. Still it's a lot faster than LLVM's own interpreter (which by all means is not intended to run code fast in any way)

Example run of test/misc/src/sha1test.c over 64MB of random data

Environment (Core i7 3.2GHz) ARMv7 BCM2709 (Rpi2)
Native 0.39s 3.54s
VMIR JIT n/a 17.5s
VMIR 4.8s 1m 42s
LLVM LLI 7m 39s n/a

Status

VMIR currently passes the gcc torture test suite on optimization level 0, 1 and 2. Those tests can be found in test/gcc-torture. Use make && ./runtest to run the tests.

Missing features, known bugs

  • The built-in libc is lacking a lot of functions and features. This is where most work needs to be done.
  • No support for vector types (Ie, code must be compiled with -fno-vectorize -fno-slp-vectorize).
  • Not all instructions classes / value types are JITed.
  • No C++ STL solution. Ideas welcome...

Compiling C/C++ to Bitcode

VMIR uses the same target as Google NativeClient. There are small examples in test/misc.

When building bigger projects consisting of multiple files you must llvm-link to combine the .bc files into a single file.

Compiling C/C++ to WebAssembly

Building for WebAssembly is a bit more involved atm. There is a document here: docs/wasm.md, that shows how to setup LLVM + Binaryen and the WebAssembly Binary Toolkit. Once you have that in place there are some small examples in examples/wasm that could get you started.

Embedding VMIR

Including VMIR in your own project is pretty straight forward. Just copy the files from src/ to your project but only compile vmir.c (it will include all other .c -files on its own). The API is defined in vmir.h. See src/main.c for example how to load and execute binaries.

VMIR's libc also offers an option to use TLSF for memory allocation. The default built-in allocator is a very simple linear search first-fit algorithm.

Wait? Wut? Why?

You might ask yourself what the purpose of VMIR actually is and why it even exists?

As with many of these kind of project I just wanted to scratch and itch but also be able to ship plugins written in C and C++ for another project of mine.

Now with the rise of WebAssembly I intend to focus more on that as the primary input to VMIR mostly because it's more stable than LLVM's Bitcode, which is not really meant to be used as a shippable object code.

Given enough time I also hope to improve the JIT engine to be able to emit code for more architectures (In particular ARMv8 and x86_64).

Follow me on https://twitter.com/andoma

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].