LLVM: include/llvm/Option/OptTable.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_OPTION_OPTTABLE_H

10#define LLVM_OPTION_OPTTABLE_H

11

19#include

20#include

21#include

22

23namespace llvm {

24

27

28namespace opt {

29

34

35

36

38 unsigned Mask = ~0U;

39

40public:

41 explicit Visibility(unsigned Mask) : Mask(Mask) {}

43

44 operator unsigned() const { return Mask; }

45};

46

47

48

49

50

51

52

53

55public:

56

62

63

68

69

70

71

72

73

74

75 std::array<std::pair<std::array<unsigned int, 2 >,

76 const char *>,

77 1 >

89

91

93

98

105

107

112

120

125 Prefixes.push_back(StrTable[PrefixOffset]);

126 }

127

130 unsigned PrefixIndex) const {

131 return StrTable[getPrefixOffsets(PrefixesTable)[PrefixIndex]];

132 }

133

137

140 unsigned PrefixLength =

142 return getPrefixedName(StrTable).drop_front(PrefixLength);

143 }

144 };

145

146public:

150 "This helper is only for valid registered subcommands.");

152 SubCommands, [&](const auto &C) { return SubCommand == C.Name; });

153 assert(SCIT != SubCommands.end() &&

154 "This helper is only for valid registered subcommands.");

155 auto SubCommandIDs = CandidateInfo->getSubCommandIDs(SubCommandIDsTable);

156 unsigned CurrentSubCommandID = SCIT - &SubCommands[0];

158 }

159

160private:

161

162

164

165

166

167

168

170

171

173

174 bool IgnoreCase;

175

176

178

179

181

182 bool GroupedShortOptions = false;

183 bool DashDashParsing = false;

184 const char *EnvVar = nullptr;

185

186 unsigned InputOptionID = 0;

187 unsigned UnknownOptionID = 0;

188

189protected:

190

191

193

194

195

197

198

200

201private:

203 unsigned id = Opt.getID();

205 return OptionInfos[id - 1];

206 }

207

208 std::unique_ptr parseOneArgGrouped(InputArgList &Args,

209 unsigned &Index) const;

210

211protected:

212

213

219

220

221 void buildPrefixChars();

222

223public:

225

226

228

230

231

233 return PrefixesTable;

234 }

235

236

237 unsigned getNumOptions() const { return OptionInfos.size(); }

238

239

240

241

242

244

245

247 return getInfo(id).getName(*StrTable, PrefixesTable);

248 }

249

250

252 const Info &I = getInfo(id);

254 : I.getPrefix(*StrTable, PrefixesTable, 0);

255 }

256

259 const Info &I = getInfo(id);

260 I.appendPrefixes(*StrTable, PrefixesTable, Prefixes);

261 }

262

263

265 return getInfo(id).getPrefixedName(*StrTable);

266 }

267

268

270 return getInfo(id).Kind;

271 }

272

273

275 return getInfo(id).GroupID;

276 }

277

278

282

283

284

285

288 auto Info = getInfo(id);

292 return Text;

294 }

295

296

297

299 return getInfo(id).MetaVar;

300 }

301

302

304

305

307

308

309

311

312

313

314

315

316

317

318

319

320

321

322 std::vectorstd::string suggestValueCompletions(StringRef Option,

324

325

326

327

328

329

330

331 std::vectorstd::string findByPrefix(StringRef Cur,

333 unsigned int DisableFlags) const;

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351 unsigned findNearest(StringRef Option, std::string &NearestString,

353 unsigned MinimumLength = 4,

354 unsigned MaximumDistance = UINT_MAX) const;

355

356 unsigned findNearest(StringRef Option, std::string &NearestString,

357 unsigned FlagsToInclude, unsigned FlagsToExclude = 0,

358 unsigned MinimumLength = 4,

359 unsigned MaximumDistance = UINT_MAX) const;

360

361private:

362 unsigned

363 internalFindNearest(StringRef Option, std::string &NearestString,

364 unsigned MinimumLength, unsigned MaximumDistance,

365 std::function<bool(const Info &)> ExcludeOption) const;

366

367public:

372

374 unsigned FlagsToInclude, unsigned FlagsToExclude = 0) const {

375 return findNearest(Option, ExactString, FlagsToInclude, FlagsToExclude, 4,

376 0) == 0;

377 }

378

379

380

381

382

383

384

385

386

387

388

389

390

391 std::unique_ptr

392 ParseOneArg(const ArgList &Args, unsigned &Index,

394

395 std::unique_ptr ParseOneArg(const ArgList &Args, unsigned &Index,

396 unsigned FlagsToInclude,

397 unsigned FlagsToExclude) const;

398

399private:

400 std::unique_ptr

401 internalParseOneArg(const ArgList &Args, unsigned &Index,

402 std::function<bool(const Option &)> ExcludeOption) const;

403

404public:

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

422 unsigned &MissingArgCount,

424

426 unsigned &MissingArgCount, unsigned FlagsToInclude,

427 unsigned FlagsToExclude = 0) const;

428

429private:

432 unsigned &MissingArgCount,

433 std::function<bool(const Option &)> ExcludeOption) const;

434

435public:

436

437

438

439

440

441

442

443

446 std::function<void(StringRef)> ErrorFn) const;

447

448

449

450

451

452

453

454

455

456

457

458

459

460 void printHelp(raw_ostream &OS, const char *Usage, const char *Title,

461 bool ShowHidden = false, bool ShowAllAliases = false,

463 StringRef SubCommand = {}) const;

464

465 void printHelp(raw_ostream &OS, const char *Usage, const char *Title,

466 unsigned FlagsToInclude, unsigned FlagsToExclude,

467 bool ShowAllAliases) const;

468

469private:

470 void internalPrintHelp(raw_ostream &OS, const char *Usage, const char *Title,

471 StringRef SubCommand, bool ShowHidden,

472 bool ShowAllAliases,

473 std::function<bool(const Info &)> ExcludeOption,

474 Visibility VisibilityMask) const;

475};

476

477

486

488protected:

493 bool IgnoreCase = false,

496 : OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase, SubCommands,

497 SubCommandIDsTable) {

498 for (auto PrefixOffset : PrefixesUnionOffsets)

501 }

502};

503

504}

505

506}

507

508#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \

509 ID_PREFIX, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \

510 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \

511 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \

512 ID_PREFIX##ID

513

514#define LLVM_MAKE_OPT_ID(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, \

515 GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, PARAM, \

516 HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \

517 SUBCOMMANDIDS_OFFSET) \

518 LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \

519 OPT_, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \

520 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \

521 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET)

522

523#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \

524 ID_PREFIX, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \

525 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \

526 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \

527 llvm::opt::OptTable::Info { \

528 PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, HELPTEXT, HELPTEXTSFORVARIANTS, \

529 METAVAR, ID_PREFIX##ID, llvm::opt::Option::KIND##Class, PARAM, FLAGS, \

530 VISIBILITY, ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES, \

531 SUBCOMMANDIDS_OFFSET \

532 }

533

534#define LLVM_CONSTRUCT_OPT_INFO( \

535 PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, ALIASARGS, \

536 FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \

537 SUBCOMMANDIDS_OFFSET) \

538 LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \

539 OPT_, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \

540 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \

541 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET)

542

543#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

Analysis containing CSE Info

This file defines the SmallString class.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.

A table of densely packed, null-terminated strings indexed by offset.

LLVM Value Representation.

An efficient, type-erasing, non-owning reference to a callable.

ArgList - Ordered collection of driver arguments.

A concrete instance of a particular driver option.

LLVM_ABI GenericOptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})

OptSpecifier - Wrapper class for abstracting references to option IDs.

Provide access to the Option info table.

Definition OptTable.h:54

void buildPrefixChars()

Build (or rebuild) the PrefixChars member.

bool isValidForSubCommand(const Info *CandidateInfo, StringRef SubCommand) const

Definition OptTable.h:147

StringRef getOptionName(OptSpecifier id) const

Lookup the name of the given option.

Definition OptTable.h:246

const char * getOptionHelpText(OptSpecifier id, Visibility VisibilityMask) const

Definition OptTable.h:286

unsigned getOptionKind(OptSpecifier id) const

Get the kind of the given option.

Definition OptTable.h:269

unsigned FirstSearchableIndex

The index of the first option which can be parsed (i.e., is not a special option like 'input' or 'unk...

Definition OptTable.h:192

const char * getOptionMetaVar(OptSpecifier id) const

Get the meta-variable name to use when describing this options values in the help text.

Definition OptTable.h:298

unsigned findNearest(StringRef Option, std::string &NearestString, Visibility VisibilityMask=Visibility(), unsigned MinimumLength=4, unsigned MaximumDistance=UINT_MAX) const

Find the OptTable option that most closely matches the given string.

SmallVector< StringRef > PrefixesUnion

The union of all option prefixes.

Definition OptTable.h:196

const char * getOptionHelpText(OptSpecifier id) const

Get the help text to use to describe this option.

Definition OptTable.h:279

StringRef getOptionPrefix(OptSpecifier id) const

Lookup the prefix of the given option.

Definition OptTable.h:251

bool findExact(StringRef Option, std::string &ExactString, unsigned FlagsToInclude, unsigned FlagsToExclude=0) const

Definition OptTable.h:373

void setInitialOptionsFromEnvironment(const char *E)

Specify the environment variable where initial options should be read.

Definition OptTable.h:303

OptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})

Initialize OptTable using Tablegen'ed OptionInfos.

void setDashDashParsing(bool Value)

Set whether "--" stops option parsing and treats all subsequent arguments as positional.

Definition OptTable.h:310

unsigned getOptionGroupID(OptSpecifier id) const

Get the group id for the given option.

Definition OptTable.h:274

StringRef getOptionPrefixedName(OptSpecifier id) const

Lookup the prefixed name of the given option.

Definition OptTable.h:264

ArrayRef< StringTable::Offset > getPrefixesTable() const

Return the prefixes table used for option names.

Definition OptTable.h:232

SmallString< 8 > PrefixChars

The union of the first element of all option prefixes.

Definition OptTable.h:199

void appendOptionPrefixes(OptSpecifier id, SmallVectorImpl< StringRef > &Prefixes) const

Definition OptTable.h:257

unsigned getNumOptions() const

Return the total number of option classes.

Definition OptTable.h:237

bool findExact(StringRef Option, std::string &ExactString, Visibility VisibilityMask=Visibility()) const

Definition OptTable.h:368

ArrayRef< SubCommand > getSubCommands() const

Definition OptTable.h:229

const StringTable & getStrTable() const

Return the string table used for option names.

Definition OptTable.h:227

void setGroupedShortOptions(bool Value)

Support grouped short options. e.g. -ab represents -a -b.

Definition OptTable.h:306

Option - Abstract representation for a single form of driver argument.

PrecomputedOptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, ArrayRef< StringTable::Offset > PrefixesUnionOffsets, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})

Definition OptTable.h:489

Helper for overload resolution while transitioning from FlagsToInclude/FlagsToExclude APIs to Visibil...

Definition OptTable.h:37

Visibility(unsigned Mask)

Definition OptTable.h:41

This class implements an extremely fast bulk output stream that can only output to a stream.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

auto find_if(R &&Range, UnaryPredicate P)

Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.

Entry for a single option instance in the option data table.

Definition OptTable.h:64

void appendPrefixes(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, SmallVectorImpl< StringRef > &Prefixes) const

Definition OptTable.h:121

bool hasNoPrefix() const

Definition OptTable.h:92

unsigned ID

Definition OptTable.h:80

StringTable::Offset PrefixedNameOffset

Definition OptTable.h:66

unsigned getNumPrefixes(ArrayRef< StringTable::Offset > PrefixesTable) const

Definition OptTable.h:94

bool hasSubCommands() const

Definition OptTable.h:106

unsigned char Param

Definition OptTable.h:82

StringRef getPrefixedName(const StringTable &StrTable) const

Definition OptTable.h:134

ArrayRef< StringTable::Offset > getPrefixOffsets(ArrayRef< StringTable::Offset > PrefixesTable) const

Definition OptTable.h:100

unsigned int Visibility

Definition OptTable.h:84

const char * Values

Definition OptTable.h:88

unsigned short AliasID

Definition OptTable.h:86

StringRef getPrefix(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, unsigned PrefixIndex) const

Definition OptTable.h:128

StringRef getName(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable) const

Definition OptTable.h:138

unsigned short GroupID

Definition OptTable.h:85

unsigned int Flags

Definition OptTable.h:83

const char * HelpText

Definition OptTable.h:67

const char * MetaVar

Definition OptTable.h:79

unsigned SubCommandIDsOffset

Definition OptTable.h:90

ArrayRef< unsigned > getSubCommandIDs(ArrayRef< unsigned > SubCommandIDsTable) const

Definition OptTable.h:114

unsigned getNumSubCommandIDs(ArrayRef< unsigned > SubCommandIDsTable) const

Definition OptTable.h:108

unsigned PrefixesOffset

Definition OptTable.h:65

unsigned char Kind

Definition OptTable.h:81

std::array< std::pair< std::array< unsigned int, 2 >, const char * >, 1 > HelpTextsForVariants

Definition OptTable.h:78

const char * AliasArgs

Definition OptTable.h:87

Represents a subcommand and its options in the option table.

Definition OptTable.h:57

const char * Name

Definition OptTable.h:58

const char * Usage

Definition OptTable.h:60

const char * HelpText

Definition OptTable.h:59