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:
parent
8f2c27ba41
commit
ba03b226c8
5 changed files with 62 additions and 0 deletions
26
llvm/mc/__init__.py
Normal file
26
llvm/mc/__init__.py
Normal 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)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue