@@ -1484,21 +1484,6 @@ def get_binaryen_bin():
14841484
14851485def run_binaryen_command (tool , infile , outfile = None , args = [], debug = False , stdout = None ):
14861486 cmd = [os .path .join (get_binaryen_bin (), tool )]
1487- if outfile and tool == 'wasm-opt' and \
1488- (settings .DEBUG_LEVEL < 3 or settings .GENERATE_SOURCE_MAP ):
1489- # remove any dwarf debug info sections, if the debug level is <3, as
1490- # we don't need them; also remove them if we use source maps (which are
1491- # implemented separately from dwarf).
1492- # note that we add this pass first, so that it doesn't interfere with
1493- # the final set of passes (which may generate stack IR, and nothing
1494- # should be run after that)
1495- # TODO: if lld can strip dwarf then we don't need this. atm though it can
1496- # only strip all debug info or none, which includes the name section
1497- # which we may need
1498- # TODO: once fastcomp is gone, either remove source maps entirely, or
1499- # support them by emitting a source map at the end from the dwarf,
1500- # and use llvm-objcopy to remove that final dwarf
1501- cmd += ['--strip-dwarf' ]
15021487 cmd += args
15031488 if infile :
15041489 cmd += [infile ]
@@ -1534,8 +1519,22 @@ def run_binaryen_command(tool, infile, outfile=None, args=[], debug=False, stdou
15341519 return ret
15351520
15361521
1537- def run_wasm_opt (* args , ** kwargs ):
1538- return run_binaryen_command ('wasm-opt' , * args , ** kwargs )
1522+ def run_wasm_opt (infile , outfile = None , args = [], ** kwargs ):
1523+ if outfile and (settings .DEBUG_LEVEL < 3 or settings .GENERATE_SOURCE_MAP ):
1524+ # remove any dwarf debug info sections, if the debug level is <3, as
1525+ # we don't need them; also remove them if we use source maps (which are
1526+ # implemented separately from dwarf).
1527+ # note that we add this pass first, so that it doesn't interfere with
1528+ # the final set of passes (which may generate stack IR, and nothing
1529+ # should be run after that)
1530+ # TODO: if lld can strip dwarf then we don't need this. atm though it can
1531+ # only strip all debug info or none, which includes the name section
1532+ # which we may need
1533+ # TODO: once fastcomp is gone, either remove source maps entirely, or
1534+ # support them by emitting a source map at the end from the dwarf,
1535+ # and use llvm-objcopy to remove that final dwarf
1536+ args .insert (0 , '--strip-dwarf' )
1537+ return run_binaryen_command ('wasm-opt' , infile , outfile , args = args , ** kwargs )
15391538
15401539
15411540save_intermediate_counter = 0
0 commit comments