From 39cbfaadbcd0008492fc1ea967b6cc1301a938a1 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 7 Jan 2009 18:54:26 +0000 Subject: [PATCH] ccc: Make proper synthetic arguments in places we have to construct "fake" options, allowing Tools to be oblivious to whether an argument is real or synthetic. This kills off DerivedArg & a number of FIXMEs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61871 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/ccc/ccclib/Arguments.py | 40 +++++++++++++++++------------------ tools/ccc/ccclib/Driver.py | 15 +++++++------ tools/ccc/ccclib/Tools.py | 34 ++++++----------------------- 3 files changed, 35 insertions(+), 54 deletions(-) diff --git a/tools/ccc/ccclib/Arguments.py b/tools/ccc/ccclib/Arguments.py index 06367890ab..934cc72667 100644 --- a/tools/ccc/ccclib/Arguments.py +++ b/tools/ccc/ccclib/Arguments.py @@ -189,23 +189,6 @@ class JoinedAndSeparateValuesArg(Arg): return ([self.opt.name + self.getJoinedValue(args)] + [self.getSeparateValue(args)]) -class DerivedArg(ValueArg): - """DerivedArg - A synthesized argument which does not correspend - to an item in the argument vector.""" - - def __init__(self, value): - # FIXME: The UnknownOption() here is a total hack so we can - # rely on arg.opt not being nil. Ok for now since DerivedArg - # is dying. - super(DerivedArg, self).__init__(-1, UnknownOption()) - self.value = value - - def getValue(self, args): - return self.value - - def render(self, args): - return [self.value] - ### class InputIndex: @@ -220,7 +203,8 @@ class ArgList: """ArgList - Collect an input argument vector along with a set of parsed Args and supporting information.""" - def __init__(self, argv): + def __init__(self, parser, argv): + self.parser = parser self.argv = list(argv) self.syntheticArgv = [] self.lastArgs = {} @@ -240,11 +224,27 @@ class ArgList: raise RuntimeError,'Unknown source ID for index.' - def getSyntheticIndex(self, *strings): + def makeIndex(self, *strings): pos = len(self.syntheticArgv) self.syntheticArgv.extend(strings) return InputIndex(1, pos) + def makeFlagArg(self, option): + return Arg(self.makeIndex(option.name), + option) + + def makeInputArg(self, string): + return PositionalArg(self.makeIndex(string), + self.parser.inputOption) + + def makeUnknownArg(self, string): + return PositionalArg(self.makeIndex(string), + self.parser.unknownOption) + + def makeSeparateArg(self, string, option): + return SeparateValueArg(self.makeIndex(option.name, string), + option) + # Support use as a simple arg list. def __iter__(self): @@ -483,7 +483,7 @@ class OptionParser: iargs = enumerate(argv) it = iter(iargs) - args = ArgList(argv) + args = ArgList(self, argv) for pos,a in it: i = InputIndex(0, pos) # FIXME: Handle '@' diff --git a/tools/ccc/ccclib/Driver.py b/tools/ccc/ccclib/Driver.py index 83a814eb48..85b440e23e 100644 --- a/tools/ccc/ccclib/Driver.py +++ b/tools/ccc/ccclib/Driver.py @@ -416,7 +416,8 @@ class Driver(object): if not archs: # FIXME: Need to infer arch so that we sub -Xarch # correctly. - archs.append(Arguments.DerivedArg('i386')) + archs.append(args.makeSeparateArg('i386', + self.parser.archOption)) actions = self.buildNormalPipeline(args) @@ -548,9 +549,9 @@ class Driver(object): # string. Why? if args.getJoinedValue(arg) == archName: # FIXME: This is wrong, we don't want a - # DerivedArg we want an actual parsed version - # of this arg. - filteredArgs.append(Arguments.DerivedArg(args.getSeparateValue(arg))) + # unknown arg we want an actual parsed + # version of this arg. + filteredArgs.append(args.makeUnknownArg(args.getSeparateValue(arg))) else: filteredArgs.append(arg) @@ -625,11 +626,13 @@ class Driver(object): output = finalOutput # Contruct a named destination? elif atTopLevel or hasSaveTemps: - output = Arguments.DerivedArg(namedOutput) + output = args.makeSeparateArg(namedOutput, + self.parser.oOption) else: # Output to temp file... fd,filename = tempfile.mkstemp(suffix='.'+phase.type.tempSuffix) - output = Arguments.DerivedArg(filename) + output = args.makeSeparateArg(filename, + self.parser.oOption) tool.constructJob(phase, arch, jobList, inputs, output, phase.type, forwardArgs, args) diff --git a/tools/ccc/ccclib/Tools.py b/tools/ccc/ccclib/Tools.py index f48aec9d56..0dd0e30e8b 100644 --- a/tools/ccc/ccclib/Tools.py +++ b/tools/ccc/ccclib/Tools.py @@ -30,21 +30,13 @@ class GCC_Common_Tool(Tool): cmd_args = sum(map(arglist.render, args),[]) + extraArgs if arch: - # FIXME: Clean this up. - if isinstance(arch, Arguments.DerivedArg): - cmd_args.extend(['-arch', arglist.getValue(arch)]) - else: - cmd_args.extend(arglist.render(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: - # FIXME: Ditch this hack. - if isinstance(output, Arguments.DerivedArg): - cmd_args.extend(['-o', arglist.getValue(output)]) - else: - cmd_args.extend(arglist.render(output)) + cmd_args.extend(arglist.render(output)) cmd_args.extend(['-x', input.type.name]) if isinstance(input.source, Jobs.PipedJob): @@ -105,17 +97,9 @@ class DarwinAssemblerTool(Tool): cmd_args = [] if arch: - # FIXME: Clean this up. - if isinstance(arch, Arguments.DerivedArg): - cmd_args.extend(['-arch', - arglist.getValue(arch)]) - else: - cmd_args.extend(arglist.render(arch)) + cmd_args.extend(arglist.render(arch)) cmd_args.append('-force_cpusubtype_ALL') - if isinstance(output, Arguments.DerivedArg): - cmd_args.extend(['-o', arglist.getValue(output)]) - else: - cmd_args.extend(arglist.render(output)) + cmd_args.extend(arglist.render(output)) if isinstance(input.source, Jobs.PipedJob): cmd_args.append('-') else: @@ -138,10 +122,7 @@ class Collect2Tool(Tool): cmd_args.extend(arglist.render(arg)) for input in inputs: cmd_args.append(arglist.getValue(input.source)) - if isinstance(output, Arguments.DerivedArg): - cmd_args.extend(['-o', arglist.getValue(output)]) - else: - cmd_args.extend(arglist.render(output)) + cmd_args.extend(arglist.render(output)) cmd_args.extend(['-L/usr/lib/gcc/i686-apple-darwin10/4.2.1', '-lcrt1.10.5.o', '-lgcc_s.10.5', @@ -158,10 +139,7 @@ class LipoTool(Tool): assert outputType is Types.ImageType cmd_args = ['-create'] - if isinstance(output, Arguments.DerivedArg): - cmd_args.extend(['-o', arglist.getValue(output)]) - else: - cmd_args.extend(arglist.render(output)) + cmd_args.extend(arglist.render(output)) for input in inputs: cmd_args.append(arglist.getValue(input.source)) jobs.addJob(Jobs.Command('lipo', cmd_args)) -- 2.40.0