Skip to content

Commit 020659c

Browse files
committed
CMD: add command to list arguments to calls
1 parent 99d2c4a commit 020659c

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

chc/cmdline/c_project/cprojectutil.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from contextlib import contextmanager
3939

4040
from typing import (
41-
Any, cast, Dict, Generator, List, Optional, NoReturn, TYPE_CHECKING)
41+
Any, cast, Dict, Generator, List, Optional, NoReturn, Tuple, TYPE_CHECKING)
4242

4343
from chc.app.CApplication import CApplication
4444

@@ -291,6 +291,7 @@ def cproject_report_file(args: argparse.Namespace) -> NoReturn:
291291
filename: str = args.filename
292292
showcode: bool = args.showcode
293293
showopen: bool = args.open
294+
showinvariants: bool = args.showinvariants
294295

295296
targetpath = os.path.abspath(tgtpath)
296297
projectpath = targetpath
@@ -320,7 +321,8 @@ def pofilter(po: "CFunctionPO") -> bool:
320321
return True
321322

322323
if showcode:
323-
print(RP.file_code_tostring(cfile, pofilter=pofilter))
324+
print(RP.file_code_tostring(
325+
cfile, pofilter=pofilter, showinvs=showinvariants))
324326

325327
print(RP.file_proofobligation_stats_tostring(cfile))
326328

@@ -523,6 +525,58 @@ def collect_fi_callees(cfile: "CFile") -> None:
523525
exit(0)
524526

525527

528+
def cproject_collect_call_arguments(args: argparse.Namespace) -> NoReturn:
529+
530+
# arguments
531+
tgtpath: str = args.tgtpath
532+
projectname: str = args.projectname
533+
534+
targetpath = os.path.abspath(tgtpath)
535+
projectpath = targetpath
536+
contractpath = os.path.join(targetpath, "chc_contracts")
537+
538+
if not UF.has_analysisresults_path(targetpath, projectname):
539+
print_error(
540+
f"No analysis results found for {projectname} in {targetpath}")
541+
exit(1)
542+
543+
capp = CApplication(
544+
projectpath, projectname, targetpath, contractpath)
545+
546+
# callee -> (file, caller) -> arguments
547+
result: Dict[str, Dict[Tuple[int, str, str], List[str]]] = {}
548+
549+
counter: int = 0
550+
for cfile in capp.cfiles:
551+
for cfun in cfile.get_functions():
552+
for instr in cfun.call_instrs:
553+
callee = str(instr.callee)
554+
callargs = instr.callargs
555+
result.setdefault(callee, {})
556+
result[callee][(counter, cfile.cfilename, cfun.name)] = [
557+
str(i) for i in callargs]
558+
counter += 1
559+
560+
lines: List[str] = []
561+
562+
for callee in sorted(result):
563+
lines.append("\n" + callee)
564+
lines.append("-" * len(callee))
565+
for (index, cfilename, caller) in sorted(result[callee]):
566+
calltxt = (
567+
callee
568+
+ "("
569+
+ ", ".join(result[callee][(index, cfilename, caller)])
570+
+ ")")
571+
lines.append(
572+
("[" + cfilename + ".c:" + caller + "] ").ljust(35)
573+
+ calltxt)
574+
575+
print("\n".join(lines))
576+
577+
exit(0)
578+
579+
526580
def cproject_missing_summaries(args: argparse.Namespace) -> NoReturn:
527581
"""CLI command to output library functions without summaries."""
528582

chc/cmdline/chkc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,10 @@ def parse() -> argparse.Namespace:
13761376
"--open",
13771377
action="store_true",
13781378
help="only show open proof obligations (or violations)")
1379+
cprojectreportfile.add_argument(
1380+
"--showinvariants",
1381+
action="store_true",
1382+
help="show location invariants on the code")
13791383
cprojectreportfile.set_defaults(func=P.cproject_report_file)
13801384

13811385
# --- count-statements
@@ -1400,6 +1404,14 @@ def parse() -> argparse.Namespace:
14001404
"--save", help="name of file (without extension) to save the results")
14011405
cprojectcallgraph.set_defaults(func=P.cproject_make_callgraph)
14021406

1407+
# --- collect-call-arguments
1408+
cprojectcollectcallargs = cprojectparsers.add_parser("collect-call-arguments")
1409+
cprojectcollectcallargs.add_argument(
1410+
"tgtpath", help="directory that contains the analysis results")
1411+
cprojectcollectcallargs.add_argument(
1412+
"projectname", help="name of the project")
1413+
cprojectcollectcallargs.set_defaults(func=P.cproject_collect_call_arguments)
1414+
14031415
# --- missing-summaries
14041416
cprojectmissingsummaries = cprojectparsers.add_parser("missing-summaries")
14051417
cprojectmissingsummaries.add_argument(

0 commit comments

Comments
 (0)