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. llvm-svn: 61967
This commit is contained in:
parent
c25d7a7fe0
commit
a3491665a6
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import platform
|
||||
import sys
|
||||
import tempfile
|
||||
from pprint import pprint
|
||||
|
|
@ -7,6 +8,7 @@ from pprint import pprint
|
|||
|
||||
import Arguments
|
||||
import Jobs
|
||||
import HostInfo
|
||||
import Phases
|
||||
import Tools
|
||||
import Types
|
||||
|
|
@ -25,6 +27,7 @@ class MissingArgumentError(ValueError):
|
|||
|
||||
class Driver(object):
|
||||
def __init__(self):
|
||||
self.hostInfo = None
|
||||
self.parser = Arguments.OptionParser()
|
||||
|
||||
def run(self, argv):
|
||||
|
|
@ -38,7 +41,7 @@ class Driver(object):
|
|||
# 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 @@ class Driver(object):
|
|||
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 @@ class Driver(object):
|
|||
|
||||
self.handleImmediateOptions(args)
|
||||
|
||||
if cccUseDriverDriver:
|
||||
if self.hostInfo.useDriverDriver():
|
||||
phases = self.buildPipeline(args)
|
||||
else:
|
||||
phases = self.buildNormalPipeline(args)
|
||||
|
|
@ -414,9 +426,7 @@ class Driver(object):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue