MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / run_binaryen_command

Function run_binaryen_command

tools/building.py:1243–1281  ·  view source on GitHub ↗
(tool, infile, outfile=None, args=None, debug=False, stdout=None)

Source from the content-addressed store, hash-verified

1241
1242
1243def run_binaryen_command(tool, infile, outfile=None, args=None, debug=False, stdout=None):
1244 cmd = [os.path.join(get_binaryen_bin(), tool)]
1245 if args:
1246 cmd += args
1247 if infile:
1248 cmd += [infile]
1249 if outfile:
1250 cmd += ['-o', outfile]
1251 if settings.ERROR_ON_WASM_CHANGES_AFTER_LINK:
1252 # emit some extra helpful text for common issues
1253 extra = ''
1254 # a plain -O0 build *almost* doesn't need post-link changes, except for
1255 # legalization. show a clear error for those (as the flags the user passed
1256 # in are not enough to see what went wrong)
1257 if settings.LEGALIZE_JS_FFI:
1258 extra += '\nnote: to disable int64 legalization (which requires changes after link) use -sWASM_BIGINT'
1259 if settings.OPT_LEVEL > 1:
1260 extra += '\nnote: -O2+ optimizations always require changes, build with -O0 or -O1 instead'
1261 exit_with_error(f'changes to the wasm are required after link, but disallowed by ERROR_ON_WASM_CHANGES_AFTER_LINK: {cmd}{extra}')
1262 if debug:
1263 cmd += ['-g'] # preserve the debug info
1264 # if the features are not already handled, handle them
1265 cmd += get_binaryen_feature_flags()
1266 # if we are emitting a source map, every time we load and save the wasm
1267 # we must tell binaryen to update it
1268 # TODO: all tools should support source maps; wasm-ctor-eval does not atm,
1269 # for example
1270 if settings.GENERATE_SOURCE_MAP and outfile and tool in {'wasm-opt', 'wasm-emscripten-finalize', 'wasm-metadce'}:
1271 cmd += [f'--input-source-map={infile}.map']
1272 cmd += [f'--output-source-map={outfile}.map']
1273 if shared.SKIP_SUBPROCS:
1274 shared.print_compiler_stage(cmd)
1275 return ''
1276 ret = check_call(cmd, stdout=stdout).stdout
1277 if outfile:
1278 save_intermediate(outfile, '%s.wasm' % tool)
1279 global binaryen_kept_debug_info
1280 binaryen_kept_debug_info = '-g' in cmd
1281 return ret
1282
1283
1284def run_wasm_opt(infile, outfile=None, args=[], **kwargs): # noqa

Callers 4

eval_ctorsFunction · 0.85
metadceFunction · 0.85
wasm2jsFunction · 0.85
run_wasm_optFunction · 0.85

Calls 6

get_binaryen_binFunction · 0.85
exit_with_errorFunction · 0.85
check_callFunction · 0.85
save_intermediateFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected