From 5d010254cf66150f48360cabc279b0175a356254 Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Sun, 20 Dec 2009 21:00:50 -0500 Subject: [PATCH] Start to clean things up to get into a state usable by others. --- .gitignore | 3 + Makefile | 20 - README | 59 + Target.i | 26 - cl-llvm.asd | 50 +- examples/test.lisp | 52 +- src/Makefile | 32 + src/analysis.i | 6 + src/core.i | 257 +++++ src/execution-engine.i | 21 + src/generated/analysis.lisp | 30 + src/generated/core.lisp | 1893 ++++++++++++++++++++++++++++++++ src/generated/execution-engine.lisp | 129 +++ src/generated/target.lisp | 89 ++ src/generated/transforms-scalar.lisp | 76 ++ llvm-extras.cpp => src/llvm-extras.cpp | 7 + src/load-c-lib.lisp | 7 - src/packages-post.lisp | 13 + src/packages.lisp | 4 + src/stuff.lisp | 55 +- src/target.i | 8 + src/transforms-scalar.i | 3 + src/typemaps.i | 47 + 23 files changed, 2757 insertions(+), 130 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 README delete mode 100644 Target.i rewrite cl-llvm.asd (69%) create mode 100644 src/Makefile create mode 100644 src/analysis.i create mode 100644 src/core.i create mode 100644 src/execution-engine.i create mode 100644 src/generated/analysis.lisp create mode 100644 src/generated/core.lisp create mode 100644 src/generated/execution-engine.lisp create mode 100644 src/generated/target.lisp create mode 100644 src/generated/transforms-scalar.lisp rename llvm-extras.cpp => src/llvm-extras.cpp (79%) create mode 100644 src/packages-post.lisp create mode 100644 src/packages.lisp create mode 100644 src/target.i create mode 100644 src/transforms-scalar.i create mode 100644 src/typemaps.i diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce68fe8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.so +*~ diff --git a/Makefile b/Makefile deleted file mode 100644 index 05e494f..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -all: cl-llvm.so - -bindings: - swig -cffi -noswig-lisp -outdir src/generated -module core /usr/include/llvm-c/Core.h - swig -cffi -noswig-lisp -outdir src/generated -module analysis /usr/include/llvm-c/Analysis.h - swig -cffi -noswig-lisp -outdir src/generated -module execution-engine /usr/include/llvm-c/ExecutionEngine.h - swig -cffi -noswig-lisp -outdir src/generated -module target Target.i - swig -cffi -noswig-lisp -outdir src/generated -module transforms-scalar /usr/include/llvm-c/Transforms/Scalar.h - -CFLAGS=$(shell llvm-config --cflags) -CXXFLAGS=$(CFLAGS) -LDFLAGS=$(shell llvm-config --ldflags) -LINKER=g++ - -LIBS=-Wl,--whole-archive $(shell llvm-config --libs core jit interpreter native asmparser) -Wl,--no-whole-archive - -llvm-extras.o: llvm-extras.cpp - -cl-llvm.so: llvm-extras.o - $(LINKER) -shared -o $@ $(LDFLAGS) $^ $(LIBS) diff --git a/README b/README new file mode 100644 index 0000000..13281fe --- /dev/null +++ b/README @@ -0,0 +1,59 @@ +This is a wrapper around the LLVM C API. The design is to be a fairly +thin wrapper, without much lispification. + +NOTE: currently I've checked in the generated bindings in +src/generated/*.lisp. These are autogenerated with SWIG, but with +slightly modified versions of the LLVM .h files to make them work +better with SWIG. (so you shouldn't rebuild them). I'm working on +getting the changes upstream. Oh, and I patched SWIG too because it's +got some annoying bugs in its CFFI generator. :) + +USING +===== + +1) Build the shared library. + + Ensure you have llvm installed (including llvm-dev if applicable + for your distribution), then run: + + $ make -C src build + +2) Make the asdf system available. + + The way I do that is like this: + + $ ln -s $PWD/cl-llvm.asd ~/.sbcl/systems + +3) (require 'cl-llvm) + +NOTES +===== + +There are a few things which I have adjusted in the wrapper: + +1) The LLVM C API has a concept of a global context. I do not use the + C-level global context in the Lisp bindings, but instead have a + lisp-level dynamic variable *llvm-context*, which you may + rebind. (e.g. if you want to use LLVM from multiple threads without + locking, give each thread its own *llvm-context*). + + Whenever the LLVM C API has a pair of functions like + "LLVMInt32Type" and "LLVMInt32TypeInContext", I have instead + created a single function "LLVMInt32Type", which takes the same + arguments as the C function, but also takes an extra optional + argument for the context that defaults to *llvm-context*. + +2) Where the C API takes a pointer and a count for an array of values, + such as LLVMFunctionType, I have replaced the pointer/length + arguments with a list argument, in the same position. + +3) ...Except for LLVMAddIncoming, which in the C API, took an array of + incoming values/blocks to add to the PHI node. I simplified it to + take one at a time: call it multiple times to add multiple incoming + values. + +4) Where the C API uses an output array argument, such as + LLVMGetStructElementTypes, I instead return a list. + +5) Where the C API takes a pointer to a char *ErrorMsg, ...FIXME + something... diff --git a/Target.i b/Target.i deleted file mode 100644 index e300d7e..0000000 --- a/Target.i +++ /dev/null @@ -1,26 +0,0 @@ - // Target is annoying, handle it manually. :( -%{ -#include "/usr/include/llvm-c/Target.h" -%} - -LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); - -void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); -char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); -LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); -unsigned LLVMPointerSize(LLVMTargetDataRef); -LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); -unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); -unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); -unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); -unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); -unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); -unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); -unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, - LLVMValueRef GlobalVar); -unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, - unsigned long long Offset); -unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, - unsigned Element); -void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy); -void LLVMDisposeTargetData(LLVMTargetDataRef); diff --git a/cl-llvm.asd b/cl-llvm.asd dissimilarity index 69% index cd9b03a..c385548 100644 --- a/cl-llvm.asd +++ b/cl-llvm.asd @@ -1,17 +1,33 @@ -;; -*- Lisp -*- - -(defsystem :cl-llvm - :author "James Knight" - :depends-on (:cffi) - :version "0.1" - :components - ((:module "src" - :serial t - :components ((:file "load-c-lib") - (:module "generated" - :components ((:file "core") - (:file "analysis") - (:file "execution-engine") - (:file "target") - (:file "transforms-scalar"))) - (:file "stuff"))))) +;; -*- Lisp -*- + +(defsystem :cl-llvm + :author "James Y Knight" + :depends-on (:cffi) + :version "0.1" + :components + ((:module "src" + :serial t + :components ((:file "packages") + (:file "load-c-lib") + (:module "generated" + :serial t + :components ((:file "core") + (:file "analysis") + (:file "target") + (:file "execution-engine") + (:file "transforms-scalar"))) + (:file "stuff") + (:file "packages-post"))))) + +;; HACK, how do you really do this? Presumably there's a way with ASDF +;; to note that a shared lib should be loaded? + +(require :cffi) + +(pushnew (merge-pathnames "src/" (make-pathname :name nil :type nil :defaults *load-truename*)) + cffi:*foreign-library-directories*) + +(cffi:define-foreign-library cl-llvm + (t (:or (:default "cl-llvm") "cl-llvm.so"))) + +(cffi:use-foreign-library cl-llvm) diff --git a/examples/test.lisp b/examples/test.lisp index 53ab927..f320aba 100644 --- a/examples/test.lisp +++ b/examples/test.lisp @@ -1,14 +1,14 @@ (require 'cl-llvm) ;;; HACK! make sigabrt not abort. -(defun sigabrt-handler (signal info context) - (declare (ignore signal info)) - (declare (type system-area-pointer context)) - (sb-sys:with-interrupts - (error "sigabrt at #X~X" - (with-alien ((context (* sb-sys:os-context-t) context)) - (sb-sys:sap-int (sb-vm:context-pc context)))))) -(sb-sys:enable-interrupt sb-posix:sigabrt #'sigabrt-handler) +;; (defun sigabrt-handler (signal info context) +;; (declare (ignore signal info)) +;; (declare (type system-area-pointer context)) +;; (sb-sys:with-interrupts +;; (error "sigabrt at #X~X" +;; (with-alien ((context (* sb-sys:os-context-t) context)) +;; (sb-sys:sap-int (sb-vm:context-pc context)))))) +;; (sb-sys:enable-interrupt sb-posix:sigabrt #'sigabrt-handler) ;; Make a factorial function! (defun build-fac-fun () @@ -73,6 +73,42 @@ (LLVMDisposeBuilder builder) fac))) +(defun build-string-fun () + (let* ((mod *jit-module*)) + ;; Build it + (let* ((fac_args (list (LLVMInt32TypeInContext *llvm-context*))) + (fac (LLVMAddFunction mod "fac" (LLVMFunctionType* (LLVMInt32TypeInContext *llvm-context*) + fac_args 0))) + ;; Create code-builder object; this is reused throughout the rest of the function. + (builder (LLVMCreateBuilderInContext *llvm-context*))) + + ;; Use the c-call calling convention (the default) + (LLVMSetFunctionCallConv fac (cffi:foreign-enum-value 'LLVMCallConv :LLVMCCallConv)) + + ;; Create 4 new basic blocks: entry, iftrue, iffalse, end + (let* ((entry (LLVMAppendBasicBlockInContext *llvm-context* fac "entry"))) + (LLVMPositionBuilderAtEnd builder entry) + (let ((global (LLVMAddGlobal mod (LLVMArrayType (LLVMInt8Type) 5) ".str"))) + (LLVMSetInitializer global (LLVMConstStringInContext *llvm-context* "asdf" 4 0)) + (LLVMSetGlobalConstant global 1) + (LLVMBuildRet builder (LLVMBuildGEP* builder global (list (LLVMConstInt (LLVMInt32Type) 0 0) + (LLVMConstInt (LLVMInt32Type) 0 0)))))) + + ;; Dump textual description for debugging purposes + (LLVMDumpValue fac) + + ;; Verify that module is valid + (when (/= 0 (LLVMVerifyModule mod :LLVMPrintMessageAction (cffi:null-pointer))) + (error "Module didn't verify!")) + + ;; Run some optimizations +; (LLVMRunFunctionPassManager *jit-pass-manager* fac) +; (LLVMDumpValue fac) + + ;; Clean up + (LLVMDisposeBuilder builder) + fac))) + ;; Run the code! (defun run-fun (fun n) (let ((fun-ptr (LLVMGetPointerToGlobal *jit-execution-engine* fun))) diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..379978e --- /dev/null +++ b/src/Makefile @@ -0,0 +1,32 @@ +#LLVM_HEADERS=/usr/include/ +SWIG=swig +SWIGFLAGS=-cffi -noswig-lisp -generate-typedef -I$(LLVM_HEADERS) + +CFLAGS=$(shell llvm-config --cflags) +CXXFLAGS=$(CFLAGS) +LDFLAGS=$(shell llvm-config --ldflags) +LINKER=g++ +LLVM_LIBS=-Wl,--whole-archive $(shell llvm-config --libs core jit interpreter native asmparser) -Wl,--no-whole-archive + +BINDINGS_FILES=$(addprefix generated/,\ + core.lisp \ + analysis.lisp \ + execution-engine.lisp \ + target.lisp \ + transforms-scalar.lisp) + +all: build + +build: cl-llvm.so +bindings: $(BINDINGS_FILES) + +generated/%.lisp: %.i + $(SWIG) $(SWIGFLAGS) -o $@ -module $* $< + +llvm-extras.o: llvm-extras.cpp + +cl-llvm.so: llvm-extras.o + $(LINKER) -shared -o $@ $(LDFLAGS) $^ $(LLVM_LIBS) + +clean: + rm $(BINDINGS_FILES) cl-llvm.so llvm-extras.o diff --git a/src/analysis.i b/src/analysis.i new file mode 100644 index 0000000..b3d4a37 --- /dev/null +++ b/src/analysis.i @@ -0,0 +1,6 @@ +%include "typemaps.i" + +%include "llvm-c/Analysis.h" + +// TODO: +// LLVMVerifyModule has OutMessage diff --git a/src/core.i b/src/core.i new file mode 100644 index 0000000..ee5c2c0 --- /dev/null +++ b/src/core.i @@ -0,0 +1,257 @@ +%include "typemaps.i" + +typedef unsigned char uint8_t; + +// Rename/wrap functions that take pointer arguments + +%rename LLVMFunctionType "%%LLVMFunctionType"; +%rename LLVMGetParamTypes "%%LLVMGetParamTypes"; +%rename LLVMGetStructElementTypes "%%LLVMGetStructElementTypes"; +%rename LLVMConstArray "%%LLVMConstArray"; +%rename LLVMConstVector "%%LLVMConstVector"; +%rename LLVMConstGEP "%%LLVMConstGEP"; +%rename LLVMConstInBoundsGEP "%%LLVMConstInBoundsGEP"; +%rename LLVMConstExtractValue "%%LLVMConstExtractValue"; +%rename LLVMConstInsertValue "%%LLVMConstInsertValue"; +%rename LLVMGetParams "%%LLVMGetParams"; +%rename LLVMAddIncoming "%%LLVMAddIncoming"; +%rename LLVMBuildAggregateRet "%%LLVMBuildAggregateRet"; +%rename LLVMBuildInvoke "%%LLVMBuildInvoke"; +%rename LLVMBuildGEP "%%LLVMBuildGEP"; +%rename LLVMBuildInBoundsGEP "%%LLVMBuildInBoundsGEP"; +%rename LLVMBuildCall "%%LLVMBuildCall"; + +// Rename/wrap "InContext" functions. +%ignore LLVMModuleCreateWithName; +%rename LLVMModuleCreateWithNameInContext "%%LLVMModuleCreateWithNameInContext"; +%ignore LLVMInt1Type; +%rename LLVMInt1TypeInContext "%%LLVMInt1TypeInContext"; +%ignore LLVMInt8Type; +%rename LLVMInt8TypeInContext "%%LLVMInt8TypeInContext"; +%ignore LLVMInt16Type; +%rename LLVMInt16TypeInContext "%%LLVMInt16TypeInContext"; +%ignore LLVMInt32Type; +%rename LLVMInt32TypeInContext "%%LLVMInt32TypeInContext"; +%ignore LLVMInt64Type; +%rename LLVMInt64TypeInContext "%%LLVMInt64TypeInContext"; +%ignore LLVMIntType; +%rename LLVMIntTypeInContext "%%LLVMIntTypeInContext"; +%ignore LLVMFloatType; +%rename LLVMFloatTypeInContext "%%LLVMFloatTypeInContext"; + +%ignore LLVMDoubleType; +%rename LLVMDoubleTypeInContext "%%LLVMDoubleTypeInContext"; +%ignore LLVMX86FP80Type; +%rename LLVMX86FP80TypeInContext "%%LLVMX86FP80TypeInContext"; +%ignore LLVMFP128Type; +%rename LLVMFP128TypeInContext "%%LLVMFP128TypeInContext"; +%ignore LLVMPPCFP128Type; + +%rename LLVMPPCFP128TypeInContext "%%LLVMPPCFP128TypeInContext"; +%ignore LLVMStructType; +%rename LLVMStructTypeInContext "%%LLVMStructTypeInContext"; +%ignore LLVMVoidType; + +%rename LLVMVoidTypeInContext "%%LLVMVoidTypeInContext"; +%ignore LLVMLabelType; +%rename LLVMLabelTypeInContext "%%LLVMLabelTypeInContext"; +%ignore LLVMOpaqueType; +%rename LLVMOpaqueTypeInContext "%%LLVMOpaqueTypeInContext"; + +%ignore LLVMConstString; +%rename LLVMConstStringInContext "%%LLVMConstStringInContext"; +%ignore LLVMConstStruct; +%rename LLVMConstStructInContext "%%LLVMConstStructInContext"; +%ignore LLVMAppendBasicBlock; +%rename LLVMAppendBasicBlockInContext "%%LLVMAppendBasicBlockInContext"; +%ignore LLVMInsertBasicBlock; +%rename LLVMInsertBasicBlockInContext "%%LLVMInsertBasicBlockInContext"; +%ignore LLVMCreateBuilder; +%rename LLVMCreateBuilderInContext "%%LLVMCreateBuilderInContext"; + +%include "llvm-c/Core.h" + + +%insert("swiglisp") %{ +;;; The wrappers to expose the "InContext" versions of the functions +;;; in a more lispy way. +(declaim (special *llvm-context*)) + +(defun LLVMModuleCreateWithName (ModuleId &optional (context *llvm-context*)) + (%LLVMModuleCreateWithNameInContext ModuleId context)) + +(defun LLVMInt1Type (&optional (context *llvm-context*)) + (%LLVMInt1TypeInContext context)) + +(defun LLVMInt8Type (&optional (context *llvm-context*)) + (%LLVMInt8TypeInContext context)) + +(defun LLVMInt16Type (&optional (context *llvm-context*)) + (%LLVMInt16TypeInContext context)) + +(defun LLVMInt32Type (&optional (context *llvm-context*)) + (%LLVMInt32TypeInContext context)) + +(defun LLVMInt64Type (&optional (context *llvm-context*)) + (%LLVMInt64TypeInContext context)) + +(defun LLVMIntType (NumBits &optional (context *llvm-context*)) + (%LLVMIntTypeInContext context NumBits)) + +(defun LLVMFloatType (&optional (context *llvm-context*)) + (%LLVMFloatTypeInContext context)) + +(defun LLVMDoubleType (&optional (context *llvm-context*)) + (%LLVMDoubleTypeInContext context)) + +(defun LLVMX86FP80Type (&optional (context *llvm-context*)) + (%LLVMX86FP80TypeInContext context)) + +(defun LLVMFP128Type (&optional (context *llvm-context*)) + (%LLVMFP128TypeInContext context)) + +(defun LLVMPPCFP128Type (&optional (context *llvm-context*)) + (%LLVMPPCFP128TypeInContext context)) + +;; LLVMStructTypeInContext handled below. + +(defun LLVMVoidType (&optional (context *llvm-context*)) + (%LLVMVoidTypeInContext context)) + +(defun LLVMLabelType (&optional (context *llvm-context*)) + (%LLVMLabelTypeInContext context)) + +(defun LLVMOpaqueType (&optional (context *llvm-context*)) + (%LLVMOpaqueTypeInContext context)) + +;; LLVMConstStringInContext handled below +;; LLVMConstStructInContext handled below + +(defun LLVMAppendBasicBlock (Fn Name &optional (context *llvm-context*)) + (%LLVMAppendBasicBlockInContext context Fn Name)) + +(defun LLVMInsertBasicBlock (BB Name &optional (context *llvm-context*)) + (%LLVMInsertBasicBlockInContext context BB Name)) + +(defun LLVMCreateBuilder (&optional (context *llvm-context*)) + (%LLVMCreateBuilderInContext context)) + + +;; More complex wrappers for dealing with pointers. + +(defmacro with-array-and-length ((array len list) &body body) + (let ((list-v (gensym "list"))) + `(let* ((,list-v ,list) + (,len (length ,list-v))) + (cffi:with-foreign-object (,array :pointer ,len) + (loop for l in ,list-v + for i from 0 + do + (setf (cffi:mem-aref ,array :pointer i) l)) + (progn ,@body))))) + +(defun LLVMFunctionType (ret params is-var-arg) + "Combines the C API's ParamTypes array and ParamCount arguments into +a single list PARAMS." + (with-array-and-length (array len params) + (%LLVMFunctionType ret array len is-var-arg))) + +(defun LLVMGetParamTypes (function-type) + "Returns a list of param types rather than filling out a Dest pointer argument" + (let ((len (LLVMCountParamTypes function-type))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetParamTypes function-type array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMStructType (element-types is-packed &optional (context *llvm-context*)) + (with-array-and-length (array len element-types) + (%LLVMStructTypeInContext context array len is-packed))) + +(defun LLVMGetStructElementTypes (struct-type) + "Returns a list of param types rather than filling out a Dest pointer argument" + (let ((len (LLVMCountStructElementTypes struct-type))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetStructElementTypes struct-type array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMConstString (str dont-null-terminate &optional (context *llvm-context*)) + (cffi:with-foreign-string ((foreign-string num-bytes) str) + (%LLVMConstStringInContext context foreign-string num-bytes dont-null-terminate))) + +(defun LLVMConstStruct (vals packed-p &optional (context *llvm-context*)) + (with-array-and-length (array len vals) + (%LLVMConstStructInContext context array len packed-p))) + +(defun LLVMConstArray (type vals) + (with-array-and-length (array len vals) + (%LLVMConstArray type array len))) + +(defun LLVMConstVector (vals) + (with-array-and-length (array len vals) + (%LLVMConstVector array len))) + +(defun LLVMConstGEP (ptr indices) + (with-array-and-length (array len indices) + (%LLVMConstGEP ptr array len))) + +(defun LLVMConstInBoundsGEP (ptr indices) + (with-array-and-length (array len indices) + (%LLVMConstInBoundsGEP ptr array len))) + +(defun LLVMConstExtractValue (AggConstant indices) + (with-array-and-length (array len indices) + (%LLVMConstExtractValue AggConstant array len))) + +(defun LLVMConstInsertValue (AggConstant ValConstant indices) + (with-array-and-length (array len indices) + (%LLVMConstInsertValue AggConstant ValConstant array len))) + +(defun LLVMGetParams (fn) + "Returns a list of params rather than filling out a Dest pointer argument." + (let ((len (LLVMCountParams fn))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetParams fn array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMAddIncoming (phi-node incoming-val incoming-block) + "Unlike the C API (but like the C++ API...), takes only a single +incoming val and incoming block. Call multiple times if you want to +add multiple incoming values." + (cffi:with-foreign-objects ((incoming-vals :pointer) + (incoming-blocks :pointer)) + (setf (cffi:mem-aref incoming-vals :pointer 0) incoming-val) + (setf (cffi:mem-aref incoming-blocks :pointer 0) incoming-block) + (%LLVMAddIncoming phi-node incoming-vals incoming-blocks 1))) + +(defun LLVMBuildAggregateRet (builder vals) + (with-array-and-length (array len vals) + (%LLVMBuildAggregateRet builder array len))) + +(defun LLVMBuildInvoke (builder fn args then catch name) + (with-array-and-length (array len args) + (%LLVMBuildInvoke builder fn array len then catch name))) + +(defun LLVMBuildGEP (builder ptr indices name) + (with-array-and-length (array len indices) + (%LLVMBuildGEP builder ptr array len name))) + +(defun LLVMBuildInBoundsGEP (builder ptr indices name) + (with-array-and-length (array len indices) + (%LLVMBuildInBoundsGEP builder ptr array len name))) + +(defun LLVMBuildCall (builder fn args name) + "Combines the C API's Args array and NumArgs arguments into a single +list ARGS." + (with-array-and-length (array len args) + (%LLVMBuildCall builder fn array len name))) + +;; TODO: +;; LLVMCreateMemoryBufferWithContentsOfFile has OutMemBuf, OutMessage +;; LLVMCreateMemoryBufferWithSTDIN has OutMemBuf, OutMessage +%} diff --git a/src/execution-engine.i b/src/execution-engine.i new file mode 100644 index 0000000..0ccd949 --- /dev/null +++ b/src/execution-engine.i @@ -0,0 +1,21 @@ +%include "typemaps.i" + +%rename LLVMCreateJITCompiler "%%LLVMCreateJITCompiler"; + +%include "llvm-c/ExecutionEngine.h" + +%insert("swiglisp") %{ + +(defun LLVMCreateJITCompiler (provider opt) + (cffi:with-foreign-objects ((out-engine :pointer) + (out-error-str :pointer)) + (if (null (%LLVMCreateJITCompiler out-engine provider opt out-error-str)) + (cffi:mem-ref out-engine :pointer) + (let* ((error-str (cffi:mem-ref out-error-str :pointer)) + (error-str-lisp (cffi:foreign-string-to-lisp error-str))) + (LLVMDisposeMessage error-str) + (error "LLVMCreateJITCompiler: ~s" error-str-lisp))))) + +%} + +// TODO: lots of functions that need special wrappings diff --git a/src/generated/analysis.lisp b/src/generated/analysis.lisp new file mode 100644 index 0000000..b0adf6a --- /dev/null +++ b/src/generated/analysis.lisp @@ -0,0 +1,30 @@ +;;; This file was automatically generated by SWIG (http://www.swig.org). +;;; Version 1.3.40 +;;; +;;; Do not make changes to this file unless you know what you are doing--modify +;;; the SWIG interface file instead. + +(in-package :llvm) + + +(cffi:defcenum LLVMVerifierFailureAction + :LLVMAbortProcessAction + :LLVMPrintMessageAction + :LLVMReturnStatusAction) + +(cffi:defcfun ("LLVMVerifyModule" LLVMVerifyModule) :boolean + (M LLVMModuleRef) + (Action LLVMVerifierFailureAction) + (OutMessage :pointer)) + +(cffi:defcfun ("LLVMVerifyFunction" LLVMVerifyFunction) :boolean + (Fn LLVMValueRef) + (Action LLVMVerifierFailureAction)) + +(cffi:defcfun ("LLVMViewFunctionCFG" LLVMViewFunctionCFG) :void + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMViewFunctionCFGOnly" LLVMViewFunctionCFGOnly) :void + (Fn LLVMValueRef)) + + diff --git a/src/generated/core.lisp b/src/generated/core.lisp new file mode 100644 index 0000000..605d318 --- /dev/null +++ b/src/generated/core.lisp @@ -0,0 +1,1893 @@ +;;; This file was automatically generated by SWIG (http://www.swig.org). +;;; Version 1.3.40 +;;; +;;; Do not make changes to this file unless you know what you are doing--modify +;;; the SWIG interface file instead. + +(in-package :llvm) + + +(cffi:defctype uint8_t :unsigned-char) + +(cffi:defctype LLVMBool :int) + +(cffi:defctype LLVMContextRef :pointer) + +(cffi:defctype LLVMModuleRef :pointer) + +(cffi:defctype LLVMTypeRef :pointer) + +(cffi:defctype LLVMTypeHandleRef :pointer) + +(cffi:defctype LLVMValueRef :pointer) + +(cffi:defctype LLVMBasicBlockRef :pointer) + +(cffi:defctype LLVMBuilderRef :pointer) + +(cffi:defctype LLVMModuleProviderRef :pointer) + +(cffi:defctype LLVMMemoryBufferRef :pointer) + +(cffi:defctype LLVMPassManagerRef :pointer) + +(cffi:defctype LLVMUseIteratorRef :pointer) + +(cffi:defcenum LLVMAttribute + (:LLVMZExtAttribute #.(cl:ash 1 0)) + (:LLVMSExtAttribute #.(cl:ash 1 1)) + (:LLVMNoReturnAttribute #.(cl:ash 1 2)) + (:LLVMInRegAttribute #.(cl:ash 1 3)) + (:LLVMStructRetAttribute #.(cl:ash 1 4)) + (:LLVMNoUnwindAttribute #.(cl:ash 1 5)) + (:LLVMNoAliasAttribute #.(cl:ash 1 6)) + (:LLVMByValAttribute #.(cl:ash 1 7)) + (:LLVMNestAttribute #.(cl:ash 1 8)) + (:LLVMReadNoneAttribute #.(cl:ash 1 9)) + (:LLVMReadOnlyAttribute #.(cl:ash 1 10)) + (:LLVMNoInlineAttribute #.(cl:ash 1 11)) + (:LLVMAlwaysInlineAttribute #.(cl:ash 1 12)) + (:LLVMOptimizeForSizeAttribute #.(cl:ash 1 13)) + (:LLVMStackProtectAttribute #.(cl:ash 1 14)) + (:LLVMStackProtectReqAttribute #.(cl:ash 1 15)) + (:LLVMNoCaptureAttribute #.(cl:ash 1 21)) + (:LLVMNoRedZoneAttribute #.(cl:ash 1 22)) + (:LLVMNoImplicitFloatAttribute #.(cl:ash 1 23)) + (:LLVMNakedAttribute #.(cl:ash 1 24)) + (:LLVMInlineHintAttribute #.(cl:ash 1 25))) + +(cffi:defcenum LLVMOpcode + (:LLVMRet #.1) + (:LLVMBr #.2) + (:LLVMSwitch #.3) + (:LLVMInvoke #.4) + (:LLVMUnwind #.5) + (:LLVMUnreachable #.6) + (:LLVMAdd #.7) + (:LLVMFAdd #.8) + (:LLVMSub #.9) + (:LLVMFSub #.10) + (:LLVMMul #.11) + (:LLVMFMul #.12) + (:LLVMUDiv #.13) + (:LLVMSDiv #.14) + (:LLVMFDiv #.15) + (:LLVMURem #.16) + (:LLVMSRem #.17) + (:LLVMFRem #.18) + (:LLVMShl #.19) + (:LLVMLShr #.20) + (:LLVMAShr #.21) + (:LLVMAnd #.22) + (:LLVMOr #.23) + (:LLVMXor #.24) + (:LLVMMalloc #.25) + (:LLVMFree #.26) + (:LLVMAlloca #.27) + (:LLVMLoad #.28) + (:LLVMStore #.29) + (:LLVMGetElementPtr #.30) + (:LLVMTrunk #.31) + (:LLVMZExt #.32) + (:LLVMSExt #.33) + (:LLVMFPToUI #.34) + (:LLVMFPToSI #.35) + (:LLVMUIToFP #.36) + (:LLVMSIToFP #.37) + (:LLVMFPTrunc #.38) + (:LLVMFPExt #.39) + (:LLVMPtrToInt #.40) + (:LLVMIntToPtr #.41) + (:LLVMBitCast #.42) + (:LLVMICmp #.43) + (:LLVMFCmp #.44) + (:LLVMPHI #.45) + (:LLVMCall #.46) + (:LLVMSelect #.47) + (:LLVMVAArg #.50) + (:LLVMExtractElement #.51) + (:LLVMInsertElement #.52) + (:LLVMShuffleVector #.53) + (:LLVMExtractValue #.54) + (:LLVMInsertValue #.55)) + +(cffi:defcenum LLVMTypeKind + :LLVMVoidTypeKind + :LLVMFloatTypeKind + :LLVMDoubleTypeKind + :LLVMX86_FP80TypeKind + :LLVMFP128TypeKind + :LLVMPPC_FP128TypeKind + :LLVMLabelTypeKind + :LLVMIntegerTypeKind + :LLVMFunctionTypeKind + :LLVMStructTypeKind + :LLVMArrayTypeKind + :LLVMPointerTypeKind + :LLVMOpaqueTypeKind + :LLVMVectorTypeKind + :LLVMMetadataTypeKind) + +(cffi:defcenum LLVMLinkage + :LLVMExternalLinkage + :LLVMAvailableExternallyLinkage + :LLVMLinkOnceAnyLinkage + :LLVMLinkOnceODRLinkage + :LLVMWeakAnyLinkage + :LLVMWeakODRLinkage + :LLVMAppendingLinkage + :LLVMInternalLinkage + :LLVMPrivateLinkage + :LLVMDLLImportLinkage + :LLVMDLLExportLinkage + :LLVMExternalWeakLinkage + :LLVMGhostLinkage + :LLVMCommonLinkage + :LLVMLinkerPrivateLinkage) + +(cffi:defcenum LLVMVisibility + :LLVMDefaultVisibility + :LLVMHiddenVisibility + :LLVMProtectedVisibility) + +(cffi:defcenum LLVMCallConv + (:LLVMCCallConv #.0) + (:LLVMFastCallConv #.8) + (:LLVMColdCallConv #.9) + (:LLVMX86StdcallCallConv #.64) + (:LLVMX86FastcallCallConv #.65)) + +(cffi:defcenum LLVMIntPredicate + (:LLVMIntEQ #.32) + :LLVMIntNE + :LLVMIntUGT + :LLVMIntUGE + :LLVMIntULT + :LLVMIntULE + :LLVMIntSGT + :LLVMIntSGE + :LLVMIntSLT + :LLVMIntSLE) + +(cffi:defcenum LLVMRealPredicate + :LLVMRealPredicateFalse + :LLVMRealOEQ + :LLVMRealOGT + :LLVMRealOGE + :LLVMRealOLT + :LLVMRealOLE + :LLVMRealONE + :LLVMRealORD + :LLVMRealUNO + :LLVMRealUEQ + :LLVMRealUGT + :LLVMRealUGE + :LLVMRealULT + :LLVMRealULE + :LLVMRealUNE + :LLVMRealPredicateTrue) + +(cffi:defcfun ("LLVMDisposeMessage" LLVMDisposeMessage) :void + (Message :string)) + +(cffi:defcfun ("LLVMContextCreate" LLVMContextCreate) LLVMContextRef) + +(cffi:defcfun ("LLVMGetGlobalContext" LLVMGetGlobalContext) LLVMContextRef) + +(cffi:defcfun ("LLVMContextDispose" LLVMContextDispose) :void + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMModuleCreateWithNameInContext" %LLVMModuleCreateWithNameInContext) LLVMModuleRef + (ModuleID :string) + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMDisposeModule" LLVMDisposeModule) :void + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetDataLayout" LLVMGetDataLayout) :string + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMSetDataLayout" LLVMSetDataLayout) :void + (M LLVMModuleRef) + (Triple :string)) + +(cffi:defcfun ("LLVMGetTarget" LLVMGetTarget) :string + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMSetTarget" LLVMSetTarget) :void + (M LLVMModuleRef) + (Triple :string)) + +(cffi:defcfun ("LLVMAddTypeName" LLVMAddTypeName) :boolean + (M LLVMModuleRef) + (Name :string) + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMDeleteTypeName" LLVMDeleteTypeName) :void + (M LLVMModuleRef) + (Name :string)) + +(cffi:defcfun ("LLVMGetTypeByName" LLVMGetTypeByName) LLVMTypeRef + (M LLVMModuleRef) + (Name :string)) + +(cffi:defcfun ("LLVMDumpModule" LLVMDumpModule) :void + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetTypeKind" LLVMGetTypeKind) LLVMTypeKind + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetTypeContext" LLVMGetTypeContext) LLVMContextRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMInt1TypeInContext" %LLVMInt1TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMInt8TypeInContext" %LLVMInt8TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMInt16TypeInContext" %LLVMInt16TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMInt32TypeInContext" %LLVMInt32TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMInt64TypeInContext" %LLVMInt64TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMIntTypeInContext" %LLVMIntTypeInContext) LLVMTypeRef + (C LLVMContextRef) + (NumBits :unsigned-int)) + +(cffi:defcfun ("LLVMGetIntTypeWidth" LLVMGetIntTypeWidth) :unsigned-int + (IntegerTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMFloatTypeInContext" %LLVMFloatTypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMDoubleTypeInContext" %LLVMDoubleTypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMX86FP80TypeInContext" %LLVMX86FP80TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMFP128TypeInContext" %LLVMFP128TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMPPCFP128TypeInContext" %LLVMPPCFP128TypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMFunctionType" %LLVMFunctionType) LLVMTypeRef + (ReturnType LLVMTypeRef) + (ParamTypes :pointer) + (ParamCount :unsigned-int) + (IsVarArg :boolean)) + +(cffi:defcfun ("LLVMIsFunctionVarArg" LLVMIsFunctionVarArg) :boolean + (FunctionTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetReturnType" LLVMGetReturnType) LLVMTypeRef + (FunctionTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMCountParamTypes" LLVMCountParamTypes) :unsigned-int + (FunctionTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetParamTypes" %LLVMGetParamTypes) :void + (FunctionTy LLVMTypeRef) + (Dest :pointer)) + +(cffi:defcfun ("LLVMStructTypeInContext" %LLVMStructTypeInContext) LLVMTypeRef + (C LLVMContextRef) + (ElementTypes :pointer) + (ElementCount :unsigned-int) + (Packed :boolean)) + +(cffi:defcfun ("LLVMCountStructElementTypes" LLVMCountStructElementTypes) :unsigned-int + (StructTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetStructElementTypes" %LLVMGetStructElementTypes) :void + (StructTy LLVMTypeRef) + (Dest :pointer)) + +(cffi:defcfun ("LLVMIsPackedStruct" LLVMIsPackedStruct) :boolean + (StructTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMArrayType" LLVMArrayType) LLVMTypeRef + (ElementType LLVMTypeRef) + (ElementCount :unsigned-int)) + +(cffi:defcfun ("LLVMPointerType" LLVMPointerType) LLVMTypeRef + (ElementType LLVMTypeRef) + (AddressSpace :unsigned-int)) + +(cffi:defcfun ("LLVMVectorType" LLVMVectorType) LLVMTypeRef + (ElementType LLVMTypeRef) + (ElementCount :unsigned-int)) + +(cffi:defcfun ("LLVMGetElementType" LLVMGetElementType) LLVMTypeRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetArrayLength" LLVMGetArrayLength) :unsigned-int + (ArrayTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetPointerAddressSpace" LLVMGetPointerAddressSpace) :unsigned-int + (PointerTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetVectorSize" LLVMGetVectorSize) :unsigned-int + (VectorTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMVoidTypeInContext" %LLVMVoidTypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMLabelTypeInContext" %LLVMLabelTypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMOpaqueTypeInContext" %LLVMOpaqueTypeInContext) LLVMTypeRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMCreateTypeHandle" LLVMCreateTypeHandle) LLVMTypeHandleRef + (PotentiallyAbstractTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMRefineType" LLVMRefineType) :void + (AbstractTy LLVMTypeRef) + (ConcreteTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMResolveTypeHandle" LLVMResolveTypeHandle) LLVMTypeRef + (TypeHandle LLVMTypeHandleRef)) + +(cffi:defcfun ("LLVMDisposeTypeHandle" LLVMDisposeTypeHandle) :void + (TypeHandle LLVMTypeHandleRef)) + +(cffi:defcfun ("LLVMTypeOf" LLVMTypeOf) LLVMTypeRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMGetValueName" LLVMGetValueName) :string + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMSetValueName" LLVMSetValueName) :void + (Val LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMDumpValue" LLVMDumpValue) :void + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMReplaceAllUsesWith" LLVMReplaceAllUsesWith) :void + (OldVal LLVMValueRef) + (NewVal LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAArgument" LLVMIsAArgument) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsABasicBlock" LLVMIsABasicBlock) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAInlineAsm" LLVMIsAInlineAsm) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUser" LLVMIsAUser) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstant" LLVMIsAConstant) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantAggregateZero" LLVMIsAConstantAggregateZero) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantArray" LLVMIsAConstantArray) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantExpr" LLVMIsAConstantExpr) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantFP" LLVMIsAConstantFP) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantInt" LLVMIsAConstantInt) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantPointerNull" LLVMIsAConstantPointerNull) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantStruct" LLVMIsAConstantStruct) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAConstantVector" LLVMIsAConstantVector) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAGlobalValue" LLVMIsAGlobalValue) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFunction" LLVMIsAFunction) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAGlobalAlias" LLVMIsAGlobalAlias) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAGlobalVariable" LLVMIsAGlobalVariable) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUndefValue" LLVMIsAUndefValue) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAInstruction" LLVMIsAInstruction) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsABinaryOperator" LLVMIsABinaryOperator) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsACallInst" LLVMIsACallInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAIntrinsicInst" LLVMIsAIntrinsicInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgInfoIntrinsic" LLVMIsADbgInfoIntrinsic) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgDeclareInst" LLVMIsADbgDeclareInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgFuncStartInst" LLVMIsADbgFuncStartInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgRegionEndInst" LLVMIsADbgRegionEndInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgRegionStartInst" LLVMIsADbgRegionStartInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsADbgStopPointInst" LLVMIsADbgStopPointInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAEHSelectorInst" LLVMIsAEHSelectorInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAMemIntrinsic" LLVMIsAMemIntrinsic) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAMemCpyInst" LLVMIsAMemCpyInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAMemMoveInst" LLVMIsAMemMoveInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAMemSetInst" LLVMIsAMemSetInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsACmpInst" LLVMIsACmpInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFCmpInst" LLVMIsAFCmpInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAICmpInst" LLVMIsAICmpInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAExtractElementInst" LLVMIsAExtractElementInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAGetElementPtrInst" LLVMIsAGetElementPtrInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAInsertElementInst" LLVMIsAInsertElementInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAInsertValueInst" LLVMIsAInsertValueInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAPHINode" LLVMIsAPHINode) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsASelectInst" LLVMIsASelectInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAShuffleVectorInst" LLVMIsAShuffleVectorInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAStoreInst" LLVMIsAStoreInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsATerminatorInst" LLVMIsATerminatorInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsABranchInst" LLVMIsABranchInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAInvokeInst" LLVMIsAInvokeInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAReturnInst" LLVMIsAReturnInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsASwitchInst" LLVMIsASwitchInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUnreachableInst" LLVMIsAUnreachableInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUnwindInst" LLVMIsAUnwindInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUnaryInstruction" LLVMIsAUnaryInstruction) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAAllocaInst" LLVMIsAAllocaInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsACastInst" LLVMIsACastInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsABitCastInst" LLVMIsABitCastInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFPExtInst" LLVMIsAFPExtInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFPToSIInst" LLVMIsAFPToSIInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFPToUIInst" LLVMIsAFPToUIInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAFPTruncInst" LLVMIsAFPTruncInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAIntToPtrInst" LLVMIsAIntToPtrInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAPtrToIntInst" LLVMIsAPtrToIntInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsASExtInst" LLVMIsASExtInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsASIToFPInst" LLVMIsASIToFPInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsATruncInst" LLVMIsATruncInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAUIToFPInst" LLVMIsAUIToFPInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAZExtInst" LLVMIsAZExtInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAExtractValueInst" LLVMIsAExtractValueInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsALoadInst" LLVMIsALoadInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsAVAArgInst" LLVMIsAVAArgInst) LLVMValueRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMGetFirstUse" LLVMGetFirstUse) LLVMUseIteratorRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMGetNextUse" LLVMGetNextUse) LLVMUseIteratorRef + (U LLVMUseIteratorRef)) + +(cffi:defcfun ("LLVMGetUser" LLVMGetUser) LLVMValueRef + (U LLVMUseIteratorRef)) + +(cffi:defcfun ("LLVMGetUsedValue" LLVMGetUsedValue) LLVMValueRef + (U LLVMUseIteratorRef)) + +(cffi:defcfun ("LLVMGetOperand" LLVMGetOperand) LLVMValueRef + (Val LLVMValueRef) + (Index :unsigned-int)) + +(cffi:defcfun ("LLVMConstNull" LLVMConstNull) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstAllOnes" LLVMConstAllOnes) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetUndef" LLVMGetUndef) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMIsConstant" LLVMIsConstant) :boolean + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsNull" LLVMIsNull) :boolean + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMIsUndef" LLVMIsUndef) :boolean + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMConstPointerNull" LLVMConstPointerNull) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstInt" LLVMConstInt) LLVMValueRef + (IntTy LLVMTypeRef) + (N :unsigned-long-long) + (SignExtend :boolean)) + +(cffi:defcfun ("LLVMConstIntOfString" LLVMConstIntOfString) LLVMValueRef + (IntTy LLVMTypeRef) + (Text :string) + (Radix :unsigned-char)) + +(cffi:defcfun ("LLVMConstIntOfStringAndSize" LLVMConstIntOfStringAndSize) LLVMValueRef + (IntTy LLVMTypeRef) + (Text :string) + (SLen :unsigned-int) + (Radix :unsigned-char)) + +(cffi:defcfun ("LLVMConstReal" LLVMConstReal) LLVMValueRef + (RealTy LLVMTypeRef) + (N :double)) + +(cffi:defcfun ("LLVMConstRealOfString" LLVMConstRealOfString) LLVMValueRef + (RealTy LLVMTypeRef) + (Text :string)) + +(cffi:defcfun ("LLVMConstRealOfStringAndSize" LLVMConstRealOfStringAndSize) LLVMValueRef + (RealTy LLVMTypeRef) + (Text :string) + (SLen :unsigned-int)) + +(cffi:defcfun ("LLVMConstIntGetZExtValue" LLVMConstIntGetZExtValue) :unsigned-long-long + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMConstIntGetSExtValue" LLVMConstIntGetSExtValue) :long-long + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMConstStringInContext" %LLVMConstStringInContext) LLVMValueRef + (C LLVMContextRef) + (Str :string) + (Length :unsigned-int) + (DontNullTerminate :boolean)) + +(cffi:defcfun ("LLVMConstStructInContext" %LLVMConstStructInContext) LLVMValueRef + (C LLVMContextRef) + (ConstantVals :pointer) + (Count :unsigned-int) + (Packed :boolean)) + +(cffi:defcfun ("LLVMConstArray" %LLVMConstArray) LLVMValueRef + (ElementTy LLVMTypeRef) + (ConstantVals :pointer) + (Length :unsigned-int)) + +(cffi:defcfun ("LLVMConstVector" %LLVMConstVector) LLVMValueRef + (ScalarConstantVals :pointer) + (Size :unsigned-int)) + +(cffi:defcfun ("LLVMGetConstOpcode" LLVMGetConstOpcode) LLVMOpcode + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMAlignOf" LLVMAlignOf) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMSizeOf" LLVMSizeOf) LLVMValueRef + (Ty LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstNeg" LLVMConstNeg) LLVMValueRef + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFNeg" LLVMConstFNeg) LLVMValueRef + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMConstNot" LLVMConstNot) LLVMValueRef + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMConstAdd" LLVMConstAdd) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstNSWAdd" LLVMConstNSWAdd) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFAdd" LLVMConstFAdd) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstSub" LLVMConstSub) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFSub" LLVMConstFSub) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstMul" LLVMConstMul) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFMul" LLVMConstFMul) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstUDiv" LLVMConstUDiv) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstSDiv" LLVMConstSDiv) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstExactSDiv" LLVMConstExactSDiv) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFDiv" LLVMConstFDiv) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstURem" LLVMConstURem) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstSRem" LLVMConstSRem) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFRem" LLVMConstFRem) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstAnd" LLVMConstAnd) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstOr" LLVMConstOr) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstXor" LLVMConstXor) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstICmp" LLVMConstICmp) LLVMValueRef + (Predicate LLVMIntPredicate) + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstFCmp" LLVMConstFCmp) LLVMValueRef + (Predicate LLVMRealPredicate) + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstShl" LLVMConstShl) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstLShr" LLVMConstLShr) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstAShr" LLVMConstAShr) LLVMValueRef + (LHSConstant LLVMValueRef) + (RHSConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstGEP" %LLVMConstGEP) LLVMValueRef + (ConstantVal LLVMValueRef) + (ConstantIndices :pointer) + (NumIndices :unsigned-int)) + +(cffi:defcfun ("LLVMConstInBoundsGEP" %LLVMConstInBoundsGEP) LLVMValueRef + (ConstantVal LLVMValueRef) + (ConstantIndices :pointer) + (NumIndices :unsigned-int)) + +(cffi:defcfun ("LLVMConstTrunc" LLVMConstTrunc) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstSExt" LLVMConstSExt) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstZExt" LLVMConstZExt) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstFPTrunc" LLVMConstFPTrunc) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstFPExt" LLVMConstFPExt) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstUIToFP" LLVMConstUIToFP) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstSIToFP" LLVMConstSIToFP) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstFPToUI" LLVMConstFPToUI) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstFPToSI" LLVMConstFPToSI) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstPtrToInt" LLVMConstPtrToInt) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstIntToPtr" LLVMConstIntToPtr) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstBitCast" LLVMConstBitCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstZExtOrBitCast" LLVMConstZExtOrBitCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstSExtOrBitCast" LLVMConstSExtOrBitCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstTruncOrBitCast" LLVMConstTruncOrBitCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstPointerCast" LLVMConstPointerCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstIntCast" LLVMConstIntCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef) + (isSigned :boolean)) + +(cffi:defcfun ("LLVMConstFPCast" LLVMConstFPCast) LLVMValueRef + (ConstantVal LLVMValueRef) + (ToType LLVMTypeRef)) + +(cffi:defcfun ("LLVMConstSelect" LLVMConstSelect) LLVMValueRef + (ConstantCondition LLVMValueRef) + (ConstantIfTrue LLVMValueRef) + (ConstantIfFalse LLVMValueRef)) + +(cffi:defcfun ("LLVMConstExtractElement" LLVMConstExtractElement) LLVMValueRef + (VectorConstant LLVMValueRef) + (IndexConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstInsertElement" LLVMConstInsertElement) LLVMValueRef + (VectorConstant LLVMValueRef) + (ElementValueConstant LLVMValueRef) + (IndexConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstShuffleVector" LLVMConstShuffleVector) LLVMValueRef + (VectorAConstant LLVMValueRef) + (VectorBConstant LLVMValueRef) + (MaskConstant LLVMValueRef)) + +(cffi:defcfun ("LLVMConstExtractValue" %LLVMConstExtractValue) LLVMValueRef + (AggConstant LLVMValueRef) + (IdxList :pointer) + (NumIdx :unsigned-int)) + +(cffi:defcfun ("LLVMConstInsertValue" %LLVMConstInsertValue) LLVMValueRef + (AggConstant LLVMValueRef) + (ElementValueConstant LLVMValueRef) + (IdxList :pointer) + (NumIdx :unsigned-int)) + +(cffi:defcfun ("LLVMConstInlineAsm" LLVMConstInlineAsm) LLVMValueRef + (Ty LLVMTypeRef) + (AsmString :string) + (Constraints :string) + (HasSideEffects :boolean)) + +(cffi:defcfun ("LLVMGetGlobalParent" LLVMGetGlobalParent) LLVMModuleRef + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMIsDeclaration" LLVMIsDeclaration) :boolean + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMGetLinkage" LLVMGetLinkage) LLVMLinkage + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMSetLinkage" LLVMSetLinkage) :void + (Global LLVMValueRef) + (Linkage LLVMLinkage)) + +(cffi:defcfun ("LLVMGetSection" LLVMGetSection) :string + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMSetSection" LLVMSetSection) :void + (Global LLVMValueRef) + (Section :string)) + +(cffi:defcfun ("LLVMGetVisibility" LLVMGetVisibility) LLVMVisibility + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMSetVisibility" LLVMSetVisibility) :void + (Global LLVMValueRef) + (Viz LLVMVisibility)) + +(cffi:defcfun ("LLVMGetAlignment" LLVMGetAlignment) :unsigned-int + (Global LLVMValueRef)) + +(cffi:defcfun ("LLVMSetAlignment" LLVMSetAlignment) :void + (Global LLVMValueRef) + (Bytes :unsigned-int)) + +(cffi:defcfun ("LLVMAddGlobal" LLVMAddGlobal) LLVMValueRef + (M LLVMModuleRef) + (Ty LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMGetNamedGlobal" LLVMGetNamedGlobal) LLVMValueRef + (M LLVMModuleRef) + (Name :string)) + +(cffi:defcfun ("LLVMGetFirstGlobal" LLVMGetFirstGlobal) LLVMValueRef + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetLastGlobal" LLVMGetLastGlobal) LLVMValueRef + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetNextGlobal" LLVMGetNextGlobal) LLVMValueRef + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMGetPreviousGlobal" LLVMGetPreviousGlobal) LLVMValueRef + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMDeleteGlobal" LLVMDeleteGlobal) :void + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMGetInitializer" LLVMGetInitializer) LLVMValueRef + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMSetInitializer" LLVMSetInitializer) :void + (GlobalVar LLVMValueRef) + (ConstantVal LLVMValueRef)) + +(cffi:defcfun ("LLVMIsThreadLocal" LLVMIsThreadLocal) :boolean + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMSetThreadLocal" LLVMSetThreadLocal) :void + (GlobalVar LLVMValueRef) + (IsThreadLocal :boolean)) + +(cffi:defcfun ("LLVMIsGlobalConstant" LLVMIsGlobalConstant) :boolean + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMSetGlobalConstant" LLVMSetGlobalConstant) :void + (GlobalVar LLVMValueRef) + (IsConstant :boolean)) + +(cffi:defcfun ("LLVMAddAlias" LLVMAddAlias) LLVMValueRef + (M LLVMModuleRef) + (Ty LLVMTypeRef) + (Aliasee LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMAddFunction" LLVMAddFunction) LLVMValueRef + (M LLVMModuleRef) + (Name :string) + (FunctionTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMGetNamedFunction" LLVMGetNamedFunction) LLVMValueRef + (M LLVMModuleRef) + (Name :string)) + +(cffi:defcfun ("LLVMGetFirstFunction" LLVMGetFirstFunction) LLVMValueRef + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetLastFunction" LLVMGetLastFunction) LLVMValueRef + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMGetNextFunction" LLVMGetNextFunction) LLVMValueRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetPreviousFunction" LLVMGetPreviousFunction) LLVMValueRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMDeleteFunction" LLVMDeleteFunction) :void + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetIntrinsicID" LLVMGetIntrinsicID) :unsigned-int + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetFunctionCallConv" LLVMGetFunctionCallConv) :unsigned-int + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMSetFunctionCallConv" LLVMSetFunctionCallConv) :void + (Fn LLVMValueRef) + (CC :unsigned-int)) + +(cffi:defcfun ("LLVMGetGC" LLVMGetGC) :string + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMSetGC" LLVMSetGC) :void + (Fn LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMAddFunctionAttr" LLVMAddFunctionAttr) :void + (Fn LLVMValueRef) + (PA LLVMAttribute)) + +(cffi:defcfun ("LLVMGetFunctionAttr" LLVMGetFunctionAttr) LLVMAttribute + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMRemoveFunctionAttr" LLVMRemoveFunctionAttr) :void + (Fn LLVMValueRef) + (PA LLVMAttribute)) + +(cffi:defcfun ("LLVMCountParams" LLVMCountParams) :unsigned-int + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetParams" %LLVMGetParams) :void + (Fn LLVMValueRef) + (Params :pointer)) + +(cffi:defcfun ("LLVMGetParam" LLVMGetParam) LLVMValueRef + (Fn LLVMValueRef) + (Index :unsigned-int)) + +(cffi:defcfun ("LLVMGetParamParent" LLVMGetParamParent) LLVMValueRef + (Inst LLVMValueRef)) + +(cffi:defcfun ("LLVMGetFirstParam" LLVMGetFirstParam) LLVMValueRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetLastParam" LLVMGetLastParam) LLVMValueRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetNextParam" LLVMGetNextParam) LLVMValueRef + (Arg LLVMValueRef)) + +(cffi:defcfun ("LLVMGetPreviousParam" LLVMGetPreviousParam) LLVMValueRef + (Arg LLVMValueRef)) + +(cffi:defcfun ("LLVMAddAttribute" LLVMAddAttribute) :void + (Arg LLVMValueRef) + (PA LLVMAttribute)) + +(cffi:defcfun ("LLVMRemoveAttribute" LLVMRemoveAttribute) :void + (Arg LLVMValueRef) + (PA LLVMAttribute)) + +(cffi:defcfun ("LLVMGetAttribute" LLVMGetAttribute) LLVMAttribute + (Arg LLVMValueRef)) + +(cffi:defcfun ("LLVMSetParamAlignment" LLVMSetParamAlignment) :void + (Arg LLVMValueRef) + (align :unsigned-int)) + +(cffi:defcfun ("LLVMBasicBlockAsValue" LLVMBasicBlockAsValue) LLVMValueRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMValueIsBasicBlock" LLVMValueIsBasicBlock) :boolean + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMValueAsBasicBlock" LLVMValueAsBasicBlock) LLVMBasicBlockRef + (Val LLVMValueRef)) + +(cffi:defcfun ("LLVMGetBasicBlockParent" LLVMGetBasicBlockParent) LLVMValueRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMCountBasicBlocks" LLVMCountBasicBlocks) :unsigned-int + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetBasicBlocks" LLVMGetBasicBlocks) :void + (Fn LLVMValueRef) + (BasicBlocks :pointer)) + +(cffi:defcfun ("LLVMGetFirstBasicBlock" LLVMGetFirstBasicBlock) LLVMBasicBlockRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetLastBasicBlock" LLVMGetLastBasicBlock) LLVMBasicBlockRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMGetNextBasicBlock" LLVMGetNextBasicBlock) LLVMBasicBlockRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetPreviousBasicBlock" LLVMGetPreviousBasicBlock) LLVMBasicBlockRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetEntryBasicBlock" LLVMGetEntryBasicBlock) LLVMBasicBlockRef + (Fn LLVMValueRef)) + +(cffi:defcfun ("LLVMAppendBasicBlockInContext" %LLVMAppendBasicBlockInContext) LLVMBasicBlockRef + (C LLVMContextRef) + (Fn LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMInsertBasicBlockInContext" %LLVMInsertBasicBlockInContext) LLVMBasicBlockRef + (C LLVMContextRef) + (BB LLVMBasicBlockRef) + (Name :string)) + +(cffi:defcfun ("LLVMDeleteBasicBlock" LLVMDeleteBasicBlock) :void + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetInstructionParent" LLVMGetInstructionParent) LLVMBasicBlockRef + (Inst LLVMValueRef)) + +(cffi:defcfun ("LLVMGetFirstInstruction" LLVMGetFirstInstruction) LLVMValueRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetLastInstruction" LLVMGetLastInstruction) LLVMValueRef + (BB LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetNextInstruction" LLVMGetNextInstruction) LLVMValueRef + (Inst LLVMValueRef)) + +(cffi:defcfun ("LLVMGetPreviousInstruction" LLVMGetPreviousInstruction) LLVMValueRef + (Inst LLVMValueRef)) + +(cffi:defcfun ("LLVMSetInstructionCallConv" LLVMSetInstructionCallConv) :void + (Instr LLVMValueRef) + (CC :unsigned-int)) + +(cffi:defcfun ("LLVMGetInstructionCallConv" LLVMGetInstructionCallConv) :unsigned-int + (Instr LLVMValueRef)) + +(cffi:defcfun ("LLVMAddInstrAttribute" LLVMAddInstrAttribute) :void + (Instr LLVMValueRef) + (index :unsigned-int) + (arg2 LLVMAttribute)) + +(cffi:defcfun ("LLVMRemoveInstrAttribute" LLVMRemoveInstrAttribute) :void + (Instr LLVMValueRef) + (index :unsigned-int) + (arg2 LLVMAttribute)) + +(cffi:defcfun ("LLVMSetInstrParamAlignment" LLVMSetInstrParamAlignment) :void + (Instr LLVMValueRef) + (index :unsigned-int) + (align :unsigned-int)) + +(cffi:defcfun ("LLVMIsTailCall" LLVMIsTailCall) :boolean + (CallInst LLVMValueRef)) + +(cffi:defcfun ("LLVMSetTailCall" LLVMSetTailCall) :void + (CallInst LLVMValueRef) + (IsTailCall :boolean)) + +(cffi:defcfun ("LLVMAddIncoming" %LLVMAddIncoming) :void + (PhiNode LLVMValueRef) + (IncomingValues :pointer) + (IncomingBlocks :pointer) + (Count :unsigned-int)) + +(cffi:defcfun ("LLVMCountIncoming" LLVMCountIncoming) :unsigned-int + (PhiNode LLVMValueRef)) + +(cffi:defcfun ("LLVMGetIncomingValue" LLVMGetIncomingValue) LLVMValueRef + (PhiNode LLVMValueRef) + (Index :unsigned-int)) + +(cffi:defcfun ("LLVMGetIncomingBlock" LLVMGetIncomingBlock) LLVMBasicBlockRef + (PhiNode LLVMValueRef) + (Index :unsigned-int)) + +(cffi:defcfun ("LLVMCreateBuilderInContext" %LLVMCreateBuilderInContext) LLVMBuilderRef + (C LLVMContextRef)) + +(cffi:defcfun ("LLVMPositionBuilder" LLVMPositionBuilder) :void + (Builder LLVMBuilderRef) + (Block LLVMBasicBlockRef) + (Instr LLVMValueRef)) + +(cffi:defcfun ("LLVMPositionBuilderBefore" LLVMPositionBuilderBefore) :void + (Builder LLVMBuilderRef) + (Instr LLVMValueRef)) + +(cffi:defcfun ("LLVMPositionBuilderAtEnd" LLVMPositionBuilderAtEnd) :void + (Builder LLVMBuilderRef) + (Block LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMGetInsertBlock" LLVMGetInsertBlock) LLVMBasicBlockRef + (Builder LLVMBuilderRef)) + +(cffi:defcfun ("LLVMClearInsertionPosition" LLVMClearInsertionPosition) :void + (Builder LLVMBuilderRef)) + +(cffi:defcfun ("LLVMInsertIntoBuilder" LLVMInsertIntoBuilder) :void + (Builder LLVMBuilderRef) + (Instr LLVMValueRef)) + +(cffi:defcfun ("LLVMInsertIntoBuilderWithName" LLVMInsertIntoBuilderWithName) :void + (Builder LLVMBuilderRef) + (Instr LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMDisposeBuilder" LLVMDisposeBuilder) :void + (Builder LLVMBuilderRef)) + +(cffi:defcfun ("LLVMBuildRetVoid" LLVMBuildRetVoid) LLVMValueRef + (arg0 LLVMBuilderRef)) + +(cffi:defcfun ("LLVMBuildRet" LLVMBuildRet) LLVMValueRef + (arg0 LLVMBuilderRef) + (V LLVMValueRef)) + +(cffi:defcfun ("LLVMBuildAggregateRet" %LLVMBuildAggregateRet) LLVMValueRef + (arg0 LLVMBuilderRef) + (RetVals :pointer) + (N :unsigned-int)) + +(cffi:defcfun ("LLVMBuildBr" LLVMBuildBr) LLVMValueRef + (arg0 LLVMBuilderRef) + (Dest LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMBuildCondBr" LLVMBuildCondBr) LLVMValueRef + (arg0 LLVMBuilderRef) + (If LLVMValueRef) + (Then LLVMBasicBlockRef) + (Else LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMBuildSwitch" LLVMBuildSwitch) LLVMValueRef + (arg0 LLVMBuilderRef) + (V LLVMValueRef) + (Else LLVMBasicBlockRef) + (NumCases :unsigned-int)) + +(cffi:defcfun ("LLVMBuildInvoke" %LLVMBuildInvoke) LLVMValueRef + (arg0 LLVMBuilderRef) + (Fn LLVMValueRef) + (Args :pointer) + (NumArgs :unsigned-int) + (Then LLVMBasicBlockRef) + (Catch LLVMBasicBlockRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildUnwind" LLVMBuildUnwind) LLVMValueRef + (arg0 LLVMBuilderRef)) + +(cffi:defcfun ("LLVMBuildUnreachable" LLVMBuildUnreachable) LLVMValueRef + (arg0 LLVMBuilderRef)) + +(cffi:defcfun ("LLVMAddCase" LLVMAddCase) :void + (Switch LLVMValueRef) + (OnVal LLVMValueRef) + (Dest LLVMBasicBlockRef)) + +(cffi:defcfun ("LLVMBuildAdd" LLVMBuildAdd) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildNSWAdd" LLVMBuildNSWAdd) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFAdd" LLVMBuildFAdd) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSub" LLVMBuildSub) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFSub" LLVMBuildFSub) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildMul" LLVMBuildMul) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFMul" LLVMBuildFMul) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildUDiv" LLVMBuildUDiv) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSDiv" LLVMBuildSDiv) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildExactSDiv" LLVMBuildExactSDiv) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFDiv" LLVMBuildFDiv) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildURem" LLVMBuildURem) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSRem" LLVMBuildSRem) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFRem" LLVMBuildFRem) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildShl" LLVMBuildShl) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildLShr" LLVMBuildLShr) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildAShr" LLVMBuildAShr) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildAnd" LLVMBuildAnd) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildOr" LLVMBuildOr) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildXor" LLVMBuildXor) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildNeg" LLVMBuildNeg) LLVMValueRef + (arg0 LLVMBuilderRef) + (V LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFNeg" LLVMBuildFNeg) LLVMValueRef + (arg0 LLVMBuilderRef) + (V LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildNot" LLVMBuildNot) LLVMValueRef + (arg0 LLVMBuilderRef) + (V LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildMalloc" LLVMBuildMalloc) LLVMValueRef + (arg0 LLVMBuilderRef) + (Ty LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildArrayMalloc" LLVMBuildArrayMalloc) LLVMValueRef + (arg0 LLVMBuilderRef) + (Ty LLVMTypeRef) + (Val LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildAlloca" LLVMBuildAlloca) LLVMValueRef + (arg0 LLVMBuilderRef) + (Ty LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildArrayAlloca" LLVMBuildArrayAlloca) LLVMValueRef + (arg0 LLVMBuilderRef) + (Ty LLVMTypeRef) + (Val LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFree" LLVMBuildFree) LLVMValueRef + (arg0 LLVMBuilderRef) + (PointerVal LLVMValueRef)) + +(cffi:defcfun ("LLVMBuildLoad" LLVMBuildLoad) LLVMValueRef + (arg0 LLVMBuilderRef) + (PointerVal LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildStore" LLVMBuildStore) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (Ptr LLVMValueRef)) + +(cffi:defcfun ("LLVMBuildGEP" %LLVMBuildGEP) LLVMValueRef + (B LLVMBuilderRef) + (Pointer LLVMValueRef) + (Indices :pointer) + (NumIndices :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildInBoundsGEP" %LLVMBuildInBoundsGEP) LLVMValueRef + (B LLVMBuilderRef) + (Pointer LLVMValueRef) + (Indices :pointer) + (NumIndices :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildStructGEP" LLVMBuildStructGEP) LLVMValueRef + (B LLVMBuilderRef) + (Pointer LLVMValueRef) + (Idx :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildGlobalString" LLVMBuildGlobalString) LLVMValueRef + (B LLVMBuilderRef) + (Str :string) + (Name :string)) + +(cffi:defcfun ("LLVMBuildGlobalStringPtr" LLVMBuildGlobalStringPtr) LLVMValueRef + (B LLVMBuilderRef) + (Str :string) + (Name :string)) + +(cffi:defcfun ("LLVMBuildTrunc" LLVMBuildTrunc) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildZExt" LLVMBuildZExt) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSExt" LLVMBuildSExt) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFPToUI" LLVMBuildFPToUI) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFPToSI" LLVMBuildFPToSI) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildUIToFP" LLVMBuildUIToFP) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSIToFP" LLVMBuildSIToFP) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFPTrunc" LLVMBuildFPTrunc) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFPExt" LLVMBuildFPExt) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildPtrToInt" LLVMBuildPtrToInt) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildIntToPtr" LLVMBuildIntToPtr) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildBitCast" LLVMBuildBitCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildZExtOrBitCast" LLVMBuildZExtOrBitCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSExtOrBitCast" LLVMBuildSExtOrBitCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildTruncOrBitCast" LLVMBuildTruncOrBitCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildPointerCast" LLVMBuildPointerCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildIntCast" LLVMBuildIntCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFPCast" LLVMBuildFPCast) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (DestTy LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildICmp" LLVMBuildICmp) LLVMValueRef + (arg0 LLVMBuilderRef) + (Op LLVMIntPredicate) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildFCmp" LLVMBuildFCmp) LLVMValueRef + (arg0 LLVMBuilderRef) + (Op LLVMRealPredicate) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildPhi" LLVMBuildPhi) LLVMValueRef + (arg0 LLVMBuilderRef) + (Ty LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildCall" %LLVMBuildCall) LLVMValueRef + (arg0 LLVMBuilderRef) + (Fn LLVMValueRef) + (Args :pointer) + (NumArgs :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildSelect" LLVMBuildSelect) LLVMValueRef + (arg0 LLVMBuilderRef) + (If LLVMValueRef) + (Then LLVMValueRef) + (Else LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildVAArg" LLVMBuildVAArg) LLVMValueRef + (arg0 LLVMBuilderRef) + (List LLVMValueRef) + (Ty LLVMTypeRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildExtractElement" LLVMBuildExtractElement) LLVMValueRef + (arg0 LLVMBuilderRef) + (VecVal LLVMValueRef) + (Index LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildInsertElement" LLVMBuildInsertElement) LLVMValueRef + (arg0 LLVMBuilderRef) + (VecVal LLVMValueRef) + (EltVal LLVMValueRef) + (Index LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildShuffleVector" LLVMBuildShuffleVector) LLVMValueRef + (arg0 LLVMBuilderRef) + (V1 LLVMValueRef) + (V2 LLVMValueRef) + (Mask LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildExtractValue" LLVMBuildExtractValue) LLVMValueRef + (arg0 LLVMBuilderRef) + (AggVal LLVMValueRef) + (Index :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildInsertValue" LLVMBuildInsertValue) LLVMValueRef + (arg0 LLVMBuilderRef) + (AggVal LLVMValueRef) + (EltVal LLVMValueRef) + (Index :unsigned-int) + (Name :string)) + +(cffi:defcfun ("LLVMBuildIsNull" LLVMBuildIsNull) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildIsNotNull" LLVMBuildIsNotNull) LLVMValueRef + (arg0 LLVMBuilderRef) + (Val LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMBuildPtrDiff" LLVMBuildPtrDiff) LLVMValueRef + (arg0 LLVMBuilderRef) + (LHS LLVMValueRef) + (RHS LLVMValueRef) + (Name :string)) + +(cffi:defcfun ("LLVMCreateModuleProviderForExistingModule" LLVMCreateModuleProviderForExistingModule) LLVMModuleProviderRef + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMDisposeModuleProvider" LLVMDisposeModuleProvider) :void + (MP LLVMModuleProviderRef)) + +(cffi:defcfun ("LLVMCreateMemoryBufferWithContentsOfFile" LLVMCreateMemoryBufferWithContentsOfFile) :boolean + (Path :string) + (OutMemBuf :pointer) + (OutMessage :pointer)) + +(cffi:defcfun ("LLVMCreateMemoryBufferWithSTDIN" LLVMCreateMemoryBufferWithSTDIN) :boolean + (OutMemBuf :pointer) + (OutMessage :pointer)) + +(cffi:defcfun ("LLVMDisposeMemoryBuffer" LLVMDisposeMemoryBuffer) :void + (MemBuf LLVMMemoryBufferRef)) + +(cffi:defcfun ("LLVMCreatePassManager" LLVMCreatePassManager) LLVMPassManagerRef) + +(cffi:defcfun ("LLVMCreateFunctionPassManager" LLVMCreateFunctionPassManager) LLVMPassManagerRef + (MP LLVMModuleProviderRef)) + +(cffi:defcfun ("LLVMRunPassManager" LLVMRunPassManager) :boolean + (PM LLVMPassManagerRef) + (M LLVMModuleRef)) + +(cffi:defcfun ("LLVMInitializeFunctionPassManager" LLVMInitializeFunctionPassManager) :boolean + (FPM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMRunFunctionPassManager" LLVMRunFunctionPassManager) :boolean + (FPM LLVMPassManagerRef) + (F LLVMValueRef)) + +(cffi:defcfun ("LLVMFinalizeFunctionPassManager" LLVMFinalizeFunctionPassManager) :boolean + (FPM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMDisposePassManager" LLVMDisposePassManager) :void + (PM LLVMPassManagerRef)) + +;;; The wrappers to expose the "InContext" versions of the functions +;;; in a more lispy way. +(declaim (special *llvm-context*)) + +(defun LLVMModuleCreateWithName (ModuleId &optional (context *llvm-context*)) + (%LLVMModuleCreateWithNameInContext ModuleId context)) + +(defun LLVMInt1Type (&optional (context *llvm-context*)) + (%LLVMInt1TypeInContext context)) + +(defun LLVMInt8Type (&optional (context *llvm-context*)) + (%LLVMInt8TypeInContext context)) + +(defun LLVMInt16Type (&optional (context *llvm-context*)) + (%LLVMInt16TypeInContext context)) + +(defun LLVMInt32Type (&optional (context *llvm-context*)) + (%LLVMInt32TypeInContext context)) + +(defun LLVMInt64Type (&optional (context *llvm-context*)) + (%LLVMInt64TypeInContext context)) + +(defun LLVMIntType (NumBits &optional (context *llvm-context*)) + (%LLVMIntTypeInContext context NumBits)) + +(defun LLVMFloatType (&optional (context *llvm-context*)) + (%LLVMFloatTypeInContext context)) + +(defun LLVMDoubleType (&optional (context *llvm-context*)) + (%LLVMDoubleTypeInContext context)) + +(defun LLVMX86FP80Type (&optional (context *llvm-context*)) + (%LLVMX86FP80TypeInContext context)) + +(defun LLVMFP128Type (&optional (context *llvm-context*)) + (%LLVMFP128TypeInContext context)) + +(defun LLVMPPCFP128Type (&optional (context *llvm-context*)) + (%LLVMPPCFP128TypeInContext context)) + +;; LLVMStructTypeInContext handled below. + +(defun LLVMVoidType (&optional (context *llvm-context*)) + (%LLVMVoidTypeInContext context)) + +(defun LLVMLabelType (&optional (context *llvm-context*)) + (%LLVMLabelTypeInContext context)) + +(defun LLVMOpaqueType (&optional (context *llvm-context*)) + (%LLVMOpaqueTypeInContext context)) + +;; LLVMConstStringInContext handled below +;; LLVMConstStructInContext handled below + +(defun LLVMAppendBasicBlock (Fn Name &optional (context *llvm-context*)) + (%LLVMAppendBasicBlockInContext context Fn Name)) + +(defun LLVMInsertBasicBlock (BB Name &optional (context *llvm-context*)) + (%LLVMInsertBasicBlockInContext context BB Name)) + +(defun LLVMCreateBuilder (&optional (context *llvm-context*)) + (%LLVMCreateBuilderInContext context)) + + +;; More complex wrappers for dealing with pointers. + +(defmacro with-array-and-length ((array len list) &body body) + (let ((list-v (gensym "list"))) + `(let* ((,list-v ,list) + (,len (length ,list-v))) + (cffi:with-foreign-object (,array :pointer ,len) + (loop for l in ,list-v + for i from 0 + do + (setf (cffi:mem-aref ,array :pointer i) l)) + (progn ,@body))))) + +(defun LLVMFunctionType (ret params is-var-arg) + "Combines the C API's ParamTypes array and ParamCount arguments into +a single list PARAMS." + (with-array-and-length (array len params) + (%LLVMFunctionType ret array len is-var-arg))) + +(defun LLVMGetParamTypes (function-type) + "Returns a list of param types rather than filling out a Dest pointer argument" + (let ((len (LLVMCountParamTypes function-type))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetParamTypes function-type array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMStructType (element-types is-packed &optional (context *llvm-context*)) + (with-array-and-length (array len element-types) + (%LLVMStructTypeInContext context array len is-packed))) + +(defun LLVMGetStructElementTypes (struct-type) + "Returns a list of param types rather than filling out a Dest pointer argument" + (let ((len (LLVMCountStructElementTypes struct-type))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetStructElementTypes struct-type array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMConstString (str dont-null-terminate &optional (context *llvm-context*)) + (cffi:with-foreign-string ((foreign-string num-bytes) str) + (%LLVMConstStringInContext context foreign-string num-bytes dont-null-terminate))) + +(defun LLVMConstStruct (vals packed-p &optional (context *llvm-context*)) + (with-array-and-length (array len vals) + (%LLVMConstStructInContext context array len packed-p))) + +(defun LLVMConstArray (type vals) + (with-array-and-length (array len vals) + (%LLVMConstArray type array len))) + +(defun LLVMConstVector (vals) + (with-array-and-length (array len vals) + (%LLVMConstVector array len))) + +(defun LLVMConstGEP (ptr indices) + (with-array-and-length (array len indices) + (%LLVMConstGEP ptr array len))) + +(defun LLVMConstInBoundsGEP (ptr indices) + (with-array-and-length (array len indices) + (%LLVMConstInBoundsGEP ptr array len))) + +(defun LLVMConstExtractValue (AggConstant indices) + (with-array-and-length (array len indices) + (%LLVMConstExtractValue AggConstant array len))) + +(defun LLVMConstInsertValue (AggConstant ValConstant indices) + (with-array-and-length (array len indices) + (%LLVMConstInsertValue AggConstant ValConstant array len))) + +(defun LLVMGetParams (fn) + "Returns a list of params rather than filling out a Dest pointer argument." + (let ((len (LLVMCountParams fn))) + (cffi:with-foreign-object (array :pointer len) + (%LLVMGetParams fn array) + (loop for i from 0 below len + collect + (cffi:mem-aref array :pointer i))))) + +(defun LLVMAddIncoming (phi-node incoming-val incoming-block) + "Unlike the C API (but like the C++ API...), takes only a single +incoming val and incoming block. Call multiple times if you want to +add multiple incoming values." + (cffi:with-foreign-objects ((incoming-vals :pointer) + (incoming-blocks :pointer)) + (setf (cffi:mem-aref incoming-vals :pointer 0) incoming-val) + (setf (cffi:mem-aref incoming-blocks :pointer 0) incoming-block) + (%LLVMAddIncoming phi-node incoming-vals incoming-blocks 1))) + +(defun LLVMBuildAggregateRet (builder vals) + (with-array-and-length (array len vals) + (%LLVMBuildAggregateRet builder array len))) + +(defun LLVMBuildInvoke (builder fn args then catch name) + (with-array-and-length (array len args) + (%LLVMBuildInvoke builder fn array len then catch name))) + +(defun LLVMBuildGEP (builder ptr indices name) + (with-array-and-length (array len indices) + (%LLVMBuildGEP builder ptr array len name))) + +(defun LLVMBuildInBoundsGEP (builder ptr indices name) + (with-array-and-length (array len indices) + (%LLVMBuildInBoundsGEP builder ptr array len name))) + +(defun LLVMBuildCall (builder fn args name) + "Combines the C API's Args array and NumArgs arguments into a single +list ARGS." + (with-array-and-length (array len args) + (%LLVMBuildCall builder fn array len name))) + +;; TODO: +;; LLVMCreateMemoryBufferWithContentsOfFile has OutMemBuf, OutMessage +;; LLVMCreateMemoryBufferWithSTDIN has OutMemBuf, OutMessage + + + diff --git a/src/generated/execution-engine.lisp b/src/generated/execution-engine.lisp new file mode 100644 index 0000000..18c24f1 --- /dev/null +++ b/src/generated/execution-engine.lisp @@ -0,0 +1,129 @@ +;;; This file was automatically generated by SWIG (http://www.swig.org). +;;; Version 1.3.40 +;;; +;;; Do not make changes to this file unless you know what you are doing--modify +;;; the SWIG interface file instead. + +(in-package :llvm) + + +(cffi:defcfun ("LLVMLinkInJIT" LLVMLinkInJIT) :void) + +(cffi:defcfun ("LLVMLinkInInterpreter" LLVMLinkInInterpreter) :void) + +(cffi:defctype LLVMGenericValueRef :pointer) + +(cffi:defctype LLVMExecutionEngineRef :pointer) + +(cffi:defcfun ("LLVMCreateGenericValueOfInt" LLVMCreateGenericValueOfInt) LLVMGenericValueRef + (Ty LLVMTypeRef) + (N :unsigned-long-long) + (IsSigned :boolean)) + +(cffi:defcfun ("LLVMCreateGenericValueOfPointer" LLVMCreateGenericValueOfPointer) LLVMGenericValueRef + (P :pointer)) + +(cffi:defcfun ("LLVMCreateGenericValueOfFloat" LLVMCreateGenericValueOfFloat) LLVMGenericValueRef + (Ty LLVMTypeRef) + (N :double)) + +(cffi:defcfun ("LLVMGenericValueIntWidth" LLVMGenericValueIntWidth) :unsigned-int + (GenValRef LLVMGenericValueRef)) + +(cffi:defcfun ("LLVMGenericValueToInt" LLVMGenericValueToInt) :unsigned-long-long + (GenVal LLVMGenericValueRef) + (IsSigned :boolean)) + +(cffi:defcfun ("LLVMGenericValueToPointer" LLVMGenericValueToPointer) :pointer + (GenVal LLVMGenericValueRef)) + +(cffi:defcfun ("LLVMGenericValueToFloat" LLVMGenericValueToFloat) :double + (TyRef LLVMTypeRef) + (GenVal LLVMGenericValueRef)) + +(cffi:defcfun ("LLVMDisposeGenericValue" LLVMDisposeGenericValue) :void + (GenVal LLVMGenericValueRef)) + +(cffi:defcfun ("LLVMCreateExecutionEngine" LLVMCreateExecutionEngine) :boolean + (OutEE :pointer) + (MP LLVMModuleProviderRef) + (OutError :pointer)) + +(cffi:defcfun ("LLVMCreateInterpreter" LLVMCreateInterpreter) :boolean + (OutInterp :pointer) + (MP LLVMModuleProviderRef) + (OutError :pointer)) + +(cffi:defcfun ("LLVMCreateJITCompiler" %LLVMCreateJITCompiler) :boolean + (OutJIT :pointer) + (MP LLVMModuleProviderRef) + (OptLevel :unsigned-int) + (OutError :pointer)) + +(cffi:defcfun ("LLVMDisposeExecutionEngine" LLVMDisposeExecutionEngine) :void + (EE LLVMExecutionEngineRef)) + +(cffi:defcfun ("LLVMRunStaticConstructors" LLVMRunStaticConstructors) :void + (EE LLVMExecutionEngineRef)) + +(cffi:defcfun ("LLVMRunStaticDestructors" LLVMRunStaticDestructors) :void + (EE LLVMExecutionEngineRef)) + +(cffi:defcfun ("LLVMRunFunctionAsMain" LLVMRunFunctionAsMain) :boolean + (EE LLVMExecutionEngineRef) + (F LLVMValueRef) + (ArgC :unsigned-int) + (ArgV :pointer) + (EnvP :pointer)) + +(cffi:defcfun ("LLVMRunFunction" LLVMRunFunction) LLVMGenericValueRef + (EE LLVMExecutionEngineRef) + (F LLVMValueRef) + (NumArgs :unsigned-int) + (Args :pointer)) + +(cffi:defcfun ("LLVMFreeMachineCodeForFunction" LLVMFreeMachineCodeForFunction) :void + (EE LLVMExecutionEngineRef) + (F LLVMValueRef)) + +(cffi:defcfun ("LLVMAddModuleProvider" LLVMAddModuleProvider) :void + (EE LLVMExecutionEngineRef) + (MP LLVMModuleProviderRef)) + +(cffi:defcfun ("LLVMRemoveModuleProvider" LLVMRemoveModuleProvider) :boolean + (EE LLVMExecutionEngineRef) + (MP LLVMModuleProviderRef) + (OutMod :pointer) + (OutError :pointer)) + +(cffi:defcfun ("LLVMFindFunction" LLVMFindFunction) :boolean + (EE LLVMExecutionEngineRef) + (Name :string) + (OutFn :pointer)) + +(cffi:defcfun ("LLVMGetExecutionEngineTargetData" LLVMGetExecutionEngineTargetData) LLVMTargetDataRef + (EE LLVMExecutionEngineRef)) + +(cffi:defcfun ("LLVMAddGlobalMapping" LLVMAddGlobalMapping) :void + (EE LLVMExecutionEngineRef) + (Global LLVMValueRef) + (Addr :pointer)) + +(cffi:defcfun ("LLVMGetPointerToGlobal" LLVMGetPointerToGlobal) :pointer + (EE LLVMExecutionEngineRef) + (Global LLVMValueRef)) + + +(defun LLVMCreateJITCompiler (provider opt) + (cffi:with-foreign-objects ((out-engine :pointer) + (out-error-str :pointer)) + (if (null (%LLVMCreateJITCompiler out-engine provider opt out-error-str)) + (cffi:mem-ref out-engine :pointer) + (let* ((error-str (cffi:mem-ref out-error-str :pointer)) + (error-str-lisp (cffi:foreign-string-to-lisp error-str))) + (LLVMDisposeMessage error-str) + (error "LLVMCreateJITCompiler: ~s" error-str-lisp))))) + + + + diff --git a/src/generated/target.lisp b/src/generated/target.lisp new file mode 100644 index 0000000..89d6f36 --- /dev/null +++ b/src/generated/target.lisp @@ -0,0 +1,89 @@ +;;; This file was automatically generated by SWIG (http://www.swig.org). +;;; Version 1.3.40 +;;; +;;; Do not make changes to this file unless you know what you are doing--modify +;;; the SWIG interface file instead. + +(in-package :llvm) + + +(cffi:defcenum LLVMByteOrdering + :LLVMBigEndian + :LLVMLittleEndian) + +(cffi:defctype LLVMTargetDataRef :pointer) + +(cffi:defctype LLVMStructLayoutRef :pointer) + +(cffi:defcfun ("LLVMInitializeAllTargetInfos" LLVMInitializeAllTargetInfos) :void) + +(cffi:defcfun ("LLVMInitializeAllTargets" LLVMInitializeAllTargets) :void) + +(cffi:defcfun ("LLVMInitializeNativeTarget" LLVMInitializeNativeTarget) :boolean) + +(cffi:defcfun ("LLVMCreateTargetData" LLVMCreateTargetData) LLVMTargetDataRef + (StringRep :string)) + +(cffi:defcfun ("LLVMAddTargetData" LLVMAddTargetData) :void + (arg0 LLVMTargetDataRef) + (arg1 LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMCopyStringRepOfTargetData" LLVMCopyStringRepOfTargetData) :string + (arg0 LLVMTargetDataRef)) + +(cffi:defcfun ("LLVMByteOrder" LLVMByteOrder) LLVMByteOrdering + (arg0 LLVMTargetDataRef)) + +(cffi:defcfun ("LLVMPointerSize" LLVMPointerSize) :unsigned-int + (arg0 LLVMTargetDataRef)) + +(cffi:defcfun ("LLVMSizeOfTypeInBits" LLVMSizeOfTypeInBits) :unsigned-long-long + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMStoreSizeOfType" LLVMStoreSizeOfType) :unsigned-long-long + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMABISizeOfType" LLVMABISizeOfType) :unsigned-long-long + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMABIAlignmentOfType" LLVMABIAlignmentOfType) :unsigned-int + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMCallFrameAlignmentOfType" LLVMCallFrameAlignmentOfType) :unsigned-int + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMPreferredAlignmentOfType" LLVMPreferredAlignmentOfType) :unsigned-int + (arg0 LLVMTargetDataRef) + (arg1 LLVMTypeRef)) + +(cffi:defcfun ("LLVMPreferredAlignmentOfGlobal" LLVMPreferredAlignmentOfGlobal) :unsigned-int + (arg0 LLVMTargetDataRef) + (GlobalVar LLVMValueRef)) + +(cffi:defcfun ("LLVMElementAtOffset" LLVMElementAtOffset) :unsigned-int + (arg0 LLVMTargetDataRef) + (StructTy LLVMTypeRef) + (Offset :unsigned-long-long)) + +(cffi:defcfun ("LLVMOffsetOfElement" LLVMOffsetOfElement) :unsigned-long-long + (arg0 LLVMTargetDataRef) + (StructTy LLVMTypeRef) + (Element :unsigned-int)) + +(cffi:defcfun ("LLVMInvalidateStructLayout" LLVMInvalidateStructLayout) :void + (arg0 LLVMTargetDataRef) + (StructTy LLVMTypeRef)) + +(cffi:defcfun ("LLVMDisposeTargetData" LLVMDisposeTargetData) :void + (arg0 LLVMTargetDataRef)) + +(cffi:defcfun ("CLLLVM_LLVMIntPtrTypeInContext" %LLVMIntPtrTypeInContext) LLVMTypeRef + (Context LLVMContextRef) + (TD LLVMTargetDataRef)) + + diff --git a/src/generated/transforms-scalar.lisp b/src/generated/transforms-scalar.lisp new file mode 100644 index 0000000..147e3a8 --- /dev/null +++ b/src/generated/transforms-scalar.lisp @@ -0,0 +1,76 @@ +;;; This file was automatically generated by SWIG (http://www.swig.org). +;;; Version 1.3.40 +;;; +;;; Do not make changes to this file unless you know what you are doing--modify +;;; the SWIG interface file instead. + +(in-package :llvm) + + +(cffi:defcfun ("LLVMAddAggressiveDCEPass" LLVMAddAggressiveDCEPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddCFGSimplificationPass" LLVMAddCFGSimplificationPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddDeadStoreEliminationPass" LLVMAddDeadStoreEliminationPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddGVNPass" LLVMAddGVNPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddIndVarSimplifyPass" LLVMAddIndVarSimplifyPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddInstructionCombiningPass" LLVMAddInstructionCombiningPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddJumpThreadingPass" LLVMAddJumpThreadingPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLICMPass" LLVMAddLICMPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLoopDeletionPass" LLVMAddLoopDeletionPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLoopIndexSplitPass" LLVMAddLoopIndexSplitPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLoopRotatePass" LLVMAddLoopRotatePass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLoopUnrollPass" LLVMAddLoopUnrollPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddLoopUnswitchPass" LLVMAddLoopUnswitchPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddMemCpyOptPass" LLVMAddMemCpyOptPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddPromoteMemoryToRegisterPass" LLVMAddPromoteMemoryToRegisterPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddReassociatePass" LLVMAddReassociatePass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddSCCPPass" LLVMAddSCCPPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddScalarReplAggregatesPass" LLVMAddScalarReplAggregatesPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddSimplifyLibCallsPass" LLVMAddSimplifyLibCallsPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddTailCallEliminationPass" LLVMAddTailCallEliminationPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddConstantPropagationPass" LLVMAddConstantPropagationPass) :void + (PM LLVMPassManagerRef)) + +(cffi:defcfun ("LLVMAddDemoteMemoryToRegisterPass" LLVMAddDemoteMemoryToRegisterPass) :void + (PM LLVMPassManagerRef)) + + diff --git a/llvm-extras.cpp b/src/llvm-extras.cpp similarity index 79% rename from llvm-extras.cpp rename to src/llvm-extras.cpp index b04a08b..273d5e7 100644 --- a/llvm-extras.cpp +++ b/src/llvm-extras.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -11,6 +12,8 @@ int CLLLVM_LLVMInitializeNativeTarget() { LLVMInitializeNativeTarget(); } +// Functions missing in the LLVM C API + LLVMModuleRef CLLLVM_LLVMModuleProviderGetModule(LLVMModuleProviderRef modprovider) { return llvm::wrap(llvm::unwrap(modprovider)->getModule()); } @@ -24,4 +27,8 @@ LLVMModuleRef CLLLVM_LLVMParseAssemblyString(const char *AsmString, Error.Print("sbcl", llvm::errs()); } +LLVMTypeRef CLLLVM_LLVMIntPtrTypeInContext(LLVMContextRef Context, LLVMTargetDataRef TD) { + return llvm::wrap(llvm::unwrap(TD)->getIntPtrType(*llvm::unwrap(Context))); +} + } diff --git a/src/load-c-lib.lisp b/src/load-c-lib.lisp index fb93c68..e69de29 100644 --- a/src/load-c-lib.lisp +++ b/src/load-c-lib.lisp @@ -1,7 +0,0 @@ -;; HACK, how do you really do this? -(require :cffi) - -(cffi:define-foreign-library cl-llvm - (t (:default "/home/jknight/Projects/llvm/cl-llvm/cl-llvm"))) - -(cffi:use-foreign-library cl-llvm) diff --git a/src/packages-post.lisp b/src/packages-post.lisp new file mode 100644 index 0000000..f7f348c --- /dev/null +++ b/src/packages-post.lisp @@ -0,0 +1,13 @@ +(in-package :llvm) + +;; Export all symbols starting with "LLVM". + +(labels ((starts-with (s prefix) + (let* ((x (mismatch s prefix))) + (or (null x) (= x (length prefix)))))) + (do-symbols (symbol (find-package :llvm)) + (let ((symbol-name (symbol-name symbol))) + (when (or (starts-with symbol-name "LLVM") (starts-with symbol-name "CLLLVM")) + (export symbol))))) + +(export '(*llvm-context* *jit-module* *jit-module-provider* *jit-execution-engine* *jit-pass-manager*)) diff --git a/src/packages.lisp b/src/packages.lisp new file mode 100644 index 0000000..6e879df --- /dev/null +++ b/src/packages.lisp @@ -0,0 +1,4 @@ +(cl:defpackage :llvm + (:use + #:common-lisp)) + diff --git a/src/stuff.lisp b/src/stuff.lisp index dee0aaf..f0b12c6 100644 --- a/src/stuff.lisp +++ b/src/stuff.lisp @@ -1,53 +1,4 @@ -;; Define some wrappers around the low-level C API functions to make them easier to use. - -(defun LLVMFunctionType* (ret params is-var-arg) - (let ((len (length params))) - (cffi:with-foreign-object (array :pointer len) - (loop for param in params - for i from 0 - do - (setf (cffi:mem-aref array :pointer i) param)) - (LLVMFunctionType ret array len is-var-arg)))) - -(defun LLVMBuildCall* (builder fn args name) - (let ((len (length args))) - (cffi:with-foreign-object (array :pointer len) - (loop for arg in args - for i from 0 - do - (setf (cffi:mem-aref array :pointer i) arg)) - (LLVMBuildCall builder fn array len name)))) - -(defun LLVMAddIncoming* (phi-node incoming-val incoming-block) - (cffi:with-foreign-objects ((incoming-vals :pointer) - (incoming-blocks :pointer)) - (setf (cffi:mem-aref incoming-vals :pointer 0) incoming-val) - (setf (cffi:mem-aref incoming-blocks :pointer 0) incoming-block) - (LLVMAddIncoming phi-node incoming-vals incoming-blocks 1))) - -(defun LLVMCreateJITCompiler* (provider opt) - (cffi:with-foreign-objects ((out-engine :pointer) - (out-error-str :pointer)) - (if (= 0 (LLVMCreateJITCompiler out-engine provider opt out-error-str)) - (cffi:mem-ref out-engine :pointer) - (let* ((error-str (cffi:mem-ref out-error-str :pointer)) - (error-str-lisp (cffi:foreign-string-to-lisp error-str))) - (LLVMDisposeMessage error-str) - (error "LLVMCreateJITCompiler: ~s" error-str-lisp))))) - - -(defun LLVMBuildGEP* (builder ptr indices) - (let ((len (length indices))) - (cffi:with-foreign-object (array :pointer len) - (loop for arg in indices - for i from 0 - do - (setf (cffi:mem-aref array :pointer i) arg)) - (LLVMBuildGEP builder ptr array len "")))) - - - - +(in-package :llvm) ;; Load up the native codegen. (cffi:defcfun ("CLLLVM_LLVMInitializeNativeTarget" CLLLVM_LLVMInitializeNativeTarget) :int) (cffi:defcfun ("CLLLVM_LLVMModuleProviderGetModule" CLLLVM_LLVMModuleProviderGetModule) :pointer @@ -74,7 +25,7 @@ ;; Top-level LLVM module for running the JIT in. Other modules can be made for codegen-to-disk, but ;; only a single module for JIT execution can exist in the process. -(defvar *jit-module* (LLVMModuleCreateWithNameInContext "jit-module" *llvm-context*)) +(defvar *jit-module* (LLVMModuleCreateWithName "jit-module")) ;; Module provider...dunno what the purpose of this is, it wraps the module ;; Delete with LLVMDisposeModuleProvider; don't delete the wrapped module @@ -82,7 +33,7 @@ ;; Create the JIT compiler, optimization level 2 (whatever that means). This call fails if you run ;; it twice in a process. (which is why we can have only one module for JIT code) -(defvar *jit-execution-engine* (LLVMCreateJITCompiler* *jit-module-provider* 2)) +(defvar *jit-execution-engine* (LLVMCreateJITCompiler *jit-module-provider* 2)) ;; Optimization passes. Cleanup with LLVMDisposePassManager. (defvar *jit-pass-manager* (LLVMCreateFunctionPassManager *jit-module-provider*)) diff --git a/src/target.i b/src/target.i new file mode 100644 index 0000000..7fad340 --- /dev/null +++ b/src/target.i @@ -0,0 +1,8 @@ +%include "typemaps.i" + +%ignore LLVMIntPtrType; +%rename CLLLVM_LLVMIntPtrTypeInContext "%%LLVMIntPtrTypeInContext"; + +%include "llvm-c/Target.h" + +LLVMTypeRef CLLLVM_LLVMIntPtrTypeInContext(LLVMContextRef Context, LLVMTargetDataRef TD); diff --git a/src/transforms-scalar.i b/src/transforms-scalar.i new file mode 100644 index 0000000..f11a2f9 --- /dev/null +++ b/src/transforms-scalar.i @@ -0,0 +1,3 @@ +%include "typemaps.i" + +%include "llvm-c/Transforms/Scalar.h" diff --git a/src/typemaps.i b/src/typemaps.i new file mode 100644 index 0000000..4f14467 --- /dev/null +++ b/src/typemaps.i @@ -0,0 +1,47 @@ + +// Put everything in a package +%insert("lisphead") %{ +(in-package :llvm)%} + +%typemap(cin) LLVMBool ":boolean"; +%typemap(cout) LLVMBool ":boolean"; + +// These typemaps are a bit silly: all they do is provide +// documentation in the interfaces. All the actual types degenerate into +// :pointer, in any case, via defctype. + +// For Core.h +%typemap(cin) LLVMContextRef "LLVMContextRef"; +%typemap(cout) LLVMContextRef "LLVMContextRef"; +%typemap(cin) LLVMModuleRef "LLVMModuleRef"; +%typemap(cout) LLVMModuleRef "LLVMModuleRef"; +%typemap(cin) LLVMTypeRef "LLVMTypeRef"; +%typemap(cout) LLVMTypeRef "LLVMTypeRef"; +%typemap(cin) LLVMTypeHandleRef "LLVMTypeHandleRef"; +%typemap(cout) LLVMTypeHandleRef "LLVMTypeHandleRef"; +%typemap(cin) LLVMValueRef "LLVMValueRef"; +%typemap(cout) LLVMValueRef "LLVMValueRef"; +%typemap(cin) LLVMBasicBlockRef "LLVMBasicBlockRef"; +%typemap(cout) LLVMBasicBlockRef "LLVMBasicBlockRef"; +%typemap(cin) LLVMBuilderRef "LLVMBuilderRef"; +%typemap(cout) LLVMBuilderRef "LLVMBuilderRef"; +%typemap(cin) LLVMModuleProviderRef "LLVMModuleProviderRef"; +%typemap(cout) LLVMModuleProviderRef "LLVMModuleProviderRef"; +%typemap(cin) LLVMMemoryBufferRef "LLVMMemoryBufferRef"; +%typemap(cout) LLVMMemoryBufferRef "LLVMMemoryBufferRef"; +%typemap(cin) LLVMPassManagerRef "LLVMPassManagerRef"; +%typemap(cout) LLVMPassManagerRef "LLVMPassManagerRef"; +%typemap(cin) LLVMUseIteratorRef "LLVMUseIteratorRef"; +%typemap(cout) LLVMUseIteratorRef "LLVMUseIteratorRef"; + +// For ExecutionEngine.h +%typemap(cin) LLVMGenericValueRef "LLVMGenericValueRef"; +%typemap(cout) LLVMGenericValueRef "LLVMGenericValueRef"; +%typemap(cin) LLVMExecutionEngineRef "LLVMExecutionEngineRef"; +%typemap(cout) LLVMExecutionEngineRef "LLVMExecutionEngineRef"; + +// For Target.h +%typemap(cin) LLVMTargetDataRef "LLVMTargetDataRef"; +%typemap(cout) LLVMTargetDataRef "LLVMTargetDataRef"; +%typemap(cin) LLVMStructLayoutRef "LLVMStructLayoutRef"; +%typemap(cout) LLVMStructLayoutRef "LLVMStructLayoutRef"; -- 2.11.4.GIT