Skip to content

Commit b0e1c0a

Browse files
committed
REP: small fix for patchcandidates on MIPS
don't use the hardcoded ARM attribute to access the function from the instruction object. This adds a new abstract method/property to the generic Instruction class which returns the associated Function. All the arch-specific instructions already had a member for it but with an arch-specific name so this new property just wraps around that
1 parent 1d898e0 commit b0e1c0a

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

chb/app/Instruction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from chb.bctypes.BCTyp import BCTyp
6363
from chb.invariants.XVariable import XVariable
6464
from chb.invariants.XXpr import XXpr
65+
from chb.app.Function import Function
6566

6667

6768
class Instruction(ABC):
@@ -97,6 +98,11 @@ def mnemonic_stem(self) -> str:
9798

9899
return self.mnemonic
99100

101+
@property
102+
@abstractmethod
103+
def function(self) -> 'Function':
104+
...
105+
100106
@property
101107
@abstractmethod
102108
def opcodetext(self) -> str:

chb/arm/ARMInstruction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def __init__(self, armblock: "ARMBlock", xnode: ET.Element) -> None:
8080
def armblock(self) -> "ARMBlock":
8181
return self._armblock
8282

83+
@property
84+
def function(self) -> "ARMFunction":
85+
return self.armfunction
86+
8387
@property
8488
def armfunction(self) -> "ARMFunction":
8589
return self.armblock.armfunction

chb/cmdline/reportcmds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,15 @@ def include_target(target: 'CallTarget') -> bool:
11791179
patchcallsites = libcalls.patch_callsites()
11801180

11811181
for pc in sorted(patchcallsites, key=lambda pc:pc.faddr):
1182-
instr = cast("ARMInstruction", pc.instr)
1182+
instr = pc.instr
11831183
dstarg = pc.dstarg
11841184
if dstarg is None:
11851185
chklogger.logger.warning(
11861186
"No expression found for destination argument: %s",
11871187
str(instr))
11881188
continue
11891189
dstoffset = dstarg.stack_address_offset()
1190-
fn = instr.armfunction
1190+
fn = instr.function
11911191
stackframe = fn.stackframe
11921192
stackbuffer = stackframe.get_stack_buffer(dstoffset)
11931193
if stackbuffer is None:

chb/pwr/PowerInstruction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def pwrblock(self) -> "PowerBlock":
7474
def pwrfunction(self) -> "PowerFunction":
7575
return self.pwrblock.pwrfunction
7676

77+
@property
78+
def function(self) -> "PowerFunction":
79+
return self.pwrfunction
80+
7781
@property
7882
def pwrdictionary(self) -> "PowerDictionary":
7983
return self.pwrblock.pwrdictionary

chb/x86/X86Instruction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def x86functiondictionary(self) -> "FunctionDictionary":
9191
def x86function(self) -> "X86Function":
9292
return self.x86block.x86function
9393

94+
@property
95+
def function(self) -> "X86Function":
96+
return self.x86function
97+
9498
@property
9599
def opcode(self) -> X86Opcode:
96100
if self._opcode is None:

0 commit comments

Comments
 (0)