(js_file, wasm_file, debug_info, last)
| 803 | |
| 804 | # run binaryen's wasm-metadce to dce both js and wasm |
| 805 | def metadce(js_file, wasm_file, debug_info, last): |
| 806 | logger.debug('running meta-DCE') |
| 807 | temp_files = shared.get_temp_files() |
| 808 | extra_info = {"exports": [[asmjs_mangle(x), x] for x in settings.WASM_EXPORTS]} |
| 809 | |
| 810 | txt = acorn_optimizer(js_file, ['emitDCEGraph', '--no-print'], return_output=True, extra_info=extra_info) |
| 811 | if shared.SKIP_SUBPROCS: |
| 812 | # The next steps depend on the output from this step, so we can't do them if we aren't actually running. |
| 813 | return js_file |
| 814 | graph = json.loads(txt) |
| 815 | # ensure that functions expected to be exported to the outside are roots |
| 816 | required_symbols = user_requested_exports.union(set(settings.SIDE_MODULE_IMPORTS)) |
| 817 | for item in graph: |
| 818 | if 'export' in item: |
| 819 | export = asmjs_mangle(item['export']) |
| 820 | if settings.EXPORT_ALL or export in required_symbols: |
| 821 | item['root'] = True |
| 822 | |
| 823 | # fix wasi imports TODO: support wasm stable with an option? |
| 824 | WASI_IMPORTS = { |
| 825 | 'environ_get', |
| 826 | 'environ_sizes_get', |
| 827 | 'args_get', |
| 828 | 'args_sizes_get', |
| 829 | 'fd_write', |
| 830 | 'fd_close', |
| 831 | 'fd_read', |
| 832 | 'fd_seek', |
| 833 | 'fd_fdstat_get', |
| 834 | 'fd_sync', |
| 835 | 'fd_pread', |
| 836 | 'fd_pwrite', |
| 837 | 'proc_exit', |
| 838 | 'clock_res_get', |
| 839 | 'clock_time_get', |
| 840 | 'path_open', |
| 841 | 'random_get', |
| 842 | } |
| 843 | for item in graph: |
| 844 | if 'import' in item and item['import'][1] in WASI_IMPORTS: |
| 845 | item['import'][0] = settings.WASI_MODULE_NAME |
| 846 | |
| 847 | # map import/export names to native wasm symbols. |
| 848 | import_name_map = {} |
| 849 | export_name_map = {} |
| 850 | for item in graph: |
| 851 | if 'import' in item: |
| 852 | name = item['import'][1] |
| 853 | import_name_map[item['name']] = name |
| 854 | if asmjs_mangle(name) in settings.SIDE_MODULE_IMPORTS: |
| 855 | item['root'] = True |
| 856 | elif 'export' in item: |
| 857 | export_name_map[item['name']] = item['export'] |
| 858 | temp = temp_files.get('.json', prefix='emcc_dce_graph_').name |
| 859 | utils.write_file(temp, json.dumps(graph, indent=2)) |
| 860 | # run wasm-metadce |
| 861 | args = ['--graph-file=' + temp] |
| 862 | if last: |
no test coverage detected