-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrix.py
69 lines (60 loc) · 1.86 KB
/
strix.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
65
66
67
68
69
import syfco
import subprocess
import os
from aigertoverilog import aiger_to_verilog
strix_path = os.path.abspath("../bin")
custom_env = os.environ.copy()
custom_env["PATH"] = strix_path + ":" + custom_env["PATH"]
def synthesize(
spec: str,
target: str = "verilog",
overwrite_params: dict = {},
timeout=60,
module_name="fsm",
) -> str:
"""
Runs the strix binary with options
- target: aag (AIGER ASCII), aig (AIGER binary), aiger (alias for aag), hoa, bdd, pg, verilog (experimental)
- spec: should be in tlsf format
- overwrite_params: overwrite parameters in tlsf file
- module_name: only used when target = verilog. Defines the verilog output module name
"""
verilog_mode = target == "verilog"
if target == "aiger":
target = "aag"
inputs = ",".join(syfco.inputs(spec, overwrite_params=overwrite_params))
outputs = ",".join(syfco.outputs(spec, overwrite_params=overwrite_params))
ltl_formula = syfco.convert(
spec,
format="ltl",
mode="fully",
quote="double",
overwrite_params=overwrite_params,
)
out = subprocess.run(
[
"strix",
"--ins",
inputs,
"--outs",
outputs,
"-f",
ltl_formula,
"-o",
"aag" if verilog_mode else target,
],
capture_output=True,
timeout=timeout,
text=True,
env=custom_env,
)
if out.stderr != "":
raise Exception(out.stderr)
# First line is REALIZABLE / UNREALIZABLE
lines = out.stdout.splitlines()
if lines[0] != "REALIZABLE":
raise Exception(lines[0])
# we have to convert aag to verilog because strix doesn't have direct support
if not verilog_mode:
return "\n".join(lines[1:])
return aiger_to_verilog("\n".join(lines[1:]), module_name)