mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-13 06:34:24 +00:00
Add (hidden) TableGen command option '-clang-component' which specifies the
component's warnings to process for '-gen-clang-diags-defs'. Also, when the component is specified, generate a '#if' prologue at the top of the generated .def file (to match the current files). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66975 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
04a847e706
commit
557f7f88ba
@ -22,8 +22,8 @@ typedef std::vector<Record*> RecordVector;
|
|||||||
typedef std::vector<Record*> SuperClassVector;
|
typedef std::vector<Record*> SuperClassVector;
|
||||||
typedef std::vector<RecordVal> RecordValVector;
|
typedef std::vector<RecordVal> RecordValVector;
|
||||||
|
|
||||||
static const RecordVal* findRecordVal(const RecordValVector& Vals,
|
static const RecordVal* findRecordVal(const Record& R, const std::string &key) {
|
||||||
const std::string &key) {
|
const RecordValVector &Vals = R.getValues();
|
||||||
for (RecordValVector::const_iterator I=Vals.begin(), E=Vals.end(); I!=E; ++I)
|
for (RecordValVector::const_iterator I=Vals.begin(), E=Vals.end(); I!=E; ++I)
|
||||||
if ((*I).getName() == key)
|
if ((*I).getName() == key)
|
||||||
return &*I;
|
return &*I;
|
||||||
@ -49,6 +49,11 @@ static void EmitEscaped(std::ostream& OS, const std::string &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void EmitAllCaps(std::ostream& OS, const std::string &s) {
|
||||||
|
for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I)
|
||||||
|
OS << char(toupper(*I));
|
||||||
|
}
|
||||||
|
|
||||||
static void ProcessDiag(std::ostream& OS, const Record* DiagClass,
|
static void ProcessDiag(std::ostream& OS, const Record* DiagClass,
|
||||||
const Record& R) {
|
const Record& R) {
|
||||||
|
|
||||||
@ -57,12 +62,9 @@ static void ProcessDiag(std::ostream& OS, const Record* DiagClass,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
OS << "DIAG(" << R.getName() << ", ";
|
OS << "DIAG(" << R.getName() << ", ";
|
||||||
|
EmitAllCaps(OS, DiagKind->getName());
|
||||||
|
|
||||||
const std::string &s = DiagKind->getName();
|
const RecordVal* Text = findRecordVal(R, "Text");
|
||||||
for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I)
|
|
||||||
OS << char(toupper(*I));
|
|
||||||
|
|
||||||
const RecordVal* Text = findRecordVal(R.getValues(), "Text");
|
|
||||||
assert(Text && "No 'Text' entry in Diagnostic.");
|
assert(Text && "No 'Text' entry in Diagnostic.");
|
||||||
const StringInit* TextVal = dynamic_cast<const StringInit*>(Text->getValue());
|
const StringInit* TextVal = dynamic_cast<const StringInit*>(Text->getValue());
|
||||||
assert(TextVal && "Value 'Text' must be a string.");
|
assert(TextVal && "Value 'Text' must be a string.");
|
||||||
@ -77,8 +79,30 @@ void ClangDiagsDefsEmitter::run(std::ostream &OS) {
|
|||||||
const Record* DiagClass = Records.getClass("Diagnostic");
|
const Record* DiagClass = Records.getClass("Diagnostic");
|
||||||
assert(DiagClass && "No Diagnostic class defined.");
|
assert(DiagClass && "No Diagnostic class defined.");
|
||||||
|
|
||||||
|
// Write the #if guard
|
||||||
|
if (!Component.empty()) {
|
||||||
|
OS << "#ifdef ";
|
||||||
|
EmitAllCaps(OS, Component);
|
||||||
|
OS << "START\n__";
|
||||||
|
EmitAllCaps(OS, Component);
|
||||||
|
OS << "START = DIAG_START_";
|
||||||
|
EmitAllCaps(OS, Component);
|
||||||
|
OS << ",\n#undef ";
|
||||||
|
EmitAllCaps(OS, Component);
|
||||||
|
OS << "START\n#endif\n";
|
||||||
|
}
|
||||||
|
|
||||||
for (RecordVector::const_iterator I=Diags.begin(), E=Diags.end(); I!=E; ++I) {
|
for (RecordVector::const_iterator I=Diags.begin(), E=Diags.end(); I!=E; ++I) {
|
||||||
// FIXME: Compare the component.
|
if (!Component.empty()) {
|
||||||
|
const RecordVal* V = findRecordVal(**I, "Component");
|
||||||
|
if (!V)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const StringInit* SV = dynamic_cast<const StringInit*>(V->getValue());
|
||||||
|
if (SV->getValue() != Component)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ProcessDiag(OS, DiagClass, **I);
|
ProcessDiag(OS, DiagClass, **I);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,8 +23,10 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
class ClangDiagsDefsEmitter : public TableGenBackend {
|
class ClangDiagsDefsEmitter : public TableGenBackend {
|
||||||
RecordKeeper &Records;
|
RecordKeeper &Records;
|
||||||
|
const std::string& Component;
|
||||||
public:
|
public:
|
||||||
explicit ClangDiagsDefsEmitter(RecordKeeper &R) : Records(R) {}
|
explicit ClangDiagsDefsEmitter(RecordKeeper &R, const std::string& component)
|
||||||
|
: Records(R), Component(component) {}
|
||||||
|
|
||||||
// run - Output the .def file contents
|
// run - Output the .def file contents
|
||||||
void run(std::ostream &OS);
|
void run(std::ostream &OS);
|
||||||
|
@ -110,6 +110,11 @@ namespace {
|
|||||||
cl::list<std::string>
|
cl::list<std::string>
|
||||||
IncludeDirs("I", cl::desc("Directory of include files"),
|
IncludeDirs("I", cl::desc("Directory of include files"),
|
||||||
cl::value_desc("directory"), cl::Prefix);
|
cl::value_desc("directory"), cl::Prefix);
|
||||||
|
|
||||||
|
cl::opt<std::string>
|
||||||
|
ClangComponent("clang-component",
|
||||||
|
cl::desc("Only use warnings from specified component"),
|
||||||
|
cl::value_desc("component"), cl::Hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +207,7 @@ int main(int argc, char **argv) {
|
|||||||
AsmWriterEmitter(Records).run(*Out);
|
AsmWriterEmitter(Records).run(*Out);
|
||||||
break;
|
break;
|
||||||
case GenClangDiagsDefs:
|
case GenClangDiagsDefs:
|
||||||
ClangDiagsDefsEmitter(Records).run(*Out);
|
ClangDiagsDefsEmitter(Records, ClangComponent).run(*Out);
|
||||||
break;
|
break;
|
||||||
case GenDAGISel:
|
case GenDAGISel:
|
||||||
DAGISelEmitter(Records).run(*Out);
|
DAGISelEmitter(Records).run(*Out);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user