var ffi      = require('ffi'),
    ref      = require('ref'),
    refTypes = require('./ref-types')

var ptr           = refTypes.ptr,
    void_         = ref.types.void,
    TypeRefArray  = refTypes.TypeRefArray,
    ArgRefArray   = refTypes.ArgRefArray


// Build the FFI library
var Library = ffi.Library('libLLVM-3.5', {
  'LLVMModuleCreateWithName': [ptr,   ['CString']],
  'LLVMDumpModule':           [void_, [ptr]],
  'LLVMDumpValue':            [void_, [ptr]],
  'LLVMAddFunction':          [ptr,   [ptr, 'CString', ptr]],

  'LLVMCreateFunctionPassManagerForModule': [ptr, [ptr]],

  'LLVMAppendBasicBlock':     [ptr,   [ptr, 'CString']],

  'LLVMCreateBuilder':        [ptr,   []],
  'LLVMPositionBuilderAtEnd': [void_, [ptr, ptr]],
  'LLVMGetInsertBlock':       [ptr,   [ptr]],
  'LLVMBuildGlobalStringPtr': [ptr,   [ptr, 'CString', 'CString']],
  'LLVMBuildCall':            [ptr,   [ptr, ptr, ArgRefArray, 'uint', 'CString']],
  'LLVMBuildRet':             [ptr,   [ptr, ptr]],
  'LLVMBuildRetVoid':         [ptr,   [ptr]],
  'LLVMBuildAlloca':          [ptr,   [ptr, ptr, 'CString']],
  'LLVMBuildGEP':             [ptr,   [ptr, ptr, ArgRefArray, 'uint', 'CString']],
  'LLVMBuildStructGEP':       [ptr,   [ptr, ptr, 'uint', 'CString']],
  'LLVMBuildStore':           [ptr,   [ptr, ptr, ptr]],
  'LLVMBuildLoad':            [ptr,   [ptr, ptr, 'CString']],
  'LLVMBuildPointerCast':     [ptr,   [ptr, ptr, ptr, 'CString']],

  'LLVMFunctionType':         [ptr, [ptr, TypeRefArray, 'uint', 'bool']],
  'LLVMInt64Type':            [ptr, []],
  'LLVMInt32Type':            [ptr, []],
  'LLVMInt8Type':             [ptr, []],
  'LLVMVoidType':             [ptr, []],
  'LLVMPointerType':          [ptr, [ptr, 'uint']],
  'LLVMStructType':           [ptr, [TypeRefArray, 'uint', 'bool']],
  'LLVMDumpType':             [ptr, [ptr]],
  'LLVMTypeOf':               [ptr, [ptr]],
  'LLVMGetElementType':       [ptr, [ptr]],
  'LLVMGetTypeKind':          ['int', [ptr]],

  'LLVMConstString':          [ptr, ['CString', 'uint', 'bool']],
  'LLVMConstInt':             [ptr, [ptr, 'ulonglong', 'bool']],
  'LLVMConstIntCast':         [ptr, [ptr, ptr, 'bool']],
  'LLVMConstIntToPtr':        [ptr, [ptr, ptr]],
  'LLVMConstFPCast':          [ptr, [ptr, ptr]],
  'LLVMConstBitCast':         [ptr, [ptr, ptr]],
  'LLVMConstPointerCast':     [ptr, [ptr, ptr]],

  'LLVMGetParam':             [ptr, [ptr, 'uint']],

  'LLVMWriteBitcodeToFile':   ['int', [ptr, 'CString']]
})

module.exports = Library


@@ -318,16 +318,43 @@
 3.5', %7B%0A
+  // Modules and functions%0A
   'LLVMM
@@ -393,24 +393,24 @@
 CString'%5D%5D,%0A
-
   'LLVMDumpM
@@ -617,63 +617,52 @@
 %0A%0A  
-'LLVMAppendBasicBlock':     %5Bptr,   %5Bptr, 'CString'%5D%5D,%0A
+// Instruction builder and support functions
 %0A  '
@@ -748,24 +748,81 @@
 ptr, ptr%5D%5D,%0A
+  'LLVMAppendBasicBlock':     %5Bptr,   %5Bptr, 'CString'%5D%5D,%0A
   'LLVMGetIn
@@ -847,32 +847,59 @@
 %5Bptr,   %5Bptr%5D%5D,%0A
+  // Building instructions%0A
   'LLVMBuildGlob
@@ -1527,24 +1527,47 @@
 String'%5D%5D,%0A%0A
+  // Type constructors%0A
   'LLVMFunct
@@ -1904,32 +1904,63 @@
 uint', 'bool'%5D%5D,
+%0A%0A  // Type functions/utilities
 %0A  'LLVMDumpType
@@ -2115,32 +2115,65 @@
 'int', %5Bptr%5D%5D,%0A%0A
+  // Constant values and casting%0A
   'LLVMConstStri

Add some comments to library FFI definition