class Option(object):
"""Root option class."""
- def __init__(self, name):
+
+ def __init__(self, name, isLinkerInput=False, noOptAsInput=False):
self.name = name
+ self.isLinkerInput = isLinkerInput
+ self.noOptAsInput = noOptAsInput
def accept(self, index, arg, it):
"""accept(index, arg, iterator) -> Arg or None
if arg.startswith(self.name):
return JoinedValueArg(index, self)
+class CommaJoinedOption(Option):
+ """An option which literally prefixs its argument, but which
+ conceptually may have an arbitrary number of arguments which are
+ separated by commas."""
+
+ def accept(self, index, arg, it):
+ if arg.startswith(self.name):
+ return CommaJoinedValuesArg(index, self)
+
class SeparateOption(Option):
"""An option which is followed by its value."""
assert opt is not None
self.index = index
self.opt = opt
-
+
def __repr__(self):
return '<%s index=%r opt=%r>' % (self.__class__.__name__,
self.index,
assert self.opt
return [self.opt.name]
+ def renderAsInput(self, args):
+ return self.render(args)
+
class ValueArg(Arg):
"""ValueArg - An instance of an option which has an argument."""
def render(self, args):
return [self.opt.name + self.getValue(args)]
+ def renderAsInput(self, args):
+ if self.opt.noOptAsInput:
+ return [self.getValue(args)]
+ return self.render(args)
+
class SeparateValueArg(ValueArg):
"""SeparateValueArg - A single value argument where the value
follows the option in the argument vector."""
def render(self, args):
return [self.opt.name, self.getValue(args)]
+ def renderAsInput(self, args):
+ if self.opt.noOptAsInput:
+ return [self.getValue(args)]
+ return self.render(args)
+
class MultipleValuesArg(Arg):
"""MultipleValuesArg - An argument with multiple values which
follow the option in the argument vector."""
def render(self, args):
return [self.opt.name] + self.getValues(args)
+class CommaJoinedValuesArg(Arg):
+ """CommaJoinedValuesArg - An argument with multiple values joined
+ by commas and joined (suffixed) to the option.
+
+ The key point of this arg is that it renders its values into
+ separate arguments, which allows it to be used as a generic
+ mechanism for passing arguments through to tools."""
+
+ def getValues(self, args):
+ return args.getInputString(self.index)[len(self.opt.name):].split(',')
+
+ def render(self, args):
+ return [self.opt.name + ','.join(self.getValues(args))]
+
+ def renderAsInput(self, args):
+ return self.getValues(args)
+
# FIXME: Man, this is lame. It is only used by -Xarch. Maybe easier to
# just special case?
class JoinedAndSeparateValuesArg(Arg):
def render(self, arg):
return arg.render(self)
+ def renderAsInput(self, arg):
+ return arg.renderAsInput(self)
+
def getValue(self, arg):
return arg.getValue(self)
self.addOption(FlagOption('-v'))
# Input/output stuff
- self.oOption = self.addOption(JoinedOrSeparateOption('-o'))
+ self.oOption = self.addOption(JoinedOrSeparateOption('-o', noOptAsInput=True))
self.xOption = self.addOption(JoinedOrSeparateOption('-x'))
self.ObjCOption = self.addOption(FlagOption('-ObjC'))
# Blanket pass-through options.
- self.addOption(JoinedOption('-Wa,'))
+ self.addOption(CommaJoinedOption('-Wa,'))
self.addOption(SeparateOption('-Xassembler'))
- self.addOption(JoinedOption('-Wp,'))
+ self.addOption(CommaJoinedOption('-Wp,'))
self.addOption(SeparateOption('-Xpreprocessor'))
- self.addOption(JoinedOption('-Wl,'))
- self.addOption(SeparateOption('-Xlinker'))
+ self.addOption(CommaJoinedOption('-Wl,', isLinkerInput=True))
+ self.addOption(SeparateOption('-Xlinker', isLinkerInput=True, noOptAsInput=True))
####
# Bring on the random garbage.
self.addOption(FlagOption('-traditional'))
self.addOption(FlagOption('--traditional'))
self.addOption(FlagOption('-no_dead_strip_inits_and_terms'))
+ self.addOption(JoinedOption('-weak-l', isLinkerInput=True))
+ self.addOption(SeparateOption('-weak_framework', isLinkerInput=True))
+ self.addOption(SeparateOption('-weak_library', isLinkerInput=True))
self.whyloadOption = self.addOption(FlagOption('-whyload'))
self.whatsloadedOption = self.addOption(FlagOption('-whatsloaded'))
self.sectalignOption = self.addOption(MultiArgOption('-sectalign', numArgs=3))
self.Zunexported_symbols_listOption = self.addOption(JoinedOrSeparateOption('-Zunexported_symbols_list'))
self.Zweak_reference_mismatchesOption = self.addOption(JoinedOrSeparateOption('-Zweak_reference_mismatches'))
- # I dunno why these don't end up working when joined. Maybe
- # because of translation?
- self.filelistOption = self.addOption(SeparateOption('-filelist'))
- self.addOption(SeparateOption('-framework'))
+ self.addOption(SeparateOption('-filelist', isLinkerInput=True))
+ self.addOption(SeparateOption('-framework', isLinkerInput=True))
# FIXME: Alias.
self.addOption(SeparateOption('-install_name'))
self.Zinstall_nameOption = self.addOption(JoinedOrSeparateOption('-Zinstall_name'))
self.addOption(JoinedOrSeparateOption('-U'))
self.ZOption = self.addOption(JoinedOrSeparateOption('-Z'))
- self.addOption(JoinedOrSeparateOption('-l'))
+ self.addOption(JoinedOrSeparateOption('-l', isLinkerInput=True))
self.uOption = self.addOption(JoinedOrSeparateOption('-u'))
self.tOption = self.addOption(JoinedOrSeparateOption('-t'))
self.yOption = self.addOption(JoinedOption('-y'))
self.claim(inputTypeOpt)
klass = inputType
inputs.append((klass, a))
- elif a.opt is self.parser.filelistOption:
- # Treat as a linker input. Investigate how gcc is
- # handling this.
+ elif a.opt.isLinkerInput:
+ # Treat as a linker input.
#
# FIXME: This might not be good enough. We may
# need to introduce another type for this case, so
args.getLastArg(self.parser.saveTempsOption2))
hasNoIntegratedCPP = args.getLastArg(self.parser.noIntegratedCPPOption)
hasPipe = args.getLastArg(self.parser.pipeOption)
+
+ # FIXME: forward will die, this isn't really how things are
+ # done, instead everything comes from the arglist. For this we
+ # need a DerivedArgList for handling -Xarch, and some way to
+ # still figure out what to forward to the generic gcc tool.
forward = []
for a in args:
if a.opt is self.parser.inputOption:
pass
# FIXME: Needs to be part of option.
- elif a.opt.name in ('-E', '-S', '-c',
- '-arch', '-fsyntax-only', '-combine', '-x',
- '-###'):
+ elif (a.opt.name in ('-E', '-S', '-c',
+ '-arch', '-fsyntax-only', '-combine', '-x',
+ '-###') or
+ a.opt.isLinkerInput):
pass
else:
#
# FIXME: gcc has some special case in here so that it doesn't
# create output files if they would conflict with an input.
- inputName = args.getValue(baseInput)
if phase.type is Types.ImageType:
namedOutput = "a.out"
else:
+ inputName = args.getValue(baseInput)
base,_ = os.path.splitext(inputName)
assert phase.type.tempSuffix is not None
namedOutput = base + '.' + phase.type.tempSuffix
if isinstance(input.source, Jobs.PipedJob):
cmd_args.append('-')
else:
- cmd_args.append(arglist.getValue(input.source))
+ assert isinstance(input.source, Arguments.Arg)
+ # If this is a linker input then assume we can forward
+ # just by rendering.
+ if input.source.opt.isLinkerInput:
+ cmd_args.extend(arglist.render(input.source))
+ else:
+ cmd_args.extend(arglist.renderAsInput(input.source))
jobs.addJob(Jobs.Command('gcc', cmd_args))
if isinstance(input.source, Jobs.PipedJob):
cmd_args.append('-')
else:
- cmd_args.append(arglist.getValue(input.source))
+ cmd_args.extend(arglist.renderAsInput(input.source))
jobs.addJob(Jobs.Command('as', cmd_args))
class GCC_AssembleTool(GCC_Common_Tool):
"-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.."])
for input in inputs:
- cmd_args.append(arglist.getValue(input.source))
+ cmd_args.extend(arglist.renderAsInput(input.source))
if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or
arglist.getLastArg(arglist.parser.f_profileGenerateOption) or
cmd_args = ['-create']
cmd_args.extend(arglist.render(output))
for input in inputs:
- cmd_args.append(arglist.getValue(input.source))
+ cmd_args.extend(arglist.renderAsInput(input.source))
jobs.addJob(Jobs.Command('lipo', cmd_args))