1 //===- Args.cpp -----------------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lld/Common/Args.h"
11 #include "lld/Common/ErrorHandler.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringExtras.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Option/ArgList.h"
20 int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
21 auto *A = Args.getLastArg(Key);
26 if (to_integer(A->getValue(), V, 10))
29 StringRef Spelling = Args.getArgString(A->getIndex());
30 error(Spelling + ": number expected, but got '" + A->getValue() + "'");
34 std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
35 std::vector<StringRef> V;
36 for (auto *Arg : Args.filtered(Id))
37 V.push_back(Arg->getValue());
41 uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
42 StringRef Key, uint64_t Default) {
43 for (auto *Arg : Args.filtered(Id)) {
44 std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
45 if (KV.first == Key) {
46 uint64_t Result = Default;
47 if (!to_integer(KV.second, Result))
48 error("invalid " + Key + ": " + KV.second);
55 std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
56 SmallVector<StringRef, 0> Arr;
57 MB.getBuffer().split(Arr, '\n');
59 std::vector<StringRef> Ret;
60 for (StringRef S : Arr) {
62 if (!S.empty() && S[0] != '#')