Skip to content

Commit 7ccc8e3

Browse files
committed
TYP: add support for volatile global variables
1 parent b406023 commit 7ccc8e3

File tree

11 files changed

+75
-7
lines changed

11 files changed

+75
-7
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250821"
1+
chbversion: str = "0.3.0-20250823"

chb/app/GlobalMemoryMap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ def gtype(self) -> Optional["BCTyp"]:
206206
return self.mmap.bcdictionary.typ(int(tix))
207207
return None
208208

209+
@property
210+
def is_volatile(self) -> bool:
211+
return self.gtype is not None and self.gtype.is_volatile
212+
209213
@property
210214
def size(self) -> Optional[int]:
211215
s = self._xnode.get("size", None)

chb/arm/opcodes/ARMLoadRegisterHalfword.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,8 @@ def has_cast() -> bool:
251251

252252
if xd.is_ok:
253253
rhs = xd.cxrmem
254-
rhsval = None if has_cast() else xd.cxrmem
255254
hl_lhs = XU.xvariable_to_ast_lval(
256-
lhs, xdata, iaddr, astree, rhs=rhsval)
255+
lhs, xdata, iaddr, astree, rhs=xd.cxrmem)
257256
hl_rhs = XU.xxpr_to_ast_def_expr(rhs, xdata, iaddr, astree)
258257

259258
elif xd.is_cxaddr_ok:

chb/bctypes/BCAttribute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def name(self) -> str:
5353
def params(self) -> List["BCAttrParam"]:
5454
return [self.bcd.attrparam(i) for i in self.args]
5555

56+
@property
57+
def is_volatile(self) -> bool:
58+
return self.name == "volatile"
59+
5660
def __str__(self) -> str:
5761
return self.name + "(" + ", ".join(str(p) for p in self.params) + ")"
5862

chb/bctypes/BCTyp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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
@@ -191,6 +191,10 @@ def is_typedef(self) -> bool:
191191
def is_unknown(self) -> bool:
192192
return False
193193

194+
@property
195+
def is_volatile(self) -> bool:
196+
return any(a.is_volatile for a in self.attrs)
197+
194198
@property
195199
def attrs(self) -> List["BCAttribute"]:
196200
attrs = self.bcd.attributes(self.args[-1])

chb/cmdline/commandutil.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,11 +2534,16 @@ def ddata_gvars(args: argparse.Namespace) -> NoReturn:
25342534
sgtype = str(gtype)
25352535
else:
25362536
sgtype = ""
2537+
if gloc.is_volatile:
2538+
vt = " (volatile)"
2539+
else:
2540+
vt = ""
25372541
print(gloc.addr.rjust(8)
25382542
+ " "
25392543
+ gloc.name.ljust(60)
25402544
+ " "
2541-
+ sgtype.ljust(20))
2545+
+ sgtype.ljust(20)
2546+
+ vt)
25422547

25432548
(count, coverage) = memmap.coverage()
25442549

chb/invariants/VAssemblyVariable.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
"""
4141

42-
from typing import Any, Dict, List, Sequence, Tuple, TYPE_CHECKING
42+
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING
4343

4444
from chb.app.Register import Register
4545

@@ -96,6 +96,9 @@ def is_auxiliary_variable(self) -> bool:
9696
def is_global_variable(self) -> bool:
9797
return False
9898

99+
def get_global_variable_address(self) -> Optional[str]:
100+
return None
101+
99102
@property
100103
def is_global_value(self) -> bool:
101104
return False
@@ -297,6 +300,12 @@ def argument_index(self) -> int:
297300
"Assembly variable is not a stack argument: "
298301
+ str(self))
299302

303+
def get_global_variable_address(self) -> Optional[str]:
304+
if self.is_global_variable:
305+
if self.offset.is_constant_value_offset:
306+
return hex(self.offset.offsetvalue())
307+
return None
308+
300309
def has_unknown_base(self) -> bool:
301310
return self.base.is_unknown
302311

@@ -417,6 +426,11 @@ def is_auxiliary_variable(self) -> bool:
417426
def is_global_value(self) -> bool:
418427
return self.auxvar.is_global_value
419428

429+
def get_global_variable_address(self) -> Optional[str]:
430+
if self.is_global_value:
431+
return self.auxvar.get_global_variable_address()
432+
return None
433+
420434
@property
421435
def is_stack_base_address(self) -> bool:
422436
return self.auxvar.is_stack_base_address

chb/invariants/VConstantValueVariable.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def is_bridge_variable(self) -> bool:
128128
def is_global_value(self) -> bool:
129129
return False
130130

131+
def get_global_variable_address(self) -> Optional[str]:
132+
return None
133+
131134
@property
132135
def is_function_return_value(self) -> bool:
133136
return False
@@ -350,6 +353,11 @@ def is_global_value(self) -> bool:
350353
avar = self.variable.denotation
351354
return avar.is_memory_variable and avar.is_global_variable
352355

356+
def get_global_variable_address(self) -> Optional[str]:
357+
if self.is_global_value:
358+
return self.variable.denotation.get_global_variable_address()
359+
return None
360+
353361
@property
354362
def is_argument_value(self) -> bool:
355363
avar = self.variable.denotation

chb/invariants/XVariable.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# ------------------------------------------------------------------------------
2929
"""Symbolic value, identified by name and sequence number"""
3030

31-
from typing import Any, cast, Dict, List, Tuple, TYPE_CHECKING
31+
from typing import Any, cast, Dict, List, Optional, Tuple, TYPE_CHECKING
3232

3333
from chb.app.Register import Register
3434

@@ -201,6 +201,11 @@ def is_global_variable(self) -> bool:
201201
return (self.has_denotation()
202202
and (self.denotation.is_global_variable or self.is_global_value))
203203

204+
def get_global_variable_address(self) -> Optional[str]:
205+
if self.is_global_variable:
206+
return self.denotation.get_global_variable_address()
207+
return None
208+
204209
@property
205210
def is_structured_var(self) -> bool:
206211
return (self.has_denotation() and self.denotation.is_structured_var)

chb/invariants/XXpr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def is_global_address(self) -> bool:
149149
def is_global_variable(self) -> bool:
150150
return False
151151

152+
def get_global_variable_address(self) -> Optional[str]:
153+
return None
154+
152155
def is_int_const_value(self, n: int) -> bool:
153156
return False
154157

@@ -381,6 +384,9 @@ def is_structured_expr(self) -> bool:
381384
def is_global_variable(self) -> bool:
382385
return self.variable.is_global_variable
383386

387+
def get_global_variable_address(self) -> Optional[str]:
388+
return self.variable.get_global_variable_address()
389+
384390
@property
385391
def is_function_return_value(self) -> bool:
386392
return (self.variable.has_denotation()

0 commit comments

Comments
 (0)