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
@@ -73,8 +73,10 @@ def __init__(
7373 self .expanded = False
7474 self ._ssavals : List [XVariable ] = []
7575 self ._vars : List [XVariable ] = []
76+ self ._vars_r : List [Optional [XVariable ]] = []
7677 self ._types : List ["BCTyp" ] = []
7778 self ._xprs : List [XXpr ] = []
79+ self ._xprs_r : List [Optional [XXpr ]] = []
7880 self ._intervals : List [XInterval ] = []
7981 self ._strs : List [str ] = []
8082 self ._ints : List [int ] = []
@@ -121,6 +123,12 @@ def vars(self) -> List[XVariable]:
121123 self ._expand ()
122124 return self ._vars
123125
126+ @property
127+ def vars_r (self ) -> List [Optional [XVariable ]]:
128+ if not self .expanded :
129+ self ._expand ()
130+ return self ._vars_r
131+
124132 @property
125133 def types (self ) -> List ["BCTyp" ]:
126134 if not self .expanded :
@@ -161,12 +169,29 @@ def get_var(self, index: int) -> XVariable:
161169 + str (len (self .vars ))
162170 + ")" )
163171
172+ def get_var_x (self , index : int ) -> Optional [XVariable ]:
173+ if index < len (self .vars_r ):
174+ return self .vars_r [index ]
175+ else :
176+ raise UF .CHBError (
177+ "xdata: var-index out-of-bound: "
178+ + str (index )
179+ + " (length is "
180+ + str (len (self .vars ))
181+ + ")" )
182+
164183 @property
165184 def xprs (self ) -> List [XXpr ]:
166185 if not self .expanded :
167186 self ._expand ()
168187 return self ._xprs
169188
189+ @property
190+ def xprs_r (self ) -> List [Optional [XXpr ]]:
191+ if not self .expanded :
192+ self ._expand ()
193+ return self ._xprs_r
194+
170195 @property
171196 def intervals (self ) -> List [XInterval ]:
172197 if not self .expanded :
@@ -223,6 +248,18 @@ def reachingdeflocs_for_s(self, var: str) -> Sequence[XSymbol]:
223248 return rdef .deflocations
224249 return []
225250
251+ @property
252+ def is_ok (self ) -> bool :
253+ """Returns false if the data key is ar: and one or more of the
254+ variables and/or expressions are error values (None). Returns true
255+ otherwise."""
256+
257+ key = self .tags [0 ]
258+ if key .startswith ("ar:" ):
259+ return all (self .vars_r ) and all (self .xprs_r )
260+ else :
261+ return True
262+
226263 def _expand (self ) -> None :
227264 """Expand the arguments based on the argument string in the keys.
228265
@@ -240,49 +277,72 @@ def _expand(self) -> None:
240277 key = self .tags [0 ]
241278 if key .startswith ("a:" ):
242279 keyletters = key [2 :]
243- for (i , c ) in enumerate (keyletters ):
244- arg = self .args [i ]
245- xd = self .xprdictionary
246- bd = self .bdictionary
247- bcd = self .bcdictionary
248- if c == "v" :
280+ use_result = False
281+ elif key .startswith ("ar:" ):
282+ keyletters = key [3 :]
283+ use_result = True
284+ else :
285+ chklogger .logger .error (
286+ "InstrXData tag: %s not recognized" , key )
287+ return
288+
289+ for (i , c ) in enumerate (keyletters ):
290+ arg = self .args [i ]
291+ xd = self .xprdictionary
292+ bd = self .bdictionary
293+ bcd = self .bcdictionary
294+ if c == "v" :
295+ if use_result :
296+ if arg == - 2 :
297+ self ._vars_r .append (None )
298+ else :
299+ self ._vars_r .append (xd .variable (arg ))
300+ else :
249301 self ._vars .append (xd .variable (arg ))
250- elif c == "x" :
251- self ._xprs .append (xd .xpr (arg ))
252- elif c == "a" :
253- self ._xprs .append (xd .xpr (arg ))
254- elif c == "s" :
255- self ._strs .append (bd .string (arg ))
256- elif c == "i" :
257- self ._intervals .append (xd .interval (arg ))
258- elif c == "l" :
259- self ._ints .append (arg )
260- elif c == "t" :
261- self ._types .append (bcd .typ (arg ))
262- elif c == "r" :
263- varinvd = self .varinvdictionary
264- rdef = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
265- rdef = cast (Optional [ReachingDefFact ], rdef )
266- self ._reachingdefs .append (rdef )
267- elif c == "d" :
268- varinvd = self .varinvdictionary
269- use = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
270- use = cast (Optional [DefUse ], use )
271- self ._defuses .append (use )
272- elif c == "h" :
273- varinvd = self .varinvdictionary
274- usehigh = varinvd .var_invariant_fact (arg ) if arg > 0 else None
275- usehigh = cast (Optional [DefUseHigh ], usehigh )
276- self ._defuseshigh .append (usehigh )
277- elif c == "f" :
278- varinvd = self .varinvdictionary
279- flagrdef = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
280- flagrdef = cast (Optional [FlagReachingDefFact ], flagrdef )
281- self ._flagreachingdefs .append (flagrdef )
282- elif c == "c" :
283- self ._ssavals .append (xd .variable (arg ))
302+
303+ elif c == "x" :
304+ if use_result :
305+ if arg == - 2 :
306+ self ._xprs_r .append (None )
307+ else :
308+ self ._xprs_r .append (xd .xpr (arg ))
284309 else :
285- raise UF .CHBError ("Key letter not recognized: " + c )
310+ self ._xprs .append (xd .xpr (arg ))
311+
312+ elif c == "a" :
313+ self ._xprs .append (xd .xpr (arg ))
314+ elif c == "s" :
315+ self ._strs .append (bd .string (arg ))
316+ elif c == "i" :
317+ self ._intervals .append (xd .interval (arg ))
318+ elif c == "l" :
319+ self ._ints .append (arg )
320+ elif c == "t" :
321+ self ._types .append (bcd .typ (arg ))
322+ elif c == "r" :
323+ varinvd = self .varinvdictionary
324+ rdef = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
325+ rdef = cast (Optional [ReachingDefFact ], rdef )
326+ self ._reachingdefs .append (rdef )
327+ elif c == "d" :
328+ varinvd = self .varinvdictionary
329+ use = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
330+ use = cast (Optional [DefUse ], use )
331+ self ._defuses .append (use )
332+ elif c == "h" :
333+ varinvd = self .varinvdictionary
334+ usehigh = varinvd .var_invariant_fact (arg ) if arg > 0 else None
335+ usehigh = cast (Optional [DefUseHigh ], usehigh )
336+ self ._defuseshigh .append (usehigh )
337+ elif c == "f" :
338+ varinvd = self .varinvdictionary
339+ flagrdef = varinvd .var_invariant_fact (arg ) if arg >= 0 else None
340+ flagrdef = cast (Optional [FlagReachingDefFact ], flagrdef )
341+ self ._flagreachingdefs .append (flagrdef )
342+ elif c == "c" :
343+ self ._ssavals .append (xd .variable (arg ))
344+ else :
345+ raise UF .CHBError ("Key letter not recognized: " + c )
286346
287347 @property
288348 def is_function_argument (self ) -> bool :
0 commit comments