Skip to content

Commit b0cabde

Browse files
committed
ARM:BFC: conversion for result values
1 parent 3f806fd commit b0cabde

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

chb/arm/opcodes/ARMBitFieldClear.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2023 Aarno Labs LLC
7+
# Copyright (c) 2021-2025 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@
3030
from chb.app.InstrXData import InstrXData
3131

3232
from chb.arm.ARMDictionaryRecord import armregistry
33-
from chb.arm.ARMOpcode import ARMOpcode, simplify_result
33+
from chb.arm.ARMOpcode import ARMOpcode, ARMOpcodeXData, simplify_result
3434
from chb.arm.ARMOperand import ARMOperand
3535

3636
import chb.arm.ARMPseudoCode as APC
@@ -41,11 +41,34 @@
4141
import chb.invariants.XXprUtil as XU
4242

4343
import chb.util.fileutil as UF
44-
4544
from chb.util.IndexedTable import IndexedTableValue
45+
from chb.util.loggingutil import chklogger
4646

4747
if TYPE_CHECKING:
4848
from chb.arm.ARMDictionary import ARMDictionary
49+
from chb.invariants.XVariable import XVariable
50+
from chb.invariants.XXpr import XXpr
51+
52+
53+
class ARMBitFieldClearXData(ARMOpcodeXData):
54+
"""Data format:
55+
- variables:
56+
0: vrd
57+
58+
- expressions:
59+
0: xrd
60+
"""
61+
62+
def __init__(self, xdata: InstrXData) -> None:
63+
ARMOpcodeXData.__init__(self, xdata)
64+
65+
@property
66+
def vrd(self) -> "XVariable":
67+
return self.var(0, "vrd")
68+
69+
@property
70+
def xrd(self) -> "XXpr":
71+
return self.xpr(0, "xrd")
4972

5073

5174
@armregistry.register_tag("BFC", ARMOpcode)
@@ -60,10 +83,8 @@ class ARMBitFieldClear(ARMOpcode):
6083
args[2]: width
6184
args[3]: msb position
6285
63-
xdata format: a:vxrdh
64-
---------------------
65-
vars[0]: lhs (Rd)
66-
xprs[0]: rhs (Rd)
86+
xdata format
87+
------------
6788
rdefs[0]: rhs
6889
uses[0]: lhs
6990
useshigh[0]: lhs
@@ -102,8 +123,9 @@ def width(self) -> int:
102123
return self.args[2]
103124

104125
def annotation(self, xdata: InstrXData) -> str:
105-
lhs = str(xdata.vars[0])
106-
rhs = str(xdata.xprs[0])
126+
xd = ARMBitFieldClearXData(xdata)
127+
lhs = str(xd.vrd)
128+
rhs = str(xd.xrd)
107129
assignment = (
108130
lhs
109131
+ " := bit-field-clear("
@@ -112,13 +134,16 @@ def annotation(self, xdata: InstrXData) -> str:
112134
+ str(self.lsb)
113135
+ ", " + str(self.width)
114136
+ ")")
137+
return xd.add_instruction_condition(assignment)
138+
'''
115139
if xdata.has_unknown_instruction_condition():
116140
return "if ? then " + assignment
117141
elif xdata.has_instruction_condition():
118142
c = str(xdata.xprs[1])
119143
return "if " + c + " then " + assignment
120144
else:
121145
return assignment
146+
'''
122147

123148
def ast_prov(
124149
self,
@@ -149,6 +174,22 @@ def ast_prov(
149174
bytestring=bytestring,
150175
annotations=annotations)
151176

177+
rdefs = xdata.reachingdefs
178+
astree.add_expr_reachingdefs(ll_op1, [rdefs[0]])
179+
180+
# high-level assignment
181+
182+
xd = ARMBitFieldClearXData(xdata)
183+
184+
if not xd.is_ok:
185+
chklogger.logger.error(
186+
"BFC: Encountered error value for rhs at address %s", iaddr)
187+
return ([], [ll_assign])
188+
189+
lhs = xd.vrd
190+
rhsop = xd.xrd
191+
192+
'''
152193
lhsasts = XU.xvariable_to_ast_lvals(lhs, xdata, astree)
153194
if len(lhsasts) == 0:
154195
raise UF.CHBError("BitFieldClear (BFC): no lval found")
@@ -170,8 +211,11 @@ def ast_prov(
170211
+ ", ".join(str(v) for v in rhsasts))
171212
172213
hl_rhs1 = rhsasts[0]
214+
'''
173215

174-
hl_rhs = astree.mk_binary_op("band", hl_rhs1, maskconst)
216+
hl_lhs = XU.xvariable_to_ast_lval(lhs, xdata, iaddr, astree)
217+
hl_rhsop = XU.xxpr_to_ast_def_expr(rhsop, xdata, iaddr, astree)
218+
hl_rhs = astree.mk_binary_op("band", hl_rhsop, maskconst)
175219

176220
hl_assign = astree.mk_assign(
177221
hl_lhs,
@@ -184,7 +228,7 @@ def ast_prov(
184228
astree.add_instr_mapping(hl_assign, ll_assign)
185229
astree.add_instr_address(hl_assign, [iaddr])
186230
astree.add_expr_mapping(hl_rhs, ll_rhs)
187-
astree.add_expr_mapping(hl_rhs1, ll_op1)
231+
astree.add_expr_mapping(hl_rhsop, ll_op1)
188232
astree.add_lval_mapping(hl_lhs, ll_lhs)
189233
astree.add_expr_reachingdefs(ll_rhs, [rdefs[0]])
190234
astree.add_expr_reachingdefs(ll_op1, [rdefs[0]])

0 commit comments

Comments
 (0)