From 699f8c3524eb179f7cb8302b4a5d19abbd547125 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Wed, 11 Sep 2013 00:23:05 +0000 Subject: [python-bindings] Removed unused import byref from llvm/disassembler.py. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190455 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/llvm/disassembler.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bindings/python/llvm/disassembler.py') diff --git a/bindings/python/llvm/disassembler.py b/bindings/python/llvm/disassembler.py index dcef9ac..2a1b701 100644 --- a/bindings/python/llvm/disassembler.py +++ b/bindings/python/llvm/disassembler.py @@ -10,7 +10,6 @@ from ctypes import CFUNCTYPE from ctypes import POINTER from ctypes import addressof -from ctypes import byref from ctypes import c_byte from ctypes import c_char_p from ctypes import c_int -- cgit v1.1 From 60e4d7f618ffc8b91c6fa2638e3c25a085c2fb1e Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Sun, 17 Nov 2013 15:17:08 +0000 Subject: python: Properly initialize before trying to create disasm As the "LLVMInitializeAll*" functions are not available as symbols in the shared library they can't be used, and as a workaround a list of the targets is kept and the individual symbols tried. As soon as the "All"-functions are changed to proper symbols (as opposed to static inlines in the headers) this hack will be replace with simple calls to the corresponding "LLVMInitializeAll*" functions. Reviewed By: indygreg CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1879 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194964 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/llvm/disassembler.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'bindings/python/llvm/disassembler.py') diff --git a/bindings/python/llvm/disassembler.py b/bindings/python/llvm/disassembler.py index 2a1b701..9e781ae 100644 --- a/bindings/python/llvm/disassembler.py +++ b/bindings/python/llvm/disassembler.py @@ -33,6 +33,29 @@ callbacks = {} # Constants for set_options Option_UseMarkup = 1 + + +_initialized = False +_targets = ['AArch64', 'ARM', 'Hexagon', 'MSP430', 'Mips', 'NVPTX', 'PowerPC', 'R600', 'Sparc', 'SystemZ', 'X86', 'XCore'] +def _ensure_initialized(): + global _initialized + if not _initialized: + # Here one would want to call the functions + # LLVMInitializeAll{TargetInfo,TargetMC,Disassembler}s, but + # unfortunately they are only defined as static inline + # functions in the header files of llvm-c, so they don't exist + # as symbols in the shared library. + # So until that is fixed use this hack to initialize them all + for tgt in _targets: + for initializer in ("TargetInfo", "TargetMC", "Disassembler"): + try: + f = getattr(lib, "LLVMInitialize" + tgt + initializer) + except AttributeError: + continue + f() + _initialized = True + + class Disassembler(LLVMObject): """Represents a disassembler instance. @@ -47,6 +70,9 @@ class Disassembler(LLVMObject): The triple argument is the triple to create the disassembler for. This is something like 'i386-apple-darwin9'. """ + + _ensure_initialized() + ptr = lib.LLVMCreateDisasm(c_char_p(triple), c_void_p(None), c_int(0), callbacks['op_info'](0), callbacks['symbol_lookup'](0)) if not ptr.contents: -- cgit v1.1 From e8a957d2a91d02af0b9c3808b31067d236b22196 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Sun, 17 Nov 2013 15:40:57 +0000 Subject: python: Fix check for disasm creation failure Check should be for pointer being NULL, not what it points to. Also adds a test for this case. Reviewed By: indygreg Differential Revision: http://llvm-reviews.chandlerc.com/D1878 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194965 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/llvm/disassembler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bindings/python/llvm/disassembler.py') diff --git a/bindings/python/llvm/disassembler.py b/bindings/python/llvm/disassembler.py index 9e781ae..f2df275 100644 --- a/bindings/python/llvm/disassembler.py +++ b/bindings/python/llvm/disassembler.py @@ -75,7 +75,7 @@ class Disassembler(LLVMObject): ptr = lib.LLVMCreateDisasm(c_char_p(triple), c_void_p(None), c_int(0), callbacks['op_info'](0), callbacks['symbol_lookup'](0)) - if not ptr.contents: + if not ptr: raise Exception('Could not obtain disassembler for triple: %s' % triple) -- cgit v1.1