diff options
author | Jez Ng <me@jezng.com> | 2013-06-19 01:56:47 -0700 |
---|---|---|
committer | Jez Ng <me@jezng.com> | 2013-06-19 14:09:13 -0700 |
commit | 7656f948388b5a3421996196ea36c7bb052bb884 (patch) | |
tree | e7a1967ccce8cf5f0a0e077dcacda2116f4d6b8d | |
parent | be5d45fe2932f9452c623b63720cb7d9857a1baa (diff) |
Lay the groundwork for optimized source maps.
-rwxr-xr-x | emcc | 7 | ||||
-rw-r--r-- | tools/js-optimizer.js | 12 | ||||
-rw-r--r-- | tools/js_optimizer.py | 20 | ||||
-rw-r--r-- | tools/shared.py | 4 |
4 files changed, 30 insertions, 13 deletions
@@ -869,7 +869,6 @@ try: if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level] if llvm_lto is None: llvm_lto = opt_level >= 3 if opt_level <= 0: keep_llvm_debug = keep_js_debug = True # always keep debug in -O0 - if opt_level > 0: keep_llvm_debug = False # JS optimizer wipes out llvm debug info from being visible if closure is None and opt_level == 3: closure = True if DEBUG: start_time = time.time() # done after parsing arguments, which might affect debug state @@ -1496,7 +1495,8 @@ try: if shared.Settings.ASM_JS: js_optimizer_queue = ['asm'] + js_optimizer_queue logging.debug('applying js optimization passes: %s', js_optimizer_queue) - final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache) + final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache, + keep_llvm_debug and keep_js_debug) if DEBUG: save_intermediate('js_opts') else: for name in js_optimizer_queue: @@ -1504,7 +1504,8 @@ try: if shared.Settings.ASM_JS: passes = ['asm'] + passes logging.debug('applying js optimization pass: %s', passes) - final = shared.Building.js_optimizer(final, passes, jcache) + final = shared.Building.js_optimizer(final, passes, jcache, + keep_llvm_debug and keep_js_debug) save_intermediate(name) js_optimizer_queue = [] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 07317e0a..21ce54a8 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -11,6 +11,7 @@ // *** Environment setup code *** var arguments_ = []; +var debug = false; var ENVIRONMENT_IS_NODE = typeof process === 'object'; var ENVIRONMENT_IS_WEB = typeof window === 'object'; @@ -146,7 +147,7 @@ var generatedFunctions = false; // whether we have received only generated funct var minifierInfo = null; function srcToAst(src) { - return uglify.parser.parse(src); + return uglify.parser.parse(src, false, debug); } function astToSrc(ast, compress) { @@ -2750,6 +2751,14 @@ var passes = { var suffix = ''; +arguments_ = arguments_.filter(function (arg) { + if (!/^--/.test(arg)) return true; + + if (arg === '--debug') debug = true; + else throw new Error('Unrecognized flag: ' + arg); +}); + + var src = read(arguments_[0]); var ast = srcToAst(src); //printErr(JSON.stringify(ast)); throw 1; @@ -2758,6 +2767,7 @@ var minifierInfoStart = src.indexOf('// MINIFY_INFO:') if (minifierInfoStart > 0) minifierInfo = JSON.parse(src.substr(minifierInfoStart + 15)); //printErr(JSON.stringify(minifierInfo)); + arguments_.slice(1).forEach(function(arg) { passes[arg](ast); }); diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 0452a725..e99c02be 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, compress, debug=False): #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,11 @@ 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'] + + (['compress'] if compress else []) + + (['--debug'] if debug 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:') @@ -103,7 +107,7 @@ def run_on_chunk(command): if DEBUG and not shared.WINDOWS: print >> sys.stderr, '.' # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console. return filename -def run_on_js(filename, passes, js_engine, jcache): +def run_on_js(filename, passes, js_engine, jcache, debug=False): if isinstance(jcache, bool) and jcache: jcache = shared.JCache if jcache: shared.JCache.ensure() @@ -171,7 +175,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, 'compress' in passes, debug).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 @@ -247,7 +251,9 @@ EMSCRIPTEN_FUNCS(); if len(filenames) > 0: # XXX Use '--nocrankshaft' to disable crankshaft to work around v8 bug 1895, needed for older v8/node (node 0.6.8+ should be ok) - commands = map(lambda filename: js_engine + [JS_OPTIMIZER, filename, 'noPrintMetadata'] + passes, filenames) + commands = map(lambda filename: js_engine + + [JS_OPTIMIZER, filename, 'noPrintMetadata'] + + (['--debug'] if debug else []) + passes, filenames) #print [' '.join(command) for command in commands] cores = min(cores, filenames) @@ -315,6 +321,6 @@ EMSCRIPTEN_FUNCS(); return filename -def run(filename, passes, js_engine, jcache): - return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache)) +def run(filename, passes, js_engine, jcache, debug=False): + return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, debug)) diff --git a/tools/shared.py b/tools/shared.py index c16c9115..89ceeccb 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1213,8 +1213,8 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e return opts @staticmethod - def js_optimizer(filename, passes, jcache): - return js_optimizer.run(filename, passes, listify(NODE_JS), jcache) + def js_optimizer(filename, passes, jcache, debug): + return js_optimizer.run(filename, passes, listify(NODE_JS), jcache, debug) @staticmethod def closure_compiler(filename, pretty=True): |