Skip to content

Commit d4f2df2

Browse files
committed
XPR: add function name as global variable to symbol table
1 parent f89f859 commit d4f2df2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

chb/invariants/XXprUtil.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ def xconstant_to_ast_expr(
211211
return astree.mk_start_of(lval)
212212
else:
213213
return astree.mk_address_of(lval)
214+
215+
elif (
216+
xdata.app.systeminfo.has_function_name(hex(xc.intvalue))):
217+
fname = xdata.app.systeminfo.function_name(hex(xc.intvalue))
218+
if xdata.app.bcfiles.has_vardecl(fname):
219+
vardecl = xdata.app.bcfiles.vardecl(fname)
220+
astree.globalsymboltable.add_symbol(
221+
vardecl.vname,
222+
vtype=vardecl.vtype.convert(astree.typconverter),
223+
globaladdress=xc.intvalue)
224+
gvaddr = astree.globalsymboltable.global_variable_name(
225+
hex(xc.intvalue))
226+
if gvaddr is not None:
227+
lval = astree.mk_vinfo_lval(gvaddr, anonymous=anonymous)
228+
return astree.mk_address_of(lval)
229+
else:
230+
return astree.mk_integer_constant(xc.intvalue)
231+
else:
232+
return astree.mk_integer_constant(xc.intvalue)
214233
else:
215234
return astree.mk_integer_constant(xc.intvalue)
216235

@@ -564,6 +583,13 @@ def stack_variable_to_lval_expression(
564583
return astree.mk_vinfo_lval_expression(
565584
vinfo, astoffset, anonymous=anonymous)
566585

586+
if offset.offset.is_field_offset:
587+
fieldoffset = cast("VMemoryOffsetFieldOffset", offset.offset)
588+
astoffset = field_offset_to_ast_offset(
589+
fieldoffset, xdata, iaddr, astree, anonymous=anonymous)
590+
return astree.mk_vinfo_lval_expression(
591+
vinfo, astoffset, anonymous=anonymous)
592+
567593
chklogger.logger.warning(
568594
"Stack variable offset %s of %s not yet handled at address %s",
569595
str(offset.offset), str(vinfo), iaddr)
@@ -636,6 +662,19 @@ def global_variable_to_lval_expression(
636662
return astree.mk_vinfo_lval_expression(
637663
vinfo, astoffset, anonymous=anonymous)
638664

665+
if not anonymous:
666+
if vinfo is None:
667+
chklogger.logger.error(
668+
"Conversion of global variable with address %s and offset "
669+
+ "%s at address %s not yet supported",
670+
str(hexgaddr), str(offset.offset), iaddr)
671+
else:
672+
chklogger.logger.error(
673+
"Conversion of global variable %s access with offset "
674+
+ "%s at address %s not yet supported",
675+
str(vinfo), str(offset.offset), iaddr)
676+
return astree.mk_temp_lval_expression()
677+
639678
if not anonymous:
640679
chklogger.logger.error(
641680
"Conversion of global variable %s at address %s not yet supported",

0 commit comments

Comments
 (0)