mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
tblgen: Add support for non-inheritable attributes
This patch makes the necessary changes to TableGen to support non-inheritable attributes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123958 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4c93a0f092
commit
be111ef182
@ -462,8 +462,9 @@ void ClangAttrClassEmitter::run(raw_ostream &OS) {
|
||||
for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
|
||||
i != e; ++i) {
|
||||
Record &R = **i;
|
||||
const std::string &SuperName = R.getSuperClasses().back()->getName();
|
||||
|
||||
OS << "class " << R.getName() << "Attr : public Attr {\n";
|
||||
OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
|
||||
|
||||
std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args");
|
||||
std::vector<Argument*> Args;
|
||||
@ -494,7 +495,7 @@ void ClangAttrClassEmitter::run(raw_ostream &OS) {
|
||||
}
|
||||
|
||||
OS << " )\n";
|
||||
OS << " : Attr(attr::" << R.getName() << ", L)\n";
|
||||
OS << " : " << SuperName << "(attr::" << R.getName() << ", L)\n";
|
||||
|
||||
for (ai = Args.begin(); ai != ae; ++ai) {
|
||||
OS << " , ";
|
||||
@ -558,31 +559,58 @@ void ClangAttrImplEmitter::run(raw_ostream &OS) {
|
||||
}
|
||||
}
|
||||
|
||||
static void EmitAttrList(raw_ostream &OS, StringRef Class,
|
||||
const std::vector<Record*> &AttrList) {
|
||||
std::vector<Record*>::const_iterator i = AttrList.begin(), e = AttrList.end();
|
||||
|
||||
if (i != e) {
|
||||
// Move the end iterator back to emit the last attribute.
|
||||
for(--e; i != e; ++i)
|
||||
OS << Class << "(" << (*i)->getName() << ")\n";
|
||||
|
||||
OS << "LAST_" << Class << "(" << (*i)->getName() << ")\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
void ClangAttrListEmitter::run(raw_ostream &OS) {
|
||||
OS << "// This file is generated by TableGen. Do not edit.\n\n";
|
||||
|
||||
OS << "#ifndef LAST_ATTR\n";
|
||||
OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n";
|
||||
OS << "#endif\n\n";
|
||||
|
||||
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
|
||||
std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
|
||||
|
||||
if (i != e) {
|
||||
// Move the end iterator back to emit the last attribute.
|
||||
for(--e; i != e; ++i)
|
||||
OS << "ATTR(" << (*i)->getName() << ")\n";
|
||||
|
||||
OS << "LAST_ATTR(" << (*i)->getName() << ")\n\n";
|
||||
OS << "#ifndef INHERITABLE_ATTR\n";
|
||||
OS << "#define INHERITABLE_ATTR(NAME) ATTR(NAME)\n";
|
||||
OS << "#endif\n\n";
|
||||
|
||||
OS << "#ifndef LAST_INHERITABLE_ATTR\n";
|
||||
OS << "#define LAST_INHERITABLE_ATTR(NAME) INHERITABLE_ATTR(NAME)\n";
|
||||
OS << "#endif\n\n";
|
||||
|
||||
Record *InhClass = Records.getClass("InheritableAttr");
|
||||
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"),
|
||||
NonInhAttrs, InhAttrs;
|
||||
for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
|
||||
i != e; ++i) {
|
||||
if ((*i)->isSubClassOf(InhClass))
|
||||
InhAttrs.push_back(*i);
|
||||
else
|
||||
NonInhAttrs.push_back(*i);
|
||||
}
|
||||
|
||||
EmitAttrList(OS, "INHERITABLE_ATTR", InhAttrs);
|
||||
EmitAttrList(OS, "ATTR", NonInhAttrs);
|
||||
|
||||
OS << "#undef LAST_ATTR\n";
|
||||
OS << "#undef INHERITABLE_ATTR\n";
|
||||
OS << "#undef LAST_INHERITABLE_ATTR\n";
|
||||
OS << "#undef ATTR\n";
|
||||
}
|
||||
|
||||
void ClangAttrPCHReadEmitter::run(raw_ostream &OS) {
|
||||
OS << "// This file is generated by TableGen. Do not edit.\n\n";
|
||||
|
||||
Record *InhClass = Records.getClass("InheritableAttr");
|
||||
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"),
|
||||
ArgRecords;
|
||||
std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(), ai, ae;
|
||||
@ -596,6 +624,8 @@ void ClangAttrPCHReadEmitter::run(raw_ostream &OS) {
|
||||
for (; i != e; ++i) {
|
||||
Record &R = **i;
|
||||
OS << " case attr::" << R.getName() << ": {\n";
|
||||
if (R.isSubClassOf(InhClass))
|
||||
OS << " bool isInherited = Record[Idx++];\n";
|
||||
ArgRecords = R.getValueAsListOfDefs("Args");
|
||||
Args.clear();
|
||||
for (ai = ArgRecords.begin(), ae = ArgRecords.end(); ai != ae; ++ai) {
|
||||
@ -609,6 +639,8 @@ void ClangAttrPCHReadEmitter::run(raw_ostream &OS) {
|
||||
(*ri)->writePCHReadArgs(OS);
|
||||
}
|
||||
OS << ");\n";
|
||||
if (R.isSubClassOf(InhClass))
|
||||
OS << " cast<InheritableAttr>(New)->setInherited(isInherited);\n";
|
||||
OS << " break;\n";
|
||||
OS << " }\n";
|
||||
}
|
||||
@ -616,6 +648,7 @@ void ClangAttrPCHReadEmitter::run(raw_ostream &OS) {
|
||||
}
|
||||
|
||||
void ClangAttrPCHWriteEmitter::run(raw_ostream &OS) {
|
||||
Record *InhClass = Records.getClass("InheritableAttr");
|
||||
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"), Args;
|
||||
std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(), ai, ae;
|
||||
|
||||
@ -627,9 +660,11 @@ void ClangAttrPCHWriteEmitter::run(raw_ostream &OS) {
|
||||
Record &R = **i;
|
||||
OS << " case attr::" << R.getName() << ": {\n";
|
||||
Args = R.getValueAsListOfDefs("Args");
|
||||
if (!Args.empty())
|
||||
if (R.isSubClassOf(InhClass) || !Args.empty())
|
||||
OS << " const " << R.getName() << "Attr *SA = cast<" << R.getName()
|
||||
<< "Attr>(A);\n";
|
||||
if (R.isSubClassOf(InhClass))
|
||||
OS << " Record.push_back(SA->isInherited());\n";
|
||||
for (ai = Args.begin(), ae = Args.end(); ai != ae; ++ai)
|
||||
createArgument(**ai, R.getName())->writePCHWrite(OS);
|
||||
OS << " break;\n";
|
||||
|
Loading…
Reference in New Issue
Block a user