[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)
Justin Bogner via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 10:26:36 PDT 2023
================
@@ -930,77 +936,83 @@ namespace {
OS << getLowerName() << "(" << getUpperName() << ")";
}
void writeCtorDefaultInitializers(raw_ostream &OS) const override {
- OS << getLowerName() << "(" << type << "(0))";
+ OS << getLowerName() << "(" << fullType << "(0))";
}
void writeCtorParameters(raw_ostream &OS) const override {
- OS << type << " " << getUpperName();
+ OS << fullType << " " << getUpperName();
}
void writeDeclarations(raw_ostream &OS) const override {
- auto i = uniques.cbegin(), e = uniques.cend();
- // The last one needs to not have a comma.
- --e;
+ if (!isExternal) {
+ auto i = uniques.cbegin(), e = uniques.cend();
+ // The last one needs to not have a comma.
+ --e;
+
+ OS << "public:\n";
+ OS << " enum " << shortType << " {\n";
+ for (; i != e; ++i)
+ OS << " " << *i << ",\n";
+ OS << " " << *e << "\n";
+ OS << " };\n";
+ }
- OS << "public:\n";
- OS << " enum " << type << " {\n";
- for (; i != e; ++i)
- OS << " " << *i << ",\n";
- OS << " " << *e << "\n";
- OS << " };\n";
OS << "private:\n";
- OS << " " << type << " " << getLowerName() << ";";
+ OS << " " << fullType << " " << getLowerName() << ";";
}
void writePCHReadDecls(raw_ostream &OS) const override {
- OS << " " << getAttrName() << "Attr::" << type << " " << getLowerName()
- << "(static_cast<" << getAttrName() << "Attr::" << type
- << ">(Record.readInt()));\n";
+ OS << " " << fullType << " " << getLowerName()
+ << "(static_cast<" << fullType << ">(Record.readInt()));\n";
}
void writePCHReadArgs(raw_ostream &OS) const override {
OS << getLowerName();
}
void writePCHWrite(raw_ostream &OS) const override {
- OS << "Record.push_back(SA->get" << getUpperName() << "());\n";
+ OS << "Record.push_back(static_cast<uint64_t>(SA->get" << getUpperName()
+ << "()));\n";
}
void writeValue(raw_ostream &OS) const override {
// FIXME: this isn't 100% correct -- some enum arguments require printing
// as a string literal, while others require printing as an identifier.
// Tablegen currently does not distinguish between the two forms.
- OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << type << "ToStr(get"
- << getUpperName() << "()) << \"\\\"";
+ OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << shortType
+ << "ToStr(get" << getUpperName() << "()) << \"\\\"";
}
void writeDump(raw_ostream &OS) const override {
OS << " switch(SA->get" << getUpperName() << "()) {\n";
for (const auto &I : uniques) {
- OS << " case " << getAttrName() << "Attr::" << I << ":\n";
+ OS << " case " << fullType << "::" << I << ":\n";
OS << " OS << \" " << I << "\";\n";
OS << " break;\n";
}
+ if (isExternal) {
+ OS << " default:\n";
+ OS << " llvm_unreachable(\"Invalid attribute value\");\n";
+ }
----------------
bogner wrote:
It's a little unfortunate that we have to add this based only on `isExternal`, but since there's no way to tell if we've used every enum value or not I don't think there's a better option
https://github.com/llvm/llvm-project/pull/70835
More information about the cfe-commits
mailing list