added methods to Instr which describe possible branch/terminator properties
This commit is contained in:
parent
65c4558cac
commit
3e77a55de3
3 changed files with 45 additions and 0 deletions
|
|
@ -105,6 +105,26 @@ class Instr(object):
|
|||
def opcode(self):
|
||||
return self.mcinst.getOpcode()
|
||||
|
||||
def is_branch(self):
|
||||
return self.tm.instr_analysis.isBranch(self.mcinst)
|
||||
|
||||
def is_cond_branch(self):
|
||||
return self.tm.instr_analysis.isConditionalBranch(self.mcinst)
|
||||
|
||||
def is_uncond_branch(self):
|
||||
return self.tm.instr_analysis.isUnconditionalBranch(self.mcinst)
|
||||
|
||||
def is_indirect_branch(self):
|
||||
return self.tm.instr_analysis.isIndirectBranch(self.mcinst)
|
||||
|
||||
def is_call(self):
|
||||
return self.tm.instr_analysis.isCall(self.mcinst)
|
||||
|
||||
def is_return(self):
|
||||
return self.tm.instr_analysis.isReturn(self.mcinst)
|
||||
|
||||
def is_terminator(self):
|
||||
return self.tm.instr_analysis.isTerminator(self.mcinst)
|
||||
|
||||
class BadInstr(Instr):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -105,6 +105,18 @@ class TargetInstrInfo:
|
|||
class MCInstrAnalysis:
|
||||
_include_ = "llvm/MC/MCInstrAnalysis.h"
|
||||
|
||||
|
||||
def _take_mcinst_ret_bool():
|
||||
return Method(cast(Bool, bool), const(ref(MCInst)))
|
||||
|
||||
isBranch = _take_mcinst_ret_bool()
|
||||
isConditionalBranch = _take_mcinst_ret_bool()
|
||||
isUnconditionalBranch = _take_mcinst_ret_bool()
|
||||
isIndirectBranch = _take_mcinst_ret_bool()
|
||||
isCall = _take_mcinst_ret_bool()
|
||||
isReturn = _take_mcinst_ret_bool()
|
||||
isTerminator = _take_mcinst_ret_bool()
|
||||
|
||||
@MCInstPrinter
|
||||
class MCInstPrinter:
|
||||
_include_ = "llvm/MC/MCInstPrinter.h"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ if llvm.version >= (3, 4):
|
|||
llvm.target.initialize_all()
|
||||
|
||||
def print_instructions(dasm, bs):
|
||||
branch_properties = [
|
||||
'is_branch',
|
||||
'is_cond_branch',
|
||||
'is_uncond_branch',
|
||||
'is_indirect_branch',
|
||||
'is_call',
|
||||
'is_return',
|
||||
'is_terminator'
|
||||
]
|
||||
|
||||
print("print instructions")
|
||||
for (addr, data, inst) in dasm.decode(bs, 0x4000):
|
||||
|
||||
|
|
@ -25,6 +35,9 @@ if llvm.version >= (3, 4):
|
|||
for line in str(inst).split("\n"):
|
||||
print("\t\t%-24s %s" % ("".join(map(lambda b: "%02x" % b, data))+":", line.strip()))
|
||||
|
||||
for bp in branch_properties:
|
||||
print("\t\t%-22s%r" % (bp+":", getattr(inst, bp)() ))
|
||||
|
||||
|
||||
x86 = TargetMachine.x86()
|
||||
print("x86: LE=%s" % x86.is_little_endian())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue