mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 01:29:52 +00:00
[TableGen] Clang changes to support Record::getValueAsString and getValueAsListOfStrings returning StringRef instead of std::string
This is the clang version of D33710. Differential Revision: https://reviews.llvm.org/D33711 llvm-svn: 304326
This commit is contained in:
parent
2b8419a22d
commit
0064858b0e
@ -718,9 +718,9 @@ namespace {
|
||||
};
|
||||
|
||||
// Unique the enums, but maintain the original declaration ordering.
|
||||
std::vector<std::string>
|
||||
uniqueEnumsInOrder(const std::vector<std::string> &enums) {
|
||||
std::vector<std::string> uniques;
|
||||
std::vector<StringRef>
|
||||
uniqueEnumsInOrder(const std::vector<StringRef> &enums) {
|
||||
std::vector<StringRef> uniques;
|
||||
SmallDenseSet<StringRef, 8> unique_set;
|
||||
for (const auto &i : enums) {
|
||||
if (unique_set.insert(i).second)
|
||||
@ -731,7 +731,8 @@ namespace {
|
||||
|
||||
class EnumArgument : public Argument {
|
||||
std::string type;
|
||||
std::vector<std::string> values, enums, uniques;
|
||||
std::vector<StringRef> values, enums, uniques;
|
||||
|
||||
public:
|
||||
EnumArgument(const Record &Arg, StringRef Attr)
|
||||
: Argument(Arg, Attr), type(Arg.getValueAsString("Type")),
|
||||
@ -850,7 +851,7 @@ namespace {
|
||||
|
||||
class VariadicEnumArgument: public VariadicArgument {
|
||||
std::string type, QualifiedTypeName;
|
||||
std::vector<std::string> values, enums, uniques;
|
||||
std::vector<StringRef> values, enums, uniques;
|
||||
|
||||
protected:
|
||||
void writeValueImpl(raw_ostream &OS) const override {
|
||||
@ -1591,8 +1592,9 @@ struct AttributeSubjectMatchRule {
|
||||
}
|
||||
|
||||
std::string getEnumValueName() const {
|
||||
std::string Result =
|
||||
"SubjectMatchRule_" + MetaSubject->getValueAsString("Name");
|
||||
SmallString<128> Result;
|
||||
Result += "SubjectMatchRule_";
|
||||
Result += MetaSubject->getValueAsString("Name");
|
||||
if (isSubRule()) {
|
||||
Result += "_";
|
||||
if (isNegatedSubRule())
|
||||
@ -1601,7 +1603,7 @@ struct AttributeSubjectMatchRule {
|
||||
}
|
||||
if (isAbstractRule())
|
||||
Result += "_abstract";
|
||||
return Result;
|
||||
return Result.str();
|
||||
}
|
||||
|
||||
std::string getEnumValue() const { return "attr::" + getEnumValueName(); }
|
||||
@ -2603,7 +2605,7 @@ void EmitClangAttrPCHWrite(RecordKeeper &Records, raw_ostream &OS) {
|
||||
// append a unique suffix to distinguish this set of target checks from other
|
||||
// TargetSpecificAttr records.
|
||||
static void GenerateTargetSpecificAttrChecks(const Record *R,
|
||||
std::vector<std::string> &Arches,
|
||||
std::vector<StringRef> &Arches,
|
||||
std::string &Test,
|
||||
std::string *FnName) {
|
||||
// It is assumed that there will be an llvm::Triple object
|
||||
@ -2613,8 +2615,9 @@ static void GenerateTargetSpecificAttrChecks(const Record *R,
|
||||
Test += "(";
|
||||
|
||||
for (auto I = Arches.begin(), E = Arches.end(); I != E; ++I) {
|
||||
std::string Part = *I;
|
||||
Test += "T.getArch() == llvm::Triple::" + Part;
|
||||
StringRef Part = *I;
|
||||
Test += "T.getArch() == llvm::Triple::";
|
||||
Test += Part;
|
||||
if (I + 1 != E)
|
||||
Test += " || ";
|
||||
if (FnName)
|
||||
@ -2627,11 +2630,12 @@ static void GenerateTargetSpecificAttrChecks(const Record *R,
|
||||
// We know that there was at least one arch test, so we need to and in the
|
||||
// OS tests.
|
||||
Test += " && (";
|
||||
std::vector<std::string> OSes = R->getValueAsListOfStrings("OSes");
|
||||
std::vector<StringRef> OSes = R->getValueAsListOfStrings("OSes");
|
||||
for (auto I = OSes.begin(), E = OSes.end(); I != E; ++I) {
|
||||
std::string Part = *I;
|
||||
StringRef Part = *I;
|
||||
|
||||
Test += "T.getOS() == llvm::Triple::" + Part;
|
||||
Test += "T.getOS() == llvm::Triple::";
|
||||
Test += Part;
|
||||
if (I + 1 != E)
|
||||
Test += " || ";
|
||||
if (FnName)
|
||||
@ -2643,10 +2647,11 @@ static void GenerateTargetSpecificAttrChecks(const Record *R,
|
||||
// If one or more CXX ABIs are specified, check those as well.
|
||||
if (!R->isValueUnset("CXXABIs")) {
|
||||
Test += " && (";
|
||||
std::vector<std::string> CXXABIs = R->getValueAsListOfStrings("CXXABIs");
|
||||
std::vector<StringRef> CXXABIs = R->getValueAsListOfStrings("CXXABIs");
|
||||
for (auto I = CXXABIs.begin(), E = CXXABIs.end(); I != E; ++I) {
|
||||
std::string Part = *I;
|
||||
Test += "Target.getCXXABI().getKind() == TargetCXXABI::" + Part;
|
||||
StringRef Part = *I;
|
||||
Test += "Target.getCXXABI().getKind() == TargetCXXABI::";
|
||||
Test += Part;
|
||||
if (I + 1 != E)
|
||||
Test += " || ";
|
||||
if (FnName)
|
||||
@ -2684,7 +2689,7 @@ static void GenerateHasAttrSpellingStringSwitch(
|
||||
std::string Test;
|
||||
if (Attr->isSubClassOf("TargetSpecificAttr")) {
|
||||
const Record *R = Attr->getValueAsDef("Target");
|
||||
std::vector<std::string> Arches = R->getValueAsListOfStrings("Arches");
|
||||
std::vector<StringRef> Arches = R->getValueAsListOfStrings("Arches");
|
||||
GenerateTargetSpecificAttrChecks(R, Arches, Test, nullptr);
|
||||
|
||||
// If this is the C++11 variety, also add in the LangOpts test.
|
||||
@ -3323,7 +3328,7 @@ static std::string GenerateTargetRequirements(const Record &Attr,
|
||||
|
||||
// Get the list of architectures to be tested for.
|
||||
const Record *R = Attr.getValueAsDef("Target");
|
||||
std::vector<std::string> Arches = R->getValueAsListOfStrings("Arches");
|
||||
std::vector<StringRef> Arches = R->getValueAsListOfStrings("Arches");
|
||||
if (Arches.empty()) {
|
||||
PrintError(Attr.getLoc(), "Empty list of target architectures for a "
|
||||
"target-specific attr");
|
||||
@ -3340,9 +3345,10 @@ static std::string GenerateTargetRequirements(const Record &Attr,
|
||||
std::string APK = Attr.getValueAsString("ParseKind");
|
||||
for (const auto &I : Dupes) {
|
||||
if (I.first == APK) {
|
||||
std::vector<std::string> DA = I.second->getValueAsDef("Target")
|
||||
->getValueAsListOfStrings("Arches");
|
||||
std::move(DA.begin(), DA.end(), std::back_inserter(Arches));
|
||||
std::vector<StringRef> DA =
|
||||
I.second->getValueAsDef("Target")->getValueAsListOfStrings(
|
||||
"Arches");
|
||||
Arches.insert(Arches.end(), DA.begin(), DA.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1277,8 +1277,8 @@ void EmitClangDiagDocs(RecordKeeper &Records, raw_ostream &OS) {
|
||||
bool IsSynonym = GroupInfo.DiagsInGroup.empty() &&
|
||||
GroupInfo.SubGroups.size() == 1;
|
||||
|
||||
writeHeader((IsRemarkGroup ? "-R" : "-W") +
|
||||
G->getValueAsString("GroupName"),
|
||||
writeHeader(((IsRemarkGroup ? "-R" : "-W") +
|
||||
G->getValueAsString("GroupName")).str(),
|
||||
OS);
|
||||
|
||||
if (!IsSynonym) {
|
||||
|
@ -83,7 +83,7 @@ Documentation extractDocumentation(RecordKeeper &Records) {
|
||||
}
|
||||
|
||||
// Pretend no-X and Xno-Y options are aliases of X and XY.
|
||||
auto Name = R->getValueAsString("Name");
|
||||
std::string Name = R->getValueAsString("Name");
|
||||
if (Name.size() >= 4) {
|
||||
if (Name.substr(0, 3) == "no-" && OptionsByName[Name.substr(3)]) {
|
||||
Aliases[OptionsByName[Name.substr(3)]].push_back(R);
|
||||
@ -229,7 +229,7 @@ std::string getRSTStringWithTextFallback(const Record *R, StringRef Primary,
|
||||
}
|
||||
|
||||
void emitOptionWithArgs(StringRef Prefix, const Record *Option,
|
||||
ArrayRef<std::string> Args, raw_ostream &OS) {
|
||||
ArrayRef<StringRef> Args, raw_ostream &OS) {
|
||||
OS << Prefix << escapeRST(Option->getValueAsString("Name"));
|
||||
|
||||
std::pair<StringRef, StringRef> Separators =
|
||||
@ -261,14 +261,15 @@ void emitOptionName(StringRef Prefix, const Record *Option, raw_ostream &OS) {
|
||||
}
|
||||
}
|
||||
|
||||
emitOptionWithArgs(Prefix, Option, Args, OS);
|
||||
emitOptionWithArgs(Prefix, Option, std::vector<StringRef>(Args.begin(), Args.end()), OS);
|
||||
|
||||
auto AliasArgs = Option->getValueAsListOfStrings("AliasArgs");
|
||||
if (!AliasArgs.empty()) {
|
||||
Record *Alias = Option->getValueAsDef("Alias");
|
||||
OS << " (equivalent to ";
|
||||
emitOptionWithArgs(Alias->getValueAsListOfStrings("Prefixes").front(),
|
||||
Alias, Option->getValueAsListOfStrings("AliasArgs"), OS);
|
||||
emitOptionWithArgs(
|
||||
Alias->getValueAsListOfStrings("Prefixes").front(), Alias,
|
||||
AliasArgs, OS);
|
||||
OS << ")";
|
||||
}
|
||||
}
|
||||
@ -310,7 +311,7 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
|
||||
forEachOptionName(Option, DocInfo, [&](const Record *Option) {
|
||||
for (auto &Prefix : Option->getValueAsListOfStrings("Prefixes"))
|
||||
SphinxOptionIDs.push_back(
|
||||
getSphinxOptionID(Prefix + Option->getValueAsString("Name")));
|
||||
getSphinxOptionID((Prefix + Option->getValueAsString("Name")).str()));
|
||||
});
|
||||
assert(!SphinxOptionIDs.empty() && "no flags for option");
|
||||
static std::map<std::string, int> NextSuffix;
|
||||
|
@ -51,7 +51,8 @@ static std::string getParentPackageFullName(const Record *R) {
|
||||
static std::string getPackageFullName(const Record *R) {
|
||||
std::string name = getParentPackageFullName(R);
|
||||
if (!name.empty()) name += ".";
|
||||
return name + R->getValueAsString("PackageName");
|
||||
name += R->getValueAsString("PackageName");
|
||||
return name;
|
||||
}
|
||||
|
||||
static std::string getCheckerFullName(const Record *R) {
|
||||
|
Loading…
Reference in New Issue
Block a user