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 = ;
And any LLVM C API call that has a binding can be called directly:
const aModule = libLLVM;const theName = libLLVM; console; // mymodule // and since these are C bindings you are responsible for the memory management libLLVM;
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 = ; const moduleRef = libLLVM;const builderRef = libLLVM; // create params for mainconst params = libLLVM libLLVM; // create the function prototypeconst funcType = libLLVM;const func = libLLVM; libLLVM; // name the paramsconst argc = libLLVM;const argsv = libLLVM; libLLVM;libLLVM; // build body of the functionconst entry = libLLVM;libLLVM;libLLVM; // print out the LLVM IR for this moduleconsole; // clean uplibLLVM;libLLVM;
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!