make basic block scheduler more deterministic
[libfirm] / scripts / spec_util.py
index 2c71bcd..9706385 100644 (file)
@@ -1,3 +1,5 @@
+import sys
+
 abstracts = set()
 def abstract(cls):
        abstracts.add(cls)
@@ -68,3 +70,28 @@ def setnodedefaults(node):
        setdefault(node, "customSerializer", False)
        if hasattr(node, "outs"):
                node.mode = "mode_T"
+
+def trim_docstring(docstring):
+    if not docstring:
+        return ''
+    # Convert tabs to spaces (following the normal Python rules)
+    # and split into a list of lines:
+    lines = docstring.expandtabs().splitlines()
+    # Determine minimum indentation (first line doesn't count):
+    indent = sys.maxint
+    for line in lines[1:]:
+        stripped = line.lstrip()
+        if stripped:
+            indent = min(indent, len(line) - len(stripped))
+    # Remove indentation (first line is special):
+    trimmed = [lines[0].strip()]
+    if indent < sys.maxint:
+        for line in lines[1:]:
+            trimmed.append(line[indent:].rstrip())
+    # Strip off trailing and leading blank lines:
+    while trimmed and not trimmed[-1]:
+        trimmed.pop()
+    while trimmed and not trimmed[0]:
+        trimmed.pop(0)
+    # Return a single string:
+    return '\n'.join(trimmed)