@@ -8186,8 +8186,8 @@ def break_cashew():
8186
8186
def test_binaryen_metadce (self ):
8187
8187
def test (filename , expectations ):
8188
8188
# in -Os, -Oz, we remove imports wasm doesn't need
8189
- for args , expected_len , expected_exists , expected_not_exists , expected_wasm_size , expected_wasm_imports , expected_wasm_exports in expectations :
8190
- print (args , expected_len , expected_exists , expected_not_exists , expected_wasm_size , expected_wasm_imports , expected_wasm_exports )
8189
+ for args , expected_len , expected_exists , expected_not_exists , expected_wasm_size , expected_wasm_imports , expected_wasm_exports , expected_wasm_funcs in expectations :
8190
+ print (args , expected_len , expected_exists , expected_not_exists , expected_wasm_size , expected_wasm_imports , expected_wasm_exports , expected_wasm_funcs )
8191
8191
run_process ([PYTHON , EMCC , filename , '-g2' ] + args )
8192
8192
# find the imports we send from JS
8193
8193
js = open ('a.out.js' ).read ()
@@ -8212,23 +8212,26 @@ def test(filename, expectations):
8212
8212
wast = run_process ([os .path .join (Building .get_binaryen_bin (), 'wasm-dis' ), 'a.out.wasm' ], stdout = PIPE ).stdout
8213
8213
imports = wast .count ('(import ' )
8214
8214
exports = wast .count ('(export ' )
8215
+ funcs = wast .count ('\n (func ' )
8215
8216
self .assertEqual (imports , expected_wasm_imports )
8216
8217
self .assertEqual (exports , expected_wasm_exports )
8218
+ if expected_wasm_funcs is not None :
8219
+ self .assertEqual (funcs , expected_wasm_funcs )
8217
8220
8218
8221
print ('test on hello world' )
8219
8222
test (path_from_root ('tests' , 'hello_world.cpp' ), [
8220
- ([], 23 , ['abort' , 'tempDoublePtr' ], ['waka' ], 46505 , 24 , 19 ), # noqa
8221
- (['-O1' ], 18 , ['abort' , 'tempDoublePtr' ], ['waka' ], 12630 , 16 , 17 ), # noqa
8222
- (['-O2' ], 18 , ['abort' , 'tempDoublePtr' ], ['waka' ], 12616 , 16 , 17 ), # noqa
8223
- (['-O3' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2818 , 10 , 2 ), # noqa; in -O3, -Os and -Oz we metadce
8224
- (['-Os' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2771 , 10 , 2 ), # noqa
8225
- (['-Oz' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2765 , 10 , 2 ), # noqa
8223
+ ([], 23 , ['abort' , 'tempDoublePtr' ], ['waka' ], 46505 , 24 , 19 , 62 ), # noqa
8224
+ (['-O1' ], 18 , ['abort' , 'tempDoublePtr' ], ['waka' ], 12630 , 16 , 17 , 34 ), # noqa
8225
+ (['-O2' ], 18 , ['abort' , 'tempDoublePtr' ], ['waka' ], 12616 , 16 , 17 , 33 ), # noqa
8226
+ (['-O3' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2818 , 10 , 2 , 21 ), # noqa; in -O3, -Os and -Oz we metadce
8227
+ (['-Os' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2771 , 10 , 2 , 21 ), # noqa
8228
+ (['-Oz' ], 7 , ['abort' ], ['tempDoublePtr' , 'waka' ], 2765 , 10 , 2 , 21 ), # noqa
8226
8229
# finally, check what happens when we export nothing. wasm should be almost empty
8227
8230
(['-Os' , '-s' , 'EXPORTED_FUNCTIONS=[]' ],
8228
- 0 , [], ['tempDoublePtr' , 'waka' ], 8 , 0 , 0 ), # noqa; totally empty!
8231
+ 0 , [], ['tempDoublePtr' , 'waka' ], 8 , 0 , 0 , 0 ), # noqa; totally empty!
8229
8232
# but we don't metadce with linkable code! other modules may want it
8230
8233
(['-O3' , '-s' , 'MAIN_MODULE=1' ],
8231
- 1529 , ['invoke_i' ], ['waka' ], 469663 , 149 , 1443 ),
8234
+ 1529 , ['invoke_i' ], ['waka' ], 469663 , 149 , 1443 , None ), # noqa; don't compare the # of functions in a main module, which changes a lot
8232
8235
]) # noqa
8233
8236
8234
8237
print ('test on a minimal pure computational thing' )
@@ -8241,20 +8244,20 @@ def test(filename, expectations):
8241
8244
}
8242
8245
''' )
8243
8246
test ('minimal.c' , [
8244
- ([], 23 , ['abort' , 'tempDoublePtr' ], ['waka' ], 22712 , 24 , 18 ), # noqa
8245
- (['-O1' ], 11 , ['abort' , 'tempDoublePtr' ], ['waka' ], 10450 , 9 , 15 ), # noqa
8246
- (['-O2' ], 11 , ['abort' , 'tempDoublePtr' ], ['waka' ], 10440 , 9 , 15 ), # noqa
8247
+ ([], 23 , ['abort' , 'tempDoublePtr' ], ['waka' ], 22712 , 24 , 18 , 31 ), # noqa
8248
+ (['-O1' ], 11 , ['abort' , 'tempDoublePtr' ], ['waka' ], 10450 , 9 , 15 , 15 ), # noqa
8249
+ (['-O2' ], 11 , ['abort' , 'tempDoublePtr' ], ['waka' ], 10440 , 9 , 15 , 15 ), # noqa
8247
8250
# in -O3, -Os and -Oz we metadce, and they shrink it down to the minimal output we want
8248
- (['-O3' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 ), # noqa
8249
- (['-Os' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 ), # noqa
8250
- (['-Oz' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 ), # noqa
8251
+ (['-O3' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 , 1 ), # noqa
8252
+ (['-Os' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 , 1 ), # noqa
8253
+ (['-Oz' ], 0 , [], ['tempDoublePtr' , 'waka' ], 58 , 0 , 1 , 1 ), # noqa
8251
8254
])
8252
8255
8253
8256
print ('test on libc++: see effects of emulated function pointers' )
8254
8257
test (path_from_root ('tests' , 'hello_libcxx.cpp' ), [
8255
- (['-O2' ], 53 , ['abort' , 'tempDoublePtr' ], ['waka' ], 208677 , 30 , 44 ), # noqa
8258
+ (['-O2' ], 53 , ['abort' , 'tempDoublePtr' ], ['waka' ], 208677 , 30 , 44 , 661 ), # noqa
8256
8259
(['-O2' , '-s' , 'EMULATED_FUNCTION_POINTERS=1' ],
8257
- 54 , ['abort' , 'tempDoublePtr' ], ['waka' ], 208677 , 30 , 25 ), # noqa
8260
+ 54 , ['abort' , 'tempDoublePtr' ], ['waka' ], 208677 , 30 , 25 , 622 ), # noqa
8258
8261
]) # noqa
8259
8262
8260
8263
# ensures runtime exports work, even with metadce
0 commit comments