diff options
author | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
commit | ce9904c6ea8fd669978a8eefb854b330eb9828ff (patch) | |
tree | 2418ee2e96ea220977c8fb74959192036ab5b133 /bindings/python/llvm/disassembler.py | |
parent | c27b10b198c1d9e9b51f2303994313ec2778edd7 (diff) | |
parent | dbb832b83351cec97b025b61c26536ef50c3181c (diff) | |
download | external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.zip external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.gz external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.bz2 |
Merge remote-tracking branch 'upstream/release_34' into merge-20140211
Conflicts:
lib/Linker/LinkModules.cpp
lib/Support/Unix/Signals.inc
Change-Id: Ia54f291fa5dc828052d2412736e8495c1282aa64
Diffstat (limited to 'bindings/python/llvm/disassembler.py')
-rw-r--r-- | bindings/python/llvm/disassembler.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/bindings/python/llvm/disassembler.py b/bindings/python/llvm/disassembler.py index dcef9ac..f2df275 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 @@ -34,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. @@ -48,9 +70,12 @@ 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: + if not ptr: raise Exception('Could not obtain disassembler for triple: %s' % triple) |