@@ -1199,11 +1199,20 @@ def can_run_on_wasm(self, wasm):
11991199 return all_disallowed (['exception-handling' , 'simd' , 'threads' , 'bulk-memory' , 'nontrapping-float-to-int' , 'tail-call' , 'sign-ext' , 'reference-types' , 'multivalue' , 'gc' , 'multimemory' , 'memory64' , 'custom-descriptors' ])
12001200
12011201
1202+ # Returns the wat for a wasm file. If it is already wat, it just returns that
1203+ # (useful when reducing with --text, where wasm files are really wat files).
1204+ def get_wat (wasm ):
1205+ binary = open (wasm , 'rb' ).read ()
1206+ if binary .startswith (b'(module' ):
1207+ return binary .decode (encoding = 'utf-8' )
1208+ return run ([in_bin ('wasm-dis' ), wasm ] + FEATURE_OPTS )
1209+
1210+
12021211# given a wasm, find all the exports of particular kinds (for example, kinds
12031212# can be ['func', 'table'] and then we would find exported functions and
12041213# tables).
12051214def get_exports (wasm , kinds ):
1206- wat = run ([ in_bin ( ' wasm-dis' ), wasm ] + FEATURE_OPTS )
1215+ wat = get_wat ( wasm )
12071216 p = re .compile (r'^ [(]export "(.*[^\\]?)" [(](?:' + '|' .join (kinds ) + ')' )
12081217 exports = []
12091218 for line in wat .splitlines ():
@@ -1254,7 +1263,7 @@ def filter_exports(wasm, output, keep, keep_defaults=True):
12541263# Check if a wasm file would notice normally-unnoticeable changes to exports,
12551264# such as removing one that is not called.
12561265def wasm_notices_export_changes (wasm ):
1257- wat = run ([ in_bin ( ' wasm-dis' ), wasm ] + FEATURE_OPTS )
1266+ wat = get_wat ( wasm )
12581267
12591268 if '(import "fuzzing-support" "call-export' in wat :
12601269 # The call-export* imports are sensitive to the number and identity of
@@ -1555,7 +1564,7 @@ class Split(TestCaseHandler):
15551564 def handle (self , wasm ):
15561565 # get the list of function names, some of which we will decide to split
15571566 # out
1558- wat = run ([ in_bin ( ' wasm-dis' ), wasm ] + FEATURE_OPTS )
1567+ wat = get_wat ( wasm )
15591568 all_funcs = re .findall (FUNC_NAMES_REGEX , wat )
15601569
15611570 # get the original output before splitting
0 commit comments