~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to third_party/demangler.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python2
 
2
 
 
3
'''
 
4
Simple tool to run the demangler.
 
5
 
 
6
(C) 2010 Alon Zakai, MIT licensed
 
7
 
 
8
Usage: demangler.py FILENAME SPLITTER
 
9
 
 
10
Make sure you define ~/.emscripten, and fill it with something like
 
11
 
 
12
JS_ENGINE=[os.path.expanduser('~/Dev/v8/d8')]
 
13
JS_ENGINE_PARAMS=['--']
 
14
 
 
15
or
 
16
 
 
17
JS_ENGINE=[os.path.expanduser('~/Dev/tracemonkey/js/src/js')]
 
18
JS_ENGINE_PARAMS=[]
 
19
 
 
20
'''
 
21
 
 
22
import os, sys, subprocess, re
 
23
 
 
24
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
 
25
def path_from_root(*pathelems):
 
26
  return os.path.join(os.path.sep, *(__rootpath__.split(os.sep)[:-1] + list(pathelems)))
 
27
sys.path += [path_from_root('')]
 
28
from tools.shared import *
 
29
 
 
30
data = open(sys.argv[1], 'r').readlines()
 
31
 
 
32
SEEN = {}
 
33
for line in data:
 
34
  if len(line) < 4: continue
 
35
  m = re.match('^  function (?P<func>[^(]+)\(.*', line) # generated code
 
36
  if not m:
 
37
    m = re.match('^ + _*\d+: (?P<func>[^ ]+) \(\d+.*', line) # profiling output
 
38
  if not m: continue
 
39
  func = m.groups('func')[0]
 
40
  if func in SEEN: continue
 
41
  SEEN[func] = True
 
42
  cleaned = run_js(JS_ENGINE, path_from_root('third_party', 'gcc_demangler.js'), [func[1:]])
 
43
  if cleaned is None: continue
 
44
  if 'Fatal exception' in cleaned: continue
 
45
  cleaned = cleaned[1:-2]
 
46
  if cleaned == '(null)': continue
 
47
  if ' throw ' in cleaned: continue
 
48
  print func, '=', cleaned
 
49