added Target.createMCSubtargetInfo and createMCDisassembler

also added bindings to classes required by the target methods. also
added a convenience function to initialize all target components to
the llvm module
This commit is contained in:
anthony cantor 2013-08-13 15:14:16 -06:00 • committed by Siu Kwan Lam
commit ba03b226c8
5 changed files with 62 additions and 0 deletions

26
llvm/mc/__init__.py Normal file
View file

@ -0,0 +1,26 @@
from io import BytesIO
import contextlib
import llvm
from llvmpy import api
class Disassembler(llvm.Wrapper):
@staticmethod
def new(triple='', cpu='', features=''):
if not triple:
triple = api.llvm.sys.getDefaultTargetTriple()
with contextlib.closing(BytesIO()) as error:
target = api.llvm.TargetRegistry.lookupTarget(triple, error)
if not target:
raise llvm.LLVMException(error)
if not target.hasMCDisassembler():
raise llvm.LLVMException(target, "No disassembler provided for %s." % triple)
sti = target.createMCSubtargetInfo(triple, cpu, features)
if not sti:
raise llvm.LLVMException("Could not create sub target info")
return target.createMCDisassembler(sti)