-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_ic3_trace.py
64 lines (49 loc) · 1.37 KB
/
read_ic3_trace.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
53
54
55
56
57
58
59
60
61
62
63
64
import sys
import argparse
import logging
import os
import signal
import sys
import re
re_str = "[~]*[0-9]+{[a-zA-Z0-9\_\(\)<=>*+-/-\s]+}"
atom_re = re.compile(re_str)
readable_re = re.compile("[0-9]+{([a-zA-Z0-9\_\(\)<=>*+-/-\s]+)}")
trace = []
with open("/tmp/trace.txt", "r") as f:
for line in f.readlines():
line = line.strip()
to_replace = ["[","]"]
for r in to_replace:
line = line.replace(r,"")
trace_val = {}
for match in atom_re.finditer(line):
atom = match.group(0)
if not atom:
continue
val = True
if (atom[0] == "~"):
val = False
atom = atom[1:]
trace_val[atom] = val
trace.append(trace_val)
def print_trace(trace):
for (atom,value) in trace.items():
name = readable_re.match(atom)
if (value):
sys.stdout.write("%s " % name.group(1))
else:
sys.stdout.write("~%s " % name.group(1))
sys.stdout.write("\n")
index = 0
prev_state = None
for t in trace:
if index == 0:
print_trace(trace[index])
else:
changed = {}
prev_trace = trace[index - 1]
for (atom, value) in trace[index].items():
if prev_trace[atom] != value:
changed[atom] = value
print_trace(changed)
index = index + 1