diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-22 15:02:10 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-22 15:02:10 -0700 |
commit | 202461abe30f260cf403d430e51d80f225950605 (patch) | |
tree | c84ea7b7d91237bf1164f4e23798960a455ae83a | |
parent | 369167ebda362eb0c76081976ae0a48d2d3c1cbd (diff) |
fix -g2 and add testing
-rwxr-xr-x | emcc | 5 | ||||
-rwxr-xr-x | tests/runner.py | 5 | ||||
-rw-r--r-- | tools/js-optimizer.js | 10 | ||||
-rw-r--r-- | tools/js_optimizer.py | 18 |
4 files changed, 23 insertions, 15 deletions
@@ -1552,8 +1552,9 @@ try: if (not closure or shared.Settings.ASM_JS) and shared.Settings.RELOOP and debug_level < 3: js_optimizer_queue += ['registerize'] - if debug_level == 0 and opt_level > 0: - js_optimizer_queue += ['compress'] + if opt_level > 0: + if debug_level < 2 and shared.Settings.ASM_JS: js_optimizer_queue += ['minifyGlobals'] + if debug_level == 0: js_optimizer_queue += ['minifyWhitespace'] if closure and shared.Settings.ASM_JS: js_optimizer_queue += ['closure'] diff --git a/tests/runner.py b/tests/runner.py index f8ca4343..3d98cf2c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10182,6 +10182,11 @@ Options that are modified or new in %s include: (['-O2'], lambda generated: 'var b=0' in generated and not 'function _main' in generated, 'registerize/minify is run by default in -O2'), (['-O2', '--minify', '0'], lambda generated: 'var b = 0' in generated and not 'function _main' in generated, 'minify is cancelled, but not registerize'), (['-O2', '-g'], lambda generated: 'var b=0' not in generated and 'var b = 0' not in generated and 'function _main' in generated, 'registerize/minify is cancelled by -g'), + (['-O2', '-g0'], lambda generated: 'var b=0' in generated and not 'function _main' in generated, 'registerize/minify is run by default in -O2 -g0'), + (['-O2', '-g1'], lambda generated: 'var b = 0' in generated and not 'function _main' in generated, 'compress is cancelled by -g1'), + (['-O2', '-g2'], lambda generated: 'var b = 0' in generated and 'function _main' in generated, 'minify is cancelled by -g2'), + (['-O2', '-g3'], lambda generated: 'var b=0' not in generated and 'var b = 0' not in generated and 'function _main' in generated, 'registerize is cancelled by -g3'), + #(['-O2', '-g4'], lambda generated: 'var b=0' not in generated and 'var b = 0' not in generated and 'function _main' in generated, 'same as -g3 for now'), (['-s', 'INLINING_LIMIT=0'], lambda generated: 'function _dump' in generated, 'no inlining without opts'), (['-O3', '-s', 'INLINING_LIMIT=0', '--closure', '0'], lambda generated: 'function _dump' not in generated, 'lto/inlining'), (['-Os', '--llvm-lto', '1', '-s', 'ASM_JS=0'], lambda generated: 'function _dump' in generated, '-Os disables inlining'), diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index ae72437b..fba97a14 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -149,10 +149,10 @@ function srcToAst(src) { return uglify.parser.parse(src); } -function astToSrc(ast, compress) { +function astToSrc(ast, minifyWhitespace) { return uglify.uglify.gen_code(ast, { ascii_only: true, - beautify: !compress, + beautify: !minifyWhitespace, indent_level: 1 }); } @@ -2759,7 +2759,7 @@ function asmLoopOptimizer(ast) { // Passes table -var compress = false, printMetadata = true, asm = false, last = false; +var minifyWhitespace = false, printMetadata = true, asm = false, last = false; var passes = { dumpAst: dumpAst, @@ -2777,7 +2777,7 @@ var passes = { eliminate: eliminate, eliminateMemSafe: eliminateMemSafe, minifyGlobals: minifyGlobals, - compress: function() { compress = true }, + minifyWhitespace: function() { minifyWhitespace = true }, noPrintMetadata: function() { printMetadata = false }, asm: function() { asm = true }, last: function() { last = true }, @@ -2803,7 +2803,7 @@ if (asm && last) { asmLoopOptimizer(ast); prepDotZero(ast); } -var js = astToSrc(ast, compress), old; +var js = astToSrc(ast, minifyWhitespace), old; if (asm && last) { js = fixDotZero(js); } diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 0452a725..f014c7d4 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -57,7 +57,7 @@ class Minifier: if curr not in INVALID_3: self.names.append(curr) #print >> sys.stderr, self.names - def minify_shell(self, shell, compress): + def minify_shell(self, shell, minify_whitespace): #print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222" # Run through js-optimizer.js to find and minify the global symbols # We send it the globals, which it parses at the proper time. JS decides how @@ -77,7 +77,7 @@ class Minifier: f.write('// MINIFY_INFO:' + self.serialize()) f.close() - output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['compress'] if compress else []), stdout=subprocess.PIPE).communicate()[0] + output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['minifyWhitespace'] if minify_whitespace else []), stdout=subprocess.PIPE).communicate()[0] assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output #print >> sys.stderr, "minified SHELL 3333333333333333", output, "\n44444444444444444444" code, metadata = output.split('// MINIFY_INFO:') @@ -130,8 +130,10 @@ def run_on_js(filename, passes, js_engine, jcache): start_funcs = js.find(start_funcs_marker) end_funcs = js.rfind(end_funcs_marker) #assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix) - asm_registerize = 'asm' in passes and 'registerize' in passes - if asm_registerize: + + minify_globals = 'minifyGlobals' in passes + if minify_globals: + passes = filter(lambda p: p != 'minifyGlobals', passes) # we will run it manually start_asm_marker = '// EMSCRIPTEN_START_ASM\n' end_asm_marker = '// EMSCRIPTEN_END_ASM\n' start_asm = js.find(start_asm_marker) @@ -146,7 +148,7 @@ def run_on_js(filename, passes, js_engine, jcache): jcache = False if suffix: - if not asm_registerize: + if not minify_globals: pre = js[:start_funcs + len(start_funcs_marker)] post = js[end_funcs + len(end_funcs_marker):] js = js[start_funcs + len(start_funcs_marker):end_funcs] @@ -171,7 +173,7 @@ EMSCRIPTEN_FUNCS(); js = js[start_funcs + len(start_funcs_marker):end_funcs] minifier = Minifier(js, js_engine) - asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'compress' in passes).split('EMSCRIPTEN_FUNCS();'); + asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes).split('EMSCRIPTEN_FUNCS();'); asm_shell_post = asm_shell_post.replace('});', '})'); pre += asm_shell_pre + '\n' + start_funcs_marker post = end_funcs_marker + asm_shell_post + post @@ -236,7 +238,7 @@ EMSCRIPTEN_FUNCS(); f = open(temp_file, 'w') f.write(chunk) f.write(suffix_marker) - if asm_registerize: + if minify_globals: f.write('\n') f.write('// MINIFY_INFO:' + minify_info) f.close() @@ -279,7 +281,7 @@ EMSCRIPTEN_FUNCS(); c.write(closure_sep) c.write(post_2) c.close() - closured = shared.Building.closure_compiler(closuree, pretty='compress' not in passes) + closured = shared.Building.closure_compiler(closuree, pretty='minifyWhitespace' not in passes) temp_files.note(closured) coutput = open(closured).read() coutput = coutput.replace('wakaUnknownBefore();', '') |