aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc63
1 files changed, 39 insertions, 24 deletions
diff --git a/emcc b/emcc
index 07193f1c..1b2be959 100755
--- a/emcc
+++ b/emcc
@@ -90,7 +90,7 @@ LLVM_OPT_LEVEL = {
3: 3,
}
-DEBUG = os.environ.get('EMCC_DEBUG')
+DEBUG = int(os.environ.get('EMCC_DEBUG') or 0)
TEMP_DIR = os.environ.get('EMCC_TEMP_DIR')
LEAVE_INPUTS_RAW = os.environ.get('EMCC_LEAVE_INPUTS_RAW') # Do not compile .ll files into .bc, just compile them with emscripten directly
# Not recommended, this is mainly for the test runner, or if you have some other
@@ -173,6 +173,11 @@ Options that are modified or new in %s include:
(without the external "s in either of those,
you would get an error)
+ -g Use debug info. Note that you need this during
+ the last compilation phase from bitcode to
+ JavaScript, or else we will remove it by
+ default in -O1 and above.
+
--typed-arrays <mode> 0: No typed arrays
1: Parallel typed arrays
2: Shared (C-like) typed arrays (default)
@@ -461,7 +466,7 @@ CC = shared.to_cc(CXX)
if os.environ.get('EMMAKEN_CXX'):
CC = CXX
-CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS # + ['-g']?
+CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS
EMMAKEN_CFLAGS = os.environ.get('EMMAKEN_CFLAGS')
if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += shlex.split(EMMAKEN_CFLAGS)
@@ -533,7 +538,7 @@ if TEMP_DIR:
shutil.rmtree(temp_dir) # clear it
os.makedirs(temp_dir)
else:
- temp_root = os.path.join(shared.TEMP_DIR, 'emcc')
+ temp_root = shared.TEMP_DIR
if not os.path.exists(temp_root):
os.makedirs(temp_root)
temp_dir = tempfile.mkdtemp(dir=temp_root)
@@ -564,6 +569,7 @@ try:
shell_path = shared.path_from_root('src', 'shell.html')
js_libraries = []
remove_duplicates = False
+ keep_debug = False
bind = False
def check_bad_eq(arg):
@@ -622,7 +628,9 @@ try:
check_bad_eq(newargs[i])
split_js_file = int(newargs[i+1])
newargs[i] = ''
- newargs[i+1] = ''
+ newargs[i+1] = ''
+ elif newargs[i] == '-g':
+ keep_debug = True
elif newargs[i] == '--bind':
bind = True
newargs[i] = '-std=c++11' # Force C++11 for embind code
@@ -683,6 +691,7 @@ try:
if closure is None: closure = 1 if opt_level >= 2 else 0
if minify_whitespace is None:
minify_whitespace = closure # if closure is run, minify whitespace
+ if opt_level <= 0: keep_debug = True # always keep debug in -O0
if closure:
assert os.path.exists(shared.CLOSURE_COMPILER), 'emcc: fatal: Closure compiler (%s) does not exist' % shared.CLOSURE_COMPILER
@@ -810,6 +819,10 @@ try:
key, value = change.split('=')
exec('shared.Settings.' + key + ' = ' + value)
+ # Apply effects from settings
+ if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2:
+ keep_debug = True # must keep debug info to do line-by-line operations
+
## Compile source code to bitcode
if DEBUG: print >> sys.stderr, 'emcc: compiling to bitcode'
@@ -994,24 +1007,24 @@ try:
if not LEAVE_INPUTS_RAW: save_intermediate('basebc', 'bc')
# Optimize, if asked to
- if llvm_opts > 0 and not LEAVE_INPUTS_RAW:
- if DEBUG: print >> sys.stderr, 'emcc: LLVM -O%d' % llvm_opts
- shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
- if DEBUG: save_intermediate('opt', 'bc')
- # Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
- if llvm_lto and shared.Building.can_use_unsafe_opts() and shared.Building.can_build_standalone():
- lto_opts = []
- if not shared.Building.can_inline(): lto_opts.append('-disable-inlining')
- lto_opts.append('-std-link-opts')
- if DEBUG: print >> sys.stderr, 'emcc: LLVM LTO:', lto_opts
- shared.Building.llvm_opt(in_temp(target_basename + '.bc'), lto_opts)
- if DEBUG: save_intermediate('lto', 'bc')
- else:
- # If possible, remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
- if not LEAVE_INPUTS_RAW and shared.Building.can_build_standalone():
- if DEBUG: print >> sys.stderr, 'emcc: LLVM dead globals elimination'
- shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-internalize', '-globaldce'])
- if DEBUG: save_intermediate('dce', 'bc')
+ if not LEAVE_INPUTS_RAW:
+ link_opts = [] if keep_debug else ['-strip-debug']
+ if llvm_opts > 0:
+ if DEBUG: print >> sys.stderr, 'emcc: LLVM -O%d' % llvm_opts
+ shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
+ if DEBUG: save_intermediate('opt', 'bc')
+ # Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
+ if shared.Building.can_build_standalone():
+ if llvm_lto and shared.Building.can_use_unsafe_opts():
+ if not shared.Building.can_inline(): link_opts.append('-disable-inlining')
+ link_opts.append('-std-link-opts')
+ else:
+ # At least remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
+ link_opts += ['-internalize', '-globaldce']
+ if link_opts:
+ if DEBUG: print >> sys.stderr, 'emcc: LLVM linktime:', link_opts
+ shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
+ if DEBUG: save_intermediate('linktime', 'bc')
# Prepare .ll for Emscripten
if not LEAVE_INPUTS_RAW:
@@ -1083,8 +1096,10 @@ try:
def flush_js_optimizer_queue():
global final, js_optimizer_queue
if len(js_optimizer_queue) > 0:
- if not DEBUG:
+ if DEBUG < 2:
+ if DEBUG: print >> sys.stderr, 'emcc: applying js optimization passes:', js_optimizer_queue
final = shared.Building.js_optimizer(final, js_optimizer_queue)
+ if DEBUG: save_intermediate('js_opts')
else:
for name in js_optimizer_queue:
print >> sys.stderr, 'emcc: applying js optimization pass:', name
@@ -1095,7 +1110,7 @@ try:
if opt_level >= 1:
if DEBUG: print >> sys.stderr, 'emcc: running pre-closure post-opts'
- if DEBUG:
+ if DEBUG >= 2:
# Clean up the syntax a bit
final = shared.Building.js_optimizer(final, [])
if DEBUG: save_intermediate('pretty')