LLVM: include/llvm/Support/CommandLine.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef LLVM_SUPPORT_COMMANDLINE_H
20#define LLVM_SUPPORT_COMMANDLINE_H
21
33#include
34#include
35#include
36#include
37#include <initializer_list>
38#include
39#include <type_traits>
40#include
41
42namespace llvm {
43
44namespace vfs {
45class FileSystem;
46}
47
48class StringSaver;
49
50
51
52namespace cl {
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
71 const char *EnvVar = nullptr,
72 bool LongOptionsUseDoubleDash = false);
73
74
76
77
78
79
80
82
83
84
85
86
87
89
90
91
92
93
95
96
98
99
100
101
102
103
104
105
107
108
109
110
111
114 ZeroOrMore = 0x01,
117
118
119
120
121
122
123
124
127
129
132 ValueDisallowed = 0x03
134
135enum OptionHidden {
138 ReallyHidden = 0x02
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
157 Positional = 0x01,
159 AlwaysPrefix = 0x03
161
163 CommaSeparated = 0x01,
166
167
168
169
170
172
173
176
177
178
180private:
183
184 void registerCategory();
185
186public:
188 StringRef const Description = "")
189 : Name(Name), Description(Description) {
190 registerCategory();
191 }
192
195};
196
197
199
200
201
203private:
206
207protected:
210
211public:
213 : Name(Name), Description(Description) {
215 }
217
218
220
221
222
224
226
227 explicit operator bool() const;
228
231
235
237};
238
241
242public:
243 SubCommandGroup(std::initializer_list<SubCommand *> IL) : Subs(IL) {}
244
246};
247
248
249
252
253
254
255
256
257 virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
259
260 virtual enum ValueExpected getValueExpectedFlagDefault() const {
262 }
263
264
265 virtual void anchor();
266
267 uint16_t NumOccurrences;
268
269
270 uint16_t Occurrences : 3;
271
272
274 uint16_t HiddenFlag : 2;
275 uint16_t Formatting : 2;
277 uint16_t FullyInitialized : 1;
278 uint16_t Position;
279 uint16_t AdditionalVals;
280
281public:
288
291 }
292
295 }
296
299 }
300
303 }
304
306 inline unsigned getPosition() const { return Position; }
308
309
314
317 }
318
319
320
321
333
334protected:
337 : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
339 FullyInitialized(false), Position(0), AdditionalVals(0) {
341 }
342
344
345public:
347
348
349
351
352
353
354
355
357
358
360
361
362
363
365
367
369
370
371
372
373
374
376 size_t FirstLineIndentedBy);
377
378
379
380
381
382
384 size_t FirstLineIndentedBy);
385
387
388
389
391 bool MultiArg = false);
392
393
397 }
398
401};
402
403
404
405
406
407
408
411
413
415};
416
417
420
422
424};
425
426
427
428
432
433 template void apply(Opt &O) const { O.setInitialValue(Init); }
434};
435
439
440 template void apply(Opt &O) const { O.setInitialValues(Inits); }
441};
442
445}
446
447template
450}
451
452
453
454
457
459
460 template void apply(Opt &O) const { O.setLocation(O, Loc); }
461};
462
465}
466
467
470
472
473 template void apply(Opt &O) const { O.addCategory(Category); }
474};
475
476
480
483
484 template void apply(Opt &O) const {
486 O.addSubCommand(*Sub);
489 O.addSubCommand(*SC);
490 }
491};
492
493
494
495template <typename R, typename Ty> struct cb {
497
499
500 template void apply(Opt &O) const { O.setCallback(CB); }
501};
502
504template
506
507template <typename R, typename C, typename... Args>
510 using arg_type = std::tuple_element_t<0, std::tuple<Args...>>;
511 static_assert(sizeof...(Args) == 1, "callback function must have one and only one parameter");
512 static_assert(std::is_same_v<result_type, void>,
513 "callback return type must be void");
514 static_assert(std::is_lvalue_reference_v<arg_type> &&
515 std::is_const_v<std::remove_reference_t<arg_type>>,
516 "callback arg_type must be a const lvalue reference");
517};
518}
519
520template
527}
528
529
530
531
534
535protected:
540
541private:
542 virtual void anchor();
543};
544
545template struct OptionValue;
546
547
548
549template <class DataType, bool isClass>
551
553
555
557
558
559 template void setValue(const DT & ) {}
560
561
562 bool compare(const DataType & ) const { return false; }
563
565 return false;
566 }
567
568protected:
570};
571
572
575 bool Valid = false;
576
577protected:
581
582public:
584
586
588 assert(Valid && "invalid option value");
590 }
591
593 Valid = true;
595 }
596
597
598 bool compare(const DataType &V) const { return Valid && (Value == V); }
599
603 if (!VC.hasValue())
604 return false;
605 return compare(VC.getValue());
606 }
607};
608
609
610template
613
614protected:
619};
620
621
622template
626
628
629
632 return *this;
633 }
634};
635
636
638template <>
642
644
646
649 return *this;
650 }
651
652private:
653 void anchor() override;
654};
655
656template <>
659
661
663
666 return *this;
667 }
668
669private:
670 void anchor() override;
671};
672
673
674
675
676
677
682};
683
684#define clEnumVal(ENUMVAL, DESC) \
685 llvm:🆑:OptionEnumValue { #ENUMVAL, int(ENUMVAL), DESC }
686#define clEnumValN(ENUMVAL, FLAGNAME, DESC) \
687 llvm:🆑:OptionEnumValue { FLAGNAME, int(ENUMVAL), DESC }
688
689
690
691
693
694
695
697
698public:
701
702 template void apply(Opt &O) const {
703 for (const auto &Value : Values)
705 Value.Description);
706 }
707};
708
709
710
713}
714
715
716
717
718
719
720
721
722
723
724
725
726
728protected:
730 public:
735 };
736
737public:
739
741
742
743
744
745
747
748
750
751
753
754
756
758
759
760
761
763
766 size_t GlobalWidth) const;
767
768
769
770
771
772 template
774 const AnyOptionValue &Default,
775 size_t GlobalWidth) const {
777 }
778
780
782
783
784
786 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
788 }
789
791
792
793
794
795
796
797
798
799
800
801
804 else
806 }
807
808
809
810
812
813protected:
815};
816
817
818
819
820
821
822
824protected:
826 public:
829
831 };
833
834public:
836
838
839
844 }
845
846
849 }
850
851
855 ArgVal = Arg;
856 else
857 ArgVal = ArgName;
858
859 for (size_t i = 0, e = Values.size(); i != e; ++i)
861 V = Values[i].V.getValue();
862 return false;
863 }
864
865 return O.error("Cannot find option named '" + ArgVal + "'!");
866 }
867
868
869
870 template
872#ifndef NDEBUG
875#endif
879 }
880
881
882
885 assert(N != Values.size() && "Option not found!");
887 }
888};
889
890
891
892
894public:
896
898
901 }
902
904
906
907
909
910
911
912
914
915
917
918
920
921
922 virtual void anchor();
923
924protected:
925
927};
928
929
930
931
933public:
936
938};
939
940
941
942extern template class basic_parser;
943
945public:
947
948
950
952
955 }
956
957
959
961 size_t GlobalWidth) const;
962
963
965};
966
967
968
970
972public:
974
975
977
980 }
981
982
984
986 size_t GlobalWidth) const;
987
988
990};
991
992
993
995
997public:
999
1000
1002
1003
1005
1007 size_t GlobalWidth) const;
1008
1009
1011};
1012
1013
1014
1016
1018public:
1020
1021
1023
1024
1026
1028 size_t GlobalWidth) const;
1029
1030
1032};
1033
1034
1035
1037
1039public:
1041
1042
1044
1045
1047
1049 size_t GlobalWidth) const;
1050
1051
1053};
1054
1055
1056
1058
1060public:
1062
1063
1065
1066
1068
1070 size_t GlobalWidth) const;
1071
1072
1074};
1075
1076
1077
1079
1080template <>
1082public:
1084
1085
1087
1088
1090
1092 size_t GlobalWidth) const;
1093
1094
1096};
1097
1098
1099
1101
1102template <>
1104public:
1106
1107
1109 unsigned long long &Val);
1110
1111
1113
1115 size_t GlobalWidth) const;
1116
1117
1119};
1120
1121
1122
1124
1126public:
1128
1129
1131
1132
1134
1136 size_t GlobalWidth) const;
1137
1138
1140};
1141
1142
1143
1145
1147public:
1149
1150
1152
1153
1155
1157 size_t GlobalWidth) const;
1158
1159
1161};
1162
1163
1164
1166
1168public:
1170
1171
1174 return false;
1175 }
1176
1177
1179
1181 size_t GlobalWidth) const;
1182
1183
1185};
1186
1187
1188
1190
1192public:
1194
1195
1198 return false;
1199 }
1200
1201
1203
1205 size_t GlobalWidth) const;
1206
1207
1209};
1210
1211
1212
1213
1214
1215
1216template <class ParserClass, class DT>
1220 P.printOptionDiff(O, OV, Default, GlobalWidth);
1221}
1222
1223
1224
1228 P.printOptionNoValue(O, GlobalWidth);
1229 }
1230};
1231
1232
1233
1237 P.printOptionDiff(O, V, Default, GlobalWidth);
1238 }
1239};
1240
1241
1242
1243template <class ParserClass, class ValDT>
1248
1250 printer.print(O, static_cast<const ParserClass &>(P), V, Default,
1251 GlobalWidth);
1252}
1253
1254
1255
1256
1257
1258
1259
1261 template static void opt(const Mod &M, Opt &O) { M.apply(O); }
1262};
1263
1264
1266 template static void opt(StringRef Str, Opt &O) {
1267 O.setArgStr(Str);
1268 }
1269};
1271 template static void opt(StringRef Str, Opt &O) {
1272 O.setArgStr(Str);
1273 }
1274};
1276 template static void opt(StringRef Str, Opt &O) {
1277 O.setArgStr(Str);
1278 }
1279};
1280
1283 O.setNumOccurrencesFlag(N);
1284 }
1285};
1286
1289};
1290
1293};
1294
1297};
1298
1302 "cl::Grouping can only apply to single character Options.");
1303 O.setMiscFlag(MF);
1304 }
1305};
1306
1307
1308template <class Opt, class Mod, class... Mods>
1309void apply(Opt *O, const Mod &M, const Mods &... Ms) {
1311 apply(O, Ms...);
1312}
1313
1314template <class Opt, class Mod> void apply(Opt *O, const Mod &M) {
1316}
1317
1318
1319
1320
1321
1322
1323template <class DataType, bool ExternalStorage, bool isClass>
1325 DataType *Location = nullptr;
1327
1328 void check_location() const {
1329 assert(Location && "cl::location(...) not specified for a command "
1330 "line option with external storage, "
1331 "or cl::init specified before cl::location()!!");
1332 }
1333
1334public:
1336
1338 if (Location)
1339 return O.error("cl::location(x) specified more than once!");
1340 Location = &L;
1341 Default = L;
1342 return false;
1343 }
1344
1345 template void setValue(const T &V, bool initial = false) {
1346 check_location();
1347 *Location = V;
1348 if (initial)
1349 Default = V;
1350 }
1351
1353 check_location();
1354 return *Location;
1355 }
1357 check_location();
1358 return *Location;
1359 }
1360
1361 operator DataType() const { return this->getValue(); }
1362
1364};
1365
1366
1367
1368
1369
1370template
1372public:
1374
1375 template void setValue(const T &V, bool initial = false) {
1376 DataType::operator=(V);
1377 if (initial)
1378 Default = V;
1379 }
1380
1382 const DataType &getValue() const { return *this; }
1383
1385};
1386
1387
1388
1389
1390
1392public:
1395
1396
1397
1399
1400 template void setValue(const T &V, bool initial = false) {
1402 if (initial)
1403 Default = V;
1404 }
1407
1409
1410 operator DataType() const { return getValue(); }
1411
1412
1414};
1415
1416
1417
1418
1419template <class DataType, bool ExternalStorage = false,
1420 class ParserClass = parser>
1423 public opt_storage<DataType, ExternalStorage, std::is_class_v> {
1424 ParserClass Parser;
1425
1426 bool handleOccurrence(unsigned pos, StringRef ArgName,
1428 typename ParserClass::parser_data_type Val =
1429 typename ParserClass::parser_data_type();
1430 if (Parser.parse(*this, ArgName, Arg, Val))
1431 return true;
1435 return false;
1436 }
1437
1438 enum ValueExpected getValueExpectedFlagDefault() const override {
1439 return Parser.getValueExpectedFlagDefault();
1440 }
1441
1443 return Parser.getExtraOptionNames(OptionNames);
1444 }
1445
1446
1447 size_t getOptionWidth() const override {
1448 return Parser.getOptionWidth(*this);
1449 }
1450
1451 void printOptionInfo(size_t GlobalWidth) const override {
1452 Parser.printOptionInfo(*this, GlobalWidth);
1453 }
1454
1455 void printOptionValue(size_t GlobalWidth, bool Force) const override {
1457 cl::printOptionDiff(*this, Parser, this->getValue(),
1459 }
1460 }
1461
1462 template <class T, class = std::enable_if_t<std::is_assignable_v<T &, T>>>
1463 void setDefaultImpl() {
1467 else
1469 }
1470
1471 template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
1472 void setDefaultImpl(...) {}
1473
1474 void setDefault() override { setDefaultImpl(); }
1475
1476 void done() {
1478 Parser.initialize();
1479 }
1480
1481public:
1482
1485
1486
1488
1490
1491 template DataType &operator=(const T &Val) {
1495 }
1496
1497 template <class... Mods>
1498 explicit opt(const Mods &... Ms)
1500 apply(this, Ms...);
1501 done();
1502 }
1503
1505 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1507 }
1508
1509 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1510 [](const typename ParserClass::parser_data_type &) {};
1511};
1512
1513extern template class opt;
1514extern template class opt;
1515extern template class optstd::string;
1516extern template class opt;
1517extern template class opt;
1518
1519
1520
1521
1522
1523
1524template <class DataType, class StorageClass> class list_storage {
1525 StorageClass *Location = nullptr;
1526 std::vector<OptionValue> Default =
1527 std::vector<OptionValue>();
1528 bool DefaultAssigned = false;
1529
1530public:
1532
1534
1536 if (Location)
1537 return O.error("cl::location(x) specified more than once!");
1538 Location = &L;
1539 return false;
1540 }
1541
1542 template void addValue(const T &V, bool initial = false) {
1543 assert(Location != nullptr &&
1544 "cl::location(...) not specified for a command "
1545 "line option with external storage!");
1546 Location->push_back(V);
1547 if (initial)
1549 }
1550
1551 const std::vector<OptionValue> &getDefault() const {
1553 }
1554
1558};
1559
1560
1561
1562
1563
1564
1565
1566
1567
1569 std::vector Storage;
1570 std::vector<OptionValue> Default;
1571 bool DefaultAssigned = false;
1572
1573public:
1574 using iterator = typename std::vector::iterator;
1575
1578
1579 using const_iterator = typename std::vector::const_iterator;
1580
1583
1584 using size_type = typename std::vector::size_type;
1585
1587
1588 bool empty() const { return Storage.empty(); }
1589
1592
1593 using reference = typename std::vector::reference;
1594 using const_reference = typename std::vector::const_reference;
1595
1598
1600 Storage.clear();
1601 }
1602
1605 return Storage.erase(first, last);
1606 }
1607
1610 return Storage.erase(first, last);
1611 }
1612
1614 return Storage.insert(pos, value);
1615 }
1617 return Storage.insert(pos, value);
1618 }
1619
1621 return Storage.insert(pos, value);
1622 }
1624 return Storage.insert(pos, value);
1625 }
1626
1629
1630 operator std::vector &() { return Storage; }
1632 std::vector *operator&() { return &Storage; }
1633 const std::vector *operator&() const { return &Storage; }
1634
1635 template void addValue(const T &V, bool initial = false) {
1636 Storage.push_back(V);
1637 if (initial)
1639 }
1640
1641 const std::vector<OptionValue> &getDefault() const {
1642 return Default;
1643 }
1644
1648};
1649
1650
1651
1652
1654 class ParserClass = parser>
1656 std::vector Positions;
1657 ParserClass Parser;
1658
1659 enum ValueExpected getValueExpectedFlagDefault() const override {
1660 return Parser.getValueExpectedFlagDefault();
1661 }
1662
1664 return Parser.getExtraOptionNames(OptionNames);
1665 }
1666
1667 bool handleOccurrence(unsigned pos, StringRef ArgName,
1669 typename ParserClass::parser_data_type Val =
1670 typename ParserClass::parser_data_type();
1674 }
1675 if (Parser.parse(*this, ArgName, Arg, Val))
1676 return true;
1679 Positions.push_back(pos);
1681 return false;
1682 }
1683
1684
1685 size_t getOptionWidth() const override {
1686 return Parser.getOptionWidth(*this);
1687 }
1688
1689 void printOptionInfo(size_t GlobalWidth) const override {
1690 Parser.printOptionInfo(*this, GlobalWidth);
1691 }
1692
1693
1694 void printOptionValue(size_t , bool ) const override {
1695 }
1696
1697 void setDefault() override {
1698 Positions.clear();
1702 }
1703
1704 void done() {
1706 Parser.initialize();
1707 }
1708
1709public:
1710
1713
1715
1717 assert(optnum < this->size() && "Invalid option index");
1718 return Positions[optnum];
1719 }
1720
1722 Positions.clear();
1724 }
1725
1726
1729 "Cannot have two default values");
1731 for (auto &Val : Vs)
1733 }
1734
1736
1737 template <class... Mods>
1738 explicit list(const Mods &... Ms)
1740 apply(this, Ms...);
1741 done();
1742 }
1743
1745 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1747 }
1748
1749 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1750 [](const typename ParserClass::parser_data_type &) {};
1751};
1752
1753
1757
1758 template <typename D, typename S, typename P>
1761 }
1762};
1763
1764
1765
1766
1767
1768
1769template <class DataType, class StorageClass> class bits_storage {
1770 unsigned *Location = nullptr;
1771
1772 template static unsigned Bit(const T &V) {
1773 unsigned BitPos = static_cast<unsigned>(V);
1774 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1775 "enum exceeds width of bit vector!");
1776 return 1 << BitPos;
1777 }
1778
1779public:
1781
1783 if (Location)
1784 return O.error("cl::location(x) specified more than once!");
1785 Location = &L;
1786 return false;
1787 }
1788
1790 assert(Location != nullptr &&
1791 "cl::location(...) not specified for a command "
1792 "line option with external storage!");
1793 *Location |= Bit(V);
1794 }
1795
1796 unsigned getBits() { return *Location; }
1797
1799 if (Location)
1800 *Location = 0;
1801 }
1802
1803 template bool isSet(const T &V) {
1804 return (*Location & Bit(V)) != 0;
1805 }
1806};
1807
1808
1809
1810
1812 unsigned Bits{0};
1813
1814 template static unsigned Bit(const T &V) {
1815 unsigned BitPos = static_cast<unsigned>(V);
1816 assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
1817 "enum exceeds width of bit vector!");
1818 return 1 << BitPos;
1819 }
1820
1821public:
1822 template void addValue(const T &V) { Bits |= Bit(V); }
1823
1825
1827
1828 template bool isSet(const T &V) { return (Bits & Bit(V)) != 0; }
1829};
1830
1831
1832
1833
1834template <class DataType, class Storage = bool,
1835 class ParserClass = parser>
1837 std::vector Positions;
1838 ParserClass Parser;
1839
1840 enum ValueExpected getValueExpectedFlagDefault() const override {
1841 return Parser.getValueExpectedFlagDefault();
1842 }
1843
1845 return Parser.getExtraOptionNames(OptionNames);
1846 }
1847
1848 bool handleOccurrence(unsigned pos, StringRef ArgName,
1850 typename ParserClass::parser_data_type Val =
1851 typename ParserClass::parser_data_type();
1852 if (Parser.parse(*this, ArgName, Arg, Val))
1853 return true;
1856 Positions.push_back(pos);
1858 return false;
1859 }
1860
1861
1862 size_t getOptionWidth() const override {
1863 return Parser.getOptionWidth(*this);
1864 }
1865
1866 void printOptionInfo(size_t GlobalWidth) const override {
1867 Parser.printOptionInfo(*this, GlobalWidth);
1868 }
1869
1870
1871 void printOptionValue(size_t , bool ) const override {
1872 }
1873
1875
1876 void done() {
1878 Parser.initialize();
1879 }
1880
1881public:
1882
1885
1887
1889 assert(optnum < this->size() && "Invalid option index");
1890 return Positions[optnum];
1891 }
1892
1893 template <class... Mods>
1894 explicit bits(const Mods &... Ms)
1896 apply(this, Ms...);
1897 done();
1898 }
1899
1901 std::function<void(const typename ParserClass::parser_data_type &)> CB) {
1903 }
1904
1905 std::function<void(const typename ParserClass::parser_data_type &)> Callback =
1906 [](const typename ParserClass::parser_data_type &) {};
1907};
1908
1909
1910
1911
1912
1915
1916 bool handleOccurrence(unsigned pos, StringRef ,
1918 return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1919 }
1920
1922 bool MultiArg = false) override {
1924 }
1925
1926
1927 size_t getOptionWidth() const override;
1928 void printOptionInfo(size_t GlobalWidth) const override;
1929
1930
1931 void printOptionValue(size_t , bool ) const override {
1932 }
1933
1934 void setDefault() override { AliasFor->setDefault(); }
1935
1936 ValueExpected getValueExpectedFlagDefault() const override {
1938 }
1939
1940 void done() {
1942 error("cl::alias must have argument name specified!");
1943 if (!AliasFor)
1944 error("cl::alias must have an cl::aliasopt(option) specified!");
1945 if (.empty())
1946 error("cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!");
1950 }
1951
1952public:
1953
1956
1958 if (AliasFor)
1959 error("cl::alias must only have one cl::aliasopt(...) specified!");
1960 AliasFor = &O;
1961 }
1962
1963 template <class... Mods>
1964 explicit alias(const Mods &... Ms)
1966 apply(this, Ms...);
1967 done();
1968 }
1969};
1970
1971
1974
1976
1978};
1979
1980
1981
1982
1985
1987};
1988
1990
1991
1992
1993
1994
1995
1997
1998
1999
2000
2002
2003
2004
2005
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2082 bool MarkEOLs = false);
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2100 bool MarkEOLs = false);
2101
2102
2103
2104
2105
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2124 bool MarkEOLs = false);
2125
2126
2127
2130 bool MarkEOLs);
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2143 bool MarkEOLs = false);
2144
2145
2147
2149
2150
2152
2153
2155
2156
2157
2159
2160
2162
2163
2164
2165 bool RelativeNames = false;
2166
2167
2168
2169 bool MarkEOLs = false;
2170
2171
2172 bool InConfigFile = false;
2173
2176
2177public:
2179
2181 MarkEOLs = X;
2182 return *this;
2183 }
2184
2186 RelativeNames = X;
2187 return *this;
2188 }
2189
2191 CurrentDir = X;
2192 return *this;
2193 }
2194
2196 SearchDirs = X;
2197 return *this;
2198 }
2199
2201 FS = X;
2202 return *this;
2203 }
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2227
2228
2230};
2231
2232
2233
2234
2235
2238
2239
2240
2243
2244
2245
2246
2247
2248bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar,
2251
2252
2253
2254
2255
2256
2257
2258
2261
2262
2263
2264
2265
2266
2267
2268
2271
2272
2273
2274
2276
2277
2278
2279
2280
2282
2283
2285
2286}
2287
2288}
2289
2290#endif
This file defines the StringMap class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Given that RA is a live value
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Allocate memory in an ever growing pool, as if by bump-pointer.
Lightweight error class with error context and mandatory checking.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Value(Type *Ty, unsigned scid)
Contains options that control response file expansion.
ExpansionContext & setCurrentDir(StringRef X)
ExpansionContext & setVFS(vfs::FileSystem *X)
ExpansionContext & setMarkEOLs(bool X)
ExpansionContext & setSearchDirs(ArrayRef< StringRef > X)
ExpansionContext & setRelativeNames(bool X)
bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
Error readConfigFile(StringRef CfgFile, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
OptionCategory(StringRef const Name, StringRef const Description="")
StringRef getDescription() const
StringRef getName() const
OptionValueCopy & operator=(const OptionValueCopy &)=default
OptionValueCopy()=default
bool compare(const GenericOptionValue &V) const override
void setValue(const DataType &V)
~OptionValueCopy()=default
const DataType & getValue() const
OptionValueCopy(const OptionValueCopy &)=default
bool compare(const DataType &V) const
bool isPositional() const
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
void setValueExpectedFlag(enum ValueExpected Val)
void setPosition(unsigned pos)
bool isConsumeAfter() const
SmallPtrSet< SubCommand *, 1 > Subs
int getNumOccurrences() const
enum ValueExpected getValueExpectedFlag() const
void addCategory(OptionCategory &C)
void setValueStr(StringRef S)
void setNumOccurrencesFlag(enum NumOccurrencesFlag Val)
void setNumAdditionalVals(unsigned n)
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void setDescription(StringRef S)
void setFormattingFlag(enum FormattingFlags V)
void setHiddenFlag(enum OptionHidden Val)
void setMiscFlag(enum MiscFlags M)
enum FormattingFlags getFormattingFlag() const
virtual void printOptionInfo(size_t GlobalWidth) const =0
enum NumOccurrencesFlag getNumOccurrencesFlag() const
SmallVector< OptionCategory *, 1 > Categories
void addSubCommand(SubCommand &S)
void setArgStr(StringRef S)
bool isDefaultOption() const
unsigned getMiscFlags() const
virtual void setDefault()=0
virtual void printOptionValue(size_t GlobalWidth, bool Force) const =0
virtual ~Option()=default
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
unsigned getNumAdditionalVals() const
void removeArgument()
Unregisters this option from the CommandLine system.
Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden)
enum OptionHidden getOptionHiddenFlag() const
bool error(const Twine &Message, raw_ostream &Errs)
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
virtual size_t getOptionWidth() const =0
unsigned getPosition() const
SubCommandGroup(std::initializer_list< SubCommand * > IL)
ArrayRef< SubCommand * > getSubCommands() const
StringRef getName() const
SubCommand(StringRef Name, StringRef Description="")
SmallVector< Option *, 4 > SinkOpts
static SubCommand & getTopLevel()
void unregisterSubCommand()
static SubCommand & getAll()
void registerSubCommand()
SmallVector< Option *, 4 > PositionalOpts
StringMap< Option * > OptionsMap
StringRef getDescription() const
ValuesClass(std::initializer_list< OptionEnumValue > Options)
alias(const alias &)=delete
void setAliasFor(Option &O)
alias & operator=(const alias &)=delete
alias(const Mods &... Ms)
void printOptionInfo(const Option &O, size_t GlobalWidth) const
enum ValueExpected getValueExpectedFlagDefault() const
void getExtraOptionNames(SmallVectorImpl< StringRef > &)
virtual StringRef getValueName() const
virtual ~basic_parser_impl()=default
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
basic_parser_impl(Option &)
size_t getOptionWidth(const Option &O) const
void printOptionName(const Option &O, size_t GlobalWidth) const
OptionValue< DataType > OptVal
DataType parser_data_type
void addValue(const T &V)
void addValue(const T &V)
bool setLocation(Option &O, unsigned &L)
bits & operator=(const bits &)=delete
ParserClass & getParser()
unsigned getPosition(unsigned optnum) const
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
bits(const bits &)=delete
GenericOptionInfo(StringRef name, StringRef helpStr)
virtual size_t getOptionWidth(const Option &O) const
generic_parser_base(Option &O)
virtual StringRef getDescription(unsigned N) const =0
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
virtual unsigned getNumOptions() const =0
virtual StringRef getOption(unsigned N) const =0
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
unsigned findOption(StringRef Name)
virtual ~generic_parser_base()=default
void getExtraOptionNames(SmallVectorImpl< StringRef > &OptionNames)
enum ValueExpected getValueExpectedFlagDefault() const
void push_back(DataType &&value)
typename std::vector< DataType >::const_iterator const_iterator
typename std::vector< DataType >::const_reference const_reference
const_iterator begin() const
iterator erase(const_iterator first, const_iterator last)
iterator insert(const_iterator pos, const DataType &value)
iterator erase(iterator first, iterator last)
const_reference operator[](size_type pos) const
void addValue(const T &V, bool initial=false)
void push_back(const DataType &value)
typename std::vector< DataType >::reference reference
reference operator[](size_type pos)
const std::vector< DataType > * operator&() const
iterator insert(iterator pos, const DataType &value)
typename std::vector< DataType >::size_type size_type
const_reference front() const
const_iterator end() const
iterator insert(const_iterator pos, DataType &&value)
iterator erase(iterator pos)
std::vector< DataType > * operator&()
const std::vector< OptionValue< DataType > > & getDefault() const
iterator erase(const_iterator pos)
iterator insert(iterator pos, DataType &&value)
typename std::vector< DataType >::iterator iterator
const std::vector< OptionValue< DataType > > & getDefault() const
void addValue(const T &V, bool initial=false)
bool setLocation(Option &O, StorageClass &L)
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
list(const list &)=delete
void setInitialValues(ArrayRef< DataType > Vs)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
list & operator=(const list &)=delete
ParserClass & getParser()
unsigned getPosition(unsigned optnum) const
void setNumAdditionalVals(unsigned n)
OptionValue< DataType > Default
DataType operator->() const
const OptionValue< DataType > & getDefault() const
void setValue(const T &V, bool initial=false)
DataType getValue() const
void setValue(const T &V, bool initial=false)
OptionValue< DataType > Default
const DataType & getValue() const
const OptionValue< DataType > & getDefault() const
const DataType & getValue() const
bool setLocation(Option &O, DataType &L)
void setValue(const T &V, bool initial=false)
const OptionValue< DataType > & getDefault() const
ParserClass & getParser()
opt & operator=(const opt &)=delete
void setInitialValue(const DataType &V)
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
DataType & operator=(const T &Val)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
OptionInfo(StringRef name, DataType v, StringRef helpStr)
OptionValue< DataType > V
bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val)
void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
enum ValueExpected getValueExpectedFlagDefault() const
enum ValueExpected getValueExpectedFlagDefault() const
void printOptionDiff(const Option &O, bool V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val)
StringRef getValueName() const override
bool parse(Option &, StringRef, StringRef Arg, char &Value)
void printOptionDiff(const Option &O, char V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, double V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val)
bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, float V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, int V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val)
StringRef getValueName() const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, long &Val)
void printOptionDiff(const Option &O, long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, long long &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, long long V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, StringRef V, const OptVal &Default, size_t GlobalWidth) const
bool parse(Option &, StringRef, StringRef Arg, std::string &Value)
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val)
void printOptionDiff(const Option &O, unsigned V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
StringRef getValueName() const override
void printOptionDiff(const Option &O, unsigned long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, unsigned long long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long long &Val)
DataType parser_data_type
SmallVector< OptionInfo, 8 > Values
void removeLiteralOption(StringRef Name)
Remove the specified option.
StringRef getDescription(unsigned N) const override
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
Add an entry to the mapping table.
const GenericOptionValue & getOptionValue(unsigned N) const override
StringRef getOption(unsigned N) const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
unsigned getNumOptions() const override
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
The virtual file system interface.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
std::function< void(raw_ostream &)> VersionPrinterTy
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
void PrintVersionMessage()
Utility function for printing version number.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a string of Windows command line arguments, which may contain quotes and escaped quotes.
list_initializer< Ty > list_init(ArrayRef< Ty > Vals)
OptionCategory & getGeneralCategory()
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
void apply(Opt *O, const Mod &M, const Mods &... Ms)
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
void printBuildConfig(raw_ostream &OS)
Prints the compiler build configuration.
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
initializer< Ty > init(const Ty &Val)
ArrayRef< StringRef > getCompilerBuildConfig()
An array of optional enabled settings in the LLVM build configuration, which may be of interest to co...
LocationClass< Ty > location(Ty &L)
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
void PrintHelpMessage(bool Hidden=false, bool Categorized=false)
This function just prints the help message, exactly the same way as if the -help or -help-hidden opti...
void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Mod
The access may modify the value stored in memory.
@ Default
The result values are uniform if and only if all operands are uniform.
Implement std::hash so that hash_code can be used in STL containers.
Description of the encoding of one expression Op.
GenericOptionValue()=default
GenericOptionValue(const GenericOptionValue &)=default
GenericOptionValue & operator=(const GenericOptionValue &)=default
~GenericOptionValue()=default
virtual bool compare(const GenericOptionValue &V) const =0
void print(const Option &O, const parser< DT > &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
void print(const Option &O, const parser< ParserDT > &P, const ValDT &, const OptionValue< ValDT > &, size_t GlobalWidth)
~OptionValueBase()=default
OptionValueBase & operator=(const OptionValueBase &)=default
OptionValueBase(const OptionValueBase &)=default
OptionValueBase()=default
bool compare(const DataType &) const
const DataType & getValue() const
~OptionValueBase()=default
bool compare(const GenericOptionValue &) const override
OptionValue< DataType > WrapperType
void setValue(const DT &)
OptionValue< cl::boolOrDefault > & operator=(const cl::boolOrDefault &V)
OptionValue(const cl::boolOrDefault &V)
OptionValue< std::string > & operator=(const std::string &V)
OptionValue(const std::string &V)
OptionValue(const DataType &V)
OptionValue< DataType > & operator=(const DT &V)
void apply(alias &A) const
static void opt(FormattingFlags FF, Option &O)
static void opt(MiscFlags MF, Option &O)
static void opt(NumOccurrencesFlag N, Option &O)
static void opt(StringRef Str, Opt &O)
static void opt(ValueExpected VE, Option &O)
static void opt(StringRef Str, Opt &O)
static void opt(StringRef Str, Opt &O)
static void opt(const Mod &M, Opt &O)
OptionCategory & Category
cb(std::function< R(Ty)> CB)
void apply(Option &O) const
std::tuple_element_t< 0, std::tuple< Args... > > arg_type
initializer(const Ty &Val)
list_initializer(ArrayRef< Ty > Vals)
void apply(list< D, S, P > &L) const
void apply(Option &O) const
value_desc(StringRef Str)