blob: a8a808bd4d0f3a1d31e1554e426045ab12151a5c [file] [log] [blame]
Daniel Dunbara5677512009-01-05 19:53:30 +00001class Option(object):
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00002 """Option - Root option class."""
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +00003
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00004 def __init__(self, name, group=None, isLinkerInput=False, noOptAsInput=False):
5 assert group is None or isinstance(group, OptionGroup)
Daniel Dunbara5677512009-01-05 19:53:30 +00006 self.name = name
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00007 self.group = group
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +00008 self.isLinkerInput = isLinkerInput
9 self.noOptAsInput = noOptAsInput
Daniel Dunbara5677512009-01-05 19:53:30 +000010
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +000011 def matches(self, opt):
12 """matches(opt) -> bool
13
14 Predicate for whether this option is part of the given option
15 (which may be a group)."""
16 if self is opt:
17 return True
18 elif self.group:
19 return self.group.matches(opt)
20 else:
21 return False
22
Daniel Dunbara5677512009-01-05 19:53:30 +000023 def accept(self, index, arg, it):
24 """accept(index, arg, iterator) -> Arg or None
25
26 Accept the argument at the given index, returning an Arg, or
27 return None if the option does not accept this argument.
28
29 May raise MissingArgumentError.
30 """
31 abstract
32
33 def __repr__(self):
34 return '<%s name=%r>' % (self.__class__.__name__,
35 self.name)
36
Daniel Dunbar11672ec2009-01-13 18:51:26 +000037 def forwardToGCC(self):
38 # FIXME: Get rid of this hack.
39 if self.name == '<input>':
40 return False
41
42 if self.isLinkerInput:
43 return False
44
45 return self.name not in ('-E', '-S', '-c',
46 '-arch', '-fsyntax-only', '-combine', '-x',
47 '-###')
48
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +000049class OptionGroup(Option):
50 """OptionGroup - A fake option class used to group options so that
51 the driver can efficiently refer to an entire set of options."""
52
53 def __init__(self, name):
54 super(OptionGroup, self).__init__(name)
55
56 def accept(self, index, arg, it):
57 raise RuntimeError,"accept() should never be called on an OptionGroup"
58
Daniel Dunbar5039f212009-01-06 02:30:10 +000059# Dummy options
60
61class InputOption(Option):
62 def __init__(self):
63 super(InputOption, self).__init__('<input>')
64
65 def accept(self):
66 raise RuntimeError,"accept() should never be used on InputOption instance."
67
68class UnknownOption(Option):
69 def __init__(self):
70 super(UnknownOption, self).__init__('<unknown>')
71
72 def accept(self):
73 raise RuntimeError,"accept() should never be used on UnknownOption instance."
74
75# Normal options
76
Daniel Dunbara5677512009-01-05 19:53:30 +000077class FlagOption(Option):
78 """An option which takes no arguments."""
79
80 def accept(self, index, arg, it):
81 if arg == self.name:
82 return Arg(index, self)
83
84class JoinedOption(Option):
85 """An option which literally prefixes its argument."""
86
87 def accept(self, index, arg, it):
88 if arg.startswith(self.name):
89 return JoinedValueArg(index, self)
90
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +000091class CommaJoinedOption(Option):
92 """An option which literally prefixs its argument, but which
93 conceptually may have an arbitrary number of arguments which are
94 separated by commas."""
95
96 def accept(self, index, arg, it):
97 if arg.startswith(self.name):
98 return CommaJoinedValuesArg(index, self)
99
Daniel Dunbara5677512009-01-05 19:53:30 +0000100class SeparateOption(Option):
101 """An option which is followed by its value."""
102
103 def accept(self, index, arg, it):
104 if arg == self.name:
105 try:
106 _,value = it.next()
107 except StopIteration:
108 raise MissingArgumentError,self
109 return SeparateValueArg(index, self)
110
111class MultiArgOption(Option):
112 """An option which takes multiple arguments."""
113
114 def __init__(self, name, numArgs):
115 assert numArgs > 1
116 super(MultiArgOption, self).__init__(name)
117 self.numArgs = numArgs
118
119 def accept(self, index, arg, it):
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000120 if arg == self.name:
Daniel Dunbara5677512009-01-05 19:53:30 +0000121 try:
122 values = [it.next()[1] for i in range(self.numArgs)]
123 except StopIteration:
124 raise MissingArgumentError,self
125 return MultipleValuesArg(index, self)
126
127class JoinedOrSeparateOption(Option):
128 """An option which either literally prefixes its value or is
129 followed by an value."""
130
131 def accept(self, index, arg, it):
132 if arg.startswith(self.name):
133 if len(arg) != len(self.name): # Joined case
134 return JoinedValueArg(index, self)
135 else:
136 try:
137 _,value = it.next()
138 except StopIteration:
139 raise MissingArgumentError,self
140 return SeparateValueArg(index, self)
141
142class JoinedAndSeparateOption(Option):
143 """An option which literally prefixes its value and is followed by
144 an value."""
145
146 def accept(self, index, arg, it):
147 if arg.startswith(self.name):
148 try:
149 _,value = it.next()
150 except StopIteration:
151 raise MissingArgumentError,self
152 return JoinedAndSeparateValuesArg(index, self)
153
154###
155
156class Arg(object):
157 """Arg - Base class for actual driver arguments."""
158 def __init__(self, index, opt):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000159 assert opt is not None
Daniel Dunbara5677512009-01-05 19:53:30 +0000160 self.index = index
161 self.opt = opt
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000162
Daniel Dunbara5677512009-01-05 19:53:30 +0000163 def __repr__(self):
164 return '<%s index=%r opt=%r>' % (self.__class__.__name__,
165 self.index,
166 self.opt)
167
168 def render(self, args):
169 """render(args) -> [str]
170
171 Map the argument into a list of actual program arguments,
172 given the source argument array."""
173 assert self.opt
174 return [self.opt.name]
175
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000176 def renderAsInput(self, args):
177 return self.render(args)
178
Daniel Dunbara5677512009-01-05 19:53:30 +0000179class ValueArg(Arg):
180 """ValueArg - An instance of an option which has an argument."""
181
182 def getValue(self, args):
183 abstract
184
Daniel Dunbar996ce962009-01-12 07:40:25 +0000185 def getValues(self, args):
186 return [self.getValue(args)]
187
Daniel Dunbar5039f212009-01-06 02:30:10 +0000188class PositionalArg(ValueArg):
189 """PositionalArg - A simple positional argument."""
Daniel Dunbara5677512009-01-05 19:53:30 +0000190
191 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000192 return args.getInputString(self.index)
Daniel Dunbara5677512009-01-05 19:53:30 +0000193
194 def render(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000195 return [args.getInputString(self.index)]
Daniel Dunbara5677512009-01-05 19:53:30 +0000196
197class JoinedValueArg(ValueArg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000198 """JoinedValueArg - A single value argument where the value is
199 joined (suffixed) to the option."""
200
Daniel Dunbara5677512009-01-05 19:53:30 +0000201 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000202 return args.getInputString(self.index)[len(self.opt.name):]
Daniel Dunbara5677512009-01-05 19:53:30 +0000203
Daniel Dunbara5677512009-01-05 19:53:30 +0000204 def render(self, args):
205 return [self.opt.name + self.getValue(args)]
206
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000207 def renderAsInput(self, args):
208 if self.opt.noOptAsInput:
209 return [self.getValue(args)]
210 return self.render(args)
211
Daniel Dunbara5677512009-01-05 19:53:30 +0000212class SeparateValueArg(ValueArg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000213 """SeparateValueArg - A single value argument where the value
214 follows the option in the argument vector."""
215
Daniel Dunbara5677512009-01-05 19:53:30 +0000216 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000217 return args.getInputString(self.index, offset=1)
Daniel Dunbara5677512009-01-05 19:53:30 +0000218
Daniel Dunbara5677512009-01-05 19:53:30 +0000219 def render(self, args):
220 return [self.opt.name, self.getValue(args)]
221
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000222 def renderAsInput(self, args):
223 if self.opt.noOptAsInput:
224 return [self.getValue(args)]
225 return self.render(args)
226
Daniel Dunbara5677512009-01-05 19:53:30 +0000227class MultipleValuesArg(Arg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000228 """MultipleValuesArg - An argument with multiple values which
229 follow the option in the argument vector."""
230
231 # FIXME: Should we unify this with SeparateValueArg?
232
Daniel Dunbara5677512009-01-05 19:53:30 +0000233 def getValues(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000234 return [args.getInputString(self.index, offset=1+i)
235 for i in range(self.opt.numArgs)]
Daniel Dunbara5677512009-01-05 19:53:30 +0000236
Daniel Dunbara5677512009-01-05 19:53:30 +0000237 def render(self, args):
238 return [self.opt.name] + self.getValues(args)
239
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000240class CommaJoinedValuesArg(Arg):
241 """CommaJoinedValuesArg - An argument with multiple values joined
242 by commas and joined (suffixed) to the option.
243
244 The key point of this arg is that it renders its values into
245 separate arguments, which allows it to be used as a generic
246 mechanism for passing arguments through to tools."""
247
248 def getValues(self, args):
249 return args.getInputString(self.index)[len(self.opt.name):].split(',')
250
251 def render(self, args):
252 return [self.opt.name + ','.join(self.getValues(args))]
253
254 def renderAsInput(self, args):
255 return self.getValues(args)
256
Daniel Dunbara5677512009-01-05 19:53:30 +0000257# FIXME: Man, this is lame. It is only used by -Xarch. Maybe easier to
258# just special case?
259class JoinedAndSeparateValuesArg(Arg):
260 """JoinedAndSeparateValuesArg - An argument with both joined and
261 separate values."""
262
263 def getJoinedValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000264 return args.getInputString(self.index)[len(self.opt.name):]
Daniel Dunbara5677512009-01-05 19:53:30 +0000265
266 def getSeparateValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000267 return args.getInputString(self.index, offset=1)
Daniel Dunbara5677512009-01-05 19:53:30 +0000268
269 def render(self, args):
270 return ([self.opt.name + self.getJoinedValue(args)] +
271 [self.getSeparateValue(args)])
272
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000273###
274
275class InputIndex:
276 def __init__(self, sourceId, pos):
277 self.sourceId = sourceId
278 self.pos = pos
279
280 def __repr__(self):
281 return 'InputIndex(%d, %d)' % (self.sourceId, self.pos)
282
Daniel Dunbar11672ec2009-01-13 18:51:26 +0000283class ArgList(object):
284 """ArgList - Collect an input argument vector along with a set of
285 parsed Args and supporting information."""
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000286
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000287 def __init__(self, parser, argv):
288 self.parser = parser
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000289 self.argv = list(argv)
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000290 self.syntheticArgv = []
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000291 self.lastArgs = {}
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000292 self.args = []
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000293
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000294 def getArgs(self, option):
295 # FIXME: How efficient do we want to make this. One reasonable
296 # solution would be to embed a linked list inside each arg and
297 # automatically chain them (with pointers to head and
298 # tail). This gives us efficient access to the (first, last,
299 # all) arg(s) with little overhead.
300 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000301 if arg.opt.matches(option):
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000302 yield arg
303
Daniel Dunbar996ce962009-01-12 07:40:25 +0000304 def getArgs2(self, optionA, optionB):
305 """getArgs2 - Iterate over all arguments for two options, in
306 the order they were specified."""
307 # As long as getArgs is efficient, we can easily make this
308 # efficient by iterating both at once and always taking the
309 # earlier arg.
310 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000311 if (arg.opt.matches(optionA) or
312 arg.opt.matches(optionB)):
Daniel Dunbar996ce962009-01-12 07:40:25 +0000313 yield arg
314
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000315 def getArgs3(self, optionA, optionB, optionC):
316 """getArgs3 - Iterate over all arguments for three options, in
317 the order they were specified."""
318 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000319 if (arg.opt.matches(optionA) or
320 arg.opt.matches(optionB) or
321 arg.opt.matches(optionC)):
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000322 yield arg
323
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000324 def getLastArg(self, option):
325 return self.lastArgs.get(option)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000326
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000327 def getInputString(self, index, offset=0):
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000328 # Source 0 is argv.
329 if index.sourceId == 0:
330 return self.argv[index.pos + offset]
331
332 # Source 1 is synthetic argv.
333 if index.sourceId == 1:
334 return self.syntheticArgv[index.pos + offset]
335
336 raise RuntimeError,'Unknown source ID for index.'
337
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000338 def addLastArg(self, output, option):
339 """addLastArgs - Extend the given output vector with the last
340 instance of a given option."""
341 arg = self.getLastArg(option)
342 if arg:
343 output.extend(self.render(arg))
344
345 def addAllArgs(self, output, option):
346 """addAllArgs - Extend the given output vector with all
347 instances of a given option."""
348 for arg in self.getArgs(option):
349 output.extend(self.render(arg))
350
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000351 def addAllArgs2(self, output, optionA, optionB):
352 """addAllArgs2 - Extend the given output vector with all
353 instances of two given option, with relative order preserved."""
354 for arg in self.getArgs2(optionA, optionB):
355 output.extend(self.render(arg))
356
357 def addAllArgs3(self, output, optionA, optionB, optionC):
358 """addAllArgs3 - Extend the given output vector with all
359 instances of three given option, with relative order preserved."""
360 for arg in self.getArgs3(optionA, optionB, optionC):
361 output.extend(self.render(arg))
362
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000363 def addAllArgsTranslated(self, output, option, translation):
364 """addAllArgsTranslated - Extend the given output vector with
365 all instances of a given option, rendered as separate
366 arguments with the actual option name translated to a user
367 specified string. For example, '-foox' will be render as
368 ['-bar', 'x'] if '-foo' was the option and '-bar' was the
369 translation.
370
371 This routine expects that the option can only yield ValueArg
372 instances."""
373 for arg in self.getArgs(option):
374 assert isinstance(arg, ValueArg)
375 output.append(translation)
376 output.append(self.getValue(arg))
377
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000378 def makeIndex(self, *strings):
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000379 pos = len(self.syntheticArgv)
380 self.syntheticArgv.extend(strings)
381 return InputIndex(1, pos)
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000382
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000383 def makeFlagArg(self, option):
384 return Arg(self.makeIndex(option.name),
385 option)
386
387 def makeInputArg(self, string):
388 return PositionalArg(self.makeIndex(string),
389 self.parser.inputOption)
390
391 def makeUnknownArg(self, string):
392 return PositionalArg(self.makeIndex(string),
393 self.parser.unknownOption)
394
395 def makeSeparateArg(self, string, option):
396 return SeparateValueArg(self.makeIndex(option.name, string),
397 option)
398
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000399 # Support use as a simple arg list.
400
401 def __iter__(self):
402 return iter(self.args)
403
404 def append(self, arg):
405 self.args.append(arg)
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000406 self.lastArgs[arg.opt] = arg
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000407 if arg.opt.group is not None:
408 self.lastArgs[arg.opt.group] = arg
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000409
410 # Forwarding methods.
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000411 #
412 # FIXME: Clean this up once restructuring is done.
413
414 def render(self, arg):
415 return arg.render(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000416
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000417 def renderAsInput(self, arg):
418 return arg.renderAsInput(self)
419
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000420 def getValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000421 return arg.getValue(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000422
423 def getValues(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000424 return arg.getValues(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000425
426 def getSeparateValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000427 return arg.getSeparateValue(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000428
429 def getJoinedValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000430 return arg.getJoinedValue(self)
Daniel Dunbar1dd2ada2009-01-06 06:32:49 +0000431
Daniel Dunbar11672ec2009-01-13 18:51:26 +0000432class DerivedArgList(ArgList):
433 def __init__(self, args):
434 super(DerivedArgList, self).__init__(args.parser, args.argv)
435 self.parser = args.parser
436 self.argv = args.argv
437 self.syntheticArgv = args.syntheticArgv
438 self.lastArgs = {}
439 self.args = []
440
Daniel Dunbar1dd2ada2009-01-06 06:32:49 +0000441###
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000442
Daniel Dunbara5677512009-01-05 19:53:30 +0000443class OptionParser:
444 def __init__(self):
445 self.options = []
Daniel Dunbar5039f212009-01-06 02:30:10 +0000446 self.inputOption = InputOption()
447 self.unknownOption = UnknownOption()
448
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000449 # Driver driver options
450 self.archOption = self.addOption(SeparateOption('-arch'))
451
452 # Misc driver options
453 self.addOption(FlagOption('-pass-exit-codes'))
454 self.addOption(FlagOption('--help'))
455 self.addOption(FlagOption('--target-help'))
456
457 self.dumpspecsOption = self.addOption(FlagOption('-dumpspecs'))
458 self.dumpversionOption = self.addOption(FlagOption('-dumpversion'))
459 self.dumpmachineOption = self.addOption(FlagOption('-dumpmachine'))
460 self.printSearchDirsOption = self.addOption(FlagOption('-print-search-dirs'))
461 self.printLibgccFilenameOption = self.addOption(FlagOption('-print-libgcc-file-name'))
462 # FIXME: Hrm, where does this come from? It isn't always true that
463 # we take both - and --. For example, gcc --S ... ends up sending
464 # -fS to cc1. Investigate.
465 #
466 # FIXME: Need to implement some form of alias support inside
467 # getLastOption to handle this.
468 self.printLibgccFileNameOption2 = self.addOption(FlagOption('--print-libgcc-file-name'))
469 self.printFileNameOption = self.addOption(JoinedOption('-print-file-name='))
470 self.printProgNameOption = self.addOption(JoinedOption('-print-prog-name='))
471 self.printProgNameOption2 = self.addOption(JoinedOption('--print-prog-name='))
472 self.printMultiDirectoryOption = self.addOption(FlagOption('-print-multi-directory'))
473 self.printMultiLibOption = self.addOption(FlagOption('-print-multi-lib'))
474 self.addOption(FlagOption('-print-multi-os-directory'))
475
476 # Hmmm, who really takes this?
477 self.addOption(FlagOption('--version'))
478
479 # Pipeline control
480 self.hashHashHashOption = self.addOption(FlagOption('-###'))
481 self.EOption = self.addOption(FlagOption('-E'))
482 self.SOption = self.addOption(FlagOption('-S'))
483 self.cOption = self.addOption(FlagOption('-c'))
484 self.combineOption = self.addOption(FlagOption('-combine'))
485 self.noIntegratedCPPOption = self.addOption(FlagOption('-no-integrated-cpp'))
486 self.pipeOption = self.addOption(FlagOption('-pipe'))
487 self.saveTempsOption = self.addOption(FlagOption('-save-temps'))
488 self.saveTempsOption2 = self.addOption(FlagOption('--save-temps'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000489 # FIXME: Error out if this is used.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000490 self.addOption(JoinedOption('-specs='))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000491 # FIXME: Implement.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000492 self.addOption(FlagOption('-time'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000493 # FIXME: Implement.
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000494 self.vOption = self.addOption(FlagOption('-v'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000495
496 # Input/output stuff
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000497 self.oOption = self.addOption(JoinedOrSeparateOption('-o', noOptAsInput=True))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000498 self.xOption = self.addOption(JoinedOrSeparateOption('-x'))
499
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000500 self.ObjCOption = self.addOption(FlagOption('-ObjC'))
501 self.ObjCXXOption = self.addOption(FlagOption('-ObjC++'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000502
503 # FIXME: Weird, gcc claims this here in help but I'm not sure why;
504 # perhaps interaction with preprocessor? Investigate.
Daniel Dunbar816dd502009-01-12 17:53:19 +0000505
506 # FIXME: This is broken in Darwin cc1, it wants std* and this
507 # is std=. May need an option group for this as well.
508 self.stdOption = self.addOption(JoinedOption('-std='))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000509 self.addOption(JoinedOrSeparateOption('--sysroot'))
510
511 # Version control
512 self.addOption(JoinedOrSeparateOption('-B'))
513 self.addOption(JoinedOrSeparateOption('-V'))
514 self.addOption(JoinedOrSeparateOption('-b'))
515
516 # Blanket pass-through options.
517
Daniel Dunbar996ce962009-01-12 07:40:25 +0000518 self.WaOption = self.addOption(CommaJoinedOption('-Wa,'))
519 self.XassemblerOption = self.addOption(SeparateOption('-Xassembler'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000520
Daniel Dunbarb37c9652009-01-12 21:44:10 +0000521 self.WpOption = self.addOption(CommaJoinedOption('-Wp,'))
522 self.XpreprocessorOption = self.addOption(SeparateOption('-Xpreprocessor'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000523
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000524 self.addOption(CommaJoinedOption('-Wl,', isLinkerInput=True))
525 self.addOption(SeparateOption('-Xlinker', isLinkerInput=True, noOptAsInput=True))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000526
527 ####
528 # Bring on the random garbage.
529
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000530 self.MOption = self.addOption(FlagOption('-M'))
531 self.MDOption = self.addOption(FlagOption('-MD'))
532 self.MGOption = self.addOption(FlagOption('-MG'))
533 self.MMDOption = self.addOption(FlagOption('-MMD'))
534 self.MPOption = self.addOption(FlagOption('-MP'))
535 self.MMOption = self.addOption(FlagOption('-MM'))
536 self.MFOption = self.addOption(JoinedOrSeparateOption('-MF'))
537 self.MTOption = self.addOption(JoinedOrSeparateOption('-MT'))
538 self.MQOption = self.addOption(JoinedOrSeparateOption('-MQ'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000539 self.MachOption = self.addOption(FlagOption('-Mach'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000540 self.undefOption = self.addOption(FlagOption('-undef'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000541
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000542 self.wOption = self.addOption(FlagOption('-w'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000543 self.addOption(JoinedOrSeparateOption('-allowable_client'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000544 self.client_nameOption = self.addOption(JoinedOrSeparateOption('-client_name'))
545 self.compatibility_versionOption = self.addOption(JoinedOrSeparateOption('-compatibility_version'))
546 self.current_versionOption = self.addOption(JoinedOrSeparateOption('-current_version'))
547 self.dylinkerOption = self.addOption(FlagOption('-dylinker'))
548 self.dylinker_install_nameOption = self.addOption(JoinedOrSeparateOption('-dylinker_install_name'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000549 self.addOption(JoinedOrSeparateOption('-exported_symbols_list'))
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000550
551 self.iGroup = OptionGroup('-i')
552 self.addOption(JoinedOrSeparateOption('-idirafter', self.iGroup))
553 self.addOption(JoinedOrSeparateOption('-iquote', self.iGroup))
554 self.isysrootOption = self.addOption(JoinedOrSeparateOption('-isysroot', self.iGroup))
555 self.addOption(JoinedOrSeparateOption('-include', self.iGroup))
556 self.addOption(JoinedOption('-i', self.iGroup))
557
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000558 self.keep_private_externsOption = self.addOption(JoinedOrSeparateOption('-keep_private_externs'))
559 self.private_bundleOption = self.addOption(FlagOption('-private_bundle'))
560 self.seg1addrOption = self.addOption(JoinedOrSeparateOption('-seg1addr'))
561 self.segprotOption = self.addOption(JoinedOrSeparateOption('-segprot'))
562 self.sub_libraryOption = self.addOption(JoinedOrSeparateOption('-sub_library'))
563 self.sub_umbrellaOption = self.addOption(JoinedOrSeparateOption('-sub_umbrella'))
564 self.umbrellaOption = self.addOption(JoinedOrSeparateOption('-umbrella'))
565 self.undefinedOption = self.addOption(JoinedOrSeparateOption('-undefined'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000566 self.addOption(JoinedOrSeparateOption('-unexported_symbols_list'))
567 self.addOption(JoinedOrSeparateOption('-weak_framework'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000568 self.headerpad_max_install_namesOption = self.addOption(JoinedOption('-headerpad_max_install_names'))
569 self.twolevel_namespaceOption = self.addOption(FlagOption('-twolevel_namespace'))
570 self.twolevel_namespace_hintsOption = self.addOption(FlagOption('-twolevel_namespace_hints'))
571 self.prebindOption = self.addOption(FlagOption('-prebind'))
572 self.noprebindOption = self.addOption(FlagOption('-noprebind'))
573 self.nofixprebindingOption = self.addOption(FlagOption('-nofixprebinding'))
574 self.prebind_all_twolevel_modulesOption = self.addOption(FlagOption('-prebind_all_twolevel_modules'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000575 self.remapOption = self.addOption(FlagOption('-remap'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000576 self.read_only_relocsOption = self.addOption(SeparateOption('-read_only_relocs'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000577 self.addOption(FlagOption('-single_module'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000578 self.nomultidefsOption = self.addOption(FlagOption('-nomultidefs'))
579 self.nostartfilesOption = self.addOption(FlagOption('-nostartfiles'))
580 self.nodefaultlibsOption = self.addOption(FlagOption('-nodefaultlibs'))
581 self.nostdlibOption = self.addOption(FlagOption('-nostdlib'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000582 self.nostdincOption = self.addOption(FlagOption('-nostdinc'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000583 self.objectOption = self.addOption(FlagOption('-object'))
584 self.preloadOption = self.addOption(FlagOption('-preload'))
585 self.staticOption = self.addOption(FlagOption('-static'))
586 self.pagezero_sizeOption = self.addOption(FlagOption('-pagezero_size'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000587 self.addOption(FlagOption('-shared'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000588 self.staticLibgccOption = self.addOption(FlagOption('-static-libgcc'))
589 self.sharedLibgccOption = self.addOption(FlagOption('-shared-libgcc'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000590 self.COption = self.addOption(FlagOption('-C'))
591 self.CCOption = self.addOption(FlagOption('-CC'))
592 self.HOption = self.addOption(FlagOption('-H'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000593 self.addOption(FlagOption('-R'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000594 self.POption = self.addOption(FlagOption('-P'))
595 self.QOption = self.addOption(FlagOption('-Q'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000596 self.QnOption = self.addOption(FlagOption('-Qn'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000597 self.addOption(FlagOption('-all_load'))
598 self.addOption(FlagOption('--constant-cfstrings'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000599 self.traditionalOption = self.addOption(FlagOption('-traditional'))
600 self.traditionalCPPOption = self.addOption(FlagOption('-traditional-cpp'))
601 # FIXME: Alias.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000602 self.addOption(FlagOption('--traditional'))
603 self.addOption(FlagOption('-no_dead_strip_inits_and_terms'))
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000604 self.addOption(JoinedOption('-weak-l', isLinkerInput=True))
605 self.addOption(SeparateOption('-weak_framework', isLinkerInput=True))
606 self.addOption(SeparateOption('-weak_library', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000607 self.whyloadOption = self.addOption(FlagOption('-whyload'))
608 self.whatsloadedOption = self.addOption(FlagOption('-whatsloaded'))
609 self.sectalignOption = self.addOption(MultiArgOption('-sectalign', numArgs=3))
610 self.sectobjectsymbolsOption = self.addOption(MultiArgOption('-sectobjectsymbols', numArgs=2))
611 self.segcreateOption = self.addOption(MultiArgOption('-segcreate', numArgs=3))
612 self.segs_read_Option = self.addOption(JoinedOption('-segs_read_'))
613 self.seglinkeditOption = self.addOption(FlagOption('-seglinkedit'))
614 self.noseglinkeditOption = self.addOption(FlagOption('-noseglinkedit'))
615 self.sectcreateOption = self.addOption(MultiArgOption('-sectcreate', numArgs=3))
616 self.sectorderOption = self.addOption(MultiArgOption('-sectorder', numArgs=3))
617 self.Zall_loadOption = self.addOption(FlagOption('-Zall_load'))
618 self.Zallowable_clientOption = self.addOption(SeparateOption('-Zallowable_client'))
619 self.Zbind_at_loadOption = self.addOption(SeparateOption('-Zbind_at_load'))
620 self.ZbundleOption = self.addOption(FlagOption('-Zbundle'))
621 self.Zbundle_loaderOption = self.addOption(JoinedOrSeparateOption('-Zbundle_loader'))
622 self.Zdead_stripOption = self.addOption(FlagOption('-Zdead_strip'))
623 self.Zdylib_fileOption = self.addOption(JoinedOrSeparateOption('-Zdylib_file'))
624 self.ZdynamicOption = self.addOption(FlagOption('-Zdynamic'))
625 self.ZdynamiclibOption = self.addOption(FlagOption('-Zdynamiclib'))
626 self.Zexported_symbols_listOption = self.addOption(JoinedOrSeparateOption('-Zexported_symbols_list'))
627 self.Zflat_namespaceOption = self.addOption(FlagOption('-Zflat_namespace'))
628 self.Zfn_seg_addr_table_filenameOption = self.addOption(JoinedOrSeparateOption('-Zfn_seg_addr_table_filename'))
629 self.Zforce_cpusubtype_ALLOption = self.addOption(FlagOption('-Zforce_cpusubtype_ALL'))
630 self.Zforce_flat_namespaceOption = self.addOption(FlagOption('-Zforce_flat_namespace'))
631 self.Zimage_baseOption = self.addOption(FlagOption('-Zimage_base'))
632 self.ZinitOption = self.addOption(JoinedOrSeparateOption('-Zinit'))
633 self.Zmulti_moduleOption = self.addOption(FlagOption('-Zmulti_module'))
634 self.Zmultiply_definedOption = self.addOption(JoinedOrSeparateOption('-Zmultiply_defined'))
635 self.ZmultiplydefinedunusedOption = self.addOption(JoinedOrSeparateOption('-Zmultiplydefinedunused'))
636 self.ZmultiplydefinedunusedOption = self.addOption(JoinedOrSeparateOption('-Zmultiplydefinedunused'))
637 self.Zno_dead_strip_inits_and_termsOption = self.addOption(FlagOption('-Zno_dead_strip_inits_and_terms'))
638 self.Zseg_addr_tableOption = self.addOption(JoinedOrSeparateOption('-Zseg_addr_table'))
639 self.ZsegaddrOption = self.addOption(JoinedOrSeparateOption('-Zsegaddr'))
640 self.Zsegs_read_only_addrOption = self.addOption(JoinedOrSeparateOption('-Zsegs_read_only_addr'))
641 self.Zsegs_read_write_addrOption = self.addOption(JoinedOrSeparateOption('-Zsegs_read_write_addr'))
642 self.Zsingle_moduleOption = self.addOption(FlagOption('-Zsingle_module'))
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000643 self.ZumbrellaOption = self.addOption(JoinedOrSeparateOption('-Zumbrella'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000644 self.Zunexported_symbols_listOption = self.addOption(JoinedOrSeparateOption('-Zunexported_symbols_list'))
645 self.Zweak_reference_mismatchesOption = self.addOption(JoinedOrSeparateOption('-Zweak_reference_mismatches'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000646
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000647 self.addOption(SeparateOption('-filelist', isLinkerInput=True))
648 self.addOption(SeparateOption('-framework', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000649 # FIXME: Alias.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000650 self.addOption(SeparateOption('-install_name'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000651 self.Zinstall_nameOption = self.addOption(JoinedOrSeparateOption('-Zinstall_name'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000652 self.addOption(SeparateOption('-seg_addr_table'))
653 self.addOption(SeparateOption('-seg_addr_table_filename'))
654
655 # Where are these coming from? I can't find them...
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000656 self.eOption = self.addOption(JoinedOrSeparateOption('-e'))
657 self.rOption = self.addOption(JoinedOrSeparateOption('-r'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000658
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000659 self.pgOption = self.addOption(FlagOption('-pg'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000660 self.pOption = self.addOption(FlagOption('-p'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000661
662 doNotReallySupport = 1
663 if doNotReallySupport:
664 # Archaic gcc option.
665 self.addOption(FlagOption('-cpp-precomp'))
666 self.addOption(FlagOption('-no-cpp-precomp'))
667
668 # C options for testing
669
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000670 # FIXME: This is broken, we need -A as a single option to send
671 # stuff to cc1, but the way the ld spec is constructed it
672 # wants to see -A options but only as a separate arg.
673 self.AOption = self.addOption(JoinedOrSeparateOption('-A'))
674 self.DOption = self.addOption(JoinedOrSeparateOption('-D'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000675 self.FOption = self.addOption(JoinedOrSeparateOption('-F'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000676 self.IOption = self.addOption(JoinedOrSeparateOption('-I'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000677 self.LOption = self.addOption(JoinedOrSeparateOption('-L'))
678 self.TOption = self.addOption(JoinedOrSeparateOption('-T'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000679 self.UOption = self.addOption(JoinedOrSeparateOption('-U'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000680 self.ZOption = self.addOption(JoinedOrSeparateOption('-Z'))
681
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000682 self.addOption(JoinedOrSeparateOption('-l', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000683 self.uOption = self.addOption(JoinedOrSeparateOption('-u'))
684 self.tOption = self.addOption(JoinedOrSeparateOption('-t'))
685 self.yOption = self.addOption(JoinedOption('-y'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000686
687 # FIXME: What is going on here? '-X' goes to linker, and -X ... goes nowhere?
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000688 self.XOption = self.addOption(FlagOption('-X'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000689 # Not exactly sure how to decompose this. I split out -Xarch_
690 # because we need to recognize that in the driver driver part.
691 # FIXME: Man, this is lame it needs its own option.
692 self.XarchOption = self.addOption(JoinedAndSeparateOption('-Xarch_'))
693 self.addOption(JoinedOption('-X'))
694
695 # The driver needs to know about this flag.
696 self.syntaxOnlyOption = self.addOption(FlagOption('-fsyntax-only'))
697
698 # FIXME: Wrong?
699 # FIXME: What to do about the ambiguity of options like
700 # -dumpspecs? How is this handled in gcc?
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000701 # FIXME: Naming convention.
702 self.dOption = self.addOption(FlagOption('-d'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000703
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000704 # Use a group for this in anticipation of adding more -d
705 # options explicitly. Note that we don't put many -d things in
706 # the -d group (like -dylinker, or '-d' by itself) because it
707 # is really a gcc bug that it ships these to cc1.
708 self.dGroup = OptionGroup('-d')
709 self.addOption(JoinedOption('-d', group=self.dGroup))
Daniel Dunbar996ce962009-01-12 07:40:25 +0000710
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000711 self.gGroup = OptionGroup('-g')
Daniel Dunbar841ceea2009-01-13 06:44:28 +0000712 self.gstabsOption = self.addOption(JoinedOption('-gstabs', self.gGroup))
713 self.g0Option = self.addOption(JoinedOption('-g0', self.gGroup))
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000714 self.g3Option = self.addOption(JoinedOption('-g3', self.gGroup))
715 self.gOption = self.addOption(JoinedOption('-g', self.gGroup))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000716
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000717 self.fGroup = OptionGroup('-f')
718 self.fastOption = self.addOption(FlagOption('-fast', self.fGroup))
719 self.fastfOption = self.addOption(FlagOption('-fastf', self.fGroup))
720 self.fastcpOption = self.addOption(FlagOption('-fastcp', self.fGroup))
721
722 self.f_appleKextOption = self.addOption(FlagOption('-fapple-kext', self.fGroup))
723 self.f_noEliminateUnusedDebugSymbolsOption = self.addOption(FlagOption('-fno-eliminate-unused-debug-symbols', self.fGroup))
724 self.f_exceptionsOption = self.addOption(FlagOption('-fexceptions', self.fGroup))
725 self.f_objcOption = self.addOption(FlagOption('-fobjc', self.fGroup))
726 self.f_openmpOption = self.addOption(FlagOption('-fopenmp', self.fGroup))
727 self.f_gnuRuntimeOption = self.addOption(FlagOption('-fgnu-runtime', self.fGroup))
728 self.f_mudflapOption = self.addOption(FlagOption('-fmudflap', self.fGroup))
729 self.f_mudflapthOption = self.addOption(FlagOption('-fmudflapth', self.fGroup))
730 self.f_nestedFunctionsOption = self.addOption(FlagOption('-fnested-functions', self.fGroup))
731 self.f_pieOption = self.addOption(FlagOption('-fpie', self.fGroup))
732 self.f_profileArcsOption = self.addOption(FlagOption('-fprofile-arcs', self.fGroup))
733 self.f_profileGenerateOption = self.addOption(FlagOption('-fprofile-generate', self.fGroup))
734 self.f_createProfileOption = self.addOption(FlagOption('-fcreate-profile', self.fGroup))
735 self.f_traditionalOption = self.addOption(FlagOption('-ftraditional', self.fGroup))
Daniel Dunbar18a7c8c2009-01-13 07:39:45 +0000736 self.addOption(JoinedOption('-f', self.fGroup))
737
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000738 self.coverageOption = self.addOption(FlagOption('-coverage'))
739 self.coverageOption2 = self.addOption(FlagOption('--coverage'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000740
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000741 self.mGroup = OptionGroup('-m')
742 self.m_32Option = self.addOption(FlagOption('-m32', self.mGroup))
743 self.m_64Option = self.addOption(FlagOption('-m64', self.mGroup))
744 self.m_dynamicNoPicOption = self.addOption(JoinedOption('-mdynamic-no-pic', self.mGroup))
745 self.m_iphoneosVersionMinOption = self.addOption(JoinedOption('-miphoneos-version-min=', self.mGroup))
746 self.m_kernelOption = self.addOption(FlagOption('-mkernel', self.mGroup))
747 self.m_macosxVersionMinOption = self.addOption(JoinedOption('-mmacosx-version-min=', self.mGroup))
748 self.m_tuneOption = self.addOption(JoinedOption('-mtune=', self.mGroup))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000749
750 # Ugh. Need to disambiguate our naming convetion. -m x goes to
751 # the linker sometimes, wheres -mxxxx is used for a variety of
752 # other things.
753 self.mOption = self.addOption(SeparateOption('-m'))
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000754 self.addOption(JoinedOption('-m', self.mGroup))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000755
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000756 # FIXME: Why does Darwin send -a* to cc1?
757 self.aGroup = OptionGroup('-a')
758 self.ansiOption = self.addOption(FlagOption('-ansi', self.aGroup))
759 self.aOption = self.addOption(JoinedOption('-a', self.aGroup))
760
Daniel Dunbar816dd502009-01-12 17:53:19 +0000761 self.trigraphsOption = self.addOption(FlagOption('-trigraphs'))
762 self.pedanticOption = self.addOption(FlagOption('-pedantic'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000763 self.OOption = self.addOption(JoinedOption('-O'))
764 self.WOption = self.addOption(JoinedOption('-W'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000765 # FIXME: Weird. This option isn't really separate, --param=a=b
Daniel Dunbar816dd502009-01-12 17:53:19 +0000766 # works. There is something else going on which interprets the
767 # '='.
768 self._paramOption = self.addOption(SeparateOption('--param'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000769
Daniel Dunbardff9f502009-01-12 18:51:02 +0000770 # FIXME: What is this? I think only one is valid, but have a
771 # log that uses both.
772 self.pthreadOption = self.addOption(FlagOption('-pthread'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000773 self.addOption(FlagOption('-pthreads'))
774
Daniel Dunbara5677512009-01-05 19:53:30 +0000775 def addOption(self, opt):
776 self.options.append(opt)
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000777 return opt
Daniel Dunbara5677512009-01-05 19:53:30 +0000778
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000779 def parseArgs(self, argv):
Daniel Dunbara5677512009-01-05 19:53:30 +0000780 """
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000781 parseArgs([str]) -> ArgList
Daniel Dunbara5677512009-01-05 19:53:30 +0000782
783 Parse command line into individual option instances.
784 """
785
786 iargs = enumerate(argv)
787 it = iter(iargs)
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000788 args = ArgList(self, argv)
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000789 for pos,a in it:
790 i = InputIndex(0, pos)
Daniel Dunbara5677512009-01-05 19:53:30 +0000791 # FIXME: Handle '@'
792 if not a:
793 # gcc's handling of empty arguments doesn't make
794 # sense, but this is not a common use case. :)
795 #
796 # We just ignore them here (note that other things may
797 # still take them as arguments).
798 pass
799 elif a[0] == '-' and a != '-':
800 args.append(self.lookupOptForArg(i, a, it))
801 else:
Daniel Dunbar5039f212009-01-06 02:30:10 +0000802 args.append(PositionalArg(i, self.inputOption))
Daniel Dunbara5677512009-01-05 19:53:30 +0000803 return args
804
Daniel Dunbar5039f212009-01-06 02:30:10 +0000805 def lookupOptForArg(self, i, string, it):
806 for o in self.options:
807 arg = o.accept(i, string, it)
808 if arg is not None:
809 return arg
810 return PositionalArg(i, self.unknownOption)