@@ -2278,104 +2278,40 @@ def test_extern_prepost(self):
2278
2278
# make sure the slack is tiny compared to the whole program
2279
2279
self .assertGreater (len (js ), 100 * SLACK )
2280
2280
2281
- def test_js_optimizer (self ):
2282
- for input , expected , passes in [
2283
- (test_file ('optimizer/test-js-optimizer-minifyGlobals.js' ), read_file (test_file ('optimizer/test-js-optimizer-minifyGlobals-output.js' )),
2284
- ['minifyGlobals' ]),
2285
- (test_file ('optimizer/test-js-optimizer-minifyLocals.js' ), read_file (test_file ('optimizer/test-js-optimizer-minifyLocals-output.js' )),
2286
- ['minifyLocals' ]),
2287
- (test_file ('optimizer/JSDCE.js' ), read_file (test_file ('optimizer/JSDCE-output.js' )),
2288
- ['JSDCE' ]),
2289
- (test_file ('optimizer/JSDCE-hasOwnProperty.js' ), read_file (test_file ('optimizer/JSDCE-hasOwnProperty-output.js' )),
2290
- ['JSDCE' ]),
2291
- (test_file ('optimizer/JSDCE-fors.js' ), read_file (test_file ('optimizer/JSDCE-fors-output.js' )),
2292
- ['JSDCE' ]),
2293
- (test_file ('optimizer/AJSDCE.js' ), read_file (test_file ('optimizer/AJSDCE-output.js' )),
2294
- ['AJSDCE' ]),
2295
- (test_file ('optimizer/emitDCEGraph.js' ), read_file (test_file ('optimizer/emitDCEGraph-output.js' )),
2296
- ['emitDCEGraph' , 'noPrint' ]),
2297
- (test_file ('optimizer/emitDCEGraph2.js' ), read_file (test_file ('optimizer/emitDCEGraph2-output.js' )),
2298
- ['emitDCEGraph' , 'noPrint' ]),
2299
- (test_file ('optimizer/emitDCEGraph3.js' ), read_file (test_file ('optimizer/emitDCEGraph3-output.js' )),
2300
- ['emitDCEGraph' , 'noPrint' ]),
2301
- (test_file ('optimizer/emitDCEGraph4.js' ), read_file (test_file ('optimizer/emitDCEGraph4-output.js' )),
2302
- ['emitDCEGraph' , 'noPrint' ]),
2303
- (test_file ('optimizer/emitDCEGraph5.js' ), read_file (test_file ('optimizer/emitDCEGraph5-output.js' )),
2304
- ['emitDCEGraph' , 'noPrint' ]),
2305
- (test_file ('optimizer/minimal-runtime-applyDCEGraphRemovals.js' ), read_file (test_file ('optimizer/minimal-runtime-applyDCEGraphRemovals-output.js' )),
2306
- ['applyDCEGraphRemovals' ]),
2307
- (test_file ('optimizer/applyDCEGraphRemovals.js' ), read_file (test_file ('optimizer/applyDCEGraphRemovals-output.js' )),
2308
- ['applyDCEGraphRemovals' ]),
2309
- (test_file ('optimizer/applyImportAndExportNameChanges.js' ), read_file (test_file ('optimizer/applyImportAndExportNameChanges-output.js' )),
2310
- ['applyImportAndExportNameChanges' ]),
2311
- (test_file ('optimizer/applyImportAndExportNameChanges2.js' ), read_file (test_file ('optimizer/applyImportAndExportNameChanges2-output.js' )),
2312
- ['applyImportAndExportNameChanges' ]),
2313
- (test_file ('optimizer/minimal-runtime-emitDCEGraph.js' ), read_file (test_file ('optimizer/minimal-runtime-emitDCEGraph-output.js' )),
2314
- ['emitDCEGraph' , 'noPrint' ]),
2315
- (test_file ('optimizer/minimal-runtime-2-emitDCEGraph.js' ), read_file (test_file ('optimizer/minimal-runtime-2-emitDCEGraph-output.js' )),
2316
- ['emitDCEGraph' , 'noPrint' ]),
2317
- (test_file ('optimizer/standalone-emitDCEGraph.js' ), read_file (test_file ('optimizer/standalone-emitDCEGraph-output.js' )),
2318
- ['emitDCEGraph' , 'noPrint' ]),
2319
- (test_file ('optimizer/emittedJSPreservesParens.js' ), read_file (test_file ('optimizer/emittedJSPreservesParens-output.js' )),
2320
- []),
2321
- (test_file ('optimizer/test-growableHeap.js' ), read_file (test_file ('optimizer/test-growableHeap-output.js' )),
2322
- ['growableHeap' ]),
2323
- (test_file ('optimizer/test-unsignPointers.js' ), read_file (test_file ('optimizer/test-unsignPointers-output.js' )),
2324
- ['unsignPointers' ]),
2325
- (test_file ('optimizer/test-asanify.js' ), read_file (test_file ('optimizer/test-asanify-output.js' )),
2326
- ['asanify' ]),
2327
- (test_file ('optimizer/test-safeHeap.js' ), read_file (test_file ('optimizer/test-safeHeap-output.js' )),
2328
- ['safeHeap' ]),
2329
- (test_file ('optimizer/test-LittleEndianHeap.js' ), read_file (test_file ('optimizer/test-LittleEndianHeap-output.js' )),
2330
- ['littleEndianHeap' ]),
2331
- ]:
2332
- print (input , passes )
2333
-
2334
- if not isinstance (expected , list ):
2335
- expected = [expected ]
2336
- expected = [out .replace ('\n \n ' , '\n ' ).replace ('\n \n ' , '\n ' ) for out in expected ]
2337
-
2338
- # test calling optimizer
2339
- output = self .run_process (config .NODE_JS + [path_from_root ('tools/acorn-optimizer.js' ), input ] + passes , stdin = PIPE , stdout = PIPE ).stdout
2340
-
2341
- def check_js (js , expected ):
2342
- # print >> sys.stderr, 'chak\n==========================\n', js, '\n===========================\n'
2343
- if 'registerizeHarder' in passes :
2344
- # registerizeHarder is hard to test, as names vary by chance, nondeterminstically FIXME
2345
- def fix (src ):
2346
- if type (src ) is list :
2347
- return list (map (fix , src ))
2348
- src = '\n ' .join ([line for line in src .split ('\n ' ) if 'var ' not in line ]) # ignore vars
2349
-
2350
- def reorder (func ):
2351
- def swap (func , stuff ):
2352
- # emit EYE_ONE always before EYE_TWO, replacing i1,i2 or i2,i1 etc
2353
- for i in stuff :
2354
- if i not in func :
2355
- return func
2356
- indexes = [[i , func .index (i )] for i in stuff ]
2357
- indexes .sort (key = lambda x : x [1 ])
2358
- for j in range (len (indexes )):
2359
- func = func .replace (indexes [j ][0 ], 'STD_' + str (j ))
2360
- return func
2361
- func = swap (func , ['i1' , 'i2' , 'i3' ])
2362
- func = swap (func , ['i1' , 'i2' ])
2363
- func = swap (func , ['i4' , 'i5' ])
2364
- return func
2365
-
2366
- src = 'function ' .join (map (reorder , src .split ('function ' )))
2367
- return src
2368
- js = fix (js )
2369
- expected = fix (expected )
2370
- self .assertIdentical (expected , js .replace ('\r \n ' , '\n ' ).replace ('\n \n ' , '\n ' ).replace ('\n \n ' , '\n ' ))
2371
-
2372
- if input not in [ # tests that are native-optimizer only
2373
- test_file ('optimizer/asmLastOpts.js' ),
2374
- test_file ('optimizer/3154.js' )
2375
- ]:
2376
- check_js (output , expected )
2377
- else :
2378
- print ('(skip non-native)' )
2281
+ @parameterized ({
2282
+ 'minifyGlobals' : ('optimizer/test-js-optimizer-minifyGlobals.js' , ['minifyGlobals' ]),
2283
+ 'minifyLocals' : ('optimizer/test-js-optimizer-minifyLocals.js' , ['minifyLocals' ]),
2284
+ 'JSDCE' : ('optimizer/JSDCE.js' , ['JSDCE' ]),
2285
+ 'JSDCE-hasOwnProperty' : ('optimizer/JSDCE-hasOwnProperty.js' , ['JSDCE' ]),
2286
+ 'JSDCE-fors' : ('optimizer/JSDCE-fors.js' , ['JSDCE' ]),
2287
+ 'AJSDCE' : ('optimizer/AJSDCE.js' , ['AJSDCE' ]),
2288
+ 'emitDCEGraph' : ('optimizer/emitDCEGraph.js' , ['emitDCEGraph' , 'noPrint' ]),
2289
+ 'emitDCEGraph1' : ('optimizer/emitDCEGraph2.js' , ['emitDCEGraph' , 'noPrint' ]),
2290
+ 'emitDCEGraph3' : ('optimizer/emitDCEGraph3.js' , ['emitDCEGraph' , 'noPrint' ]),
2291
+ 'emitDCEGraph4' : ('optimizer/emitDCEGraph4.js' , ['emitDCEGraph' , 'noPrint' ]),
2292
+ 'emitDCEGraph5' : ('optimizer/emitDCEGraph5.js' , ['emitDCEGraph' , 'noPrint' ]),
2293
+ 'minimal-runtime-applyDCEGraphRemovals' : ('optimizer/minimal-runtime-applyDCEGraphRemovals.js' , ['applyDCEGraphRemovals' ]),
2294
+ 'applyDCEGraphRemovals' : ('optimizer/applyDCEGraphRemovals.js' , ['applyDCEGraphRemovals' ]),
2295
+ 'applyImportAndExportNameChanges' : ('optimizer/applyImportAndExportNameChanges.js' , ['applyImportAndExportNameChanges' ]),
2296
+ 'applyImportAndExportNameChanges2' : ('optimizer/applyImportAndExportNameChanges2.js' , ['applyImportAndExportNameChanges' ]),
2297
+ 'minimal-runtime-emitDCEGraph' : ('optimizer/minimal-runtime-emitDCEGraph.js' , ['emitDCEGraph' , 'noPrint' ]),
2298
+ 'minimal-runtime-2-emitDCEGraph' : ('optimizer/minimal-runtime-2-emitDCEGraph.js' , ['emitDCEGraph' , 'noPrint' ]),
2299
+ 'standalone-emitDCEGraph' : ('optimizer/standalone-emitDCEGraph.js' , ['emitDCEGraph' , 'noPrint' ]),
2300
+ 'emittedJSPreservesParens' : ('optimizer/emittedJSPreservesParens.js' , []),
2301
+ 'growableHeap' : ('optimizer/test-growableHeap.js' , ['growableHeap' ]),
2302
+ 'unsignPointers' : ('optimizer/test-unsignPointers.js' , ['unsignPointers' ]),
2303
+ 'asanify' : ('optimizer/test-asanify.js' , ['asanify' ]),
2304
+ 'safeHeap' : ('optimizer/test-safeHeap.js' , ['safeHeap' ]),
2305
+ 'LittleEndianHeap' : ('optimizer/test-LittleEndianHeap.js' , ['littleEndianHeap' ]),
2306
+ })
2307
+ def test_js_optimizer (self , input , passes ):
2308
+ input = test_file (input )
2309
+ expected = os .path .splitext (input )[0 ] + '-output.js'
2310
+ expected = read_file (expected ).replace ('\n \n ' , '\n ' )
2311
+
2312
+ # test calling optimizer
2313
+ js = self .run_process (config .NODE_JS + [path_from_root ('tools/acorn-optimizer.js' ), input ] + passes , stdin = PIPE , stdout = PIPE ).stdout
2314
+ self .assertIdentical (expected , js .replace ('\r \n ' , '\n ' ).replace ('\n \n ' , '\n ' ).replace ('\n \n ' , '\n ' ))
2379
2315
2380
2316
@parameterized ({
2381
2317
'wasm2js' : ('wasm2js' , ['minifyNames' , 'last' ]),
0 commit comments