-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathchecker.py
52 lines (45 loc) · 1.79 KB
/
checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
import os
import sys
from typing import List
sys.path.append(os.path.join(os.path.dirname(
os.path.abspath(__file__)), "src"))
from python.core import run_checker # noqa
from python.dump import DumpManager # noqa
from python.plugins.cfg_plotter import CFGPlotter # noqa
def main(files: List[str], draw_cfg: str = "",
binary: str = "../output/bin/iec_checker"):
for f in files:
if not os.path.isfile(f):
continue
checker_warnings, rc = run_checker(f, binary)
if rc != 0:
print(f'Report for {f}:')
for w in checker_warnings:
print(f'{w}')
continue
dump_name = f'{f}.dump.json'
plugins_warnings = []
with DumpManager(dump_name) as dm:
plugins_warnings = dm.run_all_inspections()
if draw_cfg:
cfg_plotter = CFGPlotter(dm.scheme.cfgs)
cfg_plotter.save_file(draw_cfg)
print(f'Report for {f}:')
if checker_warnings or plugins_warnings:
for w in checker_warnings:
print(f'{w}')
for p in plugins_warnings:
print(f'{w}')
else:
print('No errors found!')
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Static analysis for IEC 61131-3 programs.')
parser.add_argument("files", nargs='*', help="Path to IEC source files")
parser.add_argument("--draw-cfg", type=str,
help="Save control flow graph image at the selected path")
parser.add_argument("-b", "--binary", default=os.path.join("output", "bin", "iec_checker"),
help="File path to the OCaml binary")
args = parser.parse_args()
sys.exit(main(args.files, args.draw_cfg, args.binary))