ccc: Start defining host information.
- For use by the driver in places where the host alters driver
behavior (for example, running as a driver driver on darwin).
- Allow user override for testing purposes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61967 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/ccc/ccclib/HostInfo.py b/tools/ccc/ccclib/HostInfo.py
new file mode 100644
index 0000000..ccfd32b
--- /dev/null
+++ b/tools/ccc/ccclib/HostInfo.py
@@ -0,0 +1,76 @@
+class HostInfo(object):
+ """HostInfo - Config information about a particular host which may
+ interact with driver behavior. This can be very different from the
+ target(s) of a particular driver invocation."""
+
+ def __init__(self):
+ pass
+
+ def getArchName(self):
+ abstract
+
+ def useDriverDriver(self):
+ abstract
+
+# Darwin
+
+class DarwinHostInfo(HostInfo):
+ def useDriverDriver(self):
+ return True
+
+class DarwinPPCHostInfo(DarwinHostInfo):
+ def getArchName(self):
+ return 'ppc'
+
+class DarwinPPC_64HostInfo(DarwinHostInfo):
+ def getArchName(self):
+ return 'ppc64'
+
+class DarwinX86HostInfo(DarwinHostInfo):
+ def getArchName(self):
+ return 'i386'
+
+class DarwinX86_64HostInfo(DarwinHostInfo):
+ def getArchName(self):
+ return 'x86_64'
+
+def getDarwinHostInfo(machine, bits):
+ if machine == 'i386':
+ if bits == '32':
+ return DarwinX86HostInfo()
+ if bits == '64':
+ return DarwinX86_64HostInfo()
+ elif machine == 'ppc':
+ if bits == '32':
+ return DarwinPPCHostInfo()
+ if bits == '64':
+ return DarwinPPC_64HostInfo()
+
+ raise RuntimeError,'Unrecognized Darwin-i386 platform: %r:%r' % (machine, bits)
+
+# Unknown
+
+class UnknownHostInfo(HostInfo):
+ def getArchName(self):
+ raise RuntimeError,'getArchName() unsupported on unknown host.'
+
+ def useDriverDriver(self):
+ return False
+
+def getUnknownHostInfo(machine, bits):
+ return UnknownHostInfo()
+
+####
+
+kSystems = {
+ 'darwin' : getDarwinHostInfo,
+ 'unknown' : getUnknownHostInfo,
+ }
+
+def getHostInfo(driver, system, machine, bits):
+ handler = kSystems.get(system)
+ if handler:
+ return handler(machine, bits)
+
+ driver.warning('Unknown host %r, using generic host information.' % system)
+ return UnknownHostInfo()