fixes to make this branch compatible with llvm versions before 3.4
This commit is contained in:
parent
aa264cee2d
commit
b303fd532a
5 changed files with 48 additions and 42 deletions
|
|
@ -955,6 +955,7 @@ PyObject* TargetRegistry_targets_list()
|
|||
"llvm::Target", "llvm::Target");
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 3 and LLVM_VERSION_MINOR >= 4
|
||||
static
|
||||
PyObject* MemoryObject_readBytes(const llvm::MemoryObject *mobj,
|
||||
uint64_t addr,
|
||||
|
|
@ -986,7 +987,6 @@ fail:
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 3 and LLVM_VERSION_MINOR >= 4
|
||||
static
|
||||
PyObject* MCDisassembler_getInstruction(llvm::MCDisassembler *disasm,
|
||||
llvm::MCInst &instr,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#this file is not processed unless the llvm library is
|
||||
#version 3.4 or higher. see llvmpy/__init__.py for details.
|
||||
from binding import *
|
||||
from ..namespace import llvm
|
||||
from ..Support.StringRefMemoryObject import MemoryObject
|
||||
|
|
|
|||
|
|
@ -2,31 +2,29 @@ from binding import *
|
|||
from ..namespace import llvm
|
||||
from ..ADT.StringRef import StringRef
|
||||
|
||||
MemoryObject = llvm.Class()
|
||||
if LLVM_VERSION >= (3, 4):
|
||||
MemoryObject = llvm.Class()
|
||||
StringRefMemoryObject = llvm.Class(MemoryObject)
|
||||
|
||||
@MemoryObject
|
||||
class MemoryObject:
|
||||
_include_ = "llvm/Support/MemoryObject.h"
|
||||
@MemoryObject
|
||||
class MemoryObject:
|
||||
_include_ = "llvm/Support/MemoryObject.h"
|
||||
|
||||
getBase = Method(cast(Uint64, int))
|
||||
getExtent = Method(cast(Uint64, int))
|
||||
getBase = Method(cast(Uint64, int))
|
||||
getExtent = Method(cast(Uint64, int))
|
||||
|
||||
readBytes = CustomMethod('MemoryObject_readBytes',
|
||||
PyObjectPtr,
|
||||
cast(int, Uint64), #address
|
||||
cast(int, Uint64) #size
|
||||
)
|
||||
@CustomPythonMethod
|
||||
def readAll(self):
|
||||
result = self.readBytes(self.getBase(), self.getExtent())
|
||||
if not result:
|
||||
raise Exception("expected readBytes to be successful!")
|
||||
return result
|
||||
readBytes = CustomMethod('MemoryObject_readBytes',
|
||||
PyObjectPtr,
|
||||
cast(int, Uint64), #address
|
||||
cast(int, Uint64) #size
|
||||
)
|
||||
@CustomPythonMethod
|
||||
def readAll(self):
|
||||
result = self.readBytes(self.getBase(), self.getExtent())
|
||||
if not result:
|
||||
raise Exception("expected readBytes to be successful!")
|
||||
return result
|
||||
|
||||
|
||||
if LLVM_VERSION >= (3, 4):
|
||||
@StringRefMemoryObject
|
||||
class StringRefMemoryObject:
|
||||
_include_ = "llvm/Support/StringRefMemoryObject.h"
|
||||
|
|
|
|||
|
|
@ -3,33 +3,36 @@ from llvmpy import api, extra
|
|||
|
||||
|
||||
def main():
|
||||
triple = "i386--"
|
||||
if llvm.version < (3, 4):
|
||||
return 0
|
||||
|
||||
print("init start")
|
||||
api.llvm.InitializeAllTargets()
|
||||
api.llvm.InitializeAllTargetInfos()
|
||||
api.llvm.InitializeAllTargetMCs()
|
||||
api.llvm.InitializeAllAsmParsers()
|
||||
api.llvm.InitializeAllAsmPrinters()
|
||||
api.llvm.InitializeAllDisassemblers()
|
||||
print("init done\n")
|
||||
triple = "i386--"
|
||||
|
||||
tm = llvm.target.TargetMachine.x86()
|
||||
if not tm:
|
||||
print("error: failed to lookup target x86 \n")
|
||||
return 1
|
||||
print("init start")
|
||||
api.llvm.InitializeAllTargets()
|
||||
api.llvm.InitializeAllTargetInfos()
|
||||
api.llvm.InitializeAllTargetMCs()
|
||||
api.llvm.InitializeAllAsmParsers()
|
||||
api.llvm.InitializeAllAsmPrinters()
|
||||
api.llvm.InitializeAllDisassemblers()
|
||||
print("init done\n")
|
||||
|
||||
print("created target machine\n")
|
||||
tm = llvm.target.TargetMachine.x86()
|
||||
if not tm:
|
||||
print("error: failed to lookup target x86 \n")
|
||||
return 1
|
||||
|
||||
MII = tm.instr_info
|
||||
if not MII:
|
||||
print("error: no instruction info for target " + triple + "\n")
|
||||
return 1
|
||||
print("created target machine\n")
|
||||
|
||||
print("created instr info\n")
|
||||
MID = MII.get(919) #int3
|
||||
print("INT3(%d): flags=0x%x, tsflags=0x%x\n" % (MID.getOpcode(), MID.getFlags(), MID.TSFlags))
|
||||
MII = tm.instr_info
|
||||
if not MII:
|
||||
print("error: no instruction info for target " + triple + "\n")
|
||||
return 1
|
||||
|
||||
return 0
|
||||
print("created instr info\n")
|
||||
MID = MII.get(919) #int3
|
||||
print("INT3(%d): flags=0x%x, tsflags=0x%x\n" % (MID.getOpcode(), MID.getFlags(), MID.TSFlags))
|
||||
|
||||
return 0
|
||||
|
||||
exit(main())
|
||||
|
|
@ -652,6 +652,9 @@ def do_llvm_target():
|
|||
tm.is_little_endian()
|
||||
|
||||
def do_llvm_mc():
|
||||
if llvm.version < (3, 4):
|
||||
return
|
||||
|
||||
from llvm import target
|
||||
from llvm import mc
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue