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) {
22 if (auto *Arg = Args.getLastArg(Key)) {
23 StringRef S = Arg->getValue();
24 if (!to_integer(S, V, 10))
25 error(Arg->getSpelling() + ": number expected, but got '" + S + "'");
30 std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
31 std::vector<StringRef> V;
32 for (auto *Arg : Args.filtered(Id))
33 V.push_back(Arg->getValue());
37 uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
38 StringRef Key, uint64_t Default) {
39 for (auto *Arg : Args.filtered(Id)) {
40 std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
41 if (KV.first == Key) {
42 uint64_t Result = Default;
43 if (!to_integer(KV.second, Result))
44 error("invalid " + Key + ": " + KV.second);
51 std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
52 SmallVector<StringRef, 0> Arr;
53 MB.getBuffer().split(Arr, '\n');
55 std::vector<StringRef> Ret;
56 for (StringRef S : Arr) {
58 if (!S.empty() && S[0] != '#')