Git Product home page Git Product logo

llvm-node's Introduction

llvm-node

Build Status npm version

Node Bindings for LLVM. The API is mostly identical to the one of LLVM (when possible and not to cumbersom). All supported methods with their signatures are listed in the TypeScript definition file.

Getting Started

Install the packages using npm or yarn.

npm install --save llvm-node

Require llvm-node and you're good to go

import * as llvm from "llvm-node";
// or
const llvm = require("llvm-node");

const context = new llvm.LLVMContext();
const module = new llvm.Module("test", context);

const intType = llvm.Type.getInt32Ty(context);
const initializer = llvm.ConstantInt.get(context, 0);
const globalVariable = new llvm.GlobalVariable(module, intType, true, llvm.LinkageTypes.InternalLinkage, initializer);

const ll = module.print(); // prints IR
llvm.writeBitcodeToFile(module, biteCodeFileName); // Writes file to disk

Custom LLVM Installation

You can use the npm configuration options to set the path to the LLVM cmake directory. This is needed if you don't want to use the system default LLVM installation --- e.g. when you want to compile againt the latest dev version.

To change the LLVM version use:

npm config set cmake_LLVM_DIR $(path-to-llvm/bin/llvm-config --cmakedir)

If you want to change the value just for a single project use an .npmrc file in your project.

Debug Build

If you want to use Value.dump or Module.dump you need to use the debug build of the library (and, as well, of LLVM). In this case, run node-gyp build --debug or if using npm install run npm_config_DEBUG=true npm install llvm-node.

There variables can also be set using npm set:

npm config set [--global] DEBUG True

Develop with VS-Code

  1. Install the C++ Extension
  2. Install the Cmake Tools Extension
  3. Configure the LLVM directory in the user settings by adding the following entry
"cmake.configureSettings": {
    "LLVM_DIR": "/usr/local/Cellar/llvm/7.0.0/lib/cmake/llvm" // Output of llvm-config --cmakedir
}
  1. Run the CMake:Configure Command in Visual Studio Code
  2. Run yarn configure from the command line
  3. Run CMake:Build command in Visual Studio Code

llvm-node's People

Contributors

emlai avatar ovr avatar themas3212 avatar vihanb avatar

Watchers

 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.