aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-03-30 20:15:32 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-03-30 20:15:32 -0700
commit3b7d149de6bb40c9714f9e863485d613d2135b5c (patch)
tree99ac4e281aa31092bfb71d849f9a7ffcfbd4d2b5 /tools
parentfa8b668639e9c9656a6efa0c5ff24d33e33a9f5a (diff)
parentd241868b63fcd306f3ff1007b57363391b724a46 (diff)
Merge pull request #328 from ehsan/ogre_upstream
Upstream the work I did for porting Ogre
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ll-strip.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/ll-strip.py b/tools/ll-strip.py
new file mode 100755
index 00000000..b03e4f3a
--- /dev/null
+++ b/tools/ll-strip.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+import sys, re
+
+def print_usage():
+ print >> sys.stderr, "Usage: ll-strip.py file from to"
+ print >> sys.stderr, "\tStrip function bodies in all ll file in the [from, to] range"
+ sys.exit(1)
+
+try:
+ range_from = int(sys.argv[2])
+ range_to = int(sys.argv[3])
+ if range_from >= range_to:
+ raise "error"
+ file = open(sys.argv[1])
+except:
+ print_usage()
+
+func_start = re.compile("^define\s")
+func_end = re.compile("^}$")
+
+function_counter = 0
+in_function = False
+line_number = 0
+skip = False
+dummy_stmt = "unreachable"
+for orig_line in file:
+ line = orig_line.strip()
+ if func_start.match(line):
+ if in_function:
+ print >> sys.stderr, "Discovered a function inside another function!"
+ sys.exit(1)
+ in_function = True
+ line_number = 0
+ skip = False
+ function_counter = function_counter + 1
+ elif func_end.match(line):
+ if not in_function:
+ print >> sys.stderr, "Discovered a function end without a matching beginning!"
+ sys.exit(1)
+ in_function = False
+ line_number = 0
+ skip = False
+ elif in_function:
+ line_number = line_number + 1
+ if not skip and line_number == 1:
+ if line == dummy_stmt:
+ function_counter = function_counter - 1
+ if range_from <= function_counter <= range_to and line_number == 1:
+ #import pdb;pdb.set_trace()
+ if line != dummy_stmt:
+ skip = True
+ print dummy_stmt
+ if not skip:
+ print orig_line.rstrip("\n")
+