diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-25 12:13:19 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-25 12:13:19 -0800 |
commit | 03710544c7500d257a29c3733f171be6970e9765 (patch) | |
tree | 4612b110771daf850c9d75aa6867bb58b86d6991 | |
parent | be26b4af155fcb2d3738be5b9ae4578ca70d2d4c (diff) |
js autodebugger tool
-rw-r--r-- | tools/autodebugger_js.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/autodebugger_js.py b/tools/autodebugger_js.py new file mode 100644 index 00000000..ee90e6f1 --- /dev/null +++ b/tools/autodebugger_js.py @@ -0,0 +1,39 @@ +''' +Processes a C source file, adding debugging information. + +Similar to autodebugger.py, but runs on .js files. +''' + +import os, sys, re + +filename = sys.argv[1] +func = sys.argv[2] + +f = open(filename, 'r') +data = f.read() +f.close() + +lines = data.split('\n') +in_func = False +for i in range(len(lines)): + if lines[i].startswith('function ' + func + '('): + in_func = True + continue + elif lines[i].startswith('}'): + in_func = False + continue + if in_func: + m = re.match('^ +([$_\w\d \[\]]+) = +([^;]+);$', lines[i]) + if m and (' if ' not in lines[i-1] or '{' in lines[i-1]) and \ + (' if ' not in lines[i+1] or '{' in lines[i+1]) and \ + (' else' not in lines[i-1] or '{' in lines[i-1]) and \ + (' else' not in lines[i+1] or '{' in lines[i+1]): + var = m.groups(1)[0].rstrip().split(' ')[-1] + if 'STACKTOP' not in lines[i] and 'stackBase' not in lines[i]: + #lines[i] += ''' print("[%4d] %s = " + %s);''' % (i+1, var, var) + lines[i] += ''' print("%s = " + %s);''' % (var, var) + +print '\n'.join(lines) + +print >> sys.stderr, 'Success.' + |