зеркало из https://github.com/microsoft/clang-1.git
ccc: (Darwin) Start implementing argument translation for
Darwin/Compile tool. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62085 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
3235fdb001
Коммит
6325fcf532
|
@ -275,6 +275,13 @@ class ArgList:
|
|||
if arg.opt in (optionA, optionB):
|
||||
yield arg
|
||||
|
||||
def getArgs3(self, optionA, optionB, optionC):
|
||||
"""getArgs3 - Iterate over all arguments for three options, in
|
||||
the order they were specified."""
|
||||
for arg in self.args:
|
||||
if arg.opt in (optionA, optionB, optionC):
|
||||
yield arg
|
||||
|
||||
def getLastArg(self, option):
|
||||
return self.lastArgs.get(option)
|
||||
|
||||
|
@ -302,6 +309,18 @@ class ArgList:
|
|||
for arg in self.getArgs(option):
|
||||
output.extend(self.render(arg))
|
||||
|
||||
def addAllArgs2(self, output, optionA, optionB):
|
||||
"""addAllArgs2 - Extend the given output vector with all
|
||||
instances of two given option, with relative order preserved."""
|
||||
for arg in self.getArgs2(optionA, optionB):
|
||||
output.extend(self.render(arg))
|
||||
|
||||
def addAllArgs3(self, output, optionA, optionB, optionC):
|
||||
"""addAllArgs3 - Extend the given output vector with all
|
||||
instances of three given option, with relative order preserved."""
|
||||
for arg in self.getArgs3(optionA, optionB, optionC):
|
||||
output.extend(self.render(arg))
|
||||
|
||||
def addAllArgsTranslated(self, output, option, translation):
|
||||
"""addAllArgsTranslated - Extend the given output vector with
|
||||
all instances of a given option, rendered as separate
|
||||
|
@ -422,7 +441,7 @@ class OptionParser:
|
|||
# FIXME: Implement.
|
||||
self.addOption(FlagOption('-time'))
|
||||
# FIXME: Implement.
|
||||
self.addOption(FlagOption('-v'))
|
||||
self.vOption = self.addOption(FlagOption('-v'))
|
||||
|
||||
# Input/output stuff
|
||||
self.oOption = self.addOption(JoinedOrSeparateOption('-o', noOptAsInput=True))
|
||||
|
@ -455,11 +474,15 @@ class OptionParser:
|
|||
####
|
||||
# Bring on the random garbage.
|
||||
|
||||
self.addOption(FlagOption('-MD'))
|
||||
self.addOption(FlagOption('-MP'))
|
||||
self.addOption(FlagOption('-MM'))
|
||||
self.addOption(JoinedOrSeparateOption('-MF'))
|
||||
self.addOption(JoinedOrSeparateOption('-MT'))
|
||||
self.MOption = self.addOption(FlagOption('-M'))
|
||||
self.MDOption = self.addOption(FlagOption('-MD'))
|
||||
self.MGOption = self.addOption(FlagOption('-MG'))
|
||||
self.MMDOption = self.addOption(FlagOption('-MMD'))
|
||||
self.MPOption = self.addOption(FlagOption('-MP'))
|
||||
self.MMOption = self.addOption(FlagOption('-MM'))
|
||||
self.MFOption = self.addOption(JoinedOrSeparateOption('-MF'))
|
||||
self.MTOption = self.addOption(JoinedOrSeparateOption('-MT'))
|
||||
self.MQOption = self.addOption(JoinedOrSeparateOption('-MQ'))
|
||||
self.MachOption = self.addOption(FlagOption('-Mach'))
|
||||
self.addOption(FlagOption('-undef'))
|
||||
|
||||
|
@ -491,13 +514,14 @@ class OptionParser:
|
|||
self.noprebindOption = self.addOption(FlagOption('-noprebind'))
|
||||
self.nofixprebindingOption = self.addOption(FlagOption('-nofixprebinding'))
|
||||
self.prebind_all_twolevel_modulesOption = self.addOption(FlagOption('-prebind_all_twolevel_modules'))
|
||||
self.remapOption = self.addOption(FlagOption('-remap'))
|
||||
self.read_only_relocsOption = self.addOption(SeparateOption('-read_only_relocs'))
|
||||
self.addOption(FlagOption('-single_module'))
|
||||
self.nomultidefsOption = self.addOption(FlagOption('-nomultidefs'))
|
||||
self.nostartfilesOption = self.addOption(FlagOption('-nostartfiles'))
|
||||
self.nodefaultlibsOption = self.addOption(FlagOption('-nodefaultlibs'))
|
||||
self.nostdlibOption = self.addOption(FlagOption('-nostdlib'))
|
||||
self.addOption(FlagOption('-nostdinc'))
|
||||
self.nostdincOption = self.addOption(FlagOption('-nostdinc'))
|
||||
self.objectOption = self.addOption(FlagOption('-object'))
|
||||
self.preloadOption = self.addOption(FlagOption('-preload'))
|
||||
self.staticOption = self.addOption(FlagOption('-static'))
|
||||
|
@ -505,13 +529,17 @@ class OptionParser:
|
|||
self.addOption(FlagOption('-shared'))
|
||||
self.staticLibgccOption = self.addOption(FlagOption('-static-libgcc'))
|
||||
self.sharedLibgccOption = self.addOption(FlagOption('-shared-libgcc'))
|
||||
self.addOption(FlagOption('-C'))
|
||||
self.addOption(FlagOption('-CC'))
|
||||
self.COption = self.addOption(FlagOption('-C'))
|
||||
self.CCOption = self.addOption(FlagOption('-CC'))
|
||||
self.HOption = self.addOption(FlagOption('-H'))
|
||||
self.addOption(FlagOption('-R'))
|
||||
self.addOption(FlagOption('-P'))
|
||||
self.POption = self.addOption(FlagOption('-P'))
|
||||
self.QOption = self.addOption(FlagOption('-Q'))
|
||||
self.addOption(FlagOption('-all_load'))
|
||||
self.addOption(FlagOption('--constant-cfstrings'))
|
||||
self.addOption(FlagOption('-traditional'))
|
||||
self.traditionalOption = self.addOption(FlagOption('-traditional'))
|
||||
self.traditionalCPPOption = self.addOption(FlagOption('-traditional-cpp'))
|
||||
# FIXME: Alias.
|
||||
self.addOption(FlagOption('--traditional'))
|
||||
self.addOption(FlagOption('-no_dead_strip_inits_and_terms'))
|
||||
self.addOption(JoinedOption('-weak-l', isLinkerInput=True))
|
||||
|
@ -582,13 +610,16 @@ class OptionParser:
|
|||
# C options for testing
|
||||
|
||||
self.addOption(JoinedOrSeparateOption('-include'))
|
||||
self.AOption = self.addOption(SeparateOption('-A'))
|
||||
self.addOption(JoinedOrSeparateOption('-D'))
|
||||
# FIXME: This is broken, we need -A as a single option to send
|
||||
# stuff to cc1, but the way the ld spec is constructed it
|
||||
# wants to see -A options but only as a separate arg.
|
||||
self.AOption = self.addOption(JoinedOrSeparateOption('-A'))
|
||||
self.DOption = self.addOption(JoinedOrSeparateOption('-D'))
|
||||
self.FOption = self.addOption(JoinedOrSeparateOption('-F'))
|
||||
self.addOption(JoinedOrSeparateOption('-I'))
|
||||
self.IOption = self.addOption(JoinedOrSeparateOption('-I'))
|
||||
self.LOption = self.addOption(JoinedOrSeparateOption('-L'))
|
||||
self.TOption = self.addOption(JoinedOrSeparateOption('-T'))
|
||||
self.addOption(JoinedOrSeparateOption('-U'))
|
||||
self.UOption = self.addOption(JoinedOrSeparateOption('-U'))
|
||||
self.ZOption = self.addOption(JoinedOrSeparateOption('-Z'))
|
||||
|
||||
self.addOption(JoinedOrSeparateOption('-l', isLinkerInput=True))
|
||||
|
@ -616,6 +647,7 @@ class OptionParser:
|
|||
|
||||
# Take care on extension, the Darwin assembler wants to add a
|
||||
# flag for any -g* option.
|
||||
self.g3Option = self.addOption(JoinedOption('-g3'))
|
||||
self.gOption = self.addOption(JoinedOption('-g'))
|
||||
|
||||
self.f_appleKextOption = self.addOption(FlagOption('-fapple-kext'))
|
||||
|
@ -623,11 +655,14 @@ class OptionParser:
|
|||
self.f_objcOption = self.addOption(FlagOption('-fobjc'))
|
||||
self.f_openmpOption = self.addOption(FlagOption('-fopenmp'))
|
||||
self.f_gnuRuntimeOption = self.addOption(FlagOption('-fgnu-runtime'))
|
||||
self.f_mudflapOption = self.addOption(FlagOption('-fmudflap'))
|
||||
self.f_mudflapthOption = self.addOption(FlagOption('-fmudflapth'))
|
||||
self.f_nestedFunctionsOption = self.addOption(FlagOption('-fnested-functions'))
|
||||
self.f_pieOption = self.addOption(FlagOption('-fpie'))
|
||||
self.f_profileArcsOption = self.addOption(FlagOption('-fprofile-arcs'))
|
||||
self.f_profileGenerateOption = self.addOption(FlagOption('-fprofile-generate'))
|
||||
self.f_createProfileOption = self.addOption(FlagOption('-fcreate-profile'))
|
||||
self.f_traditionalOption = self.addOption(FlagOption('-ftraditional'))
|
||||
self.coverageOption = self.addOption(FlagOption('-coverage'))
|
||||
self.coverageOption2 = self.addOption(FlagOption('--coverage'))
|
||||
self.addOption(JoinedOption('-f'))
|
||||
|
|
|
@ -535,6 +535,7 @@ class Driver(object):
|
|||
hasSaveTemps = (args.getLastArg(self.parser.saveTempsOption) or
|
||||
args.getLastArg(self.parser.saveTempsOption2))
|
||||
hasNoIntegratedCPP = args.getLastArg(self.parser.noIntegratedCPPOption)
|
||||
hasTraditionalCPP = args.getLastArg(self.parser.traditionalCPPOption)
|
||||
hasPipe = args.getLastArg(self.parser.pipeOption)
|
||||
|
||||
# FIXME: forward will die, this isn't really how things are
|
||||
|
@ -566,9 +567,13 @@ class Driver(object):
|
|||
# about these being unused are likely to be noise anyway.
|
||||
if hasSaveTemps:
|
||||
self.claim(hasSaveTemps)
|
||||
if hasNoIntegratedCPP:
|
||||
|
||||
if hasTraditionalCPP:
|
||||
self.claim(hasTraditionalCPP)
|
||||
elif hasNoIntegratedCPP:
|
||||
self.claim(hasNoIntegratedCPP)
|
||||
|
||||
|
||||
class InputInfo:
|
||||
def __init__(self, source, type, baseInput):
|
||||
self.source = source
|
||||
|
@ -615,6 +620,7 @@ class Driver(object):
|
|||
useIntegratedCPP = False
|
||||
inputList = phase.inputs
|
||||
if (not hasNoIntegratedCPP and
|
||||
not hasTraditionalCPP and
|
||||
not hasSaveTemps and
|
||||
tool.hasIntegratedCPP()):
|
||||
if (len(phase.inputs) == 1 and
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import sys # FIXME: Shouldn't be needed.
|
||||
|
||||
import Arguments
|
||||
|
@ -114,7 +115,8 @@ class Darwin_AssembleTool(Tool):
|
|||
|
||||
cmd_args = []
|
||||
|
||||
if arglist.getLastArg(arglist.parser.gOption):
|
||||
if (arglist.getLastArg(arglist.parser.gOption) or
|
||||
arglist.getLastArg(arglist.parser.g3Option)):
|
||||
cmd_args.append('--gstabs')
|
||||
|
||||
# Derived from asm spec.
|
||||
|
@ -164,6 +166,159 @@ class GCC_LinkTool(GCC_Common_Tool):
|
|||
output, outputType, args, arglist,
|
||||
[])
|
||||
|
||||
class Darwin_X86_CompileTool(Tool):
|
||||
def __init__(self, toolChain):
|
||||
super(Darwin_X86_CompileTool, self).__init__('cc1',
|
||||
(Tool.eFlagsPipedInput |
|
||||
Tool.eFlagsPipedOutput |
|
||||
Tool.eFlagsIntegratedCPP))
|
||||
self.toolChain = toolChain
|
||||
|
||||
def constructJob(self, phase, arch, jobs, inputs,
|
||||
output, outputType, args, arglist):
|
||||
inputType = inputs[0].type
|
||||
assert not [i for i in inputs if i.type != inputType]
|
||||
|
||||
usePP = False
|
||||
if inputType is Types.CType:
|
||||
cc1Name = 'cc1'
|
||||
usePP = True
|
||||
elif inputType is Types.CTypeNoPP:
|
||||
cc1Name = 'cc1'
|
||||
usePP = False
|
||||
elif inputType is Types.ObjCType:
|
||||
cc1Name = 'cc1obj'
|
||||
usePP = True
|
||||
elif inputType is Types.ObjCTypeNoPP:
|
||||
cc1Name = 'cc1obj'
|
||||
usePP = False
|
||||
elif inputType is Types.CXXType:
|
||||
cc1Name = 'cc1plus'
|
||||
usePP = True
|
||||
elif inputType is Types.CXXTypeNoPP:
|
||||
cc1Name = 'cc1plus'
|
||||
usePP = False
|
||||
elif inputType is Types.ObjCXXType:
|
||||
cc1Name = 'cc1objplus'
|
||||
usePP = True
|
||||
elif inputType is Types.ObjCXXTypeNoPP:
|
||||
cc1Name = 'cc1objplus'
|
||||
usePP = False
|
||||
else:
|
||||
raise RuntimeError,"Unexpected input type for Darwin compile tool."
|
||||
|
||||
cmd_args = []
|
||||
if (arglist.getLastArg(arglist.parser.traditionalOption) or
|
||||
arglist.getLastArg(arglist.parser.f_traditionalOption)):
|
||||
raise ValueError,"-traditional is not supported without -E"
|
||||
|
||||
if usePP:
|
||||
# Derived from cpp_unique_options.
|
||||
|
||||
if (arglist.getLastArg(arglist.parser.COption) or
|
||||
arglist.getLastArg(arglist.parser.CCOption)):
|
||||
if not arglist.getLastArg(arglist.parser.EOption):
|
||||
raise ValueError,"-C or -CC is not supported without -E"
|
||||
if not arglist.getLastArg(arglist.parser.QOption):
|
||||
cmd_args.append('-quiet')
|
||||
arglist.addAllArgs(cmd_args, arglist.parser.nostdincOption)
|
||||
arglist.addLastArg(cmd_args, arglist.parser.vOption)
|
||||
arglist.addAllArgs2(cmd_args, arglist.parser.IOption, arglist.parser.FOption)
|
||||
arglist.addLastArg(cmd_args, arglist.parser.POption)
|
||||
|
||||
# FIXME: Handle %I properly.
|
||||
if arglist.getValue(arch) == 'x86_64':
|
||||
cmd_args.append('-imultilib')
|
||||
cmd_args.append('x86_64')
|
||||
|
||||
if arglist.getLastArg(arglist.parser.MDOption):
|
||||
cmd_args.append('-MD')
|
||||
outputOpt = arglist.getLastArg(arglist.parser.oOption)
|
||||
if outputOpt:
|
||||
base,ext = os.path.splitext(arglist.getValue(outputOpt))
|
||||
cmd_args.append(base+'.d')
|
||||
else:
|
||||
# FIXME: Get correct basename.
|
||||
cmd_args.append('FIXME.d')
|
||||
if arglist.getLastArg(arglist.parser.MMDOption):
|
||||
cmd_args.append('-MMD')
|
||||
outputOpt = arglist.getLastArg(arglist.parser.oOption)
|
||||
if outputOpt:
|
||||
base,ext = os.path.splitext(arglist.getValue(outputOpt))
|
||||
cmd_args.append(base+'.d')
|
||||
else:
|
||||
# FIXME: Get correct basename.
|
||||
cmd_args.append('FIXME.d')
|
||||
arglist.addLastArg(cmd_args, arglist.parser.MOption)
|
||||
arglist.addLastArg(cmd_args, arglist.parser.MMOption)
|
||||
arglist.addAllArgs(cmd_args, arglist.parser.MFOption)
|
||||
arglist.addLastArg(cmd_args, arglist.parser.MGOption)
|
||||
arglist.addLastArg(cmd_args, arglist.parser.MPOption)
|
||||
arglist.addAllArgs(cmd_args, arglist.parser.MQOption)
|
||||
arglist.addAllArgs(cmd_args, arglist.parser.MTOption)
|
||||
if (not arglist.getLastArg(arglist.parser.MOption) and
|
||||
not arglist.getLastArg(arglist.parser.MMOption) and
|
||||
(arglist.getLastArg(arglist.parser.MDOption) or
|
||||
arglist.getLastArg(arglist.parser.MMDOption))):
|
||||
outputOpt = arglist.getLastArg(arglist.parser.oOption)
|
||||
if outputOpt:
|
||||
cmd_args.append('-MQ')
|
||||
cmd_args.append(arglist.getValue(outputOpt))
|
||||
|
||||
arglist.addLastArg(cmd_args, arglist.parser.remapOption)
|
||||
if arglist.getLastArg(arglist.parser.g3Option):
|
||||
cmd_args.append('-dD')
|
||||
arglist.addLastArg(cmd_args, arglist.parser.HOption)
|
||||
|
||||
# FIXME: %C
|
||||
|
||||
arglist.addAllArgs3(cmd_args,
|
||||
arglist.parser.DOption,
|
||||
arglist.parser.UOption,
|
||||
arglist.parser.AOption)
|
||||
|
||||
# FIXME: Add i*
|
||||
|
||||
# FIXME: %Z
|
||||
|
||||
# FIXME: %i
|
||||
|
||||
if arglist.getLastArg(arglist.parser.f_mudflapOption):
|
||||
cmd_args.append('-D_MUDFLAP')
|
||||
cmd_args.append('-include')
|
||||
cmd_args.append('mf-runtime.h')
|
||||
|
||||
if arglist.getLastArg(arglist.parser.f_mudflapthOption):
|
||||
cmd_args.append('-D_MUDFLAP')
|
||||
cmd_args.append('-D_MUDFLAPTH')
|
||||
cmd_args.append('-include')
|
||||
cmd_args.append('mf-runtime.h')
|
||||
else:
|
||||
cmd_args.append('-fpreprocessed')
|
||||
# FIXME: There is a spec command to remove
|
||||
# -fpredictive-compilation args here. Investigate.
|
||||
|
||||
# FIXME: cc1_options
|
||||
|
||||
if arch:
|
||||
cmd_args.extend(arglist.render(arch))
|
||||
if isinstance(output, Jobs.PipedJob):
|
||||
cmd_args.extend(['-o', '-'])
|
||||
elif output is None:
|
||||
cmd_args.append('-fsyntax-only')
|
||||
else:
|
||||
cmd_args.extend(arglist.render(output))
|
||||
|
||||
for input in inputs:
|
||||
if isinstance(input.source, Jobs.PipedJob):
|
||||
cmd_args.append('-')
|
||||
else:
|
||||
cmd_args.extend(arglist.renderAsInput(input.source))
|
||||
|
||||
jobs.addJob(Jobs.Command(self.toolChain.getProgramPath(cc1Name),
|
||||
cmd_args))
|
||||
|
||||
|
||||
class Darwin_X86_LinkTool(Tool):
|
||||
def __init__(self, toolChain):
|
||||
super(Darwin_X86_LinkTool, self).__init__('collect2')
|
||||
|
@ -181,7 +336,7 @@ class Darwin_X86_LinkTool(Tool):
|
|||
try:
|
||||
return tuple(map(int, components))
|
||||
except:
|
||||
raise ArgumentError,"invalid version number %r" % version
|
||||
raise ValueError,"invalid version number %r" % version
|
||||
else:
|
||||
major,minor,minorminor = self.toolChain.darwinVersion
|
||||
return (10, major-4, minor)
|
||||
|
|
Загрузка…
Ссылка в новой задаче