2012-12-02 03:31:36 +04:00
|
|
|
#!/usr/bin/python2
|
2010-10-22 02:22:42 +04:00
|
|
|
|
|
|
|
'''
|
|
|
|
Simple tool to run the demangler.
|
|
|
|
|
2010-10-22 04:13:12 +04:00
|
|
|
(C) 2010 Alon Zakai, MIT licensed
|
|
|
|
|
2010-10-22 02:22:42 +04:00
|
|
|
Usage: demangler.py FILENAME SPLITTER
|
|
|
|
|
|
|
|
Make sure you define ~/.emscripten, and fill it with something like
|
|
|
|
|
|
|
|
JS_ENGINE=[os.path.expanduser('~/Dev/v8/d8')]
|
|
|
|
JS_ENGINE_PARAMS=['--']
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
JS_ENGINE=[os.path.expanduser('~/Dev/tracemonkey/js/src/js')]
|
|
|
|
JS_ENGINE_PARAMS=[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2011-03-22 05:48:26 +03:00
|
|
|
import os, sys, subprocess, re
|
2010-10-22 02:22:42 +04:00
|
|
|
|
2012-01-31 02:10:57 +04:00
|
|
|
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
|
2011-01-15 09:44:52 +03:00
|
|
|
def path_from_root(*pathelems):
|
2011-10-05 22:12:45 +04:00
|
|
|
return os.path.join(os.path.sep, *(__rootpath__.split(os.sep)[:-1] + list(pathelems)))
|
2012-01-31 02:10:57 +04:00
|
|
|
sys.path += [path_from_root('')]
|
|
|
|
from tools.shared import *
|
2010-10-22 02:22:42 +04:00
|
|
|
|
|
|
|
data = open(sys.argv[1], 'r').readlines()
|
|
|
|
|
|
|
|
SEEN = {}
|
|
|
|
for line in data:
|
2010-11-06 06:48:19 +03:00
|
|
|
if len(line) < 4: continue
|
2011-09-19 01:25:21 +04:00
|
|
|
m = re.match('^ function (?P<func>[^(]+)\(.*', line) # generated code
|
|
|
|
if not m:
|
|
|
|
m = re.match('^ + _*\d+: (?P<func>[^ ]+) \(\d+.*', line) # profiling output
|
2011-03-22 05:48:26 +03:00
|
|
|
if not m: continue
|
|
|
|
func = m.groups('func')[0]
|
2010-10-22 02:22:42 +04:00
|
|
|
if func in SEEN: continue
|
|
|
|
SEEN[func] = True
|
2011-01-15 09:44:52 +03:00
|
|
|
cleaned = run_js(JS_ENGINE, path_from_root('third_party', 'gcc_demangler.js'), [func[1:]])
|
2010-10-22 02:22:42 +04:00
|
|
|
if cleaned is None: continue
|
2010-10-28 06:49:11 +04:00
|
|
|
if 'Fatal exception' in cleaned: continue
|
2010-10-22 02:22:42 +04:00
|
|
|
cleaned = cleaned[1:-2]
|
|
|
|
if cleaned == '(null)': continue
|
|
|
|
if ' throw ' in cleaned: continue
|
|
|
|
print func, '=', cleaned
|
|
|
|
|