diff options
-rwxr-xr-x | emcc | 20 | ||||
-rw-r--r-- | tests/runner.py | 3 | ||||
-rw-r--r-- | tools/js-optimizer.js | 11 |
3 files changed, 29 insertions, 5 deletions
@@ -155,6 +155,14 @@ Options that are modified or new in %s include: list of arguments, for example, <cmd> of "python processor.py" will cause a python script to be run. + --compress <on> 0: Do not compress the generated JavaScript's + whitespace (default if closure compiler + will not be run) + 1: Compress the generated JavaScript's + whitespace (default if closure compiler + will be run). Note that this by itself + will not minify the code (closure does + that) The target file, if specified (-o <target>), defines what will be generated: @@ -272,6 +280,7 @@ try: llvm_opt_level = None closure = None js_transform = None + compress_whitespace = None def check_bad_eq(arg): assert '=' not in arg, 'Invalid parameter (do not use "=" with "--" options)' @@ -300,6 +309,11 @@ try: js_transform = newargs[i+1] newargs[i] = '' newargs[i+1] = '' + elif newargs[i].startswith('--compress'): + check_bad_eq(newargs[i]) + compress_whitespace = int(newargs[i+1]) + newargs[i] = '' + newargs[i+1] = '' elif newargs[i] == '-MF': # clang cannot handle this, so we fake it f = open(newargs[i+1], 'w') f.write('\n') @@ -310,6 +324,8 @@ try: if llvm_opt_level is None: llvm_opt_level = 1 if opt_level >= 1 else 0 if closure is None: closure = 1 if opt_level >= 2 else 0 + if compress_whitespace is None: + compress_whitespace = closure # if closure is run, compress whitespace if closure: assert os.path.exists(shared.CLOSURE_COMPILER), 'emcc: fatal: Closure compiler (%s) does not exist' % shared.CLOSURE_COMPILER @@ -546,6 +562,10 @@ try: final = shared.Building.js_optimizer(final, 'simplifyExpressionsPost') if DEBUG: save_intermediate('simplifyExpressionsPost') + if compress_whitespace: + final = shared.Building.js_optimizer(final, 'compress') + if DEBUG: save_intermediate('compress') + # If we were asked to also generate HTML, do that if final_suffix == 'html': if DEBUG: print >> sys.stderr, 'emcc: generating HTML' diff --git a/tests/runner.py b/tests/runner.py index a23297f6..25eac395 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -5404,7 +5404,7 @@ Options that are modified or new in %s include: assert 'SAFE_HEAP' not in generated, 'safe heap should not be used by default' assert ': while(' not in generated, 'when relooping we also js-optimize, so there should be no labelled whiles' if closure: - assert 'Module._main = ' in generated, 'closure compiler should have been run' + assert 'Module._main=' in generated, 'closure compiler should have been run (and output should be minified)' else: # closure has not been run, we can do some additional checks. TODO: figure out how to do these even with closure assert 'Module._main = ' not in generated, 'closure compiler should not have been run' @@ -5415,6 +5415,7 @@ Options that are modified or new in %s include: if opt_level >= 1: assert 'HEAP8[HEAP32[' in generated, 'eliminator should create compound expressions, and fewer one-time vars' assert ('_puts(' in generated) == (opt_level >= 1), 'with opt >= 1, llvm opts are run and they should optimize printf to puts' assert ('function _malloc(bytes) {' in generated) == (not has_malloc), 'If malloc is needed, it should be there, if not not' + assert 'function _main() {' in generated, 'Should be unminified, including whitespace' # emcc -s RELOOP=1 src.cpp ==> should pass -s to emscripten.py. --typed-arrays is a convenient alias for -s USE_TYPED_ARRAYS for params, test, text in [ diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index a77e0e09..02d7ecb3 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -127,10 +127,10 @@ function srcToAst(src) { return uglify.parser.parse(src); } -function astToSrc(ast) { +function astToSrc(ast, compress) { return uglify.uglify.gen_code(ast, { ascii_only: true, - beautify: true, + beautify: !compress, indent_level: 2 }); } @@ -1091,6 +1091,8 @@ function loopOptimizer(ast) { // Passes table +var compress = false; + var passes = { dumpAst: dumpAst, dumpSrc: dumpSrc, @@ -1102,7 +1104,8 @@ var passes = { optimizeShiftsAggressive: optimizeShiftsAggressive, simplifyExpressionsPost: simplifyExpressionsPost, hoistMultiples: hoistMultiples, - loopOptimizer: loopOptimizer + loopOptimizer: loopOptimizer, + compress: function() { compress = true; } }; // Main @@ -1120,6 +1123,6 @@ arguments_.slice(1).forEach(function(arg) { //printErr('output: ' + dump(ast)); //printErr('output: ' + astToSrc(ast)); ast = srcToAst(astToSrc(ast)); // re-parse, to simplify a little -print(astToSrc(ast)); +print(astToSrc(ast, compress)); if (metadata) print(metadata + '\n'); |