LLVM: lib/Option/Option.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
12#include "llvm/Config/llvm-config.h"
20#include
21
22using namespace llvm;
24
27
28
30 "Multi-level aliases are not supported.");
31
36 "Cannot provide alias args to a flag option.");
37 }
38}
39
41 O << "<";
43#define P(N) case N: O << #N; break
57#undef P
58 }
59
60 if (->hasNoPrefix()) {
61 O << " Prefixes:[";
62 for (size_t I = 0, N = Info->getNumPrefixes(Owner->getPrefixesTable());
64 O << '"'
65 << Info->getPrefix(Owner->getStrTable(), Owner->getPrefixesTable(), I)
66 << (I == N - 1 ? "\"" : "\", ");
67 O << ']';
68 }
69
70 O << " Name:\"" << getName() << '"';
71
74 O << " Group:";
75 Group.print(O, false);
76 }
77
80 O << " Alias:";
81 Alias.print(O, false);
82 }
83
86
87 O << ">";
88 if (AddNewLine)
89 O << "\n";
90}
91
92#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
94#endif
95
97
100 return Alias.matches(Opt);
101
102
104 return true;
105
108 return Group.matches(Opt);
109 return false;
110}
111
112std::unique_ptr Option::acceptInternal(const ArgList &Args,
114 unsigned &Index) const {
115 const size_t SpellingSize = Spelling.size();
116 const size_t ArgStringSize = StringRef(Args.getArgString(Index)).size();
119 if (SpellingSize != ArgStringSize)
120 return nullptr;
121 return std::make_unique(*this, Spelling, Index++);
122 }
124 const char *Value = Args.getArgString(Index) + SpellingSize;
125 return std::make_unique(*this, Spelling, Index++, Value);
126 }
128
129 const char *Str = Args.getArgString(Index) + SpellingSize;
130 auto A = std::make_unique(*this, Spelling, Index++);
131
132
133 const char *Prev = Str;
134 for (;; ++Str) {
135 char c = *Str;
136
137 if (!c || c == ',') {
138 if (Prev != Str) {
139 char *Value = new char[Str - Prev + 1];
140 memcpy(Value, Prev, Str - Prev);
141 Value[Str - Prev] = '\0';
142 A->getValues().push_back(Value);
143 }
144
145 if (!c)
146 break;
147
148 Prev = Str + 1;
149 }
150 }
151 A->setOwnsValues(true);
152
153 return A;
154 }
156
157 if (SpellingSize != ArgStringSize)
158 return nullptr;
159
161 if (Index > Args.getNumInputArgStrings() ||
162 Args.getArgString(Index - 1) == nullptr)
163 return nullptr;
164
165 return std::make_unique(*this, Spelling, Index - 2,
166 Args.getArgString(Index - 1));
168
169 if (SpellingSize != ArgStringSize)
170 return nullptr;
171
173 if (Index > Args.getNumInputArgStrings())
174 return nullptr;
175
176 auto A = std::make_unique(*this, Spelling, Index - 1 - getNumArgs(),
178 for (unsigned i = 1; i != getNumArgs(); ++i)
179 A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i));
180 return A;
181 }
183
184 if (SpellingSize != ArgStringSize) {
185 const char *Value = Args.getArgString(Index) + SpellingSize;
186 return std::make_unique(*this, Spelling, Index++, Value);
187 }
188
189
191 if (Index > Args.getNumInputArgStrings() ||
192 Args.getArgString(Index - 1) == nullptr)
193 return nullptr;
194
195 return std::make_unique(*this, Spelling, Index - 2,
196 Args.getArgString(Index - 1));
197 }
199
201 if (Index > Args.getNumInputArgStrings() ||
202 Args.getArgString(Index - 1) == nullptr)
203 return nullptr;
204
205 return std::make_unique(*this, Spelling, Index - 2,
206 Args.getArgString(Index - 2) + SpellingSize,
207 Args.getArgString(Index - 1));
209
210 if (SpellingSize != ArgStringSize)
211 return nullptr;
212 auto A = std::make_unique(*this, Spelling, Index++);
213 while (Index < Args.getNumInputArgStrings() &&
214 Args.getArgString(Index) != nullptr)
215 A->getValues().push_back(Args.getArgString(Index++));
216 return A;
217 }
219 auto A = std::make_unique(*this, Spelling, Index);
220 if (SpellingSize != ArgStringSize) {
221
222 A->getValues().push_back(Args.getArgString(Index) + SpellingSize);
223 }
225 while (Index < Args.getNumInputArgStrings() &&
226 Args.getArgString(Index) != nullptr)
227 A->getValues().push_back(Args.getArgString(Index++));
228 return A;
229 }
230
231 default:
233 }
234}
235
237 bool GroupedShortOption,
238 unsigned &Index) const {
240 ? std::make_unique(*this, CurArg, Index)
241 : acceptInternal(Args, CurArg, Index));
242 if ()
243 return nullptr;
244
246 if (getID() == UnaliasedOption.getID())
247 return A;
248
249
250
251
252
253
254
255
256
257
258 StringRef UnaliasedSpelling = Args.MakeArgString(
260
261
262
263
264
265
266 auto UnaliasedA =
267 std::make_unique(UnaliasedOption, UnaliasedSpelling, A->getIndex());
269 UnaliasedA->setAlias(std::move(A));
270
272
273
274
275
276
277 UnaliasedA->getValues() = RawA->getValues();
278 UnaliasedA->setOwnsValues(RawA->getOwnsValues());
280 return UnaliasedA;
281 }
282
283
285 while (*Val != '\0') {
286 UnaliasedA->getValues().push_back(Val);
287
288
289 Val += strlen(Val) + 1;
290 }
291 }
293
294 UnaliasedA->getValues().push_back("");
295 return UnaliasedA;
296}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Defines the llvm::Arg class for parsed arguments.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
ArgList - Ordered collection of driver arguments.
A concrete instance of a particular driver option.
bool getOwnsValues() const
SmallVectorImpl< const char * > & getValues()
void setOwnsValues(bool Value) const
OptSpecifier - Wrapper class for abstracting references to option IDs.
Provide access to the Option info table.
const Option getAlias() const
LLVM_ABI void dump() const
Definition Option.cpp:93
unsigned getNumArgs() const
const char * getAliasArgs() const
Get the alias arguments as a \0 separated list.
const Option getGroup() const
const Option getUnaliasedOption() const
getUnaliasedOption - Return the final option this option aliases (itself, if the option has no alias)...
LLVM_ABI bool matches(OptSpecifier ID) const
matches - Predicate for whether this option is part of the given option (which may be a group).
Definition Option.cpp:96
LLVM_ABI Option(const OptTable::Info *Info, const OptTable *Owner)
Definition Option.cpp:25
@ RemainingArgsJoinedClass
StringRef getPrefix() const
Get the default prefix for this option.
const OptTable::Info * Info
StringRef getName() const
Get the name of this option without any prefix.
LLVM_ABI std::unique_ptr< Arg > accept(const ArgList &Args, StringRef CurArg, bool GroupedShortOption, unsigned &Index) const
Potentially accept the current argument, returning a new Arg instance, or 0 if the option does not ac...
Definition Option.cpp:236
OptionClass getKind() const
LLVM_ABI void print(raw_ostream &O, bool AddNewLine=true) const
Definition Option.cpp:40
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Entry for a single option instance in the option data table.