Last active
December 25, 2015 13:49
-
-
Save pervognsen/6986969 to your computer and use it in GitHub Desktop.
annotate_clang_assembly.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make assembly listings generated by clang -g -S more human readable. | |
import re | |
import sys | |
files = {} | |
def replace(text, pattern, replacement): | |
return re.sub(pattern, replacement, text, 0, re.M) | |
def getline(filename, line): | |
if filename not in files: | |
files[filename] = list(open(filename).readlines()) | |
return files[filename][line] | |
s = open(sys.argv[1]).read() | |
# Replace .loc directives with source code. | |
s = replace(s, r"[^\n]+ ## ([^\n]+):(\d+):\d+\n", lambda m: "\n## %s:%s: %s" % (m.group(1), m.group(2), getline(m.group(1), int(m.group(2))-1))) | |
# Remove clutter. | |
s = replace(s, r"^Ltmp[^\n]*[\n]", "") | |
s = replace(s, r"^[\t]##DEBUG_VALUE[^\n]*[\n]", "") | |
s = replace(s, r"^[\t].cfi[^\n]*[\n]", "") | |
s = replace(s, r"^## BB[^\n]*[\n]", "") | |
print s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment