summaryrefslogtreecommitdiff
path: root/scripts/support.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-07-13 12:15:20 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-07-13 16:07:59 -0700
commit9e2f21c9aa1993325b5a7043d206e2baf07e9180 (patch)
tree7fc213c0bde0d4da747d85ec791f08c7f083029a /scripts/support.py
parent9d3801039d2e2f9738d2c4829ee59aa047da1cc6 (diff)
downloadbinaryen-9e2f21c9aa1993325b5a7043d206e2baf07e9180.tar.gz
binaryen-9e2f21c9aa1993325b5a7043d206e2baf07e9180.tar.bz2
binaryen-9e2f21c9aa1993325b5a7043d206e2baf07e9180.zip
separate wasm-opt out from wasm-shell: opt optimizes, shell runs wast shell tests
Diffstat (limited to 'scripts/support.py')
-rwxr-xr-xscripts/support.py57
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