diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-01 11:17:49 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-01 11:17:49 -0800 |
commit | 21e67b788795e3ea0feb8dcd636a56f4c28c21a9 (patch) | |
tree | 1139b835ba93ef4f405411b4b72301a463670c8b | |
parent | d1d6cbf8701b204bf379c6d94bb15d52f6f003aa (diff) |
add .ll debugging output option to emcc
-rwxr-xr-x | emcc | 27 | ||||
-rw-r--r-- | tools/shared.py | 14 |
2 files changed, 26 insertions, 15 deletions
@@ -457,12 +457,25 @@ try: except: pass + if DEBUG: + print >> sys.stderr, 'emcc: saving intermediate processing steps to %s' % shared.EMSCRIPTEN_TEMP_DIR + + intermediate_counter = 0 + def save_intermediate(name=None): + global intermediate_counter + shutil.copyfile(final, os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'emcc-%d%s.js' % (intermediate_counter, '' if name is None else '-' + name))) + intermediate_counter += 1 + if not LEAVE_INPUTS_RAW: - emscripten_input = in_temp(target_basename + '.bc') + final = in_temp(target_basename + '.bc') + if DEBUG: + final = shared.Building.llvm_dis(final, final + '.ll') + save_intermediate('ll') else: assert len(input_files) == 1 - emscripten_input = input_files[0] - final = shared.Building.emscripten(emscripten_input, append_ext=False) + final = input_files[0] + + final = shared.Building.emscripten(final, append_ext=False) # Apply a source code transformation, if requested source_transform = os.environ.get('EMCC_JS_PROCESSOR') @@ -473,14 +486,6 @@ try: process(final) if DEBUG: - print >> sys.stderr, 'emcc: saving intermediate processing steps to %s' % shared.EMSCRIPTEN_TEMP_DIR - - intermediate_counter = 0 - def save_intermediate(name=None): - global intermediate_counter - shutil.copyfile(final, os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'emcc-%d%s.js' % (intermediate_counter, '' if name is None else '-' + name))) - intermediate_counter += 1 - save_intermediate('original') final = shared.Building.js_optimizer(final, []) # Clean up the syntax a bit, so comparisons to later passes are simpler save_intermediate('pretty') diff --git a/tools/shared.py b/tools/shared.py index 777566cc..b8f76a0d 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -445,11 +445,16 @@ class Building: # shutil.move(filename + '.tmp.bc', filename + '.o') @staticmethod - def llvm_dis(filename): + def llvm_dis(input_filename, output_filename=None): # LLVM binary ==> LLVM assembly - try_delete(filename + '.o.ll') - output = Popen([LLVM_DIS, filename + '.o'] + LLVM_DIS_OPTS + ['-o=' + filename + '.o.ll'], stdout=PIPE).communicate()[0] - assert os.path.exists(filename + '.o.ll'), 'Could not create .ll file: ' + output + if output_filename is None: + # use test runner conventions + output_filename = input_filename + '.o.ll' + input_filename = input_filename + '.o' + try_delete(output_filename) + output = Popen([LLVM_DIS, input_filename ] + LLVM_DIS_OPTS + ['-o=' + output_filename], stdout=PIPE).communicate()[0] + assert os.path.exists(output_filename), 'Could not create .ll file: ' + output + return output_filename @staticmethod def llvm_as(input_filename, output_filename=None): @@ -461,6 +466,7 @@ class Building: try_delete(output_filename) output = Popen([LLVM_AS, input_filename, '-o=' + output_filename], stdout=PIPE).communicate()[0] assert os.path.exists(output_filename), 'Could not create bc file: ' + output + return output_filename @staticmethod def llvm_nm(filename, stdout=PIPE, stderr=None): |