This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 4/4] Add contrib/check_passes.py script


contrib/

	* check_passes.py: New.
---
 contrib/check_passes.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 contrib/check_passes.py

diff --git a/contrib/check_passes.py b/contrib/check_passes.py
new file mode 100755
index 0000000..34d18b7
--- /dev/null
+++ b/contrib/check_passes.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# Script to verify passes.def and print statistics about it
+# Requires Python 2.7+ (for collections.Counter)
+
+from collections import Counter
+import re
+import sys
+
+num_errors = 0
+
+def validate(filename):
+    with open(filename) as f:
+        linenum = 1
+        def error(msg):
+            print('%s:%i: %s' % (filename, linenum, msg))
+            global num_errors
+            num_errors += 1
+        singles = set()
+        count = Counter()
+        for line in f:
+            m = re.match(r'^\s+NEXT_PASS \((.+)\);$', line)
+            if m:
+                name = m.group(1)
+                if ',' in name:
+                    error('malformed NEXT_PASS: %s' % name)
+                if name in count or name in singles:
+                    error('duplicate pass: %s' % name)
+                singles.add(name)
+            m = re.match(r'^\s+NEXT_PASS_NUM \((.+), (.+)\);$', line)
+            if m:
+                name, num = m.group(1), int(m.group(2))
+                count[name] += 1
+                if count[name] != num:
+                    error('bad index for %s' % name)
+            linenum += 1
+
+    for name in count:
+        if count[name] == 1:
+            error('only one instance of %s' % name)
+
+    def line():
+        print('-' * 72)
+    def heading(text):
+        line()
+        print(text)
+        line()
+
+    heading('Single-instanced passes (%i)' % len(singles))
+    for name in sorted(singles):
+        print(name)
+
+    heading('Multi-instanced passes (%i)' % len(count))
+    for name in sorted(count):
+        print('%s %i' % (name, count[name]))
+
+validate('../gcc/passes.def')
+if num_errors > 0:
+    sys.exit(1)
-- 
1.7.11.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]