npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

llvm-ffi

v0.4.0

Published

FFI Interface for the LLVM 8 C API

Readme

FFI Interface for the LLVM 8 C API

This package provides FFI bindings/wrapper for the LLVM C API. Not all of the C API is currently supported by most of the core functionality is there. Added additional methods will be done as needed and Pull Requests are welcome!

Usage

Install the package via NPM:

npm i --save llvm-ffi

You obviously have to have an installation of LLVM 8, and have installed/compiled a version of libLLVM.dylib.

This library loads the path to the LLVM from the environment via the variable LLVM_PATH.

Once LLVM is in a valid location simply require this module:

const { libLLVM } = require('llvm-ffi');

And any LLVM C API call that has a binding can be called directly:

const aModule = libLLVM.LLVMModuleCreateWithName('mymodule');
const theName = libLLVM.LLVMGetModuleIdentifier(aModule);

console.log('LLVM module name:', theName); // mymodule

// and since these are C bindings you are responsible for the memory management

libLLVM.LLVMDisposeModule(aModule);

Example

Also examples/main.js for a runnable version.

To build a main function in LLVM thats callable when built into a binary:

const { libLLVM, enums } = require('llvm-ffi');

const moduleRef = libLLVM.LLVMModuleCreateWithName('main_module');
const builderRef = libLLVM.LLVMCreateBuilder();

// create params for main
const params = [
  libLLVM.LLVMInt32Type(),
  libLLVM.LLVMPointerType(libLLVM.LLVMPointerType(libLLVM.LLVMInt8Type(), 0), 0)
];

// create the function prototype
const funcType = libLLVM.LLVMFunctionType(libLLVM.LLVMVoidType(), params, params.length, 0);
const func = libLLVM.LLVMAddFunction(moduleRef, 'main', funcType);

libLLVM.LLVMSetLinkage(func, enums.LLVMLinkage.LLVMExternalLinkage);

// name the params
const argc = libLLVM.LLVMGetParam(func, 0);
const argsv = libLLVM.LLVMGetParam(func, 1);

libLLVM.LLVMSetValueName(argc, 'argc');
libLLVM.LLVMSetValueName(argsv, 'argsv');

// build body of the function
const entry = libLLVM.LLVMAppendBasicBlock(func, 'entry');
libLLVM.LLVMPositionBuilderAtEnd(builderRef, entry);
libLLVM.LLVMBuildRetVoid(builderRef);

// print out the LLVM IR for this module
console.log(libLLVM.LLVMPrintModuleToString(moduleRef));

// clean up
libLLVM.LLVMDisposeBuilder(builderRef);
libLLVM.LLVMDisposeModule(moduleRef);

And run it:

node main.js

And see the output of the LLVM IR created by the library:

; ModuleID = 'main_module'
source_filename = "main_module"

define void @main(i32 %argc, i8** %argsv) {
entry:
  ret void
}

Now go build a compiler!