diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-13 16:30:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-13 16:30:40 -0700 |
commit | 5936f053848a7e878096158e207f4e59fbd62ab6 (patch) | |
tree | 0098a28554821ff0312bc578d3ea13f1a1ea44f3 /scripts/support.py | |
parent | bb8a2aa3e5b02e297a2ef79131a511efe21d78d8 (diff) | |
parent | b0fc363b3a86ade1b5da54b3452bf00568b5b360 (diff) | |
download | binaryen-5936f053848a7e878096158e207f4e59fbd62ab6.tar.gz binaryen-5936f053848a7e878096158e207f4e59fbd62ab6.tar.bz2 binaryen-5936f053848a7e878096158e207f4e59fbd62ab6.zip |
Merge pull request #632 from WebAssembly/too
Tool renaming and refactoring
Diffstat (limited to 'scripts/support.py')
-rwxr-xr-x | scripts/support.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/support.py b/scripts/support.py index a99fb7604..2d4318980 100755 --- a/scripts/support.py +++ b/scripts/support.py @@ -87,3 +87,60 @@ def untar(tarfile, outdir): finally: if os.path.isdir(tmpdir): shutil.rmtree(tmpdir) + + +def split_wast(wast): + # .wast files can contain multiple modules, and assertions for each one. + # this splits out a wast into [(module, assertions), ..] + # we ignore module invalidity tests here. + wast = open(wast).read() + ret = [] + + def to_end(j): + depth = 1 + while depth > 0 and j < len(wast): + if wast[j] == '"': + j = wast.find('"', j + 1) + elif wast[j] == '(': + depth += 1 + elif wast[j] == ')': + depth -= 1 + elif wast[j] == ';' and wast[j + 1] == ';': + j = wast.find('\n', j) + j += 1 + return j + + i = 0 + while i >= 0: + start = wast.find('(', i) + if start >= 0 and wast[start + 1] == ';': + # block comment + i = wast.find(';)', start + 2) + assert i > 0, wast[start:] + i += 2 + continue + skip = wast.find(';', i) + if skip >= 0 and skip < start and skip + 1 < len(wast): + if wast[skip + 1] == ';': + i = wast.find('\n', i) + 1 + continue + if start < 0: + break + i = to_end(start + 1) + chunk = wast[start:i] + if chunk.startswith('(module'): + ret += [(chunk, [])] + elif chunk.startswith('(assert_invalid'): + continue + elif chunk.startswith(('(assert', '(invoke')): + ret[-1][1].append(chunk) + return ret + + +def run_command(cmd, expected_status=0, stderr=None): + print 'executing: ', ' '.join(cmd) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr) + out, err = proc.communicate() + if proc.returncode != expected_status: + raise Exception(('run_command failed', err)) + return out |