@@ -1732,10 +1732,9 @@ def emscript_wasm_backend(infile, settings, outfile, libraries=None, compiler_en
1732
1732
if libraries is None : libraries = []
1733
1733
1734
1734
if shared .Settings .EXPERIMENTAL_USE_LLD :
1735
- wast , metadata = build_wasm_lld (temp_files , infile , outfile , settings , DEBUG )
1735
+ wasm , metadata = build_wasm_lld (temp_files , infile , outfile , settings , DEBUG )
1736
1736
else :
1737
- wast = build_wasm (temp_files , infile , outfile , settings , DEBUG )
1738
- metadata = read_metadata_wast (wast , DEBUG )
1737
+ wasm , metadata = build_wasm (temp_files , infile , outfile , settings , DEBUG )
1739
1738
1740
1739
# optimize syscalls
1741
1740
@@ -1789,7 +1788,7 @@ def emscript_wasm_backend(infile, settings, outfile, libraries=None, compiler_en
1789
1788
outfile .write (pre )
1790
1789
pre = None
1791
1790
1792
- invoke_funcs = read_wast_invoke_imports ( wast )
1791
+ invoke_funcs = metadata . get ( 'invokeFuncs' , [] )
1793
1792
# List of function signatures used in jsCall functions, e.g.['v', 'vi']
1794
1793
jscall_sigs = metadata .get ('jsCallFuncType' , [])
1795
1794
@@ -1827,33 +1826,29 @@ def build_wasm(temp_files, infile, outfile, settings, DEBUG):
1827
1826
1828
1827
assert shared .Settings .BINARYEN_ROOT , 'need BINARYEN_ROOT config set so we can use Binaryen s2wasm on the backend output'
1829
1828
basename = shared .unsuffixed (outfile .name )
1830
- wast = basename + '.wast'
1831
1829
wasm = basename + '.wasm'
1832
- s2wasm_args = create_s2wasm_args (temp_s )
1833
- if DEBUG :
1834
- logging .debug ('emscript: binaryen s2wasm: ' + ' ' .join (s2wasm_args ))
1835
- t = time .time ()
1836
- #s2wasm_args += ['--debug']
1837
- shared .check_call (s2wasm_args , stdout = open (wast , 'w' ))
1838
- # Also convert wasm text to binary
1839
- wasm_as_args = [os .path .join (shared .Settings .BINARYEN_ROOT , 'bin' , 'wasm-as' ),
1840
- wast , '-o' , wasm ]
1830
+ metadata_file = basename + '.metadata'
1831
+ s2wasm_args = create_s2wasm_args (temp_s , wasm )
1841
1832
if settings ['DEBUG_LEVEL' ] >= 2 or settings ['PROFILING_FUNCS' ]:
1842
- wasm_as_args += ['-g' ]
1833
+ s2wasm_args += ['-g' ]
1843
1834
if settings ['DEBUG_LEVEL' ] >= 4 :
1844
- wasm_as_args += ['--source-map=' + wasm + '.map' ]
1835
+ s2wasm_args += ['--source-map=' + wasm + '.map' ]
1845
1836
if not settings ['SOURCE_MAP_BASE' ]:
1846
1837
logging .warn ("Wasm source map won't be usable in a browser without --source-map-base" )
1847
1838
else :
1848
- wasm_as_args += ['--source-map-url=' + settings ['SOURCE_MAP_BASE' ] + os .path .basename (settings ['WASM_BINARY_FILE' ]) + '.map' ]
1849
- logging .debug (' emscript: binaryen wasm-as: ' + ' ' .join (wasm_as_args ))
1850
- shared .check_call (wasm_as_args )
1839
+ s2wasm_args += ['--source-map-url=' + settings ['SOURCE_MAP_BASE' ] + os .path .basename (settings ['WASM_BINARY_FILE' ]) + '.map' ]
1840
+ if DEBUG :
1841
+ logging .debug ('emscript: binaryen s2wasm: ' + ' ' .join (s2wasm_args ))
1842
+ t = time .time ()
1843
+ #s2wasm_args += ['--debug']
1844
+ shared .check_call (s2wasm_args , stdout = open (metadata_file , 'w' ))
1845
+
1846
+ metadata = create_metadata_wasm (open (metadata_file ).read (), DEBUG )
1851
1847
1852
1848
if DEBUG :
1853
1849
logging .debug (' emscript: binaryen s2wasm took %s seconds' % (time .time () - t ))
1854
1850
t = time .time ()
1855
- shutil .copyfile (wast , os .path .join (shared .CANONICAL_TEMP_DIR , 'emcc-s2wasm-output.wast' ))
1856
- return wast
1851
+ return wasm , metadata
1857
1852
1858
1853
1859
1854
def build_wasm_lld (temp_files , infile , outfile , settings , DEBUG ):
@@ -1882,8 +1877,8 @@ def debug_copy(src, dst):
1882
1877
debug_copy (temp_o , 'emcc-llvm-backend-output.o' )
1883
1878
1884
1879
basename = shared .unsuffixed (outfile .name )
1885
- wast = basename + '.wast'
1886
1880
wasm = basename + '.wasm'
1881
+ metadata_file = basename + '.metadata'
1887
1882
base_wasm = basename + '.lld.wasm'
1888
1883
1889
1884
libc_rt_lib = shared .Cache .get ('wasm_libc_rt.a' , wasm_rt_fail ('wasm_libc_rt.a' ), 'a' )
@@ -1907,20 +1902,15 @@ def debug_copy(src, dst):
1907
1902
t = time .time ()
1908
1903
debug_copy (base_wasm , 'base_wasm.wasm' )
1909
1904
1910
- # TODO: We currently read exports from the wast in order to generate
1911
- # metadata. So we emit text here so we can parse wast from python.
1912
- shared .check_call ([wasm_emscripten_finalize , base_wasm , '-o' , wast , '-S' ,
1905
+ shared .check_call ([wasm_emscripten_finalize , base_wasm , '-o' , wasm ,
1913
1906
'--global-base=%s' % shared .Settings .GLOBAL_BASE ,
1914
1907
('--emscripten-reserved-function-pointers=%d' %
1915
- shared .Settings .RESERVED_FUNCTION_POINTERS )])
1916
- debug_copy ( wast , 'lld-emscripten-output.wast' )
1908
+ shared .Settings .RESERVED_FUNCTION_POINTERS )],
1909
+ stdout = open ( metadata_file , 'w' ) )
1917
1910
1918
- shared .check_call ([wasm_as , wast , '-o' , wasm ])
1919
- debug_copy (wasm , 'lld-emscripten-output.wasm' )
1911
+ metadata = create_metadata_wasm (open (metadata_file ).read (), DEBUG )
1920
1912
1921
- metadata = read_metadata_wast (wast , DEBUG )
1922
-
1923
- return wast , metadata
1913
+ return wasm , metadata
1924
1914
1925
1915
1926
1916
def read_metadata_wast (wast , DEBUG ):
@@ -2028,17 +2018,6 @@ def create_em_js(forwarded_json, metadata):
2028
2018
return em_js_funcs
2029
2019
2030
2020
2031
- def read_wast_invoke_imports (wast ):
2032
- invoke_funcs = []
2033
- for line in open (wast ).readlines ():
2034
- if line .strip ().startswith ('(import ' ):
2035
- parts = line .split ()
2036
- func_name = parts [2 ][1 :- 1 ]
2037
- if func_name .startswith ('invoke_' ):
2038
- invoke_funcs .append (func_name )
2039
- return invoke_funcs
2040
-
2041
-
2042
2021
def create_sending_wasm (invoke_funcs , jscall_sigs , forwarded_json , metadata ,
2043
2022
settings ):
2044
2023
basic_funcs = ['abort' , 'assert' , 'enlargeMemory' , 'getTotalMemory' ]
@@ -2158,13 +2137,13 @@ def wrapped():
2158
2137
raise Exception ('Expected {} to already be built' .format (archive_file ))
2159
2138
return wrapped
2160
2139
2161
- def create_s2wasm_args (temp_s ):
2140
+ def create_s2wasm_args (temp_s , wasm ):
2162
2141
compiler_rt_lib = shared .Cache .get ('wasm_compiler_rt.a' , wasm_rt_fail ('wasm_compiler_rt.a' ), 'a' )
2163
2142
libc_rt_lib = shared .Cache .get ('wasm_libc_rt.a' , wasm_rt_fail ('wasm_libc_rt.a' ), 'a' )
2164
2143
2165
2144
s2wasm_path = os .path .join (shared .Settings .BINARYEN_ROOT , 'bin' , 's2wasm' )
2166
2145
2167
- args = [s2wasm_path , temp_s , '-- emscripten-glue' ]
2146
+ args = [s2wasm_path , temp_s , '-o' , wasm , '-- emscripten-glue' , '--emit-binary ' ]
2168
2147
args += ['--global-base=%d' % shared .Settings .GLOBAL_BASE ]
2169
2148
args += ['--initial-memory=%d' % shared .Settings .TOTAL_MEMORY ]
2170
2149
args += ['--allow-memory-growth' ] if shared .Settings .ALLOW_MEMORY_GROWTH else []
@@ -2194,6 +2173,7 @@ def load_metadata(metadata_raw):
2194
2173
'initializers' : [],
2195
2174
'exports' : [],
2196
2175
'emJsFuncs' : {},
2176
+ 'invokeFuncs' : [],
2197
2177
}
2198
2178
2199
2179
for k , v in metadata_json .items ():
0 commit comments