Skip to content

Commit 640e86f

Browse files
committed
XPR: remove MemoryAddress
1 parent 7eacf6a commit 640e86f

File tree

5 files changed

+8
-273
lines changed

5 files changed

+8
-273
lines changed

chb/arm/opcodes/ARMTest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def __init__(self, d: "ARMDictionary", ixval: IndexedTableValue) -> None:
8787
ARMOpcode.__init__(self, d, ixval)
8888
self.check_key(2, 3, "Test")
8989

90+
@property
91+
def opargs(self) -> List[ARMOperand]:
92+
return [self.armd.arm_operand(self.args[i]) for i in [0, 1]]
93+
9094
@property
9195
def operands(self) -> List[ARMOperand]:
9296
return [self.armd.arm_operand(self.args[i]) for i in [0, 1]]

chb/invariants/VConstantValueVariable.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161
ctxt_iaddress_t
6262
* string
6363
* bool
64-
| MemoryAddress of
65-
int * memory_offset_t * string option "ma" 1 2
6664
| BridgeVariable of ctxt_iaddress_t * int "bv" 2 1
6765
| FieldValue of string * int * string "fv" 1 3
6866
| SymbolicValue of xpr_t "sv" 1 1
@@ -124,10 +122,6 @@ def is_frozen_test_value(self) -> bool:
124122
def is_bridge_variable(self) -> bool:
125123
return False
126124

127-
@property
128-
def is_memory_address(self) -> bool:
129-
return False
130-
131125
@property
132126
def is_global_value(self) -> bool:
133127
return False
@@ -739,58 +733,6 @@ def __str__(self) -> str:
739733
return self.name
740734

741735

742-
@varregistry.register_tag("ma", VConstantValueVariable)
743-
class MemoryAddress(VConstantValueVariable):
744-
"""Address of memory variable.
745-
746-
args[0]: index of memory base in vardictionary
747-
args[1]: index of memory offset in vardictionary
748-
args[2]: index of optional name or -1
749-
"""
750-
751-
def __init__(
752-
self,
753-
vd: "FnVarDictionary",
754-
ixval: IndexedTableValue) -> None:
755-
VConstantValueVariable.__init__(self, vd, ixval)
756-
757-
@property
758-
def is_memory_address(self) -> bool:
759-
return True
760-
761-
@property
762-
def base(self) -> VMemoryBase:
763-
return self.vd.memory_base(self.args[0])
764-
765-
@property
766-
def offset(self) -> VMemoryOffset:
767-
return self.vd.memory_offset(self.args[1])
768-
769-
@property
770-
def name(self) -> Optional[str]:
771-
if self.args[2] == -1:
772-
return None
773-
else:
774-
return self.bd.string(self.args[2])
775-
776-
def to_json_result(self) -> JSONResult:
777-
jbase = self.base.to_json_result()
778-
if not jbase.is_ok:
779-
return JSONResult("auxvariable", {}, "fail", jbase.reason)
780-
joffset = self.offset.to_json_result()
781-
if not joffset.is_ok:
782-
return JSONResult("auxvariable", {}, "fail", joffset.reason)
783-
content: Dict[str, Any] = {}
784-
content["kind"] = "ma"
785-
content["base"] = jbase.content
786-
content["offset"] = joffset.content
787-
content["txtrep"] = str(self)
788-
return JSONResult("auxvariable", content, "ok")
789-
790-
def __str__(self) -> str:
791-
return str(self.base) + " + " + str(self.offset)
792-
793-
794736
@varregistry.register_tag("fv", VConstantValueVariable)
795737
class FieldValue(VConstantValueVariable):
796738
"""Symbolic representation of a field in a struct.

chb/invariants/XVariable.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ def is_typecast_value(self) -> bool:
123123
and self.denotation.is_auxiliary_variable
124124
and self.denotation.auxvar.is_typecast_value)
125125

126-
@property
127-
def is_memory_address_value(self) -> bool:
128-
return (
129-
self.has_denotation()
130-
and self.denotation.is_auxiliary_variable
131-
and self.denotation.auxvar.is_memory_address)
132-
133126
@property
134127
def is_symbolic_expr_value(self) -> bool:
135128
return (

chb/invariants/XXpr.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ def is_attr(self) -> bool:
164164
def is_four_multiple(self) -> bool:
165165
return False
166166

167-
@property
168-
def is_memory_address_value(self) -> bool:
169-
return False
170-
171167
@property
172168
def is_stack_base_address(self) -> bool:
173169
return False
@@ -370,10 +366,6 @@ def is_initial_register_value(self) -> bool:
370366
def is_var(self) -> bool:
371367
return True
372368

373-
@property
374-
def is_memory_address_value(self) -> bool:
375-
return self.variable.is_memory_address_value
376-
377369
@property
378370
def is_tmp_variable(self) -> bool:
379371
return self.variable.is_tmp

chb/invariants/XXprUtil.py

Lines changed: 4 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
2929
Note: the boolean argument 'anonymous' is used for lvals: when true no new
3030
lvalid is generated for that lval. The argument is primarily used in the
31-
conversion of invariants to available expressions.
31+
conversion of invariants to available expressions. Also, errors are not
32+
generated if anonymous is true.
33+
3234
"""
3335

3436
from codecs import decode
@@ -55,7 +57,7 @@
5557
VMemoryVariable, VAuxiliaryVariable, VRegisterVariable)
5658
from chb.invariants.VConstantValueVariable import (
5759
VInitialRegisterValue, VInitialMemoryValue, VFunctionReturnValue,
58-
VTypeCastValue, SymbolicValue, MemoryAddress)
60+
VTypeCastValue, SymbolicValue)
5961
from chb.invariants.VMemoryBase import (
6062
VMemoryBase,
6163
VMemoryBaseBaseVar,
@@ -181,44 +183,6 @@ def xxpr_to_ast_expr(
181183
return astree.mk_temp_lval_expression()
182184

183185

184-
def xxpr_memory_address_value_to_ast_expr(
185-
xpr: X.XXpr,
186-
xdata: "InstrXData",
187-
iaddr: str,
188-
astree: ASTInterface,
189-
anonymous: bool = False) -> AST.ASTExpr:
190-
191-
if not xpr.is_memory_address_value:
192-
chklogger.logger.error(
193-
"Encountered expression that is not a memory address value: %s "
194-
+ "at address %s",
195-
str(xpr), iaddr)
196-
197-
xvar = cast(X.XprVariable, xpr).variable
198-
addr = cast("MemoryAddress", xvar.denotation.auxvar)
199-
name = addr.name
200-
if name is None:
201-
chklogger.logger.error(
202-
"AST conversion of unnamed memory address value %s not yet "
203-
+ "supported at address %s",
204-
str(xvar), iaddr)
205-
return astree.mk_temp_lval_expression()
206-
207-
if not astree.globalsymboltable.has_symbol(name):
208-
chklogger.logger.error(
209-
"AST conversion of memory address value %s not in global symbol "
210-
+ "table not yet supported at address %s",
211-
str(xvar), iaddr)
212-
return astree.mk_temp_lval_expression()
213-
214-
vinfo = astree.globalsymboltable.get_symbol(name)
215-
lval = astree.mk_vinfo_lval(vinfo)
216-
if vinfo.vtype is not None and vinfo.vtype.is_array:
217-
return astree.mk_start_of(lval)
218-
else:
219-
return astree.mk_address_of(lval)
220-
221-
222186
def vinitregister_value_to_ast_lval_expression(
223187
vconstvar: "VInitialRegisterValue",
224188
xdata: "InstrXData",
@@ -849,25 +813,6 @@ def xvariable_to_ast_def_lval_expression(
849813
return memory_variable_to_lval_expression(
850814
memvar.base, memvar.offset, xdata, iaddr, astree, anonymous=anonymous)
851815

852-
if xvar.is_memory_address_value:
853-
addr = cast("MemoryAddress", xvar.denotation.auxvar)
854-
name = addr.name
855-
if name is None:
856-
chklogger.logger.error(
857-
"AST def conversion of unnamed memory address variable %s to "
858-
+ "lval at address %s not yet supported",
859-
str(xvar), iaddr)
860-
return astree.mk_temp_lval_expression()
861-
862-
if not astree.globalsymboltable.has_symbol(name):
863-
chklogger.logger.error(
864-
"AST def conversion of memory address % to lval at address %s "
865-
+ "not yet supported",
866-
name, iaddr)
867-
868-
vinfo = astree.globalsymboltable.get_symbol(name)
869-
return astree.mk_vinfo_lval_expression(vinfo, anonymous=anonymous)
870-
871816
if xvar.is_typecast_value:
872817
tcvar = cast("VTypeCastValue", xvar.denotation.auxvar)
873818
variaddr = tcvar.iaddr
@@ -1326,10 +1271,6 @@ def xxpr_to_ast_def_expr(
13261271
if xpr.is_constant:
13271272
return xxpr_to_ast_expr(xpr, xdata, iaddr, astree, anonymous=anonymous)
13281273

1329-
if xpr.is_memory_address_value:
1330-
return xxpr_memory_address_value_to_ast_expr(
1331-
xpr, xdata, iaddr, astree, anonymous=anonymous)
1332-
13331274
if xpr.is_stack_address:
13341275
return stack_address_to_ast_expr(
13351276
xpr, xdata, iaddr, astree, anonymous=anonymous)
@@ -1453,95 +1394,6 @@ def field_offset_to_ast_offset(
14531394
offset.fieldname, offset.ckey, offset=suboffset)
14541395

14551396

1456-
def array_variable_to_ast_lval(
1457-
base: "MemoryAddress",
1458-
elementtyp: AST.ASTTyp,
1459-
offset: "VMemoryOffset",
1460-
xdata: "InstrXData",
1461-
iaddr: str,
1462-
astree: ASTInterface,
1463-
anonymous: bool = False) -> AST.ASTLval:
1464-
1465-
name = base.name
1466-
if name is None:
1467-
chklogger.logger.error(
1468-
"AST conversion of array variable at %s encountered nameless "
1469-
+ "base %s",
1470-
str(iaddr), str(base))
1471-
return astree.mk_temp_lval()
1472-
1473-
if not astree.globalsymboltable.has_symbol(name):
1474-
chklogger.logger.error(
1475-
"AST conversion of memory address value %s not in global symbol "
1476-
+ " table not yet supported at address %s",
1477-
str(name), iaddr)
1478-
return astree.mk_temp_lval()
1479-
1480-
vinfo = astree.globalsymboltable.get_symbol(name)
1481-
if not offset.is_array_index_offset:
1482-
chklogger.logger.error(
1483-
"AST conversion of array variable expected to find array index "
1484-
+ "offset, but found %s at address %s",
1485-
str(offset), iaddr)
1486-
return astree.mk_temp_lval()
1487-
1488-
astoffset = array_offset_to_ast_offset(
1489-
cast("VMemoryOffsetArrayIndexOffset", offset),
1490-
xdata,
1491-
iaddr,
1492-
astree,
1493-
anonymous=anonymous)
1494-
1495-
return astree.mk_vinfo_lval(vinfo, offset=astoffset, anonymous=anonymous)
1496-
1497-
chklogger.logger.error(
1498-
"Array variable to astlval still in progress at %s for %s with offset %s",
1499-
iaddr, str(base), str(offset))
1500-
return astree.mk_temp_lval()
1501-
1502-
1503-
def struct_variable_to_ast_lval(
1504-
base: "MemoryAddress",
1505-
structtyp: AST.ASTTypComp,
1506-
offset: "VMemoryOffset",
1507-
xdata: "InstrXData",
1508-
iaddr: str,
1509-
astree: ASTInterface,
1510-
anonymous: bool = False) -> AST.ASTLval:
1511-
1512-
name = base.name
1513-
if name is None:
1514-
chklogger.logger.error(
1515-
"AST conversion of struct variable at %s encountered nameless "
1516-
+ "base %s",
1517-
str(iaddr), str(base))
1518-
return astree.mk_temp_lval()
1519-
1520-
if not astree.globalsymboltable.has_symbol(name):
1521-
chklogger.logger.error(
1522-
"AST conversion of memory address value %s not in global symbol "
1523-
+ " table not yet supported at address %s",
1524-
str(name), iaddr)
1525-
return astree.mk_temp_lval()
1526-
1527-
vinfo = astree.globalsymboltable.get_symbol(name)
1528-
if not offset.is_field_offset:
1529-
chklogger.logger.error(
1530-
"AST conversion of struct variable expected to find field offset "
1531-
+ "but found %s at address %s",
1532-
str(offset), iaddr)
1533-
return astree.mk_temp_lval()
1534-
1535-
astoffset = field_offset_to_ast_offset(
1536-
cast("VMemoryOffsetFieldOffset", offset),
1537-
xdata,
1538-
iaddr,
1539-
astree,
1540-
anonymous=anonymous)
1541-
1542-
return astree.mk_vinfo_lval(vinfo, offset=astoffset, anonymous=anonymous)
1543-
1544-
15451397
def global_variable_to_ast_lval(
15461398
offset: "VMemoryOffset",
15471399
xdata: "InstrXData",
@@ -1700,54 +1552,6 @@ def xvariable_to_ast_lval(
17001552
memaddr=memaddr,
17011553
anonymous=anonymous)
17021554

1703-
elif (
1704-
xv.is_memory_variable
1705-
and cast("VMemoryVariable",
1706-
xv.denotation).base.is_basearray):
1707-
xvmem = cast("VMemoryVariable", xv.denotation)
1708-
base = cast("VMemoryBaseBaseArray", xvmem.base).basearray
1709-
if not base.is_memory_address_value:
1710-
chklogger.logger.error(
1711-
"AST conversion of lval %s encountered invalid BaseArray at %s",
1712-
str(xv), iaddr)
1713-
return astree.mk_temp_lval()
1714-
basevar = cast("MemoryAddress", base.denotation.auxvar)
1715-
basetyp = cast(
1716-
"VMemoryBaseBaseArray",
1717-
xvmem.base).basetyp.convert(astree.typconverter)
1718-
return array_variable_to_ast_lval(
1719-
basevar,
1720-
cast(AST.ASTTypArray, basetyp).tgttyp,
1721-
xvmem.offset,
1722-
xdata,
1723-
iaddr,
1724-
astree,
1725-
anonymous=anonymous)
1726-
1727-
elif (
1728-
xv.is_memory_variable
1729-
and cast("VMemoryVariable",
1730-
xv.denotation).base.is_basestruct):
1731-
xvmem = cast("VMemoryVariable", xv.denotation)
1732-
base = cast("VMemoryBaseBaseStruct", xvmem.base).basestruct
1733-
if not base.is_memory_address_value:
1734-
chklogger.logger.error(
1735-
"AST conversion of lval %s encountered invalie BaseStruct at %s",
1736-
str(xv), iaddr)
1737-
return astree.mk_temp_lval()
1738-
basevar = cast("MemoryAddress", base.denotation.auxvar)
1739-
basetyp = cast(
1740-
"VMemoryBaseBaseStruct",
1741-
xvmem.base).basetyp.convert(astree.typconverter)
1742-
return struct_variable_to_ast_lval(
1743-
basevar,
1744-
cast(AST.ASTTypComp, basetyp),
1745-
xvmem.offset,
1746-
xdata,
1747-
iaddr,
1748-
astree,
1749-
anonymous=anonymous)
1750-
17511555
elif (
17521556
xv.is_memory_variable
17531557
and cast("VMemoryVariable",

0 commit comments

Comments
 (0)