blob: a08a8bdd4b4bb898841cb66c98c153a2570086ed [file] [log] [blame]
Michael J. Spencer84487f12015-07-24 21:03:07 +00001//===- DriverUtils.cpp ----------------------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains utility functions for the driver. Because there
11// are so many small functions, we created this separate file to make
12// Driver.cpp less cluttered.
13//
14//===----------------------------------------------------------------------===//
15
16#include "Driver.h"
Rafael Espindola192e1fa2015-08-06 15:08:23 +000017#include "Error.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000018#include "llvm/ADT/STLExtras.h"
19
20using namespace llvm;
21
22using namespace lld;
23using namespace lld::elf2;
24
25// Create OptTable
26
27// Create prefix string literals used in Options.td
28#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
29#include "Options.inc"
30#undef PREFIX
31
32// Create table mapping all options defined in Options.td
33static const opt::OptTable::Info infoTable[] = {
34#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X6, X7, X8, X9, X10) \
35 { \
36 X1, X2, X9, X10, OPT_##ID, opt::Option::KIND##Class, X8, X7, OPT_##GROUP, \
37 OPT_##ALIAS, X6 \
38 } \
39 ,
40#include "Options.inc"
41#undef OPTION
42};
43
44class ELFOptTable : public opt::OptTable {
45public:
46 ELFOptTable() : OptTable(infoTable, array_lengthof(infoTable)) {}
47};
48
49// Parses a given list of options.
50opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
51 // Make InputArgList from string vectors.
52 ELFOptTable Table;
53 unsigned MissingIndex;
54 unsigned MissingCount;
55
56 opt::InputArgList Args = Table.ParseArgs(Argv, MissingIndex, MissingCount);
57 if (MissingCount)
58 error(Twine("missing arg value for \"") + Args.getArgString(MissingIndex) +
59 "\", expected " + Twine(MissingCount) +
60 (MissingCount == 1 ? " argument.\n" : " arguments"));
61 for (auto *Arg : Args.filtered(OPT_UNKNOWN))
62 error(Twine("unknown argument: ") + Arg->getSpelling());
63 return Args;
64}