forked from cryspen/bertie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hax-driver.py
executable file
·82 lines (68 loc) · 2.01 KB
/
hax-driver.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
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env python3
import os
import argparse
import subprocess
import sys
def shell(command, expect=0, cwd=None, env={}):
subprocess_stdout = subprocess.DEVNULL
print("Env:", env)
print("Command: ", end="")
for i, word in enumerate(command):
if i == 4:
print("'{}' ".format(word), end="")
else:
print("{} ".format(word), end="")
print("\nDirectory: {}".format(cwd))
os_env = os.environ
os_env.update(env)
ret = subprocess.run(command, cwd=cwd, env=os_env)
if ret.returncode != expect:
raise Exception("Error {}. Expected {}.".format(ret, expect))
parser = argparse.ArgumentParser(description="Perform proofs using Hax.")
sub_parser = parser.add_subparsers(
description="Extract or typecheck",
dest="sub",
help="Extract and typecheck F* etc. from the Bertie Rust code.",
)
extract_parser = sub_parser.add_parser("extract")
typecheck_parser = sub_parser.add_parser("typecheck")
typecheck_parser.add_argument(
"--lax",
action="store_true",
dest="lax",
help="Lax typecheck the code only",
)
typecheck_parser.add_argument(
"--clean",
action="store_true",
dest="clean",
help="Clean before calling make",
)
options = parser.parse_args()
cargo_hax_into = ["cargo", "hax", "-C", "-p", "bertie", ";", "into"]
hax_env = {"RUSTFLAGS": "--cfg hax"}
if options.sub == "extract":
# The extract sub command.
shell(
cargo_hax_into
+ [
"-i",
"-**::non_hax::** -**::parse_failed",
"fstar",
],
cwd=".",
env=hax_env,
)
elif options.sub == "typecheck":
# Typecheck subcommand.
custom_env = {}
if options.lax:
custom_env.update({"OTHERFLAGS": "--lax"})
if options.clean:
# shell(["rm", "-f", "proofs/fstar/extraction/.depend"])
shell(["make", "-C", "proofs/fstar/extraction/", "clean"])
shell(["make", "-C", "proofs/fstar/extraction/"], custom_env)
exit(0)
else:
parser.print_help()
exit(2)