aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc19
-rwxr-xr-xtests/runner.py4
-rw-r--r--tools/js_optimizer.py18
3 files changed, 23 insertions, 18 deletions
diff --git a/emcc b/emcc
index 2b2048e3..48ecd604 100755
--- a/emcc
+++ b/emcc
@@ -710,6 +710,7 @@ try:
save_bc = False
memory_init_file = False
use_preload_cache = False
+ make_source_map = False
if use_cxx:
default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
@@ -780,6 +781,9 @@ try:
elif newargs[i] == '-g':
keep_llvm_debug = True
keep_js_debug = True
+ elif newargs[i] == '--map':
+ make_source_map = True
+ newargs[i] = '-g' # we'll need this to get LLVM debug info
elif newargs[i] == '--bind':
bind = True
newargs[i] = ''
@@ -869,6 +873,8 @@ 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
+ if make_source_map: keep_llvm_debug = True; keep_js_debug = True
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
@@ -1498,8 +1504,7 @@ 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,
- keep_llvm_debug and keep_js_debug)
+ final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache, make_source_map)
js_transform_tempfiles.append(final)
if DEBUG: save_intermediate('js_opts')
else:
@@ -1508,8 +1513,7 @@ 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,
- keep_llvm_debug and keep_js_debug)
+ final = shared.Building.js_optimizer(final, passes, jcache, make_source_map)
js_transform_tempfiles.append(final)
save_intermediate(name)
js_optimizer_queue = []
@@ -1519,8 +1523,7 @@ try:
if DEBUG == '2':
# Clean up the syntax a bit
- final = shared.Building.js_optimizer(final, [], jcache,
- keep_llvm_debug and keep_js_debug)
+ final = shared.Building.js_optimizer(final, [], jcache, make_source_map)
if DEBUG: save_intermediate('pretty')
def get_eliminate():
@@ -1608,7 +1611,7 @@ try:
shell = open(shell_path).read()
html = open(target, 'w')
if not Compression.on:
- if keep_llvm_debug and keep_js_debug:
+ if make_source_map:
match = re.match('.*?<script[^>]*>{{{ SCRIPT_CODE }}}</script>', shell,
re.DOTALL)
if match is None:
@@ -1684,7 +1687,7 @@ try:
from tools.split import split_javascript_file
split_javascript_file(final, unsuffixed(target), split_js_file)
else:
- if keep_llvm_debug and keep_js_debug: generate_source_map(target)
+ if make_source_map: generate_source_map(target)
# copy final JS to output
shutil.move(final, target)
diff --git a/tests/runner.py b/tests/runner.py
index 1697294d..156e2bda 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -9586,7 +9586,7 @@ def process(filename):
def test_source_map(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays")
- if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g')
+ if '--map' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('--map')
src = '''
#include <stdio.h>
@@ -11754,7 +11754,7 @@ elif 'browser' in str(sys.argv):
return 0;
}
''')
- Popen([PYTHON, EMCC, cpp_file, '-o', html_file, '-g']).communicate()
+ Popen([PYTHON, EMCC, cpp_file, '-o', html_file, '--map']).communicate()
webbrowser.open_new('file://' + html_file)
print '''
Set the debugger to pause on exceptions
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index e99c02be..7a29bc8c 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, debug=False):
+ def minify_shell(self, shell, compress, source_map=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
@@ -80,7 +80,7 @@ class Minifier:
output = subprocess.Popen(self.js_engine +
[JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] +
(['compress'] if compress else []) +
- (['--debug'] if debug else []),
+ (['--debug'] if source_map 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"
@@ -107,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, debug=False):
+def run_on_js(filename, passes, js_engine, jcache, source_map=False):
if isinstance(jcache, bool) and jcache: jcache = shared.JCache
if jcache: shared.JCache.ensure()
@@ -175,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, debug).split('EMSCRIPTEN_FUNCS();');
+ asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'compress' in passes, source_map).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
@@ -211,7 +211,9 @@ EMSCRIPTEN_FUNCS();
total_size = len(js)
js = None
- cores = int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
+ # if we are making source maps, we want our debug numbering to start from the
+ # top of the file, so avoid breaking the JS into chunks
+ cores = 1 if source_map else int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
intended_num_chunks = int(round(cores * NUM_CHUNKS_PER_CORE))
chunk_size = min(MAX_CHUNK_SIZE, max(MIN_CHUNK_SIZE, total_size / intended_num_chunks))
@@ -253,7 +255,7 @@ EMSCRIPTEN_FUNCS();
# 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'] +
- (['--debug'] if debug else []) + passes, filenames)
+ (['--debug'] if source_map else []) + passes, filenames)
#print [' '.join(command) for command in commands]
cores = min(cores, filenames)
@@ -321,6 +323,6 @@ EMSCRIPTEN_FUNCS();
return filename
-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))
+def run(filename, passes, js_engine, jcache, source_map=False):
+ return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, source_map))