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