From 898072a89a98b9a3aaf99f53b57e05fe82b0255a Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 10:26:36 -0600 Subject: [PATCH 1/8] Moved existing bindings to the bindings.rb file. Changed lib/llvm.rb and lib/llvm/core.rb to reflect this change, and removed references to lib/llvm/target.rb, as it was no longer needed. --- lib/llvm.rb | 13 +- lib/llvm/analysis.rb | 13 - lib/llvm/bindings.rb | 691 ++++++++++++++++++++++++++++++++++ lib/llvm/core.rb | 603 +---------------------------- lib/llvm/core/bitcode.rb | 8 - lib/llvm/execution_engine.rb | 44 --- lib/llvm/target.rb | 9 - lib/llvm/transforms/ipo.rb | 6 - lib/llvm/transforms/scalar.rb | 25 -- 9 files changed, 703 insertions(+), 709 deletions(-) create mode 100644 lib/llvm/bindings.rb delete mode 100644 lib/llvm/target.rb diff --git a/lib/llvm.rb b/lib/llvm.rb index 688d819..e7b0dc7 100644 --- a/lib/llvm.rb +++ b/lib/llvm.rb @@ -1,12 +1,5 @@ -require 'rubygems' -require 'ffi' - module LLVM - # @private - module C - extend ::FFI::Library - - # load required libraries - ffi_lib ['LLVM-2.9', 'libLLVM-2.9'] - end + autoload :Analysis, 'llvm/analysis' + autoload :Core, 'llvm/core' + autoload :ExecutionEngine, 'llvm/execution_engine' end diff --git a/lib/llvm/analysis.rb b/lib/llvm/analysis.rb index 45cfc15..fb5a202 100644 --- a/lib/llvm/analysis.rb +++ b/lib/llvm/analysis.rb @@ -1,20 +1,7 @@ require 'llvm' require 'llvm/core' -require 'llvm/target' module LLVM - # @private - module C - enum :verifier_failure_action, [ - :abort_process, - :print_message, - :return_status - ] - - attach_function :LLVMVerifyModule, [:pointer, :verifier_failure_action, :pointer], :int - attach_function :LLVMVerifyFunction, [:pointer, :verifier_failure_action], :int - end - class Module # Verify that the module is valid. # @return [nil, String] human-readable description of any invalid diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb new file mode 100644 index 0000000..c2667a7 --- /dev/null +++ b/lib/llvm/bindings.rb @@ -0,0 +1,691 @@ +require 'rubygems' +require 'ffi' + +module LLVM + # @private + module C + + extend FFI::Library + + # Load the required library. + ffi_lib ['LLVM-2.9', 'libLLVM-2.9'] + + ######### + # Enums # + ######### + + enum :attribute, [ + :ext, 1 << 0, + :sext, 1 << 1, + :no_return, 1 << 2, + :in_reg, 1 << 3, + :struct_ret, 1 << 4, + :no_unwind, 1 << 5, + :no_alias, 1 << 6, + :by_val, 1 << 7, + :nest, 1 << 8, + :read_none, 1 << 9, + :read_only, 1 << 10, + :no_inline, 1 << 11, + :always_inline, 1 << 12, + :optimize_for_size, 1 << 13, + :stack_protect, 1 << 14, + :stack_protect_req, 1 << 15, + :no_capture, 1 << 21, + :no_red_zone, 1 << 22, + :no_implicit_float, 1 << 23, + :naked, 1 << 24 + ] + + enum :opcode, [ + # Terminator Instructions + :ret, 1, + :br, 2, + :switch, 3, + :indirectbr, 4, + :invoke, 5, + :unwind, 6, + :unreachable, 7, + + # Standard Binary Operators + :add, 8, + :fadd, 9, + :sub, 10, + :fsub, 11, + :mul, 12, + :fmul, 13, + :udiv, 14, + :sdiv, 15, + :fdiv, 16, + :urem, 17, + :srem, 18, + :frem, 19, + + # Logical Operators + :shl, 20, + :lshr, 21, + :ashr, 22, + :and, 23, + :or, 24, + :xor, 25, + + # Memory Operators + :alloca, 26, + :load, 27, + :store, 28, + :getelementptr, 29, + + # Cast Operators + :trunc, 30, + :zext, 31, + :sext, 32, + :fptoui, 33, + :fptosi, 34, + :uitofp, 35, + :sitofp, 36, + :fptrunc, 37, + :fpext, 38, + :ptrtoint, 39, + :inttoptr, 40, + :bitcast, 41, + + # Other Operators + :icmp, 42, + :fcmp, 43, + :phi, 44, + :call, 45, + :select, 46, + + # UserOp1 + # UserOp2 + :vaarg, 49, + :extractelement, 50, + :insertelement, 51, + :shufflevector, 52, + :extractvalue, 53, + :insertvalue, 54, + ] + + enum :type_kind, [ + :void, + :float, + :double, + :x86_fp80, + :fp128, + :ppc_fp128, + :label, + :integer, + :function, + :struct, + :array, + :pointer, + :opaque, + :vector, + :metadata + ] + + enum :linkage, [ + :external, + :available_externally, + :link_once_any, + :link_once_odr, + :weak_any, + :weak_odr, + :appending, + :internal, + :private, + :dll_import, + :dll_export, + :external_weak, + :ghost, + :common, + :linker_private + ] + + enum :visibility, [ + :default, + :hidden, + :protected + ] + + enum :call_conv, [ + :ccall, 0, + :fastcall, 8, + :coldcall, 9, + :x86_stdcall, 64, + :x86_fastcall, 65 + ] + + enum :int_predicate, [ + :eq, 32, + :ne, 33, + :ugt, 34, + :uge, 35, + :ult, 36, + :ule, 37, + :sgt, 38, + :sge, 39, + :slt, 40, + :sle, 41 + ] + + enum :real_predicate, [ + :false, + :oeq, + :ogt, + :oge, + :olt, + :ole, + :one, + :ord, + :uno, + :ueq, + :ugt, + :uge, + :ult, + :ule, + :une, + :true + ] + + enum :verifier_failure_action, [ + :abort_process, + :print_message, + :return_status + ] + + ############# + # Functions # + ############# + + # Error handling + attach_function :LLVMDisposeMessage, [:pointer], :void + + # Contexts + attach_function :LLVMContextCreate, [], :pointer + attach_function :LLVMGetGlobalContext, [], :pointer + attach_function :LLVMContextDispose, [:pointer], :void + + # Modules + attach_function :LLVMModuleCreateWithName, [:string], :pointer + attach_function :LLVMModuleCreateWithNameInContext, [:string, :pointer], :pointer + attach_function :LLVMDisposeModule, [:pointer], :void + attach_function :LLVMGetDataLayout, [:pointer], :string + attach_function :LLVMSetDataLayout, [:pointer, :string], :void + attach_function :LLVMGetTarget, [:pointer], :string + attach_function :LLVMSetTarget, [:pointer, :string], :void + attach_function :LLVMAddTypeName, [:pointer, :string, :pointer], :int + attach_function :LLVMDeleteTypeName, [:pointer, :string], :void + attach_function :LLVMGetTypeByName, [:pointer, :string], :pointer + attach_function :LLVMDumpModule, [:pointer], :void + + # Types + attach_function :LLVMGetTypeKind, [:pointer], :type_kind + attach_function :LLVMGetTypeContext, [:pointer], :pointer + + # Integer types + attach_function :LLVMInt1TypeInContext, [:pointer], :pointer + attach_function :LLVMInt8TypeInContext, [:pointer], :pointer + attach_function :LLVMInt16TypeInContext, [:pointer], :pointer + attach_function :LLVMInt32TypeInContext, [:pointer], :pointer + attach_function :LLVMInt64TypeInContext, [:pointer], :pointer + attach_function :LLVMIntTypeInContext, [:pointer, :uint], :pointer + + attach_function :LLVMInt1Type, [], :pointer + attach_function :LLVMInt8Type, [], :pointer + attach_function :LLVMInt16Type, [], :pointer + attach_function :LLVMInt32Type, [], :pointer + attach_function :LLVMInt64Type, [], :pointer + attach_function :LLVMIntType, [:uint], :pointer + attach_function :LLVMGetIntTypeWidth, [:pointer], :uint + + # Real types + attach_function :LLVMFloatTypeInContext, [:pointer], :pointer + attach_function :LLVMDoubleTypeInContext, [:pointer], :pointer + attach_function :LLVMX86FP80TypeInContext, [:pointer], :pointer + attach_function :LLVMFP128TypeInContext, [:pointer], :pointer + attach_function :LLVMPPCFP128TypeInContext, [:pointer], :pointer + + attach_function :LLVMFloatType, [], :pointer + attach_function :LLVMDoubleType, [], :pointer + attach_function :LLVMX86FP80Type, [], :pointer + attach_function :LLVMFP128Type, [], :pointer + attach_function :LLVMPPCFP128Type, [], :pointer + + # Function types + attach_function :LLVMFunctionType, [:pointer, :pointer, :uint, :int], :pointer + attach_function :LLVMIsFunctionVarArg, [:pointer], :int + attach_function :LLVMGetReturnType, [:pointer], :pointer + attach_function :LLVMCountParamTypes, [:pointer], :uint + attach_function :LLVMGetParamTypes, [:pointer, :pointer], :void + + # Struct types + attach_function :LLVMStructTypeInContext, [:pointer, :pointer, :uint, :int], :pointer + attach_function :LLVMStructType, [:pointer, :uint, :int], :pointer + attach_function :LLVMCountStructElementTypes, [:pointer], :uint + attach_function :LLVMGetStructElementTypes, [:pointer, :pointer], :void + attach_function :LLVMIsPackedStruct, [:pointer], :int + + # Array, pointer and vector types (sequence types) + attach_function :LLVMArrayType, [:pointer, :uint], :pointer + attach_function :LLVMPointerType, [:pointer, :uint], :pointer + attach_function :LLVMVectorType, [:pointer, :uint], :pointer + + attach_function :LLVMGetElementType, [:pointer], :pointer + attach_function :LLVMGetArrayLength, [:pointer], :uint + attach_function :LLVMGetPointerAddressSpace, [:pointer], :uint + attach_function :LLVMGetVectorSize, [:pointer], :uint + + # All other types + attach_function :LLVMVoidTypeInContext, [:pointer], :pointer + attach_function :LLVMLabelTypeInContext, [:pointer], :pointer + attach_function :LLVMOpaqueTypeInContext, [:pointer], :pointer + + attach_function :LLVMVoidType, [], :pointer + attach_function :LLVMLabelType, [], :pointer + attach_function :LLVMOpaqueType, [], :pointer + + # Type handles + attach_function :LLVMCreateTypeHandle, [:pointer], :pointer + attach_function :LLVMRefineType, [:pointer, :pointer], :void + attach_function :LLVMResolveTypeHandle, [:pointer], :pointer + attach_function :LLVMDisposeTypeHandle, [:pointer], :void + + # All values + attach_function :LLVMTypeOf, [:pointer], :pointer + attach_function :LLVMGetValueName, [:pointer], :string + attach_function :LLVMSetValueName, [:pointer, :string], :void + attach_function :LLVMDumpValue, [:pointer], :void + + # Operations on Users + attach_function :LLVMGetOperand, [:pointer, :int], :pointer + attach_function :LLVMSetOperand, [:pointer, :int, :pointer], :void + attach_function :LLVMGetNumOperands, [:pointer], :int + + # Constants of any type + attach_function :LLVMConstNull, [:pointer], :pointer + attach_function :LLVMConstAllOnes, [:pointer], :pointer + attach_function :LLVMGetUndef, [:pointer], :pointer + attach_function :LLVMIsConstant, [:pointer], :int + attach_function :LLVMIsNull, [:pointer], :int + attach_function :LLVMIsUndef, [:pointer], :int + attach_function :LLVMConstPointerNull, [:pointer], :pointer + + # Scalar constants + attach_function :LLVMConstInt, [:pointer, :ulong_long, :int], :pointer + attach_function :LLVMConstIntOfString, [:pointer, :string, :uint8], :pointer + attach_function :LLVMConstIntOfStringAndSize, [:pointer, :string, :uint, :uint8], :pointer + attach_function :LLVMConstReal, [:pointer, :double], :pointer + attach_function :LLVMConstRealOfString, [:pointer, :string], :pointer + attach_function :LLVMConstRealOfStringAndSize, [:pointer, :string, :uint], :pointer + + # Composite constants + attach_function :LLVMConstStringInContext, [:pointer, :string, :uint, :int], :pointer + attach_function :LLVMConstStructInContext, [:pointer, :pointer, :uint, :int], :pointer + + attach_function :LLVMConstString, [:string, :uint, :int], :pointer + attach_function :LLVMConstArray, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMConstStruct, [:pointer, :uint, :int], :pointer + attach_function :LLVMConstVector, [:pointer, :uint], :pointer + + # Constant expressions + attach_function :LLVMGetConstOpcode, [:pointer], :opcode + attach_function :LLVMAlignOf, [:pointer], :pointer + attach_function :LLVMSizeOf, [:pointer], :pointer + attach_function :LLVMConstNeg, [:pointer], :pointer + attach_function :LLVMConstFNeg, [:pointer], :pointer + attach_function :LLVMConstNot, [:pointer], :pointer + attach_function :LLVMConstAdd, [:pointer, :pointer], :pointer + attach_function :LLVMConstNSWAdd, [:pointer, :pointer], :pointer + attach_function :LLVMConstFAdd, [:pointer, :pointer], :pointer + attach_function :LLVMConstSub, [:pointer, :pointer], :pointer + attach_function :LLVMConstFSub, [:pointer, :pointer], :pointer + attach_function :LLVMConstMul, [:pointer, :pointer], :pointer + attach_function :LLVMConstFMul, [:pointer, :pointer], :pointer + attach_function :LLVMConstUDiv, [:pointer, :pointer], :pointer + attach_function :LLVMConstSDiv, [:pointer, :pointer], :pointer + attach_function :LLVMConstExactSDiv, [:pointer, :pointer], :pointer + attach_function :LLVMConstFDiv, [:pointer, :pointer], :pointer + attach_function :LLVMConstURem, [:pointer, :pointer], :pointer + attach_function :LLVMConstSRem, [:pointer, :pointer], :pointer + attach_function :LLVMConstFRem, [:pointer, :pointer], :pointer + attach_function :LLVMConstAnd, [:pointer, :pointer], :pointer + attach_function :LLVMConstOr, [:pointer, :pointer], :pointer + attach_function :LLVMConstXor, [:pointer, :pointer], :pointer + attach_function :LLVMConstICmp, [:int, :pointer, :pointer], :pointer + attach_function :LLVMConstFCmp, [:int, :pointer, :pointer], :pointer + attach_function :LLVMConstShl, [:pointer, :pointer], :pointer + attach_function :LLVMConstLShr, [:pointer, :pointer], :pointer + attach_function :LLVMConstAShr, [:pointer, :pointer], :pointer + attach_function :LLVMConstGEP, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMConstInBoundsGEP, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMConstTrunc, [:pointer, :pointer], :pointer + attach_function :LLVMConstSExt, [:pointer, :pointer], :pointer + attach_function :LLVMConstZExt, [:pointer, :pointer], :pointer + attach_function :LLVMConstFPTrunc, [:pointer, :pointer], :pointer + attach_function :LLVMConstFPExt, [:pointer, :pointer], :pointer + attach_function :LLVMConstUIToFP, [:pointer, :pointer], :pointer + attach_function :LLVMConstSIToFP, [:pointer, :pointer], :pointer + attach_function :LLVMConstFPToUI, [:pointer, :pointer], :pointer + attach_function :LLVMConstFPToSI, [:pointer, :pointer], :pointer + attach_function :LLVMConstPtrToInt, [:pointer, :pointer], :pointer + attach_function :LLVMConstIntToPtr, [:pointer, :pointer], :pointer + attach_function :LLVMConstBitCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstZExtOrBitCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstSExtOrBitCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstTruncOrBitCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstPointerCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstIntCast, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMConstFPCast, [:pointer, :pointer], :pointer + attach_function :LLVMConstSelect, [:pointer, :pointer, :pointer], :pointer + attach_function :LLVMConstExtractElement, [:pointer, :pointer], :pointer + attach_function :LLVMConstInsertElement, [:pointer, :pointer], :pointer + attach_function :LLVMConstShuffleVector, [:pointer, :pointer, :pointer], :pointer + attach_function :LLVMConstExtractValue, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMConstInsertValue, [:pointer, :pointer, :pointer, :uint], :pointer + attach_function :LLVMConstInlineAsm, [:pointer, :string, :string, :int], :pointer + + # Global variables, functions and aliases (globals) + attach_function :LLVMGetGlobalParent, [:pointer], :pointer + attach_function :LLVMIsDeclaration, [:pointer], :int + attach_function :LLVMGetLinkage, [:pointer], :linkage + attach_function :LLVMSetLinkage, [:pointer, :linkage], :void + attach_function :LLVMGetSection, [:pointer], :string + attach_function :LLVMSetSection, [:pointer, :string], :void + attach_function :LLVMGetVisibility, [:pointer], :visibility + attach_function :LLVMSetVisibility, [:pointer, :visibility], :void + attach_function :LLVMGetAlignment, [:pointer], :uint + attach_function :LLVMSetAlignment, [:pointer, :uint], :void + + attach_function :LLVMAddGlobal, [:pointer, :pointer, :string], :pointer + attach_function :LLVMGetNamedGlobal, [:pointer, :string], :pointer + attach_function :LLVMGetFirstGlobal, [:pointer], :pointer + attach_function :LLVMGetLastGlobal, [:pointer], :pointer + attach_function :LLVMGetNextGlobal, [:pointer], :pointer + attach_function :LLVMGetPreviousGlobal, [:pointer], :pointer + attach_function :LLVMDeleteGlobal, [:pointer], :void + attach_function :LLVMGetInitializer, [:pointer], :pointer + attach_function :LLVMSetInitializer, [:pointer, :pointer], :void + attach_function :LLVMIsThreadLocal, [:pointer], :bool + attach_function :LLVMSetThreadLocal, [:pointer, :int], :void + attach_function :LLVMIsGlobalConstant, [:pointer], :bool + attach_function :LLVMSetGlobalConstant, [:pointer, :bool], :void + + # Aliases + attach_function :LLVMAddAlias, [:pointer, :pointer, :pointer, :string], :pointer + + # Function operations + attach_function :LLVMAddFunction, [:pointer, :string, :pointer], :pointer + attach_function :LLVMGetNamedFunction, [:pointer, :string], :pointer + attach_function :LLVMGetFirstFunction, [:pointer], :pointer + attach_function :LLVMGetLastFunction, [:pointer], :pointer + attach_function :LLVMGetNextFunction, [:pointer], :pointer + attach_function :LLVMGetPreviousFunction, [:pointer], :pointer + attach_function :LLVMDeleteFunction, [:pointer], :void + attach_function :LLVMGetIntrinsicID, [:pointer], :uint + attach_function :LLVMGetFunctionCallConv, [:pointer], :call_conv + attach_function :LLVMSetFunctionCallConv, [:pointer, :call_conv], :void + attach_function :LLVMGetGC, [:pointer], :string + attach_function :LLVMSetGC, [:pointer, :string], :void + attach_function :LLVMAddFunctionAttr, [:pointer, :attribute], :void + attach_function :LLVMRemoveFunctionAttr, [:pointer, :attribute], :void + + # Parameters + attach_function :LLVMCountParams, [:pointer], :uint + attach_function :LLVMGetParams, [:pointer, :pointer], :void + attach_function :LLVMGetParam, [:pointer, :uint], :pointer + attach_function :LLVMGetParamParent, [:pointer], :pointer + attach_function :LLVMGetFirstParam, [:pointer], :pointer + attach_function :LLVMGetLastParam, [:pointer], :pointer + attach_function :LLVMGetNextParam, [:pointer], :pointer + attach_function :LLVMGetPreviousParam, [:pointer], :pointer + attach_function :LLVMAddAttribute, [:pointer, :attribute], :void + attach_function :LLVMRemoveAttribute, [:pointer, :attribute], :void + attach_function :LLVMSetParamAlignment, [:pointer, :uint], :void + + # Basic blocks + attach_function :LLVMBasicBlockAsValue, [:pointer], :pointer + attach_function :LLVMValueIsBasicBlock, [:pointer], :int + attach_function :LLVMValueAsBasicBlock, [:pointer], :pointer + attach_function :LLVMGetBasicBlockParent, [:pointer], :pointer + attach_function :LLVMCountBasicBlocks, [:pointer], :uint + attach_function :LLVMGetBasicBlocks, [:pointer, :pointer], :void + attach_function :LLVMGetFirstBasicBlock, [:pointer], :pointer + attach_function :LLVMGetLastBasicBlock, [:pointer], :pointer + attach_function :LLVMGetNextBasicBlock, [:pointer], :pointer + attach_function :LLVMGetPreviousBasicBlock, [:pointer], :pointer + attach_function :LLVMGetEntryBasicBlock, [:pointer], :pointer + + attach_function :LLVMAppendBasicBlockInContext, [:pointer, :pointer, :string], :pointer + attach_function :LLVMInsertBasicBlockInContext, [:pointer, :pointer, :string], :pointer + + attach_function :LLVMAppendBasicBlock, [:pointer, :string], :pointer + attach_function :LLVMDeleteBasicBlock, [:pointer], :void + + # Instructions + attach_function :LLVMGetInstructionParent, [:pointer], :pointer + attach_function :LLVMGetFirstInstruction, [:pointer], :pointer + attach_function :LLVMGetLastInstruction, [:pointer], :pointer + attach_function :LLVMGetNextInstruction, [:pointer], :pointer + attach_function :LLVMGetPreviousInstruction, [:pointer], :pointer + + # Call sites + attach_function :LLVMSetInstructionCallConv, [:pointer, :call_conv], :void + attach_function :LLVMGetInstructionCallConv, [:pointer], :call_conv + attach_function :LLVMAddInstrAttribute, [:pointer, :uint, :attribute], :void + attach_function :LLVMRemoveInstrAttribute, [:pointer, :uint, :attribute], :void + attach_function :LLVMSetInstrParamAlignment, [:pointer, :uint, :uint], :void + + # Call instructions + attach_function :LLVMIsTailCall, [:pointer], :int + attach_function :LLVMSetTailCall, [:pointer, :int], :void + + # Phi nodes + attach_function :LLVMAddIncoming, [:pointer, :pointer, :pointer, :uint], :void + attach_function :LLVMCountIncoming, [:pointer], :uint + attach_function :LLVMGetIncomingValue, [:pointer, :uint], :pointer + attach_function :LLVMGetIncomingBlock, [:pointer, :uint], :pointer + + # Instruction builders + attach_function :LLVMCreateBuilderInContext, [:pointer], :pointer + attach_function :LLVMCreateBuilder, [], :pointer + attach_function :LLVMPositionBuilder, [:pointer, :pointer, :pointer], :void + attach_function :LLVMPositionBuilderBefore, [:pointer, :pointer], :void + attach_function :LLVMPositionBuilderAtEnd, [:pointer, :pointer], :void + attach_function :LLVMGetInsertBlock, [:pointer], :pointer + attach_function :LLVMClearInsertionPosition, [:pointer], :void + attach_function :LLVMInsertIntoBuilder, [:pointer, :pointer], :void + attach_function :LLVMInsertIntoBuilderWithName, [:pointer, :pointer, :string], :void + attach_function :LLVMDisposeBuilder, [:pointer], :void + + # Terminators + attach_function :LLVMBuildRetVoid, [:pointer], :pointer + attach_function :LLVMBuildRet, [:pointer, :pointer], :pointer + attach_function :LLVMBuildAggregateRet, [:pointer, :pointer, :uint], :pointer + attach_function :LLVMBuildBr, [:pointer, :pointer], :pointer + attach_function :LLVMBuildCondBr, [:pointer, :pointer, :pointer, :pointer], :pointer + attach_function :LLVMBuildSwitch, [:pointer, :pointer, :pointer, :uint], :pointer + attach_function :LLVMBuildInvoke, [:pointer, :pointer, :pointer, :uint, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildUnwind, [:pointer], :pointer + attach_function :LLVMBuildUnreachable, [:pointer], :pointer + + # Switch instruction + attach_function :LLVMAddCase, [:pointer, :pointer, :pointer], :void + + # Arithmetic + attach_function :LLVMBuildAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNSWAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSub, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFSub, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildMul, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFMul, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildUDiv, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSDiv, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildExactSDiv, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFDiv, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildURem, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSRem, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFRem, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildShl, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildLShr, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildAShr, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildAnd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildOr, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildXor, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNeg, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNot, [:pointer, :pointer, :string], :pointer + + # Memory + attach_function :LLVMBuildMalloc, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildArrayMalloc, [:pointer, :pointer, :pointer, :string], :string + attach_function :LLVMBuildAlloca, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildArrayAlloca, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFree, [:pointer, :pointer], :pointer + attach_function :LLVMBuildLoad, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildStore, [:pointer, :pointer, :pointer], :pointer + attach_function :LLVMBuildGEP, [:pointer, :pointer, :pointer, :uint, :string], :pointer + attach_function :LLVMBuildInBoundsGEP, [:pointer, :pointer, :pointer, :uint, :string], :pointer + attach_function :LLVMBuildStructGEP, [:pointer, :pointer, :uint, :string], :pointer + attach_function :LLVMBuildGlobalString, [:pointer, :string, :string], :pointer + attach_function :LLVMBuildGlobalStringPtr, [:pointer, :string, :string], :pointer + + # Casts + attach_function :LLVMBuildTrunc, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildZExt, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSExt, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFPToUI, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFPToSI, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildUIToFP, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSIToFP, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFPTrunc, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFPExt, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildPtrToInt, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildIntToPtr, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildBitCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildZExtOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSExtOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildTruncOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildPointerCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildIntCast, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFPCast, [:pointer, :pointer, :pointer, :string], :pointer + + # Comparisons + attach_function :LLVMBuildICmp, [:pointer, :int_predicate, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFCmp, [:pointer, :real_predicate, :pointer, :pointer, :string], :pointer + + # Misc + attach_function :LLVMBuildPhi, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildCall, [:pointer, :pointer, :pointer, :uint, :string], :pointer + attach_function :LLVMBuildSelect, [:pointer, :pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildVAArg, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildExtractElement, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildInsertElement, [:pointer, :pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildShuffleVector, [:pointer, :pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildExtractValue, [:pointer, :pointer, :uint, :string], :pointer + attach_function :LLVMBuildInsertValue, [:pointer, :pointer, :pointer, :uint, :string], :pointer + + attach_function :LLVMBuildIsNull, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildIsNotNull, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildPtrDiff, [:pointer, :pointer, :pointer, :string], :pointer + + # Module providers + attach_function :LLVMCreateModuleProviderForExistingModule, [:pointer], :pointer + attach_function :LLVMDisposeModuleProvider, [:pointer], :void + + # Memory buffers + attach_function :LLVMCreateMemoryBufferWithContentsOfFile, [:string, :pointer, :pointer], :int + attach_function :LLVMCreateMemoryBufferWithSTDIN, [:pointer, :pointer], :int + attach_function :LLVMDisposeMemoryBuffer, [:pointer], :void + + # Pass managers + attach_function :LLVMCreatePassManager, [], :pointer + attach_function :LLVMCreateFunctionPassManager, [:pointer], :pointer + attach_function :LLVMCreateFunctionPassManagerForModule, [:pointer], :pointer + attach_function :LLVMRunPassManager, [:pointer, :pointer], :int + attach_function :LLVMInitializeFunctionPassManager, [:pointer], :int + attach_function :LLVMRunFunctionPassManager, [:pointer, :pointer], :int + attach_function :LLVMFinalizeFunctionPassManager, [:pointer], :int + attach_function :LLVMDisposePassManager, [:pointer], :void + + # Verification + attach_function :LLVMVerifyModule, [:pointer, :verifier_failure_action, :pointer], :int + attach_function :LLVMVerifyFunction, [:pointer, :verifier_failure_action], :int + + # Generic values + attach_function :LLVMCreateGenericValueOfInt, [:pointer, :long_long, :int], :pointer + attach_function :LLVMCreateGenericValueOfPointer, [:pointer], :pointer + attach_function :LLVMCreateGenericValueOfFloat, [:pointer, :double], :pointer + + attach_function :LLVMGenericValueIntWidth, [:pointer], :uint + + attach_function :LLVMGenericValueToInt, [:pointer, :int], :long_long + attach_function :LLVMGenericValueToPointer, [:pointer], :pointer + attach_function :LLVMGenericValueToFloat, [:pointer, :pointer], :double + attach_function :LLVMDisposeGenericValue, [:pointer], :void + + # Execution engines + attach_function :LLVMCreateExecutionEngineForModule, [:pointer, :pointer, :pointer], :int + attach_function :LLVMCreateInterpreterForModule, [:pointer, :pointer, :pointer], :int + attach_function :LLVMCreateJITCompilerForModule, [:pointer, :pointer, :uint, :pointer], :int + attach_function :LLVMDisposeExecutionEngine, [:pointer], :void + + attach_function :LLVMRunStaticConstructors, [:pointer], :void + attach_function :LLVMRunStaticDestructors, [:pointer], :void + + attach_function :LLVMRunFunctionAsMain, [:pointer, :pointer, :uint, :pointer, :pointer], :int + attach_function :LLVMRunFunction, [:pointer, :pointer, :uint, :pointer], :pointer + + attach_function :LLVMFreeMachineCodeForFunction, [:pointer, :pointer], :void + attach_function :LLVMAddModuleProvider, [:pointer, :pointer], :void + attach_function :LLVMRemoveModuleProvider, [:pointer, :pointer, :pointer, :pointer], :int + + attach_function :LLVMFindFunction, [:pointer, :pointer, :pointer, :pointer], :int + + attach_function :LLVMGetExecutionEngineTargetData, [:pointer], :pointer + + attach_function :LLVMAddGlobalMapping, [:pointer, :pointer, :pointer], :void + + attach_function :LLVMGetPointerToGlobal, [:pointer, :pointer], :pointer + + # Target Initialization + attach_function :LLVMInitializeX86TargetInfo, [], :void + attach_function :LLVMInitializeX86Target, [], :void + + # Target Data + attach_function :LLVMAddTargetData, [:pointer, :pointer], :void + + # Inter-procedural Optimizations + attach_function :LLVMAddGlobalDCEPass, [:pointer], :void + attach_function :LLVMAddFunctionInliningPass, [:pointer], :void + + # Scalar Optimizations + attach_function :LLVMAddAggressiveDCEPass, [:pointer], :void + attach_function :LLVMAddCFGSimplificationPass, [:pointer], :void + attach_function :LLVMAddDeadStoreEliminationPass, [:pointer], :void + attach_function :LLVMAddGVNPass, [:pointer], :void + attach_function :LLVMAddIndVarSimplifyPass, [:pointer], :void + attach_function :LLVMAddInstructionCombiningPass, [:pointer], :void + attach_function :LLVMAddJumpThreadingPass, [:pointer], :void + attach_function :LLVMAddLICMPass, [:pointer], :void + attach_function :LLVMAddLoopDeletionPass, [:pointer], :void + attach_function :LLVMAddLoopRotatePass, [:pointer], :void + attach_function :LLVMAddLoopUnrollPass, [:pointer], :void + attach_function :LLVMAddLoopUnswitchPass, [:pointer], :void + attach_function :LLVMAddMemCpyOptPass, [:pointer], :void + attach_function :LLVMAddPromoteMemoryToRegisterPass, [:pointer], :void + attach_function :LLVMAddReassociatePass, [:pointer], :void + attach_function :LLVMAddSCCPPass, [:pointer], :void + attach_function :LLVMAddScalarReplAggregatesPass, [:pointer], :void + attach_function :LLVMAddSimplifyLibCallsPass, [:pointer], :void + attach_function :LLVMAddTailCallEliminationPass, [:pointer], :void + attach_function :LLVMAddConstantPropagationPass, [:pointer], :void + attach_function :LLVMAddDemoteMemoryToRegisterPass, [:pointer], :void + + # Bitcode + attach_function :LLVMParseBitcode, [:pointer, :buffer_out, :buffer_out], :int + attach_function :LLVMParseBitcodeInContext, [:pointer, :pointer, :buffer_out, :buffer_out], :int + attach_function :LLVMWriteBitcodeToFile, [:pointer, :string], :int + attach_function :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int + end +end diff --git a/lib/llvm/core.rb b/lib/llvm/core.rb index 39dfa5e..e7335a8 100644 --- a/lib/llvm/core.rb +++ b/lib/llvm/core.rb @@ -1,598 +1,13 @@ require 'llvm' module LLVM - # @private - module C - enum :attribute, [ - :ext, 1 << 0, - :sext, 1 << 1, - :no_return, 1 << 2, - :in_reg, 1 << 3, - :struct_ret, 1 << 4, - :no_unwind, 1 << 5, - :no_alias, 1 << 6, - :by_val, 1 << 7, - :nest, 1 << 8, - :read_none, 1 << 9, - :read_only, 1 << 10, - :no_inline, 1 << 11, - :always_inline, 1 << 12, - :optimize_for_size, 1 << 13, - :stack_protect, 1 << 14, - :stack_protect_req, 1 << 15, - :no_capture, 1 << 21, - :no_red_zone, 1 << 22, - :no_implicit_float, 1 << 23, - :naked, 1 << 24 - ] - - enum :opcode, [ - # Terminator Instructions - :ret, 1, - :br, 2, - :switch, 3, - :indirectbr, 4, - :invoke, 5, - :unwind, 6, - :unreachable, 7, - - # Standard Binary Operators - :add, 8, - :fadd, 9, - :sub, 10, - :fsub, 11, - :mul, 12, - :fmul, 13, - :udiv, 14, - :sdiv, 15, - :fdiv, 16, - :urem, 17, - :srem, 18, - :frem, 19, - - # Logical Operators - :shl, 20, - :lshr, 21, - :ashr, 22, - :and, 23, - :or, 24, - :xor, 25, - - # Memory Operators - :alloca, 26, - :load, 27, - :store, 28, - :getelementptr, 29, - - # Cast Operators - :trunc, 30, - :zext, 31, - :sext, 32, - :fptoui, 33, - :fptosi, 34, - :uitofp, 35, - :sitofp, 36, - :fptrunc, 37, - :fpext, 38, - :ptrtoint, 39, - :inttoptr, 40, - :bitcast, 41, - - # Other Operators - :icmp, 42, - :fcmp, 43, - :phi, 44, - :call, 45, - :select, 46, - - # UserOp1 - # UserOp2 - :vaarg, 49, - :extractelement, 50, - :insertelement, 51, - :shufflevector, 52, - :extractvalue, 53, - :insertvalue, 54, - ] - - enum :type_kind, [ - :void, - :float, - :double, - :x86_fp80, - :fp128, - :ppc_fp128, - :label, - :integer, - :function, - :struct, - :array, - :pointer, - :opaque, - :vector, - :metadata - ] - - enum :linkage, [ - :external, - :available_externally, - :link_once_any, - :link_once_odr, - :weak_any, - :weak_odr, - :appending, - :internal, - :private, - :dll_import, - :dll_export, - :external_weak, - :ghost, - :common, - :linker_private - ] - - enum :visibility, [ - :default, - :hidden, - :protected - ] - - enum :call_conv, [ - :ccall, 0, - :fastcall, 8, - :coldcall, 9, - :x86_stdcall, 64, - :x86_fastcall, 65 - ] - - enum :int_predicate, [ - :eq, 32, - :ne, 33, - :ugt, 34, - :uge, 35, - :ult, 36, - :ule, 37, - :sgt, 38, - :sge, 39, - :slt, 40, - :sle, 41 - ] - - enum :real_predicate, [ - :false, - :oeq, - :ogt, - :oge, - :olt, - :ole, - :one, - :ord, - :uno, - :ueq, - :ugt, - :uge, - :ult, - :ule, - :une, - :true - ] - - # Error handling - attach_function :LLVMDisposeMessage, [:pointer], :void - - # Contexts - attach_function :LLVMContextCreate, [], :pointer - attach_function :LLVMGetGlobalContext, [], :pointer - attach_function :LLVMContextDispose, [:pointer], :void - - # Modules - attach_function :LLVMModuleCreateWithName, [:string], :pointer - attach_function :LLVMModuleCreateWithNameInContext, [:string, :pointer], :pointer - attach_function :LLVMDisposeModule, [:pointer], :void - attach_function :LLVMGetDataLayout, [:pointer], :string - attach_function :LLVMSetDataLayout, [:pointer, :string], :void - attach_function :LLVMGetTarget, [:pointer], :string - attach_function :LLVMSetTarget, [:pointer, :string], :void - attach_function :LLVMAddTypeName, [:pointer, :string, :pointer], :int - attach_function :LLVMDeleteTypeName, [:pointer, :string], :void - attach_function :LLVMGetTypeByName, [:pointer, :string], :pointer - attach_function :LLVMDumpModule, [:pointer], :void - - # Types - attach_function :LLVMGetTypeKind, [:pointer], :type_kind - attach_function :LLVMGetTypeContext, [:pointer], :pointer - - # Integer types - attach_function :LLVMInt1TypeInContext, [:pointer], :pointer - attach_function :LLVMInt8TypeInContext, [:pointer], :pointer - attach_function :LLVMInt16TypeInContext, [:pointer], :pointer - attach_function :LLVMInt32TypeInContext, [:pointer], :pointer - attach_function :LLVMInt64TypeInContext, [:pointer], :pointer - attach_function :LLVMIntTypeInContext, [:pointer, :uint], :pointer - - attach_function :LLVMInt1Type, [], :pointer - attach_function :LLVMInt8Type, [], :pointer - attach_function :LLVMInt16Type, [], :pointer - attach_function :LLVMInt32Type, [], :pointer - attach_function :LLVMInt64Type, [], :pointer - attach_function :LLVMIntType, [:uint], :pointer - attach_function :LLVMGetIntTypeWidth, [:pointer], :uint - - # Real types - attach_function :LLVMFloatTypeInContext, [:pointer], :pointer - attach_function :LLVMDoubleTypeInContext, [:pointer], :pointer - attach_function :LLVMX86FP80TypeInContext, [:pointer], :pointer - attach_function :LLVMFP128TypeInContext, [:pointer], :pointer - attach_function :LLVMPPCFP128TypeInContext, [:pointer], :pointer - - attach_function :LLVMFloatType, [], :pointer - attach_function :LLVMDoubleType, [], :pointer - attach_function :LLVMX86FP80Type, [], :pointer - attach_function :LLVMFP128Type, [], :pointer - attach_function :LLVMPPCFP128Type, [], :pointer - - # Function types - attach_function :LLVMFunctionType, [:pointer, :pointer, :uint, :int], :pointer - attach_function :LLVMIsFunctionVarArg, [:pointer], :int - attach_function :LLVMGetReturnType, [:pointer], :pointer - attach_function :LLVMCountParamTypes, [:pointer], :uint - attach_function :LLVMGetParamTypes, [:pointer, :pointer], :void - - # Struct types - attach_function :LLVMStructTypeInContext, [:pointer, :pointer, :uint, :int], :pointer - attach_function :LLVMStructType, [:pointer, :uint, :int], :pointer - attach_function :LLVMCountStructElementTypes, [:pointer], :uint - attach_function :LLVMGetStructElementTypes, [:pointer, :pointer], :void - attach_function :LLVMIsPackedStruct, [:pointer], :int - - # Array, pointer and vector types (sequence types) - attach_function :LLVMArrayType, [:pointer, :uint], :pointer - attach_function :LLVMPointerType, [:pointer, :uint], :pointer - attach_function :LLVMVectorType, [:pointer, :uint], :pointer - - attach_function :LLVMGetElementType, [:pointer], :pointer - attach_function :LLVMGetArrayLength, [:pointer], :uint - attach_function :LLVMGetPointerAddressSpace, [:pointer], :uint - attach_function :LLVMGetVectorSize, [:pointer], :uint - - # All other types - attach_function :LLVMVoidTypeInContext, [:pointer], :pointer - attach_function :LLVMLabelTypeInContext, [:pointer], :pointer - attach_function :LLVMOpaqueTypeInContext, [:pointer], :pointer - - attach_function :LLVMVoidType, [], :pointer - attach_function :LLVMLabelType, [], :pointer - attach_function :LLVMOpaqueType, [], :pointer - - # Type handles - attach_function :LLVMCreateTypeHandle, [:pointer], :pointer - attach_function :LLVMRefineType, [:pointer, :pointer], :void - attach_function :LLVMResolveTypeHandle, [:pointer], :pointer - attach_function :LLVMDisposeTypeHandle, [:pointer], :void - - # All values - attach_function :LLVMTypeOf, [:pointer], :pointer - attach_function :LLVMGetValueName, [:pointer], :string - attach_function :LLVMSetValueName, [:pointer, :string], :void - attach_function :LLVMDumpValue, [:pointer], :void - - # Operations on Users - attach_function :LLVMGetOperand, [:pointer, :int], :pointer - attach_function :LLVMSetOperand, [:pointer, :int, :pointer], :void - attach_function :LLVMGetNumOperands, [:pointer], :int - - # Constants of any type - attach_function :LLVMConstNull, [:pointer], :pointer - attach_function :LLVMConstAllOnes, [:pointer], :pointer - attach_function :LLVMGetUndef, [:pointer], :pointer - attach_function :LLVMIsConstant, [:pointer], :int - attach_function :LLVMIsNull, [:pointer], :int - attach_function :LLVMIsUndef, [:pointer], :int - attach_function :LLVMConstPointerNull, [:pointer], :pointer - - # Scalar constants - attach_function :LLVMConstInt, [:pointer, :ulong_long, :int], :pointer - attach_function :LLVMConstIntOfString, [:pointer, :string, :uint8], :pointer - attach_function :LLVMConstIntOfStringAndSize, [:pointer, :string, :uint, :uint8], :pointer - attach_function :LLVMConstReal, [:pointer, :double], :pointer - attach_function :LLVMConstRealOfString, [:pointer, :string], :pointer - attach_function :LLVMConstRealOfStringAndSize, [:pointer, :string, :uint], :pointer - - # Composite constants - attach_function :LLVMConstStringInContext, [:pointer, :string, :uint, :int], :pointer - attach_function :LLVMConstStructInContext, [:pointer, :pointer, :uint, :int], :pointer - - attach_function :LLVMConstString, [:string, :uint, :int], :pointer - attach_function :LLVMConstArray, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMConstStruct, [:pointer, :uint, :int], :pointer - attach_function :LLVMConstVector, [:pointer, :uint], :pointer - - # Constant expressions - attach_function :LLVMGetConstOpcode, [:pointer], :opcode - attach_function :LLVMAlignOf, [:pointer], :pointer - attach_function :LLVMSizeOf, [:pointer], :pointer - attach_function :LLVMConstNeg, [:pointer], :pointer - attach_function :LLVMConstFNeg, [:pointer], :pointer - attach_function :LLVMConstNot, [:pointer], :pointer - attach_function :LLVMConstAdd, [:pointer, :pointer], :pointer - attach_function :LLVMConstNSWAdd, [:pointer, :pointer], :pointer - attach_function :LLVMConstFAdd, [:pointer, :pointer], :pointer - attach_function :LLVMConstSub, [:pointer, :pointer], :pointer - attach_function :LLVMConstFSub, [:pointer, :pointer], :pointer - attach_function :LLVMConstMul, [:pointer, :pointer], :pointer - attach_function :LLVMConstFMul, [:pointer, :pointer], :pointer - attach_function :LLVMConstUDiv, [:pointer, :pointer], :pointer - attach_function :LLVMConstSDiv, [:pointer, :pointer], :pointer - attach_function :LLVMConstExactSDiv, [:pointer, :pointer], :pointer - attach_function :LLVMConstFDiv, [:pointer, :pointer], :pointer - attach_function :LLVMConstURem, [:pointer, :pointer], :pointer - attach_function :LLVMConstSRem, [:pointer, :pointer], :pointer - attach_function :LLVMConstFRem, [:pointer, :pointer], :pointer - attach_function :LLVMConstAnd, [:pointer, :pointer], :pointer - attach_function :LLVMConstOr, [:pointer, :pointer], :pointer - attach_function :LLVMConstXor, [:pointer, :pointer], :pointer - attach_function :LLVMConstICmp, [:int, :pointer, :pointer], :pointer - attach_function :LLVMConstFCmp, [:int, :pointer, :pointer], :pointer - attach_function :LLVMConstShl, [:pointer, :pointer], :pointer - attach_function :LLVMConstLShr, [:pointer, :pointer], :pointer - attach_function :LLVMConstAShr, [:pointer, :pointer], :pointer - attach_function :LLVMConstGEP, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMConstInBoundsGEP, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMConstTrunc, [:pointer, :pointer], :pointer - attach_function :LLVMConstSExt, [:pointer, :pointer], :pointer - attach_function :LLVMConstZExt, [:pointer, :pointer], :pointer - attach_function :LLVMConstFPTrunc, [:pointer, :pointer], :pointer - attach_function :LLVMConstFPExt, [:pointer, :pointer], :pointer - attach_function :LLVMConstUIToFP, [:pointer, :pointer], :pointer - attach_function :LLVMConstSIToFP, [:pointer, :pointer], :pointer - attach_function :LLVMConstFPToUI, [:pointer, :pointer], :pointer - attach_function :LLVMConstFPToSI, [:pointer, :pointer], :pointer - attach_function :LLVMConstPtrToInt, [:pointer, :pointer], :pointer - attach_function :LLVMConstIntToPtr, [:pointer, :pointer], :pointer - attach_function :LLVMConstBitCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstZExtOrBitCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstSExtOrBitCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstTruncOrBitCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstPointerCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstIntCast, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMConstFPCast, [:pointer, :pointer], :pointer - attach_function :LLVMConstSelect, [:pointer, :pointer, :pointer], :pointer - attach_function :LLVMConstExtractElement, [:pointer, :pointer], :pointer - attach_function :LLVMConstInsertElement, [:pointer, :pointer], :pointer - attach_function :LLVMConstShuffleVector, [:pointer, :pointer, :pointer], :pointer - attach_function :LLVMConstExtractValue, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMConstInsertValue, [:pointer, :pointer, :pointer, :uint], :pointer - attach_function :LLVMConstInlineAsm, [:pointer, :string, :string, :int], :pointer - - # Global variables, functions and aliases (globals) - attach_function :LLVMGetGlobalParent, [:pointer], :pointer - attach_function :LLVMIsDeclaration, [:pointer], :int - attach_function :LLVMGetLinkage, [:pointer], :linkage - attach_function :LLVMSetLinkage, [:pointer, :linkage], :void - attach_function :LLVMGetSection, [:pointer], :string - attach_function :LLVMSetSection, [:pointer, :string], :void - attach_function :LLVMGetVisibility, [:pointer], :visibility - attach_function :LLVMSetVisibility, [:pointer, :visibility], :void - attach_function :LLVMGetAlignment, [:pointer], :uint - attach_function :LLVMSetAlignment, [:pointer, :uint], :void - - attach_function :LLVMAddGlobal, [:pointer, :pointer, :string], :pointer - attach_function :LLVMGetNamedGlobal, [:pointer, :string], :pointer - attach_function :LLVMGetFirstGlobal, [:pointer], :pointer - attach_function :LLVMGetLastGlobal, [:pointer], :pointer - attach_function :LLVMGetNextGlobal, [:pointer], :pointer - attach_function :LLVMGetPreviousGlobal, [:pointer], :pointer - attach_function :LLVMDeleteGlobal, [:pointer], :void - attach_function :LLVMGetInitializer, [:pointer], :pointer - attach_function :LLVMSetInitializer, [:pointer, :pointer], :void - attach_function :LLVMIsThreadLocal, [:pointer], :bool - attach_function :LLVMSetThreadLocal, [:pointer, :int], :void - attach_function :LLVMIsGlobalConstant, [:pointer], :bool - attach_function :LLVMSetGlobalConstant, [:pointer, :bool], :void - - # Aliases - attach_function :LLVMAddAlias, [:pointer, :pointer, :pointer, :string], :pointer - - # Function operations - attach_function :LLVMAddFunction, [:pointer, :string, :pointer], :pointer - attach_function :LLVMGetNamedFunction, [:pointer, :string], :pointer - attach_function :LLVMGetFirstFunction, [:pointer], :pointer - attach_function :LLVMGetLastFunction, [:pointer], :pointer - attach_function :LLVMGetNextFunction, [:pointer], :pointer - attach_function :LLVMGetPreviousFunction, [:pointer], :pointer - attach_function :LLVMDeleteFunction, [:pointer], :void - attach_function :LLVMGetIntrinsicID, [:pointer], :uint - attach_function :LLVMGetFunctionCallConv, [:pointer], :call_conv - attach_function :LLVMSetFunctionCallConv, [:pointer, :call_conv], :void - attach_function :LLVMGetGC, [:pointer], :string - attach_function :LLVMSetGC, [:pointer, :string], :void - attach_function :LLVMAddFunctionAttr, [:pointer, :attribute], :void - attach_function :LLVMRemoveFunctionAttr, [:pointer, :attribute], :void - - # Parameters - attach_function :LLVMCountParams, [:pointer], :uint - attach_function :LLVMGetParams, [:pointer, :pointer], :void - attach_function :LLVMGetParam, [:pointer, :uint], :pointer - attach_function :LLVMGetParamParent, [:pointer], :pointer - attach_function :LLVMGetFirstParam, [:pointer], :pointer - attach_function :LLVMGetLastParam, [:pointer], :pointer - attach_function :LLVMGetNextParam, [:pointer], :pointer - attach_function :LLVMGetPreviousParam, [:pointer], :pointer - attach_function :LLVMAddAttribute, [:pointer, :attribute], :void - attach_function :LLVMRemoveAttribute, [:pointer, :attribute], :void - attach_function :LLVMSetParamAlignment, [:pointer, :uint], :void - - # Basic blocks - attach_function :LLVMBasicBlockAsValue, [:pointer], :pointer - attach_function :LLVMValueIsBasicBlock, [:pointer], :int - attach_function :LLVMValueAsBasicBlock, [:pointer], :pointer - attach_function :LLVMGetBasicBlockParent, [:pointer], :pointer - attach_function :LLVMCountBasicBlocks, [:pointer], :uint - attach_function :LLVMGetBasicBlocks, [:pointer, :pointer], :void - attach_function :LLVMGetFirstBasicBlock, [:pointer], :pointer - attach_function :LLVMGetLastBasicBlock, [:pointer], :pointer - attach_function :LLVMGetNextBasicBlock, [:pointer], :pointer - attach_function :LLVMGetPreviousBasicBlock, [:pointer], :pointer - attach_function :LLVMGetEntryBasicBlock, [:pointer], :pointer - - attach_function :LLVMAppendBasicBlockInContext, [:pointer, :pointer, :string], :pointer - attach_function :LLVMInsertBasicBlockInContext, [:pointer, :pointer, :string], :pointer - - attach_function :LLVMAppendBasicBlock, [:pointer, :string], :pointer - attach_function :LLVMDeleteBasicBlock, [:pointer], :void - - # Instructions - attach_function :LLVMGetInstructionParent, [:pointer], :pointer - attach_function :LLVMGetFirstInstruction, [:pointer], :pointer - attach_function :LLVMGetLastInstruction, [:pointer], :pointer - attach_function :LLVMGetNextInstruction, [:pointer], :pointer - attach_function :LLVMGetPreviousInstruction, [:pointer], :pointer - - # Call sites - attach_function :LLVMSetInstructionCallConv, [:pointer, :call_conv], :void - attach_function :LLVMGetInstructionCallConv, [:pointer], :call_conv - attach_function :LLVMAddInstrAttribute, [:pointer, :uint, :attribute], :void - attach_function :LLVMRemoveInstrAttribute, [:pointer, :uint, :attribute], :void - attach_function :LLVMSetInstrParamAlignment, [:pointer, :uint, :uint], :void - - # Call instructions - attach_function :LLVMIsTailCall, [:pointer], :int - attach_function :LLVMSetTailCall, [:pointer, :int], :void - - # Phi nodes - attach_function :LLVMAddIncoming, [:pointer, :pointer, :pointer, :uint], :void - attach_function :LLVMCountIncoming, [:pointer], :uint - attach_function :LLVMGetIncomingValue, [:pointer, :uint], :pointer - attach_function :LLVMGetIncomingBlock, [:pointer, :uint], :pointer - - # Instruction builders - attach_function :LLVMCreateBuilderInContext, [:pointer], :pointer - attach_function :LLVMCreateBuilder, [], :pointer - attach_function :LLVMPositionBuilder, [:pointer, :pointer, :pointer], :void - attach_function :LLVMPositionBuilderBefore, [:pointer, :pointer], :void - attach_function :LLVMPositionBuilderAtEnd, [:pointer, :pointer], :void - attach_function :LLVMGetInsertBlock, [:pointer], :pointer - attach_function :LLVMClearInsertionPosition, [:pointer], :void - attach_function :LLVMInsertIntoBuilder, [:pointer, :pointer], :void - attach_function :LLVMInsertIntoBuilderWithName, [:pointer, :pointer, :string], :void - attach_function :LLVMDisposeBuilder, [:pointer], :void - - # Terminators - attach_function :LLVMBuildRetVoid, [:pointer], :pointer - attach_function :LLVMBuildRet, [:pointer, :pointer], :pointer - attach_function :LLVMBuildAggregateRet, [:pointer, :pointer, :uint], :pointer - attach_function :LLVMBuildBr, [:pointer, :pointer], :pointer - attach_function :LLVMBuildCondBr, [:pointer, :pointer, :pointer, :pointer], :pointer - attach_function :LLVMBuildSwitch, [:pointer, :pointer, :pointer, :uint], :pointer - attach_function :LLVMBuildInvoke, [:pointer, :pointer, :pointer, :uint, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildUnwind, [:pointer], :pointer - attach_function :LLVMBuildUnreachable, [:pointer], :pointer - - # Switch instruction - attach_function :LLVMAddCase, [:pointer, :pointer, :pointer], :void - - # Arithmetic - attach_function :LLVMBuildAdd, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildNSWAdd, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFAdd, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSub, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFSub, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildMul, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFMul, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildUDiv, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSDiv, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildExactSDiv, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFDiv, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildURem, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSRem, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFRem, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildShl, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildLShr, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildAShr, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildAnd, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildOr, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildXor, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildNeg, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildNot, [:pointer, :pointer, :string], :pointer - - # Memory - attach_function :LLVMBuildMalloc, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildArrayMalloc, [:pointer, :pointer, :pointer, :string], :string - attach_function :LLVMBuildAlloca, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildArrayAlloca, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFree, [:pointer, :pointer], :pointer - attach_function :LLVMBuildLoad, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildStore, [:pointer, :pointer, :pointer], :pointer - attach_function :LLVMBuildGEP, [:pointer, :pointer, :pointer, :uint, :string], :pointer - attach_function :LLVMBuildInBoundsGEP, [:pointer, :pointer, :pointer, :uint, :string], :pointer - attach_function :LLVMBuildStructGEP, [:pointer, :pointer, :uint, :string], :pointer - attach_function :LLVMBuildGlobalString, [:pointer, :string, :string], :pointer - attach_function :LLVMBuildGlobalStringPtr, [:pointer, :string, :string], :pointer - - # Casts - attach_function :LLVMBuildTrunc, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildZExt, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSExt, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFPToUI, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFPToSI, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildUIToFP, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSIToFP, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFPTrunc, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFPExt, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildPtrToInt, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildIntToPtr, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildBitCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildZExtOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildSExtOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildTruncOrBitCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildPointerCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildIntCast, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFPCast, [:pointer, :pointer, :pointer, :string], :pointer - - # Comparisons - attach_function :LLVMBuildICmp, [:pointer, :int_predicate, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildFCmp, [:pointer, :real_predicate, :pointer, :pointer, :string], :pointer - - # Misc - attach_function :LLVMBuildPhi, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildCall, [:pointer, :pointer, :pointer, :uint, :string], :pointer - attach_function :LLVMBuildSelect, [:pointer, :pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildVAArg, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildExtractElement, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildInsertElement, [:pointer, :pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildShuffleVector, [:pointer, :pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildExtractValue, [:pointer, :pointer, :uint, :string], :pointer - attach_function :LLVMBuildInsertValue, [:pointer, :pointer, :pointer, :uint, :string], :pointer - - attach_function :LLVMBuildIsNull, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildIsNotNull, [:pointer, :pointer, :string], :pointer - attach_function :LLVMBuildPtrDiff, [:pointer, :pointer, :pointer, :string], :pointer - - # Module providers - attach_function :LLVMCreateModuleProviderForExistingModule, [:pointer], :pointer - attach_function :LLVMDisposeModuleProvider, [:pointer], :void - - # Memory buffers - attach_function :LLVMCreateMemoryBufferWithContentsOfFile, [:string, :pointer, :pointer], :int - attach_function :LLVMCreateMemoryBufferWithSTDIN, [:pointer, :pointer], :int - attach_function :LLVMDisposeMemoryBuffer, [:pointer], :void - - # Pass managers - attach_function :LLVMCreatePassManager, [], :pointer - attach_function :LLVMCreateFunctionPassManager, [:pointer], :pointer - attach_function :LLVMCreateFunctionPassManagerForModule, [:pointer], :pointer - attach_function :LLVMRunPassManager, [:pointer, :pointer], :int - attach_function :LLVMInitializeFunctionPassManager, [:pointer], :int - attach_function :LLVMRunFunctionPassManager, [:pointer, :pointer], :int - attach_function :LLVMFinalizeFunctionPassManager, [:pointer], :int - attach_function :LLVMDisposePassManager, [:pointer], :void - end - - require 'llvm/core/context' - require 'llvm/core/module' - require 'llvm/core/type' - require 'llvm/core/value' - require 'llvm/core/builder' - require 'llvm/core/pass_manager' - require 'llvm/core/bitcode' + require 'llvm/bindings' + + require 'llvm/core/context' + require 'llvm/core/module' + require 'llvm/core/type' + require 'llvm/core/value' + require 'llvm/core/builder' + require 'llvm/core/pass_manager' + require 'llvm/core/bitcode' end diff --git a/lib/llvm/core/bitcode.rb b/lib/llvm/core/bitcode.rb index 5b27a82..3a0358b 100644 --- a/lib/llvm/core/bitcode.rb +++ b/lib/llvm/core/bitcode.rb @@ -1,12 +1,4 @@ module LLVM - # @private - module C - attach_function :LLVMParseBitcode, [:pointer, :buffer_out, :buffer_out], :int - attach_function :LLVMParseBitcodeInContext, [:pointer, :pointer, :buffer_out, :buffer_out], :int - attach_function :LLVMWriteBitcodeToFile, [:pointer, :string], :int - attach_function :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int - end - class Module # Parse a module from a memory buffer # @param [String, LLVM::MemoryBuffer] path_or_memory_buffer diff --git a/lib/llvm/execution_engine.rb b/lib/llvm/execution_engine.rb index 35357db..47c79f4 100644 --- a/lib/llvm/execution_engine.rb +++ b/lib/llvm/execution_engine.rb @@ -1,52 +1,8 @@ require 'llvm' require 'llvm/core' -require 'llvm/target' require 'llvm/analysis' module LLVM - # @private - module C - # Generic values - attach_function :LLVMCreateGenericValueOfInt, [:pointer, :long_long, :int], :pointer - attach_function :LLVMCreateGenericValueOfPointer, [:pointer], :pointer - attach_function :LLVMCreateGenericValueOfFloat, [:pointer, :double], :pointer - - attach_function :LLVMGenericValueIntWidth, [:pointer], :uint - - attach_function :LLVMGenericValueToInt, [:pointer, :int], :long_long - attach_function :LLVMGenericValueToPointer, [:pointer], :pointer - attach_function :LLVMGenericValueToFloat, [:pointer, :pointer], :double - attach_function :LLVMDisposeGenericValue, [:pointer], :void - - # Execution engines - attach_function :LLVMCreateExecutionEngineForModule, [:pointer, :pointer, :pointer], :int - attach_function :LLVMCreateInterpreterForModule, [:pointer, :pointer, :pointer], :int - attach_function :LLVMCreateJITCompilerForModule, [:pointer, :pointer, :uint, :pointer], :int - attach_function :LLVMDisposeExecutionEngine, [:pointer], :void - - attach_function :LLVMRunStaticConstructors, [:pointer], :void - attach_function :LLVMRunStaticDestructors, [:pointer], :void - - attach_function :LLVMRunFunctionAsMain, [:pointer, :pointer, :uint, :pointer, :pointer], :int - attach_function :LLVMRunFunction, [:pointer, :pointer, :uint, :pointer], :pointer - - attach_function :LLVMFreeMachineCodeForFunction, [:pointer, :pointer], :void - attach_function :LLVMAddModuleProvider, [:pointer, :pointer], :void - attach_function :LLVMRemoveModuleProvider, [:pointer, :pointer, :pointer, :pointer], :int - - attach_function :LLVMFindFunction, [:pointer, :pointer, :pointer, :pointer], :int - - attach_function :LLVMGetExecutionEngineTargetData, [:pointer], :pointer - - attach_function :LLVMAddGlobalMapping, [:pointer, :pointer, :pointer], :void - - attach_function :LLVMGetPointerToGlobal, [:pointer, :pointer], :pointer - - attach_function :LLVMInitializeX86TargetInfo, [], :void - - attach_function :LLVMInitializeX86Target, [], :void - end - def LLVM.init_x86 LLVM::C.LLVMInitializeX86Target LLVM::C.LLVMInitializeX86TargetInfo diff --git a/lib/llvm/target.rb b/lib/llvm/target.rb deleted file mode 100644 index 4bde80e..0000000 --- a/lib/llvm/target.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'llvm' -require 'llvm/core' - -module LLVM - # @private - module C - attach_function :LLVMAddTargetData, [:pointer, :pointer], :void - end -end diff --git a/lib/llvm/transforms/ipo.rb b/lib/llvm/transforms/ipo.rb index 4ac9563..9d2ea43 100644 --- a/lib/llvm/transforms/ipo.rb +++ b/lib/llvm/transforms/ipo.rb @@ -3,12 +3,6 @@ require 'llvm/core' module LLVM - # @private - module C - attach_function :LLVMAddGlobalDCEPass, [:pointer], :void - attach_function :LLVMAddFunctionInliningPass, [:pointer], :void - end - class PassManager # @LLVMpass gdce def gdce! diff --git a/lib/llvm/transforms/scalar.rb b/lib/llvm/transforms/scalar.rb index 6ac1432..18746ee 100644 --- a/lib/llvm/transforms/scalar.rb +++ b/lib/llvm/transforms/scalar.rb @@ -2,31 +2,6 @@ require 'llvm/core' module LLVM - # @private - module C - attach_function :LLVMAddAggressiveDCEPass, [:pointer], :void - attach_function :LLVMAddCFGSimplificationPass, [:pointer], :void - attach_function :LLVMAddDeadStoreEliminationPass, [:pointer], :void - attach_function :LLVMAddGVNPass, [:pointer], :void - attach_function :LLVMAddIndVarSimplifyPass, [:pointer], :void - attach_function :LLVMAddInstructionCombiningPass, [:pointer], :void - attach_function :LLVMAddJumpThreadingPass, [:pointer], :void - attach_function :LLVMAddLICMPass, [:pointer], :void - attach_function :LLVMAddLoopDeletionPass, [:pointer], :void - attach_function :LLVMAddLoopRotatePass, [:pointer], :void - attach_function :LLVMAddLoopUnrollPass, [:pointer], :void - attach_function :LLVMAddLoopUnswitchPass, [:pointer], :void - attach_function :LLVMAddMemCpyOptPass, [:pointer], :void - attach_function :LLVMAddPromoteMemoryToRegisterPass, [:pointer], :void - attach_function :LLVMAddReassociatePass, [:pointer], :void - attach_function :LLVMAddSCCPPass, [:pointer], :void - attach_function :LLVMAddScalarReplAggregatesPass, [:pointer], :void - attach_function :LLVMAddSimplifyLibCallsPass, [:pointer], :void - attach_function :LLVMAddTailCallEliminationPass, [:pointer], :void - attach_function :LLVMAddConstantPropagationPass, [:pointer], :void - attach_function :LLVMAddDemoteMemoryToRegisterPass, [:pointer], :void - end - class PassManager # @LLVMpass adce def adce! From 43080be38aa6b9e34e6d9e34e7a9bd0499ba77eb Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 10:29:29 -0600 Subject: [PATCH 2/8] Changed the Rakefile to use the rubygems/package_task instead of rake/gempackagetask. Added the check_bindings target, which will use objdump to collect symbols from libLLVM and compare them to the symbols defined in the bindings module. --- Rakefile | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 4633c20..f453c94 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ -require 'rake/gempackagetask' +require 'rubygems/package_task' require 'rake/testtask' +LLVM_TARGET_VERSION = '2.9' + begin require 'rcov/rcovtask' @@ -37,7 +39,6 @@ def spec s.files = Dir['lib/**/*rb'] s.require_path = 'lib' - s.has_rdoc = true s.extra_rdoc_files = 'README.rdoc' s.author = "Jeremy Voorhis" @@ -46,12 +47,89 @@ def spec end end -Rake::GemPackageTask.new(spec) do |t| -end +Gem::PackageTask.new(spec) Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList["test/**/*_test.rb"] end +task :check_bindings, :verbose do |t, args| + (args = args.to_hash)[:verbose] = if args[:verbose] == 'true' then true else false end + + require 'lib/llvm/bindings' + + # Check for objdump. + if not (bin = `which objdump`.chomp)[0,1] == '/' + puts 'objdump binary not found.' + return + end + + # Locate the LLVM shared library. + lib_path = nil + + paths = ENV['LD_LIBRARY_PATH'].split(/:/).uniq + paths << '/usr/lib/' + paths << '/usr/lib64/' + + paths.each do |path| + test_path = File.join(path, "libLLVM-#{LLVM_TARGET_VERSION}.so") + if File.exists?(test_path) + lib_path = test_path + end + end + + if not lib_path + puts "libLLVM-#{LLVM_TARGET_VERSION}.so not found." + return + end + + # Grab library symbols. + lines = `#{bin} -t #{lib_path}` + + lsyms = lines.map do |l| + md = l.match(/\s(LLVM\w+)/) + if md then md[1] else nil end + end.compact.uniq + + # Defined symbols. + dsyms = Symbol.all_symbols.map do |sym| + sym = sym.to_s + if sym.match(/^LLVM[a-zA-Z]+/) then sym else nil end + end.compact + + # Sort the symbols. + bound = Array.new + unbound = Array.new + unbinds = Array.new + + lsyms.each do |sym| + if dsyms.include?(sym) then bound else unbound end << sym + end + + dsyms.each do |sym| + if not lsyms.include?(sym) then unbinds << sym end + end + + puts "Bound Functions: #{bound.length}" + puts "Unbound Functions: #{unbound.length}" + puts "Bad Bindings: #{unbinds.length}" + puts "Completeness: #{((bound.length / lsyms.length.to_f) * 100).to_i}%" + + if args[:verbose] + puts() if unbound.length > 0 and unbinds.length > 0 + + if unbound.length > 0 + puts 'Unbound Functions:' + unbound.sort.each {|sym| puts sym} + puts + end + + if unbinds.length > 0 + puts 'Bad Bindings:' + unbinds.sort.each {|sym| puts sym} + end + end +end + task :default => [:test] From 253e11fc584469e3bba07d980c5281e02505b496 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 10:37:15 -0600 Subject: [PATCH 3/8] Added missing scalar and ipo transformation passes. --- lib/llvm/bindings.rb | 21 +++++++++-- lib/llvm/transforms/ipo.rb | 26 +++++++++++-- lib/llvm/transforms/scalar.rb | 71 +++++++++++++++++++++++++++++++---- 3 files changed, 104 insertions(+), 14 deletions(-) diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb index c2667a7..7ee7656 100644 --- a/lib/llvm/bindings.rb +++ b/lib/llvm/bindings.rb @@ -656,31 +656,46 @@ module C attach_function :LLVMAddTargetData, [:pointer, :pointer], :void # Inter-procedural Optimizations - attach_function :LLVMAddGlobalDCEPass, [:pointer], :void + attach_function :LLVMAddFunctionAttrsPass, [:pointer], :void attach_function :LLVMAddFunctionInliningPass, [:pointer], :void + attach_function :LLVMAddGlobalDCEPass, [:pointer], :void + attach_function :LLVMAddIPConstantPropagationPass, [:pointer], :void + attach_function :LLVMAddIPSCCPPass, [:pointer], :void + attach_function :LLVMAddPruneEHPass, [:pointer], :void # Scalar Optimizations attach_function :LLVMAddAggressiveDCEPass, [:pointer], :void + attach_function :LLVMAddArgumentPromotionPass, [:pointer], :void attach_function :LLVMAddCFGSimplificationPass, [:pointer], :void + attach_function :LLVMAddConstantMergePass, [:pointer], :void + attach_function :LLVMAddConstantPropagationPass, [:pointer], :void + attach_function :LLVMAddDeadArgEliminationPass, [:pointer], :void attach_function :LLVMAddDeadStoreEliminationPass, [:pointer], :void + attach_function :LLVMAddDeadTypeEliminationPass, [:pointer], :void + attach_function :LLVMAddDemoteMemoryToRegisterPass, [:pointer], :void + attach_function :LLVMAddGlobalOptimizerPass, [:pointer], :void attach_function :LLVMAddGVNPass, [:pointer], :void attach_function :LLVMAddIndVarSimplifyPass, [:pointer], :void attach_function :LLVMAddInstructionCombiningPass, [:pointer], :void + attach_function :LLVMAddInternalizePass, [:pointer], :void attach_function :LLVMAddJumpThreadingPass, [:pointer], :void attach_function :LLVMAddLICMPass, [:pointer], :void attach_function :LLVMAddLoopDeletionPass, [:pointer], :void attach_function :LLVMAddLoopRotatePass, [:pointer], :void attach_function :LLVMAddLoopUnrollPass, [:pointer], :void attach_function :LLVMAddLoopUnswitchPass, [:pointer], :void + attach_function :LLVMAddLowerSetJmpPass, [:pointer], :void attach_function :LLVMAddMemCpyOptPass, [:pointer], :void attach_function :LLVMAddPromoteMemoryToRegisterPass, [:pointer], :void + attach_function :LLVMAddRaiseAllocationsPass, [:pointer], :void attach_function :LLVMAddReassociatePass, [:pointer], :void attach_function :LLVMAddSCCPPass, [:pointer], :void attach_function :LLVMAddScalarReplAggregatesPass, [:pointer], :void attach_function :LLVMAddSimplifyLibCallsPass, [:pointer], :void + attach_function :LLVMAddStripDeadPrototypesPass, [:pointer], :void + attach_function :LLVMAddStripSymbolsPass, [:pointer], :void attach_function :LLVMAddTailCallEliminationPass, [:pointer], :void - attach_function :LLVMAddConstantPropagationPass, [:pointer], :void - attach_function :LLVMAddDemoteMemoryToRegisterPass, [:pointer], :void + attach_function :LLVMAddVerifierPass, [:pointer], :void # Bitcode attach_function :LLVMParseBitcode, [:pointer, :buffer_out, :buffer_out], :int diff --git a/lib/llvm/transforms/ipo.rb b/lib/llvm/transforms/ipo.rb index 9d2ea43..c3094a5 100644 --- a/lib/llvm/transforms/ipo.rb +++ b/lib/llvm/transforms/ipo.rb @@ -4,14 +4,34 @@ module LLVM class PassManager - # @LLVMpass gdce - def gdce! - C.LLVMAddGlobalDCEPass(self) + # @LLVMpass function_attrs + def fun_attrs! + C.LLVMAddFunctionAttersPass(self) end # @LLVMpass inline def inline! C.LLVMAddFunctionInliningPass(self) end + + # @LLVMpass gdce + def gdce! + C.LLVMAddGlobalDCEPass(self) + end + + # @LLVMpass ipcp + def ipcp! + C.LLVMAddIPConstantPropagationPass(self) + end + + # @LLVMpass ipsccp + def ipsccp! + C.LLVMAddIPSCCPPass(self) + end + + # @LLVMpass prune_eh + def prune_eh! + C.LLVMAddPruneEHPass(self) + end end end diff --git a/lib/llvm/transforms/scalar.rb b/lib/llvm/transforms/scalar.rb index 18746ee..c749f3c 100644 --- a/lib/llvm/transforms/scalar.rb +++ b/lib/llvm/transforms/scalar.rb @@ -8,16 +8,51 @@ def adce! C.LLVMAddAggressiveDCEPass(self) end + # @LLVMpass arg_promotion + def arg_promote! + C.LLVMAddArgumentPromotionPass(self) + end + # @LLVMpass simplifycfg def simplifycfg! C.LLVMAddCFGSimplificationPass(self) end + # @LLVMpass const_merge + def const_merge! + C.LLVMAddConstantMergePass(self) + end + + # @LLVMpass constprop + def constprop! + C.LLVMAddConstantPropagationPass(self) + end + + # @LLVMpass dae + def dae! + C.LLVMAddDeadArgEliminationPass(self) + end + # @LLVMpass dse def dse! C.LLVMAddDeadStoreEliminationPass(self) end + # @LLVMpass dte + def dte! + C.LLVMAddDeadTypeEliminationPass(self) + end + + # @LLVMpass reg2mem + def reg2mem! + C.LLVMAddDemoteMemoryToRegisterPass(self) + end + + # @LLVMpass global_opt + def global_opt! + C.LLVMAddGlobalOptimizerPass(self) + end + # @LLVMpass gvn def gvn! C.LLVMAddGVNPass(self) @@ -33,6 +68,11 @@ def instcombine! C.LLVMAddInstructionCombiningPass(self) end + # @LLVMpass init + def init! + C.LLVMAddInternalizePass(self) + end + # @LLVMpass jump-threading def jump_threading! C.LLVMAddJumpThreadingPass(self) @@ -63,6 +103,11 @@ def loop_unswitch! C.LLVMAddLoopUnswitchPass(self) end + # @LLVMpass lsj + def lsj! + C.LLVMAddLowerSetJmpPass(self) + end + # @LLVMpass memcpyopt def memcpyopt! C.LLVMAddMemCpyOptPass(self) @@ -73,6 +118,11 @@ def mem2reg! C.LLVMAddPromoteMemoryToRegisterPass(self) end + # @LLVMpass raise_alloc + def raise_alloc! + C.LLVMAddRaiseAllocationsPass(self) + end + # @LLVMpass reassociate def reassociate! C.LLVMAddReassociatePass(self) @@ -93,19 +143,24 @@ def simplify_libcalls! C.LLVMAddSimplifyLibCallsPass(self) end + # @LLVMpass sdp + def sdp! + C.LLVMAddStripDeadPrototypesPass(self) + end + + # @LLVMpass sds + def sds! + C.LLVMAddStripSymbolsPass(self) + end + # @LLVMpass tailcallelim def tailcallelim! C.LLVMAddTailCallEliminationPass(self) end - # @LLVMpass constprop - def constprop! - C.LLVMAddConstantPropagationPass(self) - end - - # @LLVMpass reg2mem - def reg2mem! - C.LLVMAddDemoteMemoryToRegisterPass(self) + # @LLVMpass verifier + def verifier! + C.LLVMAddVerifierPass(self) end end end From b559397bc3936259829c7190b4679e2ba2af891c Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 10:41:24 -0600 Subject: [PATCH 4/8] Added bindings and methods for all supported LLVM targets. --- lib/llvm/bindings.rb | 44 ++++++++++++++++++++++- lib/llvm/execution_engine.rb | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb index 7ee7656..b1d99d9 100644 --- a/lib/llvm/bindings.rb +++ b/lib/llvm/bindings.rb @@ -649,6 +649,48 @@ module C attach_function :LLVMGetPointerToGlobal, [:pointer, :pointer], :pointer # Target Initialization + attach_function :LLVMInitializeARMTarget, [], :void + attach_function :LLVMInitializeARMTargetInfo, [], :void + + attach_function :LLVMInitializeAlphaTarget, [], :void + attach_function :LLVMInitializeAlphaTargetInfo, [], :void + + attach_function :LLVMInitializeBlackfinTarget, [], :void + attach_function :LLVMInitializeBlackfinTargetInfo, [], :void + + attach_function :LLVMInitializeCBackendTarget, [], :void + attach_function :LLVMInitializeCBackendTargetInfo, [], :void + + attach_function :LLVMInitializeCellSPUTarget, [], :void + attach_function :LLVMInitializeCellSPUTargetInfo, [], :void + + attach_function :LLVMInitializeCppBackendTarget, [], :void + attach_function :LLVMInitializeCppBackendTargetInfo, [], :void + + attach_function :LLVMInitializeMBlazeTarget, [], :void + attach_function :LLVMInitializeMBlazeTargetInfo, [], :void + + attach_function :LLVMInitializeMipsTarget, [], :void + attach_function :LLVMInitializeMipsTargetInfo, [], :void + + attach_function :LLVMInitializeMSP430Target, [], :void + attach_function :LLVMInitializeMSP430TargetInfo, [], :void + + attach_function :LLVMInitializePTXTarget, [], :void + attach_function :LLVMInitializePTXTargetInfo, [], :void + + attach_function :LLVMInitializePowerPCTarget, [], :void + attach_function :LLVMInitializePowerPCTargetInfo, [], :void + + attach_function :LLVMInitializeSparcTarget, [], :void + attach_function :LLVMInitializeSparcTargetInfo, [], :void + + attach_function :LLVMInitializeSystemZTarget, [], :void + attach_function :LLVMInitializeSystemZTargetInfo, [], :void + + attach_function :LLVMInitializeXCoreTarget, [], :void + attach_function :LLVMInitializeXCoreTargetInfo, [], :void + attach_function :LLVMInitializeX86TargetInfo, [], :void attach_function :LLVMInitializeX86Target, [], :void @@ -702,5 +744,5 @@ module C attach_function :LLVMParseBitcodeInContext, [:pointer, :pointer, :buffer_out, :buffer_out], :int attach_function :LLVMWriteBitcodeToFile, [:pointer, :string], :int attach_function :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int - end + end end diff --git a/lib/llvm/execution_engine.rb b/lib/llvm/execution_engine.rb index 47c79f4..9dc42a3 100644 --- a/lib/llvm/execution_engine.rb +++ b/lib/llvm/execution_engine.rb @@ -3,6 +3,76 @@ require 'llvm/analysis' module LLVM + def LLVM.init_arm + LLVM::C.LLVMInitializeARMTarget + LLVM::C.LLVMInitializeARMTargetInfo + end + + def LLVM.init_alpha + LLVM::C.LLVMInitializeAlphaTarget + LLVM::C.LLVMInitializeAlphaTargetInfo + end + + def LLVM.init_blackfin + LLVM::C.LLVMInitializeBlackfinTarget + LLVM::C.LLVMInitializeBlackfinTargetInfo + end + + def LLVM.init_c_backend + LLVM::C.LLVMInitializeCBackendTarget + LLVM::C.LLVMInitializeCBackendTargetInfo + end + + def LLVM.init_cell_spu + LLVM::C.LLVMInitializeCellSPUTarget + LLVM::C.LLVMInitializeCellSPUTargetInfo + end + + def LLVM.init_cpp_backend + LLVM::C.LLVMInitializeCppBackendTarget + LLVM::C.LLVMInitializeCppBackendTargetInfo + end + + def LLVM.init_mblaze + LLVM::C.LLVMInitializeMBlazeTarget + LLVM::C.LLVMInitializeMBlazeTargetInfo + end + + def LLVM.init_mips + LLVM::C.LLVMInitializeMipsTarget + LLVM::C.LLVMInitializeMipsTargetInfo + end + + def LLVM.init_mips + LLVM::C.LLVMInitializeMSP430Target + LLVM::C.LLVMInitializeMSP430TargetInfo + end + + def LLVM.init_ptx + LLVM::C.LLVMInitializePTXTarget + LLVM::C.LLVMInitializePTXTargetInfo + end + + def LLVM.init_ppc + LLVM::C.LLVMInitializePowerPCTarget + LLVM::C.LLVMInitializePowerPCTargetInfo + end + + def LLVM.init_sparc + LLVM::C.LLVMInitializeSparcTarget + LLVM::C.LLVMInitializeSparcTargetInfo + end + + def LLVM.init_sysz + LLVM::C.LLVMInitializeSystemZTarget + LLVM::C.LLVMInitializeSystemZTargetInfo + end + + def LLVM.init_xcore + LLVM::C.LLVMInitializeXCoreTarget + LLVM::C.LLVMInitializeXCoreTargetInfo + end + def LLVM.init_x86 LLVM::C.LLVMInitializeX86Target LLVM::C.LLVMInitializeX86TargetInfo From 684ba491c9676f23c48310158e67891637d321a5 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 10:57:10 -0600 Subject: [PATCH 5/8] Added missing instructions to the builder. --- lib/llvm/bindings.rb | 29 ++++++++++- lib/llvm/core/builder.rb | 107 ++++++++++++++++++++++++++++++++++++--- lib/llvm/core/value.rb | 41 +++++++++++++++ 3 files changed, 169 insertions(+), 8 deletions(-) diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb index b1d99d9..3435845 100644 --- a/lib/llvm/bindings.rb +++ b/lib/llvm/bindings.rb @@ -334,12 +334,17 @@ module C attach_function :LLVMSizeOf, [:pointer], :pointer attach_function :LLVMConstNeg, [:pointer], :pointer attach_function :LLVMConstFNeg, [:pointer], :pointer + attach_function :LLVMConstNSWNeg, [:pointer], :pointer + attach_function :LLVMConstNUWNeg, [:pointer], :pointer attach_function :LLVMConstNot, [:pointer], :pointer attach_function :LLVMConstAdd, [:pointer, :pointer], :pointer - attach_function :LLVMConstNSWAdd, [:pointer, :pointer], :pointer attach_function :LLVMConstFAdd, [:pointer, :pointer], :pointer + attach_function :LLVMConstNSWAdd, [:pointer, :pointer], :pointer + attach_function :LLVMConstNUWAdd, [:pointer, :pointer], :pointer attach_function :LLVMConstSub, [:pointer, :pointer], :pointer attach_function :LLVMConstFSub, [:pointer, :pointer], :pointer + attach_function :LLVMConstNSWSub, [:pointer, :pointer], :pointer + attach_function :LLVMConstNUWSub, [:pointer, :pointer], :pointer attach_function :LLVMConstMul, [:pointer, :pointer], :pointer attach_function :LLVMConstFMul, [:pointer, :pointer], :pointer attach_function :LLVMConstUDiv, [:pointer, :pointer], :pointer @@ -504,6 +509,7 @@ module C attach_function :LLVMBuildAggregateRet, [:pointer, :pointer, :uint], :pointer attach_function :LLVMBuildBr, [:pointer, :pointer], :pointer attach_function :LLVMBuildCondBr, [:pointer, :pointer, :pointer, :pointer], :pointer + attach_function :LLVMBuildIndirectBr, [:pointer, :pointer, :uint], :pointer attach_function :LLVMBuildSwitch, [:pointer, :pointer, :pointer, :uint], :pointer attach_function :LLVMBuildInvoke, [:pointer, :pointer, :pointer, :uint, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildUnwind, [:pointer], :pointer @@ -513,27 +519,45 @@ module C attach_function :LLVMAddCase, [:pointer, :pointer, :pointer], :void # Arithmetic + attach_function :LLVMBuildBinOp, [:pointer, :pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildAdd, [:pointer, :pointer, :pointer, :string], :pointer - attach_function :LLVMBuildNSWAdd, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildFAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNSWAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNUWAdd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildSub, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildFSub, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNSWSub, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNUWSub, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildMul, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildFMul, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNSWMul, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNUWMul, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildUDiv, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildSDiv, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildExactSDiv, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildFDiv, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildURem, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildSRem, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildFRem, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildShl, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildLShr, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildAShr, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildAnd, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildOr, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildXor, [:pointer, :pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNeg, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildFNeg, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNSWNeg, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNUWNeg, [:pointer, :pointer, :string], :pointer + attach_function :LLVMBuildNot, [:pointer, :pointer, :string], :pointer # Memory @@ -551,6 +575,7 @@ module C attach_function :LLVMBuildGlobalStringPtr, [:pointer, :string, :string], :pointer # Casts + attach_function :LLVMBuildCast, [:pointer, :pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildTrunc, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildZExt, [:pointer, :pointer, :pointer, :string], :pointer attach_function :LLVMBuildSExt, [:pointer, :pointer, :pointer, :string], :pointer diff --git a/lib/llvm/core/builder.rb b/lib/llvm/core/builder.rb index 4d905ba..9102571 100644 --- a/lib/llvm/core/builder.rb +++ b/lib/llvm/core/builder.rb @@ -76,6 +76,15 @@ def br(block) C.LLVMBuildBr(self, block)) end + # Indirect unconditional branching (i.e. goto) + # @param [LLVM::Value] addr Where to jump + # @param [Fixnum] num_dests The number of destinations that will be added. + # @return [LLVM::Instruction] + # @LLVMinst br + def ibr(addr, num_dests = 10) + Instruction.from_ptr(C.LLVMBuildIndirectBr(self, addr, num_dests)) + end + # Conditional branching (i.e. if) # @param [LLVM::Value] cond The condition # @param [LLVM::BasicBlock] iftrue Where to jump if condition is true @@ -131,6 +140,11 @@ def unwind def unreachable Instruction.from_ptr(C.LLVMBuildUnreachable(self)) end + + # @LLVMinst binop + def binop(op, lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildBinOp(self, op, lhs, rhs, name)) + end # @param [LLVM::Value] lhs Integer or vector of integers # @param [LLVM::Value] rhs Integer or vector of integers @@ -141,6 +155,15 @@ def add(lhs, rhs, name = "") Instruction.from_ptr(C.LLVMBuildAdd(self, lhs, rhs, name)) end + # @param [LLVM::Value] lhs Floating point or vector of floating points + # @param [LLVM::Value] rhs Floating point or vector of floating points + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The floating point sum of the two operands + # @LLVMinst fadd + def fadd(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildFAdd(self, lhs, rhs, name)) + end + # No signed wrap addition. # @param [LLVM::Value] lhs Integer or vector of integers # @param [LLVM::Value] rhs Integer or vector of integers @@ -151,13 +174,14 @@ def nsw_add(lhs, rhs, name = "") Instruction.from_ptr(C.LLVMBuildNSWAdd(self, lhs, rhs, name)) end - # @param [LLVM::Value] lhs Floating point or vector of floating points - # @param [LLVM::Value] rhs Floating point or vector of floating points + # No unsigned wrap addition. + # @param [LLVM::Value] lhs Integer or vector of integers + # @param [LLVM::Value] rhs Integer or vector of integers # @param [String] name Name of the result in LLVM IR - # @return [LLVM::Instruction] The floating point sum of the two operands - # @LLVMinst fadd - def fadd(lhs, rhs, name = "") - Instruction.from_ptr(C.LLVMBuildFAdd(self, lhs, rhs, name)) + # @return [LLVM::Instruction] The integer sum of the two operands + # @LLVMinst nuw_add + def nuw_add(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildNUWAdd(self, lhs, rhs, name)) end # @param [LLVM::Value] lhs Integer or vector of integers @@ -179,6 +203,26 @@ def fsub(lhs, rhs, name = "") Instruction.from_ptr(C.LLVMBuildFSub(self, lhs, rhs, name)) end + # No signed wrap subtraction. + # @param [LLVM::Value] lhs Integer or vector of integers + # @param [LLVM::Value] rhs Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The integer difference of the two operands + # @LLVMinst nsw_sub + def nsw_sub(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildNSWSub(self, lhs, rhs, name)) + end + + # No unsigned wrap subtraction. + # @param [LLVM::Value] lhs Integer or vector of integers + # @param [LLVM::Value] rhs Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The integer difference of the two operands + # @LLVMinst nuw_sub + def nuw_sub(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildNUWSub(self, lhs, rhs, name)) + end + # @param [LLVM::Value] lhs Integer or vector of integers # @param [LLVM::Value] rhs Integer or vector of integers # @param [String] name Name of the result in LLVM IR @@ -198,6 +242,26 @@ def fmul(lhs, rhs, name = "") Instruction.from_ptr(C.LLVMBuildFMul(self, lhs, rhs, name)) end + # No signed wrap multiplication. + # @param [LLVM::Value] lhs Integer or vector of integers + # @param [LLVM::Value] rhs Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The integer product of the two operands + # @LLVMinst nsw_mul + def nsw_mul(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildNSWMul(self, lhs, rhs, name)) + end + + # No unsigned wrap multiplication. + # @param [LLVM::Value] lhs Integer or vector of integers + # @param [LLVM::Value] rhs Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The integer product of the two operands + # @LLVMinst nuw_mul + def nuw_mul(lhs, rhs, name = "") + Instruction.from_ptr(C.LLVMBuildNUWMul(self, lhs, rhs, name)) + end + # Unsigned integer division # @param [LLVM::Value] lhs Integer or vector of integers # @param [LLVM::Value] rhs Integer or vector of integers @@ -332,6 +396,36 @@ def xor(lhs, rhs, name = "") def neg(arg, name = "") Instruction.from_ptr(C.LLVMBuildNeg(self, arg, name)) end + + # Floating point negation. Implemented as a shortcut to + # the equivalent sub instruction. + # @param [LLVM::Value] arg Float or vector of Floats + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The negated operand + # @LLVMinst fneg + def fneg(arg, name = "") + Instruction.from_ptr(C.LLVMBuildFNeg(self, arg, name)) + end + + # Not signed wrapped negation. Implemented as a shortcut to + # the equivalent sub instruction. + # @param [LLVM::Value] arg Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The negated operand + # @LLVMinst nsw_neg + def nsw_neg(arg, name = "") + Instruction.from_ptr(C.LLVMBuildNSWNeg(self, arg, name)) + end + + # Not unsigned wrapped negation. Implemented as a shortcut to + # the equivalent sub instruction. + # @param [LLVM::Value] arg Integer or vector of integers + # @param [String] name Name of the result in LLVM IR + # @return [LLVM::Instruction] The negated operand + # @LLVMinst nuw_neg + def nuw_neg(arg, name = "") + Instruction.from_ptr(C.LLVMBuildNUWNeg(self, arg, name)) + end # Boolean negation. # @param [LLVM::Value] arg Integer or vector of integers @@ -693,6 +787,7 @@ def icmp(pred, lhs, rhs, name = "") # :uge - unordered and greater than or equal to # :olt - ordered and less than # :ule - unordered and less than or equal to + # :ult - unordered and less than # :oge - ordered and greater than or equal to # :sge - unordered and greater than or equal to # :ole - ordered and less than or equal to diff --git a/lib/llvm/core/value.rb b/lib/llvm/core/value.rb index a872bb8..47f9183 100644 --- a/lib/llvm/core/value.rb +++ b/lib/llvm/core/value.rb @@ -305,6 +305,16 @@ def -@ self.class.from_ptr(C.LLVMConstNeg(self)) end + # "No signed wrap" negation. + def nsw_neg + self.class.from_ptr(C.LLVMConstNSWNeg(self)) + end + + # "No unsigned wrap" negation. + def nuw_neg + self.class.from_ptr(C.LLVMConstNUWNeg(self)) + end + # Boolean negation. def not self.class.from_ptr(C.LLVMConstNot(self)) @@ -320,12 +330,43 @@ def +(rhs) def nsw_add(rhs) self.class.from_ptr(C.LLVMConstNSWAdd(self, rhs)) end + + # "No unsigned wrap" addition. See + # http://llvm.org/docs/LangRef.html#i_add for discusison. + def nuw_add(rhs) + self.class.from_ptr(C.LLVMConstNUWAdd(self, rhs)) + end + + # Subtraction. + def -(rhs) + self.class.from_ptr(C.LLVMConstSub(self, rhs)) + end + + # "No signed wrap" subtraction. + def nsw_sub(rhs) + self.class.from_ptr(C.LLVMConstNSWSub(self, rhs)) + end + + # "No unsigned wrap" subtraction. + def nuw_sub(rhs) + self.class.from_ptr(C.LLVMConstNUWSub(self, rhs)) + end # Multiplication. def *(rhs) self.class.from_ptr(C.LLVMConstMul(self, rhs)) end + # "No signed wrap" Multiplication. + def nsw_sub(rhs) + self.class.from_ptr(C.LLVMConstNSWMul(self, rhs)) + end + + # "No unsigned wrap" Multiplication. + def nuw_add(rhs) + self.class.from_ptr(C.LLVMConstNUWMul(self, rhs)) + end + # Unsigned division. def udiv(rhs) self.class.from_ptr(C.LLVMConstUDiv(self, rhs)) From ffe92cf61ce00d59157744fd27323c17068fc870 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 11:25:08 -0600 Subject: [PATCH 6/8] Added the LLVMAddDestination binding and then created an subclass of Instruction (IndirectBr) to use it. --- lib/llvm/bindings.rb | 2 ++ lib/llvm/core/builder.rb | 2 +- lib/llvm/core/value.rb | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb index 3435845..a86ff6e 100644 --- a/lib/llvm/bindings.rb +++ b/lib/llvm/bindings.rb @@ -473,6 +473,8 @@ module C attach_function :LLVMGetLastInstruction, [:pointer], :pointer attach_function :LLVMGetNextInstruction, [:pointer], :pointer attach_function :LLVMGetPreviousInstruction, [:pointer], :pointer + + attach_function :LLVMAddDestination, [:pointer, :pointer], :void # Call sites attach_function :LLVMSetInstructionCallConv, [:pointer, :call_conv], :void diff --git a/lib/llvm/core/builder.rb b/lib/llvm/core/builder.rb index 9102571..e65a6df 100644 --- a/lib/llvm/core/builder.rb +++ b/lib/llvm/core/builder.rb @@ -82,7 +82,7 @@ def br(block) # @return [LLVM::Instruction] # @LLVMinst br def ibr(addr, num_dests = 10) - Instruction.from_ptr(C.LLVMBuildIndirectBr(self, addr, num_dests)) + IndirectBr.from_ptr(C.LLVMBuildIndirectBr(self, addr, num_dests)) end # Conditional branching (i.e. if) diff --git a/lib/llvm/core/value.rb b/lib/llvm/core/value.rb index 47f9183..20e1cf6 100644 --- a/lib/llvm/core/value.rb +++ b/lib/llvm/core/value.rb @@ -817,4 +817,14 @@ def add_case(val, block) C.LLVMAddCase(self, val, block) end end + + # @private + class IndirectBr < Instruction + # Adds a basic block references as a destination for this indirect branch. + def add_dest(dest) + C.LLVMAddDestination(self, dest) + end + + alias :<< :add_dest + end end From cced206b206f2e942a50e9bdb9e218bc2b251f03 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 3 Jun 2011 13:56:50 -0600 Subject: [PATCH 7/8] Laying the groundwork for adding custom C bindings for LLVM that can be bound to Ruby code using FFI. --- Rakefile | 17 ++++++++++++++++- ext/Makefile | 20 ++++++++++++++++++++ ext/support.cpp | 11 +++++++++++ lib/llvm/bindings.rb | 10 +++++++++- lib/llvm/core.rb | 4 ++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 ext/Makefile create mode 100644 ext/support.cpp diff --git a/Rakefile b/Rakefile index f453c94..3e46018 100644 --- a/Rakefile +++ b/Rakefile @@ -84,7 +84,7 @@ task :check_bindings, :verbose do |t, args| return end - # Grab library symbols. + # Grab libLLVM symbols. lines = `#{bin} -t #{lib_path}` lsyms = lines.map do |l| @@ -92,6 +92,21 @@ task :check_bindings, :verbose do |t, args| if md then md[1] else nil end end.compact.uniq + # Grab libLLVM-EB symbols. + lib_path = "ext/libLLVM-EB-#{LLVM_TARGET_VERSION}.so" + + if not File.exists?(lib_path) + puts 'Extending Bindings shared library not present.' + return + end + + lines = `#{bin} -t #{lib_path}` + + lsyms |= lsyms = lines.map do |l| + md = l.match(/\s(LLVM\w+)/) + if md then md[1] else nil end + end.compact.uniq + # Defined symbols. dsyms = Symbol.all_symbols.map do |sym| sym = sym.to_s diff --git a/ext/Makefile b/ext/Makefile new file mode 100644 index 0000000..c26bc29 --- /dev/null +++ b/ext/Makefile @@ -0,0 +1,20 @@ +LLVM_VERSION = 2.9 + +CXX = g++ +CFLAGS = -O3 -fPIC +LIBFLAGS = -shared -Wl,-soname,libLLVM-EB-$(LLVM_VERSION).so + +LIBS = /usr/local/lib/libLLVMSupport.a + +all: libLLVM-EB.so + +libLLVM-EB.so: support.o + $(CXX) $(CFLAGS) $(LIBFLAGS) -o libLLVM-EB-$(LLVM_VERSION).so support.o $(LIBS) + +support.o: support.cpp + $(CXX) $(CFLAGS) -c $< + +.PHONY: clean +clean: + rm -f *.o + rm -f *.so diff --git a/ext/support.cpp b/ext/support.cpp new file mode 100644 index 0000000..d8d8ee4 --- /dev/null +++ b/ext/support.cpp @@ -0,0 +1,11 @@ +/* + * Extended bindings for LLVM. + */ + +#include + +extern "C" { + int LLVMLoadLibraryPermanently(const char* filename) { + return llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename); + } +} diff --git a/lib/llvm/bindings.rb b/lib/llvm/bindings.rb index a86ff6e..11a8da2 100644 --- a/lib/llvm/bindings.rb +++ b/lib/llvm/bindings.rb @@ -3,8 +3,16 @@ module LLVM # @private - module C + module EB + extend FFI::Library + + ffi_lib ['LLVM-EB-2.9', 'libLLVM-EB-2.9'] + attach_function :LLVMLoadLibraryPermanently, [:string], :bool + end + + # @private + module C extend FFI::Library # Load the required library. diff --git a/lib/llvm/core.rb b/lib/llvm/core.rb index e7335a8..820ee32 100644 --- a/lib/llvm/core.rb +++ b/lib/llvm/core.rb @@ -10,4 +10,8 @@ module LLVM require 'llvm/core/builder' require 'llvm/core/pass_manager' require 'llvm/core/bitcode' + + def LLVM::load_library(filename) + EB::LLVMLoadLibraryPermanently(filename) + end end From e96e7685f87b74c4870450904ea06c5d52610766 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Tue, 14 Jun 2011 15:02:44 -0600 Subject: [PATCH 8/8] Moved the extended bindings code into the ext/LLVM-EB directory. Removed the Makefile and replaced it with one generated by the new extconf.rb file. Added the new extconf.rb file to the gem specification. Corrected a typo in the build.rb file. --- Rakefile | 2 + ext/LLVM-EB/Makefile | 157 +++++++++++++++++++++++++++++++++++++++ ext/LLVM-EB/extconf.rb | 11 +++ ext/LLVM-EB/support.cpp | 11 +++ lib/llvm/core/builder.rb | 2 +- 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 ext/LLVM-EB/Makefile create mode 100644 ext/LLVM-EB/extconf.rb create mode 100644 ext/LLVM-EB/support.cpp diff --git a/Rakefile b/Rakefile index 3e46018..960a7a2 100644 --- a/Rakefile +++ b/Rakefile @@ -41,6 +41,8 @@ def spec s.extra_rdoc_files = 'README.rdoc' + s.extensions << 'ext/LLVM-EB/extconf.rb' + s.author = "Jeremy Voorhis" s.email = "jvoorhis@gmail.com" s.homepage = "http://github.com/jvoorhis/ruby-llvm" diff --git a/ext/LLVM-EB/Makefile b/ext/LLVM-EB/Makefile new file mode 100644 index 0000000..20f305f --- /dev/null +++ b/ext/LLVM-EB/Makefile @@ -0,0 +1,157 @@ + +SHELL = /bin/sh + +#### Start of system configuration section. #### + +srcdir = . +topdir = /usr/lib64/ruby/1.8/x86_64-linux +hdrdir = $(topdir) +VPATH = $(srcdir):$(topdir):$(hdrdir) +exec_prefix = $(DESTDIR)/usr +prefix = $(DESTDIR)/usr +sharedstatedir = $(DESTDIR)/var/lib +mandir = $(DESTDIR)/usr/share/man +psdir = $(docdir) +oldincludedir = $(DESTDIR)/usr/include +localedir = $(datarootdir)/locale +bindir = $(DESTDIR)/usr/bin +libexecdir = $(DESTDIR)/usr/libexec +sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby +htmldir = $(docdir) +vendorarchdir = $(libdir)/ruby/$(ruby_version)/$(sitearch) +includedir = $(DESTDIR)/usr/include +infodir = $(DESTDIR)/usr/share/info +vendorlibdir = $(vendordir)/$(ruby_version) +sysconfdir = $(DESTDIR)/etc +libdir = $(DESTDIR)/usr/lib64 +sbindir = $(DESTDIR)/usr/sbin +rubylibdir = $(vendordir)/$(ruby_version) +docdir = $(datarootdir)/doc/$(PACKAGE) +dvidir = $(docdir) +vendordir = $(DESTDIR)/usr/lib/ruby +datarootdir = $(prefix)/share +pdfdir = $(docdir) +archdir = $(libdir)/ruby/$(ruby_version)/$(sitearch) +sitearchdir = $(libdir)/ruby/site_ruby/$(ruby_version)/$(sitearch) +datadir = $(DESTDIR)/usr/share +localstatedir = $(DESTDIR)/var +sitelibdir = $(sitedir)/$(ruby_version) + +CC = gcc +LIBRUBY = $(LIBRUBY_SO) +LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a +LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) +LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static + +RUBY_EXTCONF_H = +CFLAGS = -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fPIC $(cflags)-Wall -O3 -fPIC +INCFLAGS = -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. +DEFS = +CPPFLAGS = +CXXFLAGS = $(CFLAGS) +ldflags = -I LLVM-2.9 -o libLLVM-EB-2.9.so +dldflags = +archflag = +DLDFLAGS = $(ldflags) $(dldflags) $(archflag) +LDSHARED = $(CC) -shared +AR = ar +EXEEXT = + +RUBY_INSTALL_NAME = ruby +RUBY_SO_NAME = ruby +arch = x86_64-linux +sitearch = x86_64-linux +ruby_version = 1.8 +ruby = /usr/bin/ruby +RUBY = $(ruby) +RM = rm -f +MAKEDIRS = mkdir -p +INSTALL = /usr/bin/install -c +INSTALL_PROG = $(INSTALL) -m 0755 +INSTALL_DATA = $(INSTALL) -m 644 +COPY = cp + +#### End of system configuration section. #### + +preload = + +libpath = . $(libdir) +LIBPATH = -L. -L$(libdir) +DEFFILE = + +CLEANFILES = mkmf.log +DISTCLEANFILES = + +extout = +extout_prefix = +target_prefix = +LOCAL_LIBS = +LIBS = $(LIBRUBYARG_SHARED) -lLLVM-2.9 -lpthread -lrt -ldl -lcrypt -lm -lc +SRCS = support.cpp +OBJS = support.o +TARGET = LLVM-EB +DLLIB = $(TARGET).so +EXTSTATIC = +STATIC_LIB = + +BINDIR = $(bindir) +RUBYCOMMONDIR = $(sitedir)$(target_prefix) +RUBYLIBDIR = $(sitelibdir)$(target_prefix) +RUBYARCHDIR = $(sitearchdir)$(target_prefix) + +TARGET_SO = $(DLLIB) +CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map +CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak + +all: $(DLLIB) +static: $(STATIC_LIB) + +clean: + @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) + +distclean: clean + @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log + @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) + +realclean: distclean +install: install-so install-rb + +install-so: $(RUBYARCHDIR) +install-so: $(RUBYARCHDIR)/$(DLLIB) +$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) + $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) +install-rb: pre-install-rb install-rb-default +install-rb-default: pre-install-rb-default +pre-install-rb: Makefile +pre-install-rb-default: Makefile +$(RUBYARCHDIR): + $(MAKEDIRS) $@ + +site-install: site-install-so site-install-rb +site-install-so: install-so +site-install-rb: install-rb + +.SUFFIXES: .c .m .cc .cxx .cpp .C .o + +.cc.o: + $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< + +.cxx.o: + $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< + +.cpp.o: + $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< + +.C.o: + $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< + +.c.o: + $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< + +$(DLLIB): $(OBJS) Makefile + @-$(RM) $@ + $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) + + + +$(OBJS): ruby.h defines.h diff --git a/ext/LLVM-EB/extconf.rb b/ext/LLVM-EB/extconf.rb new file mode 100644 index 0000000..9b11d0c --- /dev/null +++ b/ext/LLVM-EB/extconf.rb @@ -0,0 +1,11 @@ +require 'mkmf' + +extname = 'LLVM-EB' + +have_library('LLVM-2.9') + +$CFLAGS << '-Wall -O3 -fPIC' +$LDFLAGS = '-I LLVM-2.9 -o libLLVM-EB-2.9.so' + +dir_config(extname) +create_makefile(extname) diff --git a/ext/LLVM-EB/support.cpp b/ext/LLVM-EB/support.cpp new file mode 100644 index 0000000..d8d8ee4 --- /dev/null +++ b/ext/LLVM-EB/support.cpp @@ -0,0 +1,11 @@ +/* + * Extended bindings for LLVM. + */ + +#include + +extern "C" { + int LLVMLoadLibraryPermanently(const char* filename) { + return llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename); + } +} diff --git a/lib/llvm/core/builder.rb b/lib/llvm/core/builder.rb index e65a6df..dfc4c7e 100644 --- a/lib/llvm/core/builder.rb +++ b/lib/llvm/core/builder.rb @@ -780,7 +780,7 @@ def icmp(pred, lhs, rhs, name = "") # :ord - ordered # :uno - unordered: isnan(X) | isnan(Y) # :oeq - ordered and equal to - # :oeq - unordered and equal to + # :ueq - unordered and equal to # :one - ordered and not equal to # :one - unordered and not equal to # :ogt - ordered and greater than