From aa0ee9b6a662503c199ac1a8b9f9302c9556e0bc Mon Sep 17 00:00:00 2001 From: anthony cantor Date: Fri, 16 Aug 2013 02:33:06 -0600 Subject: [PATCH] changes to make llvmpy compatible with development branch of llvm mostly just removing stuff and changing function prototypes. with these changes, llvmpy compiles and llvm.test() passes. --- llvm/core.py | 6 +++-- llvm/passes.py | 13 ++++++----- llvm/test_llvmpy.py | 3 ++- llvmpy/src/CallingConv.py | 18 ++++++++++----- llvmpy/src/DIBuilder.py | 25 ++++++++++++--------- llvmpy/src/DebugInfo.py | 2 +- llvmpy/src/Transforms/PassManagerBuilder.py | 4 +++- setup.py | 2 +- 8 files changed, 45 insertions(+), 28 deletions(-) diff --git a/llvm/core.py b/llvm/core.py index c7bb49c..8c4a373 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -211,8 +211,10 @@ class CCEnum(Enum): CC_X86_THISCALL = ID.X86_ThisCall CC_PTX_KERNEL = ID.PTX_Kernel CC_PTX_DEVICE = ID.PTX_Device - CC_MBLAZE_INTR = ID.MBLAZE_INTR - CC_MBLAZE_SVOL = ID.MBLAZE_SVOL + + if llvm.version <= (3, 3): + CC_MBLAZE_INTR = ID.MBLAZE_INTR + CC_MBLAZE_SVOL = ID.MBLAZE_SVOL CCEnum.declare() diff --git a/llvm/passes.py b/llvm/passes.py index 4753027..0a4c524 100644 --- a/llvm/passes.py +++ b/llvm/passes.py @@ -120,13 +120,14 @@ class PassManagerBuilder(llvm.Wrapper): def disable_unroll_loops(self, disable): self._ptr.DisableUnrollLoops = disable - @property - def disable_simplify_lib_calls(self): - return self._ptr.DisableSimplifyLibCalls + if llvm.version <= (3, 3): + @property + def disable_simplify_lib_calls(self): + return self._ptr.DisableSimplifyLibCalls - @disable_simplify_lib_calls.setter - def disable_simplify_lib_calls(self, disable): - self._ptr.DisableSimplifyLibCalls = disable + @disable_simplify_lib_calls.setter + def disable_simplify_lib_calls(self, disable): + self._ptr.DisableSimplifyLibCalls = disable def use_inliner_with_threshold(self, threshold): self._ptr.Inliner = api.llvm.createFunctionInliningPass(threshold) diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 2764cf2..72283e6 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -393,7 +393,8 @@ entry: # make sure the default is False self.assertFalse(pmb.disable_unit_at_a_time) self.assertFalse(pmb.disable_unroll_loops) - self.assertFalse(pmb.disable_simplify_lib_calls) + if llvm.version <= (3, 3): + self.assertFalse(pmb.disable_simplify_lib_calls) pmb.disable_unit_at_a_time = True self.assertTrue(pmb.disable_unit_at_a_time) diff --git a/llvmpy/src/CallingConv.py b/llvmpy/src/CallingConv.py index efca1fc..b03e65c 100644 --- a/llvmpy/src/CallingConv.py +++ b/llvmpy/src/CallingConv.py @@ -1,10 +1,16 @@ from binding import * from .namespace import llvm +ccs = ''' + C, Fast, Cold, GHC, FirstTargetCC, X86_StdCall, X86_FastCall, + ARM_APCS, ARM_AAPCS, ARM_AAPCS_VFP, MSP430_INTR, X86_ThisCall, + PTX_Kernel, PTX_Device, +''' + +if LLVM_VERSION <= (3, 3): + ccs += "MBLAZE_INTR, MBLAZE_SVOL," + +ccs += 'SPIR_FUNC, SPIR_KERNEL, Intel_OCL_BI' + CallingConv = llvm.Namespace('CallingConv') -ID = CallingConv.Enum('ID', ''' - C, Fast, Cold, GHC, FirstTargetCC, X86_StdCall, X86_FastCall, - ARM_APCS, ARM_AAPCS, ARM_AAPCS_VFP, MSP430_INTR, X86_ThisCall, - PTX_Kernel, PTX_Device, MBLAZE_INTR, MBLAZE_SVOL, SPIR_FUNC, - SPIR_KERNEL, Intel_OCL_BI - ''') # HiPE +ID = CallingConv.Enum('ID', ccs) # HiPE diff --git a/llvmpy/src/DIBuilder.py b/llvmpy/src/DIBuilder.py index cb934d4..7bc8224 100644 --- a/llvmpy/src/DIBuilder.py +++ b/llvmpy/src/DIBuilder.py @@ -6,7 +6,7 @@ DIBuilder = llvm.Class() from .Module import Module from .Value import Value, MDNode, Function, BasicBlock from .Instruction import Instruction -from .DebugInfo import DIFile, DIEnumerator, DIType, DIBasicType, DIDerivedType +from .DebugInfo import DIFile, DIEnumerator, DIType, DIBasicType, DIDerivedType, DICompositeType from .DebugInfo import DIDescriptor, DIArray, DISubrange, DIGlobalVariable from .DebugInfo import DIVariable, DISubprogram, DINameSpace, DILexicalBlockFile from .DebugInfo import DILexicalBlock @@ -25,7 +25,8 @@ class DIBuilder: new = Constructor(ref(Module)) delete = Destructor() - getCU = Method(const(ptr(MDNode))) + if LLVM_VERSION <= (3, 3): + getCU = Method(const(ptr(MDNode))) finalize = Method() createCompileUnit = Method(Void, @@ -46,12 +47,16 @@ class DIBuilder: createEnumerator = Method(DIEnumerator, stringref_arg, # Name - uint64_arg, # Val + uint64_arg if LLVM_VERSION <= (3, 3) else int64_arg, # Val ) - createNullPtrType = Method(DIType, - stringref_arg, # Name - ) + if LLVM_VERSION <= (3, 3): + createNullPtrType = Method(DIType, + stringref_arg, # Name + ) + else: + createNullPtrType = Method(DIBasicType) + createBasicType = Method(DIType, stringref_arg, # Name @@ -85,7 +90,7 @@ class DIBuilder: ref(DIDescriptor), # Context ) - createFriend = Method(DIType, + createFriend = Method(DIType if LLVM_VERSION <= (3, 3) else DIDerivedType, ref(DIType), # Ty ref(DIType), # FriendTy ) @@ -169,7 +174,7 @@ class DIBuilder: ref(DIArray), # Subscripts ) - createVectorType = Method(DIType, + createVectorType = Method(DIType if LLVM_VERSION <= (3, 3) else DICompositeType, uint64_arg, # Size uint64_arg, # AlignInBits ref(DIType), # Ty @@ -275,7 +280,7 @@ class DIBuilder: stringref_arg, # LinkageName ref(DIFile), # File unsigned_arg, # LineNo - ref(DIType), # Ty + ref(DIType if LLVM_VERSION <= (3, 3) else DICompositeType), # Ty bool_arg, # isLocalToUnit bool_arg, # isDefinition unsigned_arg, # ScopeLine @@ -293,7 +298,7 @@ class DIBuilder: stringref_arg, # LinkageName ref(DIFile), # File unsigned_arg, # LineNo - ref(DIType), # Ty + ref(DIType if LLVM_VERSION <= (3, 3) else DICompositeType), # Ty bool_arg, # isLocalToUnit bool_arg, # isDefinition unsigned_arg, # Virtuality=0 diff --git a/llvmpy/src/DebugInfo.py b/llvmpy/src/DebugInfo.py index 8ddb1ee..b316c62 100644 --- a/llvmpy/src/DebugInfo.py +++ b/llvmpy/src/DebugInfo.py @@ -44,7 +44,7 @@ class DIFile: @DIEnumerator class DIEnumerator: getName = Method(return_stringref) - getEnumValue = Method(cast(Uint64, int)) + getEnumValue = Method(cast(Uint64 if LLVM_VERSION <= (3, 3) else Int64, int)) Verify = Method(return_bool) @DIType diff --git a/llvmpy/src/Transforms/PassManagerBuilder.py b/llvmpy/src/Transforms/PassManagerBuilder.py index 146d409..a654578 100644 --- a/llvmpy/src/Transforms/PassManagerBuilder.py +++ b/llvmpy/src/Transforms/PassManagerBuilder.py @@ -33,7 +33,9 @@ class PassManagerBuilder: return Attr(getter=cast(Bool, bool), setter=cast(bool, Bool)) - DisableSimplifyLibCalls = _attr_bool() + if LLVM_VERSION <= (3, 3): + DisableSimplifyLibCalls = _attr_bool() + DisableUnitAtATime = _attr_bool() DisableUnrollLoops = _attr_bool() if LLVM_VERSION >= (3, 3): diff --git a/setup.py b/setup.py index 3e9482b..db4f75e 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,7 @@ def auto_intrinsic_gen(incdir): print("Generate intrinsic IDs") from tools import intrgen - if llvm_version.startswith('3.3'): + if llvm_version.startswith('3.3') or llvm_version.startswith('3.4'): path = "%s/llvm/IR/Intrinsics.gen" % incdir else: path = "%s/llvm/Intrinsics.gen" % incdir