1 //===- 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" 17 #include "Error.h" 18 #include "llvm/ADT/STLExtras.h" 19 20 using namespace llvm; 21 22 using namespace lld; 23 using 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 33 static 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 44 class ELFOptTable : public opt::OptTable { 45 public: 46 ELFOptTable() : OptTable(infoTable, array_lengthof(infoTable)) {} 47 }; 48 49 // Parses a given list of options. 50 opt::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 } 65