{"id":13692944,"url":"https://github.com/andoma/vmir","last_synced_at":"2026-01-23T02:49:22.035Z","repository":{"id":43924607,"uuid":"50603856","full_name":"andoma/vmir","owner":"andoma","description":"Virtual Machine for Intermediate Representation","archived":false,"fork":false,"pushed_at":"2020-07-29T07:46:49.000Z","size":866,"stargazers_count":679,"open_issues_count":19,"forks_count":77,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-05-02T20:34:25.925Z","etag":null,"topics":["llvm-bitcode","virtual-machine","webassembly"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andoma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-28T18:29:22.000Z","updated_at":"2025-04-22T20:31:04.000Z","dependencies_parsed_at":"2022-08-12T10:52:00.611Z","dependency_job_id":null,"html_url":"https://github.com/andoma/vmir","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andoma/vmir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andoma%2Fvmir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andoma%2Fvmir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andoma%2Fvmir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andoma%2Fvmir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andoma","download_url":"https://codeload.github.com/andoma/vmir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andoma%2Fvmir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28679138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"online","status_checked_at":"2026-01-23T02:00:08.296Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llvm-bitcode","virtual-machine","webassembly"],"created_at":"2024-08-02T17:01:03.781Z","updated_at":"2026-01-23T02:49:22.017Z","avatar_url":"https://github.com/andoma.png","language":"C","readme":"# VMIR - Virtual Machine for Intermediate Representation\n\n[![Build status](https://doozer.io/badge/andoma/vmir/buildstatus/master)](https://doozer.io/user/andoma/vmir)\n\nVMIR is a standalone library written in C that can parse and execute:\n\n* WebAssembly `.wasm` files\n* LLVM Bitcode `.bc` files\n\nOptionally it can generate machine code (JIT) to speed up execution significantly. JIT is currently only supported on 32 bit ARM.\n\nVMIR is licensed under the MIT license. See [LICENSE](LICENSE).\n\nTo build VMIR just type:\n```\n$ make\n```\n... and you will end up with a VMIR binary in very same directory.\nThe library is compiled from a single file [src/vmir.c](src/vmir.c) which in turn include other files to keep the code somewhat separated.\n\n\n### Example\n\nLet's create a small program and run it. Type the following well known snippet into a file called helloworld.c\n```\nint main(void)\n{\n  printf(\"Hello world\\n\");\n  return 0;\n}\n```\nThen compile it\n```\nclang -emit-llvm -target le32-unknown-nacl -c helloworld.c -o helloworld.bc\n```\nAnd finally, run it:\n```\n$ ./vmir helloworld.bc\nHello world\n```\n\nCompiling to WebAssembly requires a bit more work than a single line. However,\nthere is a pre-built version of `sha1sum` included in the source repo.\n\n````\n$ echo hello | ./vmir examples/prebuilt/sha1sum.wasm\nf572d396fae9206628714fb2ce00f72e94f2258f  -\n````\n\n\nIf you're on Linux and want to go all crazy you can use VMIR to execute Bitcode\nand WebAssembly directly from the command line by installing a kernel binfmt pointing to the VMIR executable:\n\n```\necho \":vmirwasm:M::\\x00\\x61\\x73\\x6d\\x01::${PWD}/vmir:\" | sudo tee /proc/sys/fs/binfmt_misc/register\necho \":vmirbc:M::\\x42\\x43\\xc0\\xde::${PWD}/vmir:\" | sudo tee /proc/sys/fs/binfmt_misc/register\n```\n\nAnd then you just simply just do:\n\n```\n$ echo hello | examples/prebuilt/sha1sum.wasm\nf572d396fae9206628714fb2ce00f72e94f2258f  -\n```\n\n### Performance\n\nInterpretation 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)\n\nExample run of [test/misc/src/sha1test.c](test/misc/src/sha1test.c)  over 64MB of random data\n\nEnvironment | (Core i7 3.2GHz) | ARMv7 BCM2709 (Rpi2)\n--- | --- | ---\nNative | 0.39s | 3.54s\nVMIR JIT | n/a | 17.5s\nVMIR | 4.8s | 1m 42s\nLLVM LLI | 7m 39s | n/a\n\n\n### Status\n\nVMIR currently passes the gcc torture test suite on optimization level 0, 1 and 2. Those tests can be found in [test/gcc-torture](test/gcc-torture). Use `make \u0026\u0026 ./runtest` to run the tests.\n\n\n### Missing features, known bugs\n\n* The built-in libc is lacking a lot of functions and features. This is where most work needs to be done.\n* No support for vector types (Ie, code must be compiled with `-fno-vectorize -fno-slp-vectorize`).\n* Not all instructions classes / value types are JITed.\n* No C++ STL solution. Ideas welcome...\n\n\n### Compiling C/C++ to Bitcode\n\nVMIR uses the same target as Google NativeClient. There are small examples in [test/misc](test/misc).\n\nWhen building bigger projects consisting of multiple files you must `llvm-link` to combine the `.bc` files into a single file.\n\n### Compiling C/C++ to WebAssembly\n\nBuilding for WebAssembly is a bit more involved atm. There is a document here: [docs/wasm.md](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](examples/wasm) that could get you started.\n\n### Embedding VMIR\n\nIncluding VMIR in your own project is pretty straight forward. Just copy the files from [src/](src/) to your project but only compile [vmir.c](src/vmir.c) (it will include all other .c -files on its own). The API is defined in [vmir.h](src/vmir.h). See [src/main.c](src/main.c) for example how to load and execute binaries.\n\nVMIR'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.\n\n### Wait? Wut? Why?\n\nYou might ask yourself what the purpose of VMIR actually is and why it\neven exists?\n\nAs with many of these kind of project I just wanted to scratch and itch but\nalso be able to ship plugins written in C and C++ for another project of mine.\n\nNow with the rise of WebAssembly I intend to focus more on that as the primary\ninput to VMIR mostly because it's more stable than LLVM's Bitcode, which is\nnot really meant to be used as a shippable object code.\n\nGiven enough time I also hope to improve the JIT engine to be able to emit\ncode for more architectures (In particular ARMv8 and x86_64).\n\nFollow me on https://twitter.com/andoma\n","funding_links":[],"categories":["Runtimes"],"sub_categories":["**C**"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandoma%2Fvmir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandoma%2Fvmir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandoma%2Fvmir/lists"}