Skip to content

Commit 0940b73

Browse files
committed
ARM: add astprov support for Multiply
1 parent 465f45d commit 0940b73

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250309"
1+
chbversion: str = "0.3.0-20250312"

chb/arm/opcodes/ARMMultiply.py

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525
# SOFTWARE.
2626
# ------------------------------------------------------------------------------
2727

28-
from typing import List, TYPE_CHECKING
28+
from typing import List, Tuple, TYPE_CHECKING
2929

3030
from chb.app.InstrXData import InstrXData
3131

3232
from chb.arm.ARMDictionaryRecord import armregistry
3333
from chb.arm.ARMOpcode import ARMOpcode, ARMOpcodeXData, simplify_result
3434
from chb.arm.ARMOperand import ARMOperand
3535

36+
import chb.ast.ASTNode as AST
37+
from chb.astinterface.ASTInterface import ASTInterface
38+
39+
import chb.invariants.XXprUtil as XU
40+
3641
import chb.util.fileutil as UF
3742
from chb.util.IndexedTable import IndexedTableValue
3843
from chb.util.loggingutil import chklogger
@@ -67,7 +72,7 @@ def result(self) -> "XXpr":
6772

6873
@property
6974
def rresult(self) -> "XXpr":
70-
return self.xpr(3, "result")
75+
return self.xpr(3, "rresult")
7176

7277
@property
7378
def result_simplified(self) -> str:
@@ -101,9 +106,78 @@ def __init__(self, d: "ARMDictionary", ixval: IndexedTableValue) -> None:
101106
def operands(self) -> List[ARMOperand]:
102107
return [self.armd.arm_operand(i) for i in self.args[1:]]
103108

109+
@property
110+
def opargs(self) -> List[ARMOperand]:
111+
return [self.armd.arm_operand(i) for i in self.args[1:]]
112+
104113
def annotation(self, xdata: InstrXData) -> str:
105114
xd = ARMMultiplyXData(xdata)
106115
if xd.is_ok:
107116
return xd.annotation
108117
else:
109118
return "Error value"
119+
120+
def ast_prov(
121+
self,
122+
astree: ASTInterface,
123+
iaddr: str,
124+
bytestring: str,
125+
xdata: InstrXData) -> Tuple[
126+
List[AST.ASTInstruction], List[AST.ASTInstruction]]:
127+
128+
annotations: List[str] = [iaddr, "MUL"]
129+
130+
# low-level assignment
131+
132+
(ll_lhs, _, _) = self.opargs[0].ast_lvalue(astree)
133+
(ll_op1, _, _) = self.opargs[1].ast_rvalue(astree)
134+
(ll_op2, _, _) = self.opargs[2].ast_rvalue(astree)
135+
ll_rhs = astree.mk_binary_op("mult", ll_op1, ll_op2)
136+
137+
ll_assign = astree.mk_assign(
138+
ll_lhs,
139+
ll_rhs,
140+
iaddr=iaddr,
141+
bytestring=bytestring,
142+
annotations=annotations)
143+
144+
rdefs = xdata.reachingdefs
145+
146+
astree.add_expr_reachingdefs(ll_op1, [rdefs[0]])
147+
astree.add_expr_reachingdefs(ll_op2, [rdefs[1]])
148+
149+
# high-level assignment
150+
151+
xd = ARMMultiplyXData(xdata)
152+
if not xd.is_ok:
153+
chklogger.logger.error("Error value encountered at %s", iaddr)
154+
return ([], [])
155+
156+
lhs = xd.vrd
157+
rhs1 = xd.xrn
158+
rhs2 = xd.xrm
159+
rhs3 = xd.rresult
160+
161+
defuses = xdata.defuses
162+
defuseshigh = xdata.defuseshigh
163+
164+
hl_lhs = XU.xvariable_to_ast_lval(lhs, xdata, iaddr, astree)
165+
hl_rhs = XU.xxpr_to_ast_def_expr(rhs3, xdata, iaddr, astree)
166+
167+
hl_assign = astree.mk_assign(
168+
hl_lhs,
169+
hl_rhs,
170+
iaddr=iaddr,
171+
bytestring=bytestring,
172+
annotations=annotations)
173+
174+
astree.add_instr_mapping(hl_assign, ll_assign)
175+
astree.add_instr_address(hl_assign, [iaddr])
176+
astree.add_expr_mapping(hl_rhs, ll_rhs)
177+
astree.add_lval_mapping(hl_lhs, ll_lhs)
178+
astree.add_expr_reachingdefs(hl_rhs, rdefs[2:])
179+
astree.add_expr_reachingdefs(ll_rhs, rdefs[:2])
180+
astree.add_lval_defuses(hl_lhs, defuses[0])
181+
astree.add_lval_defuses_high(hl_lhs, defuseshigh[0])
182+
183+
return ([hl_assign], [ll_assign])

chb/arm/opcodes/ARMStoreMultipleIncrementAfter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ def ast_prov(
417417
if xdata.instruction_subsumes():
418418
return self.ast_prov_ldmstmcopy(astree, iaddr, bytestring, xdata)
419419

420+
else:
421+
chklogger.logger.error(
422+
"AST conversion of STM not yet supported at address %s",
423+
iaddr)
424+
return ([], [])
425+
420426
regcount = len(xdata.reachingdefs) - 1
421427
baselhs = xdata.vars[0]
422428
memlhss = xdata.vars[1:]

0 commit comments

Comments
 (0)