44# ------------------------------------------------------------------------------
55# The MIT License (MIT)
66#
7- # Copyright (c) 2021-2024 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
3030from chb .app .InstrXData import InstrXData
3131
3232from chb .arm .ARMDictionaryRecord import armregistry
33- from chb .arm .ARMOpcode import ARMOpcode , simplify_result
33+ from chb .arm .ARMOpcode import ARMOpcode , ARMOpcodeXData , simplify_result
3434from chb .arm .ARMOperand import ARMOperand
3535
3636import chb .util .fileutil as UF
3939from chb .astinterface .ASTInterface import ASTInterface
4040
4141import chb .invariants .XXprUtil as XU
42-
4342from chb .util .IndexedTable import IndexedTableValue
43+ from chb .util .loggingutil import chklogger
4444
4545if TYPE_CHECKING :
46- import chb .arm .ARMDictionary
46+ from chb .arm .ARMDictionary import ARMDictionary
47+ from chb .invariants .XVariable import XVariable
48+ from chb .invariants .XXpr import XXpr
49+
50+
51+ class ARMBitwiseExclusiveOrXData (ARMOpcodeXData ):
52+
53+ def __init__ (self , xdata : InstrXData ) -> None :
54+ ARMOpcodeXData .__init__ (self , xdata )
55+
56+ @property
57+ def vrd (self ) -> "XVariable" :
58+ return self .var (0 , "vrd" )
59+
60+ @property
61+ def xrn (self ) -> "XXpr" :
62+ return self .xpr (0 , "xrn" )
63+
64+ @property
65+ def xrm (self ) -> "XXpr" :
66+ return self .xpr (1 , "xrm" )
67+
68+ @property
69+ def result (self ) -> "XXpr" :
70+ return self .xpr (2 , "result" )
71+
72+ @property
73+ def rresult (self ) -> "XXpr" :
74+ return self .xpr (3 , "rresult" )
75+
76+ @property
77+ def result_simplified (self ) -> str :
78+ return simplify_result (
79+ self .xdata .args [3 ], self .xdata .args [4 ], self .result , self .rresult )
80+
81+ @property
82+ def annotation (self ) -> str :
83+ assignment = str (self .vrd ) + " := " + self .result_simplified
84+ return self .add_instruction_condition (assignment )
4785
4886
4987@armregistry .register_tag ("EOR" , ARMOpcode )
@@ -74,10 +112,7 @@ class ARMBitwiseExclusiveOr(ARMOpcode):
74112 useshigh[0]: lhs
75113 """
76114
77- def __init__ (
78- self ,
79- d : "chb.arm.ARMDictionary.ARMDictionary" ,
80- ixval : IndexedTableValue ) -> None :
115+ def __init__ (self , d : "ARMDictionary" , ixval : IndexedTableValue ) -> None :
81116 ARMOpcode .__init__ (self , d , ixval )
82117 self .check_key (2 , 5 , "BitwiseExclusiveOr" )
83118
@@ -95,18 +130,11 @@ def opargs(self) -> List[ARMOperand]:
95130 return [self .armd .arm_operand (i ) for i in self .args [1 : - 1 ]]
96131
97132 def annotation (self , xdata : InstrXData ) -> str :
98- lhs = str (xdata .vars [0 ])
99- result = xdata .xprs [2 ]
100- rresult = xdata .xprs [3 ]
101- xresult = simplify_result (xdata .args [3 ], xdata .args [4 ], result , rresult )
102- assignment = lhs + " := " + xresult
103- if xdata .has_unknown_instruction_condition ():
104- return "if ? then " + assignment
105- elif xdata .has_instruction_condition ():
106- c = str (xdata .xprs [1 ])
107- return "if " + c + " then " + assignment
133+ xd = ARMBitwiseExclusiveOrXData (xdata )
134+ if xd .is_ok :
135+ return xd .annotation
108136 else :
109- return assignment
137+ return "Error value"
110138
111139 def ast_prov (
112140 self ,
@@ -137,8 +165,14 @@ def ast_prov(
137165
138166 # high-level assignment
139167
140- lhs = xdata .vars [0 ]
141- rhs = xdata .xprs [3 ]
168+ xd = ARMBitwiseExclusiveOrXData (xdata )
169+ if not xd .is_ok :
170+ chklogger .logger .error (
171+ "Encountered error value at address %s" , iaddr )
172+ return ([], [])
173+
174+ lhs = xd .vrd
175+ rhs = xd .rresult
142176 defuses = xdata .defuses
143177 defuseshigh = xdata .defuseshigh
144178
0 commit comments