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

« back to all changes in this revision

Viewing changes to tools/autodebugger_js.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
'''
 
2
Processes a C source file, adding debugging information.
 
3
 
 
4
Similar to autodebugger.py, but runs on .js files.
 
5
'''
 
6
 
 
7
import os, sys, re
 
8
 
 
9
filename = sys.argv[1]
 
10
func = sys.argv[2]
 
11
 
 
12
f = open(filename, 'r')
 
13
data = f.read()
 
14
f.close()
 
15
 
 
16
lines = data.split('\n')
 
17
in_func = False
 
18
for i in range(len(lines)):
 
19
  if lines[i].startswith('function '):
 
20
    name = lines[i].split('(')[0].split(' ')[1]
 
21
    args = lines[i].split('(')[1].split(')')[0]
 
22
    lines[i] += ' print("call %s(" + [%s] + ")");' % (name, args)
 
23
  if lines[i].startswith('function ' + func + '('):
 
24
    in_func = True
 
25
    continue
 
26
  elif lines[i].startswith('}'):
 
27
    in_func = False
 
28
    continue
 
29
  if in_func:
 
30
    m = re.match('^ +([$_\w\d \[\]]+) = +([^;]+);$', lines[i])
 
31
    if m and (' if ' not in lines[i-1] or '{' in lines[i-1]) and \
 
32
             (' if ' not in lines[i+1] or '{' in lines[i+1]) and \
 
33
             (' else' not in lines[i-1] or '{' in lines[i-1]) and \
 
34
             (' else' not in lines[i+1] or '{' in lines[i+1]):
 
35
      var = m.groups(1)[0].rstrip().split(' ')[-1]
 
36
      if 'STACKTOP' not in lines[i] and 'stackBase' not in lines[i]:
 
37
        #lines[i] += ''' print("[%4d] %s = " + %s);''' % (i+1, var, var)
 
38
        lines[i] += ''' print("%s = " + %s);''' % (var, var)
 
39
    m = re.match('^ +HEAP.*$', lines[i])
 
40
    if m and lines[i].count(' = ') == 1:
 
41
      left, right = lines[i].split(' = ')
 
42
      lines[i] += ''' print("%s = " + %s);''' % (left, left)
 
43
 
 
44
print '\n'.join(lines)
 
45
 
 
46
print >> sys.stderr, 'Success.'
 
47