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
diff --git a/tools/ccc/ccclib/Util.py b/tools/ccc/ccclib/Util.py
new file mode 100644
index 0000000..0924e8c
--- /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))