diff --git a/llvmpy/include/llvm_binding/extra.h b/llvmpy/include/llvm_binding/extra.h index b2b6f11..4c30f2d 100644 --- a/llvmpy/include/llvm_binding/extra.h +++ b/llvmpy/include/llvm_binding/extra.h @@ -955,6 +955,7 @@ PyObject* TargetRegistry_targets_list() "llvm::Target", "llvm::Target"); } +#if LLVM_VERSION_MAJOR >= 3 and LLVM_VERSION_MINOR >= 4 static PyObject* MemoryObject_readBytes(const llvm::MemoryObject *mobj, uint64_t addr, @@ -986,7 +987,6 @@ fail: Py_RETURN_NONE; } -#if LLVM_VERSION_MAJOR >= 3 and LLVM_VERSION_MINOR >= 4 static PyObject* MCDisassembler_getInstruction(llvm::MCDisassembler *disasm, llvm::MCInst &instr, diff --git a/llvmpy/src/MC/__init__.py b/llvmpy/src/MC/__init__.py index 6f2b3ed..92db727 100644 --- a/llvmpy/src/MC/__init__.py +++ b/llvmpy/src/MC/__init__.py @@ -1,3 +1,5 @@ +#this file is not processed unless the llvm library is +#version 3.4 or higher. see llvmpy/__init__.py for details. from binding import * from ..namespace import llvm from ..Support.StringRefMemoryObject import MemoryObject diff --git a/llvmpy/src/Support/StringRefMemoryObject.py b/llvmpy/src/Support/StringRefMemoryObject.py index fa3883d..f710626 100644 --- a/llvmpy/src/Support/StringRefMemoryObject.py +++ b/llvmpy/src/Support/StringRefMemoryObject.py @@ -2,31 +2,29 @@ from binding import * from ..namespace import llvm from ..ADT.StringRef import StringRef -MemoryObject = llvm.Class() if LLVM_VERSION >= (3, 4): + MemoryObject = llvm.Class() StringRefMemoryObject = llvm.Class(MemoryObject) -@MemoryObject -class MemoryObject: - _include_ = "llvm/Support/MemoryObject.h" + @MemoryObject + class MemoryObject: + _include_ = "llvm/Support/MemoryObject.h" - getBase = Method(cast(Uint64, int)) - getExtent = Method(cast(Uint64, int)) + getBase = Method(cast(Uint64, int)) + getExtent = Method(cast(Uint64, int)) - readBytes = CustomMethod('MemoryObject_readBytes', - PyObjectPtr, - cast(int, Uint64), #address - cast(int, Uint64) #size - ) - @CustomPythonMethod - def readAll(self): - result = self.readBytes(self.getBase(), self.getExtent()) - if not result: - raise Exception("expected readBytes to be successful!") - return result + readBytes = CustomMethod('MemoryObject_readBytes', + PyObjectPtr, + cast(int, Uint64), #address + cast(int, Uint64) #size + ) + @CustomPythonMethod + def readAll(self): + result = self.readBytes(self.getBase(), self.getExtent()) + if not result: + raise Exception("expected readBytes to be successful!") + return result - -if LLVM_VERSION >= (3, 4): @StringRefMemoryObject class StringRefMemoryObject: _include_ = "llvm/Support/StringRefMemoryObject.h" diff --git a/test/example-instruction-info.py b/test/example-instruction-info.py index 6ff341b..6467061 100644 --- a/test/example-instruction-info.py +++ b/test/example-instruction-info.py @@ -3,33 +3,36 @@ from llvmpy import api, extra def main(): - triple = "i386--" + if llvm.version < (3, 4): + return 0 - print("init start") - api.llvm.InitializeAllTargets() - api.llvm.InitializeAllTargetInfos() - api.llvm.InitializeAllTargetMCs() - api.llvm.InitializeAllAsmParsers() - api.llvm.InitializeAllAsmPrinters() - api.llvm.InitializeAllDisassemblers() - print("init done\n") + triple = "i386--" - tm = llvm.target.TargetMachine.x86() - if not tm: - print("error: failed to lookup target x86 \n") - return 1 + print("init start") + api.llvm.InitializeAllTargets() + api.llvm.InitializeAllTargetInfos() + api.llvm.InitializeAllTargetMCs() + api.llvm.InitializeAllAsmParsers() + api.llvm.InitializeAllAsmPrinters() + api.llvm.InitializeAllDisassemblers() + print("init done\n") - print("created target machine\n") + tm = llvm.target.TargetMachine.x86() + if not tm: + print("error: failed to lookup target x86 \n") + return 1 - MII = tm.instr_info - if not MII: - print("error: no instruction info for target " + triple + "\n") - return 1 + print("created target machine\n") - print("created instr info\n") - MID = MII.get(919) #int3 - print("INT3(%d): flags=0x%x, tsflags=0x%x\n" % (MID.getOpcode(), MID.getFlags(), MID.TSFlags)) + MII = tm.instr_info + if not MII: + print("error: no instruction info for target " + triple + "\n") + return 1 - return 0 + print("created instr info\n") + MID = MII.get(919) #int3 + print("INT3(%d): flags=0x%x, tsflags=0x%x\n" % (MID.getOpcode(), MID.getFlags(), MID.TSFlags)) + + return 0 exit(main()) \ No newline at end of file diff --git a/test/testall.py b/test/testall.py index 7710391..367f250 100644 --- a/test/testall.py +++ b/test/testall.py @@ -652,6 +652,9 @@ def do_llvm_target(): tm.is_little_endian() def do_llvm_mc(): + if llvm.version < (3, 4): + return + from llvm import target from llvm import mc