Comparing version 0.0.4 to 0.0.5
50
index.js
// petard, an llvm library | ||
ffi = require('ffi'); | ||
// load the native module | ||
@@ -21,2 +23,5 @@ var petard = require('bindings')('petard'); | ||
arrayOf: petard.getArrayTy, | ||
vectorOf: petard.getVectorTy, | ||
structOf: petard.getStructTy, | ||
pointerTo: petard.getPointerTy | ||
@@ -86,3 +91,3 @@ | ||
// structured switch statement helper | ||
var switchimpl = function Switch(cond) { | ||
var chooseimpl = function Choose(cond) { | ||
@@ -121,5 +126,46 @@ var that = this; | ||
attach("select", switchimpl); | ||
attach("choose", chooseimpl); | ||
// helper to load a jitted function | ||
var origMakeFn = petard.CodeUnit.prototype.makeFunction; | ||
petard.CodeUnit.prototype.makeFunction = function() { | ||
var fn = origMakeFn.apply(this, arguments); | ||
fn.codeUnit = this; | ||
return fn; | ||
}; | ||
function convertToRefType(ty) { | ||
if (ty.isVoidType()) return 'void'; | ||
if (ty.isIntType()) return 'int'; | ||
if (ty.isFloatType()) return 'float'; | ||
if (ty.isArrayType() && ty.element.isIntType() && ty.element.bitwidth == 8) return 'string'; | ||
if (ty.isPointerType() && ty.pointee.isIntType() && ty.pointee.bitwidth == 8) return 'string'; | ||
if (ty.isFunctionType()) { | ||
var ret = convertToRefType(ty.returns); | ||
var params = ty.parameters.map(function (p) { return convertToRefType(p); }); | ||
if (!ret) return; | ||
if (!params.every(function (p) { return !!p; })) return; | ||
return [ret, params]; | ||
} | ||
} | ||
var jitimpl = function JITFunction() { | ||
fnty = convertToRefType(this.type); | ||
if (!fnty) return; | ||
fn = this.codeUnit.jitFunction(this); | ||
return ffi.ForeignFunction(fn, fnty[0], fnty[1]); | ||
}; | ||
attach("jitCompile", jitimpl); | ||
// export everything | ||
module.exports = petard; |
{ | ||
"name": "petard", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "a js llvm library", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"clean": "node-gyp clean", | ||
"build": "node-gyp configure && node-gyp build", | ||
"build": "LLVM_CONFIG=llvm-config node-gyp configure && node-gyp build", | ||
"test": "node_modules/mocha/bin/mocha --reporter spec" | ||
@@ -27,2 +27,3 @@ }, | ||
"bindings": "^1.2.1", | ||
"ffi": "^2.0.0", | ||
"nan": "^2.1.0" | ||
@@ -29,0 +30,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
141597
36
113
613
3
+ Addedffi@^2.0.0
+ Addedbindings@1.2.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedffi@2.3.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedref@1.3.5(transitive)
+ Addedref-struct@1.1.0(transitive)