summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.flake83
-rw-r--r--.travis.yml4
-rwxr-xr-xscripts/clean_c_api_trace.py2
-rwxr-xr-xscripts/fuzz_passes.py30
-rwxr-xr-xscripts/fuzz_passes_wast.py28
-rwxr-xr-xscripts/fuzz_relooper.py20
-rwxr-xr-xscripts/gen-s-parser.py6
-rwxr-xr-xscripts/storage.py8
-rw-r--r--scripts/strip_local_names.py4
-rwxr-xr-xscripts/test/generate_lld_tests.py8
10 files changed, 60 insertions, 53 deletions
diff --git a/.flake8 b/.flake8
index 704b22c34..e8b6a7169 100644
--- a/.flake8
+++ b/.flake8
@@ -4,5 +4,6 @@ ignore =
E114, # comment indentation not a multiple of 4
E501, # line too long
E121, # continuation line under-indented for hanging indent
- E241 # space after comma (ignored for list in gen-s-parser.py)
+ E241, # space after comma (ignored for list in gen-s-parser.py)
+ W504 # line break after binary operator
exclude = ./test/emscripten,./test/spec,./test/wasm-install
diff --git a/.travis.yml b/.travis.yml
index cb9cd7360..749631011 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -45,13 +45,13 @@ jobs:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
- packages: ['cmake', 'g++-5']
+ packages: ['cmake', 'g++-5', 'python3-pip']
before_install:
- export ASAN_OPTIONS="symbolize=1"
install:
- nvm install 10
- nvm use 10
- - pip install --user flake8==3.4.1
+ - pip3 install --user flake8==3.7.8
# get jsvu in order to get more js engines
- npm install jsvu -g
- export PATH="${HOME}/.jsvu:${PATH}"
diff --git a/scripts/clean_c_api_trace.py b/scripts/clean_c_api_trace.py
index 1f8062f2d..e2bfa30ab 100755
--- a/scripts/clean_c_api_trace.py
+++ b/scripts/clean_c_api_trace.py
@@ -34,4 +34,4 @@ if start >= 0:
assert end > 0
trace = trace[:start] + trace[end + 2:]
- print trace
+ print(trace)
diff --git a/scripts/fuzz_passes.py b/scripts/fuzz_passes.py
index 04899835e..60ae95817 100755
--- a/scripts/fuzz_passes.py
+++ b/scripts/fuzz_passes.py
@@ -25,6 +25,8 @@ Usage: Provide a base filename for a runnable program, e.g. a.out.js.
Other parameters after the first are used when calling the program.
'''
+from __future__ import print_function
+
import os
import random
import shutil
@@ -50,19 +52,19 @@ PASSES = [
base = sys.argv[1]
wast = base[:-3] + '.wast'
-print '>>> base program:', base, ', wast:', wast
+print('>>> base program:', base, ', wast:', wast)
args = sys.argv[2:]
def run():
if os.path.exists(wast):
- print '>>> running using a wast of size', os.stat(wast).st_size
+ print('>>> running using a wast of size', os.stat(wast).st_size)
cmd = ['mozjs', base] + args
try:
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
- except Exception, e:
- print ">>> !!! ", e, " !!!"
+ except Exception as e:
+ print(">>> !!! ", e, " !!!")
original_wast = None
@@ -71,7 +73,7 @@ try:
# get normal output
normal = run()
- print '>>> normal output:\n', normal
+ print('>>> normal output:\n', normal)
assert normal, 'must be output'
# ensure we actually use the wast
@@ -96,22 +98,20 @@ try:
more = True
while more:
more = False
- print '>>> trying to reduce:', ' '.join(passes),
- print ' [' + str(len(passes)) + ']'
+ print('>>> trying to reduce:', ' '.join(passes), ' [' + str(len(passes)) + ']')
for i in range(len(passes)):
smaller = passes[:i] + passes[i + 1:]
- print '>>>>>> try to reduce to:', ' '.join(smaller),
- print ' [' + str(len(smaller)) + ']'
+ print('>>>>>> try to reduce to:', ' '.join(smaller), ' [' + str(len(smaller)) + ']')
try:
apply_passes(smaller)
assert run() == normal
except Exception:
# this failed too, so it's a good reduction
passes = smaller
- print '>>> reduction successful'
+ print('>>> reduction successful')
more = True
break
- print '>>> reduced to:', ' '.join(passes)
+ print('>>> reduced to:', ' '.join(passes))
tested = set()
@@ -128,17 +128,17 @@ try:
while 1:
passes = pick_passes()
- print '>>> [' + str(counter) + '] testing:', ' '.join(passes)
+ print('>>> [' + str(counter) + '] testing:', ' '.join(passes))
counter += 1
try:
apply_passes(passes)
- except Exception, e:
- print e
+ except Exception as e:
+ print(e)
simplify(passes)
break
seen = run()
if seen != normal:
- print '>>> bad output:\n', seen
+ print('>>> bad output:\n', seen)
simplify(passes)
break
diff --git a/scripts/fuzz_passes_wast.py b/scripts/fuzz_passes_wast.py
index 052969f01..18506c377 100755
--- a/scripts/fuzz_passes_wast.py
+++ b/scripts/fuzz_passes_wast.py
@@ -22,6 +22,8 @@ or validation
Usage: Provide the filename of the wast.
'''
+from __future__ import print_function
+
import os
import random
import shutil
@@ -46,7 +48,7 @@ PASSES = [
# main
wast = sys.argv[1]
-print '>>> wast:', wast
+print('>>> wast:', wast)
args = sys.argv[2:]
@@ -54,9 +56,9 @@ args = sys.argv[2:]
def run():
try:
cmd = ['bin/wasm-opt', wast]
- print 'run', cmd
+ print('run', cmd)
subprocess.check_call(cmd, stderr=open('/dev/null'))
- except Exception, e:
+ except Exception as e:
return ">>> !!! ", e, " !!!"
return 'ok'
@@ -67,7 +69,7 @@ try:
# get normal output
normal = run()
- print '>>> normal output:\n', normal
+ print('>>> normal output:\n', normal)
assert normal, 'must be output'
# ensure we actually use the wast
@@ -87,22 +89,20 @@ try:
more = True
while more:
more = False
- print '>>> trying to reduce:', ' '.join(passes),
- print ' [' + str(len(passes)) + ']'
+ print('>>> trying to reduce:', ' '.join(passes), ' [' + str(len(passes)) + ']')
for i in range(len(passes)):
smaller = passes[:i] + passes[i + 1:]
- print '>>>>>> try to reduce to:', ' '.join(smaller),
- print ' [' + str(len(smaller)) + ']'
+ print('>>>>>> try to reduce to:', ' '.join(smaller), ' [' + str(len(smaller)) + ']')
try:
apply_passes(smaller)
assert run() == normal
except Exception:
# this failed too, so it's a good reduction
passes = smaller
- print '>>> reduction successful'
+ print('>>> reduction successful')
more = True
break
- print '>>> reduced to:', ' '.join(passes)
+ print('>>> reduced to:', ' '.join(passes))
tested = set()
@@ -120,17 +120,17 @@ try:
while 1:
passes = pick_passes()
- print '>>> [' + str(counter) + '] testing:', ' '.join(passes)
+ print('>>> [' + str(counter) + '] testing:', ' '.join(passes))
counter += 1
try:
apply_passes(passes)
- except Exception, e:
- print e
+ except Exception as e:
+ print(e)
simplify(passes)
break
seen = run()
if seen != normal:
- print '>>> bad output:\n', seen
+ print('>>> bad output:\n', seen)
simplify(passes)
break
diff --git a/scripts/fuzz_relooper.py b/scripts/fuzz_relooper.py
index 3b14ed2cd..359b0fa90 100755
--- a/scripts/fuzz_relooper.py
+++ b/scripts/fuzz_relooper.py
@@ -18,13 +18,15 @@
This fuzzes the relooper using the C API.
'''
+from __future__ import print_function
+
import difflib
import os
import random
import subprocess
import time
-seed_init = long(time.time())
+seed_init = int(time.time())
seed_init *= seed_init
seed_init %= (2**32)
@@ -78,7 +80,7 @@ while True:
branches[i] = b
branch_codes[i] = [random_code() for item in range(len(b) + 1)] # one for each branch, plus the default
optimize = random.random() < 0.5
- print counter, ':', num, density, optimize, code_likelihood, code_max, max_printed, ', seed =', seed
+ print(counter, ':', num, density, optimize, code_likelihood, code_max, max_printed, ', seed =', seed)
counter += 1
for temp in ['fuzz.wasm', 'fuzz.wast', 'fast.txt', 'fuzz.slow.js',
@@ -360,28 +362,28 @@ int main() {
open('fuzz.slow.js', 'w').write(slow)
open('fuzz.c', 'w').write(fast)
- print '.'
+ print('.')
cmd = [os.environ.get('CC') or 'gcc', 'fuzz.c', '-Isrc',
'-lbinaryen', '-lasmjs',
'-lsupport', '-Llib/.', '-pthread', '-o', 'fuzz']
subprocess.check_call(cmd)
- print '^'
+ print('^')
subprocess.check_call(['./fuzz'], stdout=open('fuzz.wast', 'w'))
- print '*'
+ print('*')
fast_out = subprocess.Popen(['bin/wasm-shell', 'fuzz.wast'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()[0]
- print '-'
+ print('-')
node = os.getenv('NODE', 'nodejs')
slow_out = subprocess.Popen([node, 'fuzz.slow.js'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()[0]
- print '_'
+ print('_')
if slow_out != fast_out:
- print ''.join([a.rstrip() + '\n' for a in difflib.unified_diff(
+ print(''.join([a.rstrip() + '\n' for a in difflib.unified_diff(
slow_out.split('\n'),
fast_out.split('\n'),
fromfile='slow',
- tofile='fast')])
+ tofile='fast')]))
assert False
diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py
index c98388ad8..5b18ed340 100755
--- a/scripts/gen-s-parser.py
+++ b/scripts/gen-s-parser.py
@@ -469,7 +469,7 @@ class Node:
return "".join(prefix)
def do_insert(self, full_inst, inst, expr):
- if inst is "":
+ if not inst:
assert self.expr is None, "Repeated instruction " + full_inst
self.expr = expr
self.inst = full_inst
@@ -478,7 +478,7 @@ class Node:
prefix, key = "", None
for k in self.children:
prefix = Node._common_prefix(inst, k)
- if prefix is not "":
+ if prefix:
key = k
break
if key is None:
@@ -486,7 +486,7 @@ class Node:
self.children[inst] = Node(expr, inst=full_inst)
return
key_remainder = key[len(prefix):]
- if key_remainder is not "":
+ if key_remainder:
# split key and move everything after the prefix to a new node
child = self.children.pop(key)
self.children[prefix] = Node(children={key_remainder: child})
diff --git a/scripts/storage.py b/scripts/storage.py
index 9dad45e54..89e5f6107 100755
--- a/scripts/storage.py
+++ b/scripts/storage.py
@@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
import glob
import json
import os
@@ -40,14 +42,14 @@ def download_tar(tar_pattern, directory, revision):
tar_path = os.path.join(directory, tar_pattern)
revision_tar_path = tar_path % revision
if os.path.isfile(revision_tar_path):
- print 'Already have `%s`' % revision_tar_path
+ print('Already have `%s`' % revision_tar_path)
else:
- print 'Downloading `%s`' % revision_tar_path
+ print('Downloading `%s`' % revision_tar_path)
with open(revision_tar_path, 'w+') as f:
f.write(urllib2.urlopen(STORAGE_BASE + tar_pattern % revision).read())
# Remove any previous tarfiles.
for older_tar in glob.glob(tar_path % '*'):
if older_tar != revision_tar_path:
- print 'Removing older tar file `%s`' % older_tar
+ print('Removing older tar file `%s`' % older_tar)
os.remove(older_tar)
return revision_tar_path
diff --git a/scripts/strip_local_names.py b/scripts/strip_local_names.py
index 2e14b8e2b..bd10d8dab 100644
--- a/scripts/strip_local_names.py
+++ b/scripts/strip_local_names.py
@@ -8,6 +8,6 @@ import sys
for line in open(sys.argv[1]).readlines():
if '(local.tee ' in line or '(local.set ' in line or '(local.get ' in line:
- print line[:line.find('$')]
+ print(line[:line.find('$')])
else:
- print line,
+ print(line.rstrip())
diff --git a/scripts/test/generate_lld_tests.py b/scripts/test/generate_lld_tests.py
index 740a08591..9447fe973 100755
--- a/scripts/test/generate_lld_tests.py
+++ b/scripts/test/generate_lld_tests.py
@@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
import os
import sys
from support import run_command
@@ -28,11 +30,11 @@ def files_with_extensions(path, extensions):
def generate_wast_files(llvm_bin, emscripten_root):
- print '\n[ building wast files from C sources... ]\n'
+ print('\n[ building wast files from C sources... ]\n')
lld_path = os.path.join(shared.options.binaryen_test, 'lld')
for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']):
- print '..', src_file
+ print('..', src_file)
obj_file = src_file.replace(ext, '.o')
src_path = os.path.join(lld_path, src_file)
@@ -84,6 +86,6 @@ def generate_wast_files(llvm_bin, emscripten_root):
if __name__ == '__main__':
if len(shared.options.positional_args) != 2:
- print 'Usage: generate_lld_tests.py [llvm/bin/dir] [path/to/emscripten]'
+ print('Usage: generate_lld_tests.py [llvm/bin/dir] [path/to/emscripten]')
sys.exit(1)
generate_wast_files(*shared.options.positional_args)