|
28 | 28 |
|
29 | 29 | Note: the boolean argument 'anonymous' is used for lvals: when true no new |
30 | 30 | 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 | +
|
32 | 34 | """ |
33 | 35 |
|
34 | 36 | from codecs import decode |
|
55 | 57 | VMemoryVariable, VAuxiliaryVariable, VRegisterVariable) |
56 | 58 | from chb.invariants.VConstantValueVariable import ( |
57 | 59 | VInitialRegisterValue, VInitialMemoryValue, VFunctionReturnValue, |
58 | | - VTypeCastValue, SymbolicValue, MemoryAddress) |
| 60 | + VTypeCastValue, SymbolicValue) |
59 | 61 | from chb.invariants.VMemoryBase import ( |
60 | 62 | VMemoryBase, |
61 | 63 | VMemoryBaseBaseVar, |
@@ -181,44 +183,6 @@ def xxpr_to_ast_expr( |
181 | 183 | return astree.mk_temp_lval_expression() |
182 | 184 |
|
183 | 185 |
|
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 | | - |
222 | 186 | def vinitregister_value_to_ast_lval_expression( |
223 | 187 | vconstvar: "VInitialRegisterValue", |
224 | 188 | xdata: "InstrXData", |
@@ -849,25 +813,6 @@ def xvariable_to_ast_def_lval_expression( |
849 | 813 | return memory_variable_to_lval_expression( |
850 | 814 | memvar.base, memvar.offset, xdata, iaddr, astree, anonymous=anonymous) |
851 | 815 |
|
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 | | - |
871 | 816 | if xvar.is_typecast_value: |
872 | 817 | tcvar = cast("VTypeCastValue", xvar.denotation.auxvar) |
873 | 818 | variaddr = tcvar.iaddr |
@@ -1326,10 +1271,6 @@ def xxpr_to_ast_def_expr( |
1326 | 1271 | if xpr.is_constant: |
1327 | 1272 | return xxpr_to_ast_expr(xpr, xdata, iaddr, astree, anonymous=anonymous) |
1328 | 1273 |
|
1329 | | - if xpr.is_memory_address_value: |
1330 | | - return xxpr_memory_address_value_to_ast_expr( |
1331 | | - xpr, xdata, iaddr, astree, anonymous=anonymous) |
1332 | | - |
1333 | 1274 | if xpr.is_stack_address: |
1334 | 1275 | return stack_address_to_ast_expr( |
1335 | 1276 | xpr, xdata, iaddr, astree, anonymous=anonymous) |
@@ -1453,95 +1394,6 @@ def field_offset_to_ast_offset( |
1453 | 1394 | offset.fieldname, offset.ckey, offset=suboffset) |
1454 | 1395 |
|
1455 | 1396 |
|
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 | | - |
1545 | 1397 | def global_variable_to_ast_lval( |
1546 | 1398 | offset: "VMemoryOffset", |
1547 | 1399 | xdata: "InstrXData", |
@@ -1700,54 +1552,6 @@ def xvariable_to_ast_lval( |
1700 | 1552 | memaddr=memaddr, |
1701 | 1553 | anonymous=anonymous) |
1702 | 1554 |
|
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 | | - |
1751 | 1555 | elif ( |
1752 | 1556 | xv.is_memory_variable |
1753 | 1557 | and cast("VMemoryVariable", |
|
0 commit comments