Skip to content

Commit 0168ba8

Browse files
committed
ARM:BX: update for conversion to C expressions (BX LR only)
1 parent 2416d9f commit 0168ba8

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

chb/arm/opcodes/ARMBranchExchange.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,24 @@ def returnval(self) -> "XXpr":
7575
def rreturnval(self) -> "XXpr":
7676
return self.xdata.get_return_xxpr()
7777

78+
def has_creturnval(self) -> bool:
79+
return self.xdata.has_return_cxpr()
80+
81+
def creturnval(self) -> "XXpr":
82+
return self.xdata.get_return_cxpr()
83+
7884
@property
7985
def annotation(self) -> str:
8086
if self.xdata.is_bx_call:
8187
return "bx-call"
8288
if self.has_return_xpr():
83-
return "return " + str(self.rreturnval())
89+
cx = (" (C: "
90+
+ (str(self.creturnval()) if self.has_creturnval() else "None")
91+
+ ")")
92+
if self.is_ok:
93+
return "return " + str(self.rreturnval()) + cx
94+
else:
95+
return "Error value"
8496
else:
8597
return "Not supported yet"
8698

@@ -116,17 +128,21 @@ def is_return_instruction(self, xdata: InstrXData) -> bool:
116128

117129
def return_value(self, xdata: InstrXData) -> Optional[XXpr]:
118130
xd = ARMBranchExchangeXData(xdata)
119-
if xd.has_return_xpr():
120-
return xd.rreturnval()
131+
if xd.has_creturnval():
132+
if xd.is_ok:
133+
return xd.creturnval()
134+
else:
135+
chklogger.logger.warning(
136+
"Return value is an error value")
137+
return None
121138
else:
122139
return None
123140

124141
def is_call(self, xdata: InstrXData) -> bool:
125-
return len(xdata.tags) >= 2 and xdata.tags[1] == "call"
142+
return xdata.has_call_target()
126143

127144
def is_call_instruction(self, xdata: InstrXData) -> bool:
128-
# return xdata.has_call_target()
129-
return False
145+
return xdata.has_call_target()
130146

131147
def call_target(self, xdata: InstrXData) -> "CallTarget":
132148
if self.is_call_instruction(xdata):
@@ -145,26 +161,9 @@ def argument_count(self, xdata: InstrXData) -> int:
145161
else:
146162
raise UF.CHBError("Instruction is not a call: " + str(self))
147163

148-
def arguments(self, xdata: InstrXData) -> Sequence[XXpr]:
149-
return xdata.xprs[:self.argument_count(xdata)]
150-
151164
def annotation(self, xdata: InstrXData) -> str:
152-
"""xdata format: a:x .
153-
154-
xprs[0]: target operand
155-
"""
156-
if self.is_call_instruction(xdata):
157-
tgt = xdata.call_target(self.ixd)
158-
args = ", ".join(str(x) for x in self.arguments(xdata))
159-
return "call " + str(tgt) + "(" + args + ")"
160-
161165
xd = ARMBranchExchangeXData(xdata)
162-
if xd.has_return_xpr and xd.is_ok:
163-
return xd.annotation
164-
elif xd.is_ok:
165-
return "goto " + str(xd.xxtgt)
166-
else:
167-
return "Error value"
166+
return xd.annotation
168167

169168
def assembly_ast(
170169
self,

0 commit comments

Comments
 (0)