forked from runtimeverification/wasm-semantics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
39 lines (32 loc) · 1.38 KB
/
convert.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
# This script is not used during runtime.
# It just helps converting some conformances test to a test that we can use by removing unsupported functions and converting hexfloat to normal float.
# However it does not support multi-line assertions, function definitions, etc.
# The test files under directory tests/simple/float were generated by this script.
# example usage: python convert.py f32.wast
import re
import sys
def hex2float(h):
print(h)
if "nan" in h:
return h.replace("nan", "NaN")
elif "inf" in h:
return h.replace("inf", "Infinity")
elif "0x" not in h:
return h
else:
return h.split()[0] + " " + "%e" % (float.fromhex(h.split()[1]))
def main():
filename = sys.argv[1]
infile = "tests/wasm-tests/test/core/%s" % filename
outfile = open("tests/simple/%s-c.%s" % tuple(filename.split(".")), "w")
unsupported = ["nan:", "-nan", "reinterpret",
"assert_return_canonical_nan", "assert_return_arithmetic_nan", "assert_invalid", "assert_malformed"]
for line in (open(infile).readlines()):
if any(x in line for x in unsupported):
outfile.write(";; "+line)
else:
outfile.write(re.sub(r"(?:(?:f32|f64)\.const )([^\)]+)",
lambda m: hex2float(m.group()), line))
outfile.write("\n#clearConfig\n")
if __name__ == "__main__":
main()