Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Converting LLVM IR to JavaScript


In this recipe, we will briefly discuss how we can convert LLVM IR to JavaScript.

Getting ready

To convert IR to JavaScript, perform the following steps:

  1. We will make use of the 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.

  2. After downloading the SDK, extract it to a location and go to the root folder of the download.

  3. Install the default-jre, nodejs, cmake, build-essential, and git dependencies.

  4. Execute the following commands to install the SDK:

    ./emsdk update
    ./emsdk install latest
    ./emsdk activate latest
    
  5. See the ~/emscripten script to check whether it has the correct values, and if not, update it accordingly.

How to do it…

Perform the following steps:

  1. Write the test code for the conversion:

    $ cat test.c
    #include<stdio.h>
    
    int...