In this recipe, we will briefly discuss how we can convert LLVM IR to JavaScript.
To convert IR to JavaScript, perform the following steps:
emscripten
LLVM to JavaScript compiler. You need to download the SDK provided at https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html . You can also build it from the source code, but just for experimenting, you can use the SDK that comes with the toolchain.default-jre
, nodejs
, cmake
, build-essential
, and git
dependencies../emsdk update ./emsdk install latest ./emsdk activate latest
~/emscripten
script to check whether it has the correct values, and if not, update it accordingly.$ cat test.c #include<stdio.h> int main() { printf("hi, user! "); return 0; }
$ clang –S –emit-llvm test.c
emcc
executable located in the emsdk_portable/emscripten/master
directory to take this .ll
file as the input and convert it into JavaScript:$ ./emcc test.ll
a.out.js
file. We can execute this file using the following command:$ nodejs a.out.js hi, user!
18.119.159.178