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);
25 if (Kind != Option::FlagClass && Kind != Option::JoinedClass &&
27 continue;
28 StringRef MetaVar = T.getOptionMetaVar(ID);
29 if (MetaVar.empty() && Kind == Option::JoinedClass)
30 MetaVar = "<value>";
31 Fn(T.getOptionName(ID), MetaVar, T.getOptionHelpText(ID));
32 }
33}
34
36 unsigned &Consumed) {
37 InputArgList List(Args.begin(), Args.end());
38 Consumed = 0;
39 std::unique_ptr<Arg> A = Table().ParseOneArg(List, Consumed);
40 Consumed = std::min<unsigned>(Consumed, Args.size());
41 if (!A)
42 return createStringError("option '" + Twine(Args[0]) +
43 "' requires an argument");
44 if (A->getOption().getKind() == Option::UnknownClass)
45 return createStringError("unknown argument '" + Twine(Args[0]) + "'");
46 if (!Apply(*A))
47 return createStringError("invalid value '" + Twine(A->getValue()) +
48 "' in '" + A->getAsString(List) + "'");
49 return Error::success();
50}
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
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
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