[cfe-commits] r61967 - in /cfe/trunk/tools/ccc: ccclib/Driver.py ccclib/HostInfo.py test/ccc/phases.c
Daniel Dunbar
daniel at zuster.org
Thu Jan 8 17:00:40 PST 2009
Author: ddunbar
Date: Thu Jan 8 19:00:40 2009
New Revision: 61967
URL: http://llvm.org/viewvc/llvm-project?rev=61967&view=rev
Log:
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.
Added:
cfe/trunk/tools/ccc/ccclib/HostInfo.py
Modified:
cfe/trunk/tools/ccc/ccclib/Driver.py
cfe/trunk/tools/ccc/test/ccc/phases.c
Modified: cfe/trunk/tools/ccc/ccclib/Driver.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/Driver.py?rev=61967&r1=61966&r2=61967&view=diff
==============================================================================
--- cfe/trunk/tools/ccc/ccclib/Driver.py (original)
+++ cfe/trunk/tools/ccc/ccclib/Driver.py Thu Jan 8 19:00:40 2009
@@ -1,4 +1,5 @@
import os
+import platform
import sys
import tempfile
from pprint import pprint
@@ -7,6 +8,7 @@
import Arguments
import Jobs
+import HostInfo
import Phases
import Tools
import Types
@@ -25,6 +27,7 @@
class Driver(object):
def __init__(self):
+ self.hostInfo = None
self.parser = Arguments.OptionParser()
def run(self, argv):
@@ -38,7 +41,7 @@
# only allowed at the beginning of the command line.
cccPrintOptions = False
cccPrintPhases = False
- cccUseDriverDriver = True
+ cccHostBits = cccHostMachine = cccHostSystem = None
while argv and argv[0].startswith('-ccc-'):
opt,argv = argv[0][5:],argv[1:]
@@ -46,14 +49,23 @@
cccPrintOptions = True
elif opt == 'print-phases':
cccPrintPhases = True
- elif opt == 'no-driver-driver':
- # FIXME: Remove this once we have some way of being a
- # cross compiler driver (cross driver compiler? compiler
- # cross driver? etc.).
- cccUseDriverDriver = False
+ elif opt == 'host-bits':
+ cccHostBits,argv = argv[0],argv[1:]
+ elif opt == 'host-machine':
+ cccHostMachine,argv = argv[0],argv[1:]
+ elif opt == 'host-system':
+ cccHostSystem,argv = argv[0],argv[1:]
else:
raise ValueError,"Invalid ccc option: %r" % cccPrintOptions
+ # FIXME: How to handle override of host? ccc specific options?
+ # Abuse -b?
+ hostBits = cccHostBits or platform.architecture()[0].replace('bit','')
+ hostMachine = cccHostMachine or platform.machine()
+ hostSystem = cccHostSystem or platform.system().lower()
+ self.hostInfo = HostInfo.getHostInfo(self,
+ hostSystem, hostMachine, hostBits)
+
args = self.parser.parseArgs(argv)
# FIXME: Ho hum I have just realized -Xarch_ is broken. We really
@@ -73,7 +85,7 @@
self.handleImmediateOptions(args)
- if cccUseDriverDriver:
+ if self.hostInfo.useDriverDriver():
phases = self.buildPipeline(args)
else:
phases = self.buildNormalPipeline(args)
@@ -81,7 +93,7 @@
if cccPrintPhases:
self.printPhases(phases, args)
sys.exit(0)
-
+
if 0:
print Util.pprint(phases)
@@ -414,9 +426,7 @@
hasDashM = arg
if not archs:
- # FIXME: Need to infer arch so that we sub -Xarch
- # correctly.
- archs.append(args.makeSeparateArg('i386',
+ archs.append(args.makeSeparateArg(self.hostInfo.getArchName(),
self.parser.archOption))
actions = self.buildNormalPipeline(args)
Added: cfe/trunk/tools/ccc/ccclib/HostInfo.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/HostInfo.py?rev=61967&view=auto
==============================================================================
--- cfe/trunk/tools/ccc/ccclib/HostInfo.py (added)
+++ cfe/trunk/tools/ccc/ccclib/HostInfo.py Thu Jan 8 19:00:40 2009
@@ -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()
Modified: cfe/trunk/tools/ccc/test/ccc/phases.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/test/ccc/phases.c?rev=61967&r1=61966&r2=61967&view=diff
==============================================================================
--- cfe/trunk/tools/ccc/test/ccc/phases.c (original)
+++ cfe/trunk/tools/ccc/test/ccc/phases.c Thu Jan 8 19:00:40 2009
@@ -1,5 +1,5 @@
// One C file.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases a.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases a.c > %t &&
// RUN: grep '0: input, "a.c", c' %t &&
// RUN: grep '1: preprocessor, {0}, cpp-output' %t &&
// RUN: grep '2: compiler, {1}, assembler' %t &&
@@ -7,40 +7,40 @@
// RUN: grep '4: linker, {3}, image' %t &&
// PCH.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -x c-header a.h > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -x c-header a.h > %t &&
// RUN: grep '0: input, "a.h", c-header' %t &&
// RUN: grep '1: preprocessor, {0}, c-header-cpp-output' %t &&
// RUN: grep '2: precompiler, {1}, precompiled-header' %t &&
// Assembler w/ and w/o preprocessor.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -x assembler a.s > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -x assembler a.s > %t &&
// RUN: grep '0: input, "a.s", assembler' %t &&
// RUN: grep '1: assembler, {0}, object' %t &&
// RUN: grep '2: linker, {1}, image' %t &&
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -x assembler-with-cpp a.s > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -x assembler-with-cpp a.s > %t &&
// RUN: grep '0: input, "a.s", assembler-with-cpp' %t &&
// RUN: grep '1: preprocessor, {0}, assembler' %t &&
// RUN: grep '2: assembler, {1}, object' %t &&
// RUN: grep '3: linker, {2}, image' %t &&
// Check the various ways of early termination.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -E a.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -E a.c > %t &&
// RUN: not grep ': compiler, ' %t &&
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -fsyntax-only a.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -fsyntax-only a.c > %t &&
// RUN: grep ': compiler, {1}, nothing' %t &&
// RUN: not grep ': assembler, ' %t &&
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -S a.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -S a.c > %t &&
// RUN: not grep ': assembler, ' %t &&
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -c a.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -c a.c > %t &&
// RUN: not grep ': linker, ' %t &&
// Multiple output files.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -c a.c b.c > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -c a.c b.c > %t &&
// RUN: grep ': assembler,' %t | count 2 &&
// FIXME: Only for darwin.
// Treat -filelist as a linker input.
-// RUN: xcc -ccc-no-driver-driver -ccc-print-phases -filelist /dev/null > %t &&
+// RUN: xcc -ccc-host-system unknown -ccc-print-phases -filelist /dev/null > %t &&
// RUN: grep '1: linker, {0}, image' %t &&
// RUN: true
More information about the cfe-commits
mailing list