-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distribute scripts with
pykwasm
(#609)
* Fix typo * Add module `scripts` * Move `convert.py` into Python package * Move `preprocessor.py` into Python package * Move `kwasm` into Python package * Set Version: 0.1.30 * Set Version: 0.1.31 * Set Version: 0.1.32 --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
da66a27
commit fd9ec8c
Showing
11 changed files
with
117 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/.build/* | ||
/.kwasm-logs/ | ||
/tests/*/*-out | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.31 | ||
0.1.32 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,18 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "pykwasm" | ||
version = "0.1.31" | ||
version = "0.1.32" | ||
description = "" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
] | ||
|
||
[tool.poetry.scripts] | ||
wasm2kast = "pykwasm.wasm2kast:main" | ||
kwasm = "pykwasm.scripts.kwasm:main" | ||
kwasm-convert = "pykwasm.scripts.convert:main" | ||
kwasm-preprocess = "pykwasm.scripts.preprocessor:main" | ||
|
||
[tool.poetry.plugins.kdist] | ||
wasm-semantics = "pykwasm.kdist.plugin" | ||
|
||
|
@@ -62,6 +68,3 @@ exclude = [ | |
'src/wasm/*', | ||
'src/tests/unit/test_wasm2kast\.py', | ||
] | ||
|
||
[tool.poetry.scripts] | ||
wasm2kast = "pykwasm.wasm2kast:main" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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: kwasm-convert f32.wast | ||
|
||
import re | ||
import sys | ||
|
||
|
||
def hex2float(h: str) -> str: | ||
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() -> None: | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
from pyk.utils import run_process | ||
|
||
SCRIPT_FILE = Path(__file__).parent / 'kwasm.sh' | ||
|
||
|
||
def main() -> None: | ||
proc_res = run_process(['bash', str(SCRIPT_FILE)] + sys.argv[1:], pipe_stdout=False, check=False) | ||
sys.exit(proc_res.returncode) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Preprocessor that converts Wasm concrete syntax into a form parseable by K. | ||
# example usage: kwasm-preprocess f32.wast | ||
|
||
import re | ||
import sys | ||
|
||
|
||
def hex2float(h: str) -> str: | ||
h = re.sub('_', '', h) | ||
if 'nan' in h: | ||
# TODO: Keep bit pattern of float, don't turn all of them into simple NaNs. | ||
return re.sub('-?nan(:.*$)?', 'NaN', h) | ||
elif 'inf' in h: | ||
return h.replace('inf', 'Infinity') | ||
elif '0x' in h: | ||
try: | ||
return h.split()[0] + ' ' + '%e' % (float.fromhex(h.split()[1])) | ||
except OverflowError: | ||
return h | ||
except ValueError: | ||
return h | ||
else: | ||
return h | ||
|
||
|
||
def main() -> None: | ||
if len(list(sys.argv)) == 1: | ||
infile = sys.stdin | ||
else: | ||
infile = open(sys.argv[1]) | ||
|
||
def replace(m: re.Match) -> str: | ||
return hex2float(m.group()) | ||
|
||
for line in infile.readlines(): | ||
sys.stdout.write(re.sub(r'(?:(?:f32|f64)\.const )([^\)]+)', replace, line)) | ||
|
||
infile.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |