LLVM 24.0.0git
LibraryOptions.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/Option/ArgList.h"
12#include "llvm/Option/Option.h"
13#include "llvm/Support/Error.h"
14
15using namespace llvm;
16using namespace llvm::opt;
17
19
21 function_ref<void(StringRef, StringRef, StringRef)> Fn) const {
22 const OptTable &T = Table();
23 for (unsigned ID = 1, E = T.getNumOptions(); ID <= E; ++ID) {
24 unsigned Kind = T.getOptionKind(ID);
26 continue;
27 std::string MetaVar;
28 if (Kind == Option::SeparateOrEqClass) {
29 StringRef V = T.getOptionMetaVar(ID);
30 MetaVar = ("=" + (V.empty() ? StringRef("<value>") : V)).str();
31 }
32 Fn(T.getOptionName(ID), MetaVar, T.getOptionHelpText(ID));
33 }
34}
35
37 unsigned &Consumed) {
38 InputArgList List(Args.begin(), Args.end());
39 Consumed = 0;
40 std::unique_ptr<Arg> A = Table().ParseOneArg(List, Consumed);
41 Consumed = std::min<unsigned>(Consumed, Args.size());
42 if (!A)
43 return createStringError("option '" + Twine(Args[0]) +
44 "' requires an argument");
45 if (A->getOption().getKind() == Option::UnknownClass)
46 return createStringError("unknown argument '" + Twine(Args[0]) + "'");
47 if (!Apply(*A))
48 return createStringError("invalid value '" + Twine(A->getValue()) +
49 "' in '" + A->getAsString(List) + "'");
50 return Error::success();
51}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define T
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
void forEachOption(function_ref< void(StringRef, StringRef, StringRef)> Fn) const override
Error parse(ArrayRef< const char * > Args, unsigned &Consumed) override
Parses the option spelled by Args[0], which may take Args[1] as its value, and sets Consumed to the n...
Provide access to the Option info table.
Definition OptTable.h:55
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321