llvm.org GIT mirror llvm / 60e4d7f
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 Anders Waldenborg 7 years ago
1 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3232 # Constants for set_options
3333 Option_UseMarkup = 1
3434
35
36
37 _initialized = False
38 _targets = ['AArch64', 'ARM', 'Hexagon', 'MSP430', 'Mips', 'NVPTX', 'PowerPC', 'R600', 'Sparc', 'SystemZ', 'X86', 'XCore']
39 def _ensure_initialized():
40 global _initialized
41 if not _initialized:
42 # Here one would want to call the functions
43 # LLVMInitializeAll{TargetInfo,TargetMC,Disassembler}s, but
44 # unfortunately they are only defined as static inline
45 # functions in the header files of llvm-c, so they don't exist
46 # as symbols in the shared library.
47 # So until that is fixed use this hack to initialize them all
48 for tgt in _targets:
49 for initializer in ("TargetInfo", "TargetMC", "Disassembler"):
50 try:
51 f = getattr(lib, "LLVMInitialize" + tgt + initializer)
52 except AttributeError:
53 continue
54 f()
55 _initialized = True
56
57
3558 class Disassembler(LLVMObject):
3659 """Represents a disassembler instance.
3760
4669 The triple argument is the triple to create the disassembler for. This
4770 is something like 'i386-apple-darwin9'.
4871 """
72
73 _ensure_initialized()
74
4975 ptr = lib.LLVMCreateDisasm(c_char_p(triple), c_void_p(None), c_int(0),
5076 callbacks['op_info'](0), callbacks['symbol_lookup'](0))
5177 if not ptr.contents: