Skip to content

Commit a428b7c

Browse files
committed
[feat] Cooddy annotation script
1 parent 2541973 commit a428b7c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scripts/cooddy_annotations.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/python3
2+
3+
import json
4+
import re
5+
from argparse import ArgumentParser
6+
7+
8+
Cooddy_name_pattern = re.compile(r"^(?P<name>.*)\((?P<mangled_name>[^()]*)\)$")
9+
10+
11+
def getNames(name: str) :
12+
m = Cooddy_name_pattern.fullmatch(name)
13+
if m:
14+
return m.group("name"), m.group("mangled_name")
15+
return name, name
16+
17+
18+
def transform(utbot_json, coody_json):
19+
for coody_name, annotation in coody_json.items():
20+
funcName, mangledName = getNames(coody_name)
21+
utbot_json[mangledName] = {"name": funcName, "annotation": annotation, "properties": []}
22+
23+
24+
def main():
25+
parser = ArgumentParser(
26+
prog='cooddy_annotations.py',
27+
description='This script transforms .json annotations used by Cooddy static analyzer into annotations understandable by KLEE')
28+
parser.add_argument('filenames', metavar='Path', nargs='+', help="Cooddy annotation .json file path")
29+
parser.add_argument('Output', help="Target file path for produced KLEE annotation")
30+
args = parser.parse_args()
31+
utbot_json = dict()
32+
for filename in args.filenames:
33+
with open(filename) as file:
34+
j = json.load(file)
35+
transform(utbot_json, j)
36+
with open(args.Output, 'w') as file:
37+
json.dump(utbot_json, file, indent=" ")
38+
39+
40+
if __name__ == "__main__":
41+
main()

0 commit comments

Comments
 (0)