aboutsummaryrefslogtreecommitdiff
path: root/tools/ccc/ccclib/Util.py
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-01-05 19:53:30 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-01-05 19:53:30 +0000
commita5677511d14bbe6181de423fb5f3cafacbdbe87c (patch)
tree86a9f3b656425398b2f4e444824347db7fcac1c3 /tools/ccc/ccclib/Util.py
parent6c6fce03ea12b7b8e812fa1b24cfe5aa8705ceca (diff)
Add prototype ccc rewrite.
- Entry point is tools/ccc/xcc until we are a functional replacement for ccc. This is highly experimental (FIXME/LOC ratio of 3.4%), quite crufty, and barely usable (and then only on my specific Darwin). However, many of the right ideas are present, and it already fixes a number of things gcc gets wrong. The major missing component is argument translation for tools (translating driver arguments into cc1/ld/as/etc. arguments). This is a large part of the driver functionality and will probably double the LOC, but my hope is that the current architecture is relatively stable. Documentation & motivation to follow soon... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61739 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/ccc/ccclib/Util.py')
-rw-r--r--tools/ccc/ccclib/Util.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/ccc/ccclib/Util.py b/tools/ccc/ccclib/Util.py
new file mode 100644
index 0000000000..0924e8c248
--- /dev/null
+++ b/tools/ccc/ccclib/Util.py
@@ -0,0 +1,52 @@
+def any_true(list, predicate):
+ for i in list:
+ if predicate(i):
+ return True
+ return False
+
+def any_false(list, predicate):
+ return any_true(list, lambda x: not predicate(x))
+
+def all_true(list, predicate):
+ return not any_false(list, predicate)
+
+def all_false(list, predicate):
+ return not any_true(list, predicate)
+
+def prependLines(prependStr, str):
+ return ('\n'+prependStr).join(str.splitlines())
+
+def pprint(object, useRepr=True):
+ def recur(ob):
+ return pprint(ob, useRepr)
+ def wrapString(prefix, string, suffix):
+ return '%s%s%s' % (prefix,
+ prependLines(' ' * len(prefix),
+ string),
+ suffix)
+ def pprintArgs(name, args):
+ return wrapString(name + '(', ',\n'.join(map(recur,args)), ')')
+
+ if isinstance(object, tuple):
+ return wrapString('(', ',\n'.join(map(recur,object)),
+ [')',',)'][len(object) == 1])
+ elif isinstance(object, list):
+ return wrapString('[', ',\n'.join(map(recur,object)), ']')
+ elif isinstance(object, set):
+ return pprintArgs('set', list(object))
+ elif isinstance(object, dict):
+ elts = []
+ for k,v in object.items():
+ kr = recur(k)
+ vr = recur(v)
+ elts.append('%s : %s' % (kr,
+ prependLines(' ' * (3 + len(kr.splitlines()[-1])),
+ vr)))
+ return wrapString('{', ',\n'.join(elts), '}')
+ else:
+ if useRepr:
+ return repr(object)
+ return str(object)
+
+def prefixAndPPrint(prefix, object, useRepr=True):
+ return prefix + prependLines(' '*len(prefix), pprint(object, useRepr))