mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
Add initial implementation of a TableGen backend for converting Clang-warnings
tablegen files to the original .def preprocessor include files. This is my first TableGen backend; I don't claim that it is awesome. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66971 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
02475f1fd5
commit
04a847e706
@ -19,6 +19,7 @@ add_executable(tblgen
|
||||
TableGen.cpp
|
||||
TableGenBackend.cpp
|
||||
FastISelEmitter.cpp
|
||||
ClangDiagnosticsEmitter.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(tblgen LLVMSupport LLVMSystem)
|
||||
|
84
utils/TableGen/ClangDiagnosticsEmitter.cpp
Normal file
84
utils/TableGen/ClangDiagnosticsEmitter.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
//=- ClangDiagnosticsEmitter.cpp - Generate Clang diagnostics tables -*- C++ -*-
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// These tablegen backends emit Clang diagnostics tables.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ClangDiagnosticsEmitter.h"
|
||||
#include "Record.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/ADT/VectorExtras.h"
|
||||
|
||||
using namespace llvm;
|
||||
typedef std::vector<Record*> RecordVector;
|
||||
typedef std::vector<Record*> SuperClassVector;
|
||||
typedef std::vector<RecordVal> RecordValVector;
|
||||
|
||||
static const RecordVal* findRecordVal(const RecordValVector& Vals,
|
||||
const std::string &key) {
|
||||
for (RecordValVector::const_iterator I=Vals.begin(), E=Vals.end(); I!=E; ++I)
|
||||
if ((*I).getName() == key)
|
||||
return &*I;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const Record* getDiagKind(const Record* DiagClass, const Record &R) {
|
||||
const SuperClassVector &SC = R.getSuperClasses();
|
||||
for (SuperClassVector::const_iterator I=SC.begin(), E=SC.end(); I!=E; ++I)
|
||||
if ((*I)->isSubClassOf(DiagClass))
|
||||
return *I;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void EmitEscaped(std::ostream& OS, const std::string &s) {
|
||||
for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I)
|
||||
switch (*I) {
|
||||
default: OS << *I; break;
|
||||
case '\"': OS << "\\" << *I; break;
|
||||
case '\\': OS << "\\\\"; break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessDiag(std::ostream& OS, const Record* DiagClass,
|
||||
const Record& R) {
|
||||
|
||||
const Record* DiagKind = getDiagKind(DiagClass, R);
|
||||
if (!DiagKind)
|
||||
return;
|
||||
|
||||
OS << "DIAG(" << R.getName() << ", ";
|
||||
|
||||
const std::string &s = DiagKind->getName();
|
||||
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.");
|
||||
const StringInit* TextVal = dynamic_cast<const StringInit*>(Text->getValue());
|
||||
assert(TextVal && "Value 'Text' must be a string.");
|
||||
OS << ", \"";
|
||||
EmitEscaped(OS, TextVal->getValue());
|
||||
OS << "\")\n";
|
||||
}
|
||||
|
||||
void ClangDiagsDefsEmitter::run(std::ostream &OS) {
|
||||
const RecordVector &Diags = Records.getAllDerivedDefinitions("Diagnostic");
|
||||
|
||||
const Record* DiagClass = Records.getClass("Diagnostic");
|
||||
assert(DiagClass && "No Diagnostic class defined.");
|
||||
|
||||
for (RecordVector::const_iterator I=Diags.begin(), E=Diags.end(); I!=E; ++I) {
|
||||
// FIXME: Compare the component.
|
||||
ProcessDiag(OS, DiagClass, **I);
|
||||
}
|
||||
}
|
35
utils/TableGen/ClangDiagnosticsEmitter.h
Normal file
35
utils/TableGen/ClangDiagnosticsEmitter.h
Normal file
@ -0,0 +1,35 @@
|
||||
//===- ClangDiagnosticsEmitter.h - Generate Clang diagnostics tables -*- C++ -*-
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// These tablegen backends emit Clang diagnostics tables.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CLANGDIAGS_EMITTER_H
|
||||
#define CLANGDIAGS_EMITTER_H
|
||||
|
||||
#include "TableGenBackend.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// ClangDiagsDefsEmitter - The top-level class emits .def files containing
|
||||
/// declarations of Clang diagnostics.
|
||||
///
|
||||
class ClangDiagsDefsEmitter : public TableGenBackend {
|
||||
RecordKeeper &Records;
|
||||
public:
|
||||
explicit ClangDiagsDefsEmitter(RecordKeeper &R) : Records(R) {}
|
||||
|
||||
// run - Output the .def file contents
|
||||
void run(std::ostream &OS);
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
@ -34,6 +34,7 @@
|
||||
#include "SubtargetEmitter.h"
|
||||
#include "IntrinsicEmitter.h"
|
||||
#include "LLVMCConfigurationEmitter.h"
|
||||
#include "ClangDiagnosticsEmitter.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
@ -46,6 +47,7 @@ enum ActionType {
|
||||
GenRegisterEnums, GenRegister, GenRegisterHeader,
|
||||
GenInstrEnums, GenInstrs, GenAsmWriter,
|
||||
GenCallingConv,
|
||||
GenClangDiagsDefs,
|
||||
GenDAGISel,
|
||||
GenFastISel,
|
||||
GenSubtarget,
|
||||
@ -86,6 +88,8 @@ namespace {
|
||||
"Generate intrinsic information"),
|
||||
clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
|
||||
"Generate target intrinsic information"),
|
||||
clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
|
||||
"Generate Clang diagnostics definitions"),
|
||||
clEnumValN(GenLLVMCConf, "gen-llvmc",
|
||||
"Generate LLVMC configuration library"),
|
||||
clEnumValN(PrintEnums, "print-enums",
|
||||
@ -185,7 +189,6 @@ int main(int argc, char **argv) {
|
||||
case GenRegisterHeader:
|
||||
RegisterInfoEmitter(Records).runHeader(*Out);
|
||||
break;
|
||||
|
||||
case GenInstrEnums:
|
||||
InstrEnumEmitter(Records).run(*Out);
|
||||
break;
|
||||
@ -198,7 +201,9 @@ int main(int argc, char **argv) {
|
||||
case GenAsmWriter:
|
||||
AsmWriterEmitter(Records).run(*Out);
|
||||
break;
|
||||
|
||||
case GenClangDiagsDefs:
|
||||
ClangDiagsDefsEmitter(Records).run(*Out);
|
||||
break;
|
||||
case GenDAGISel:
|
||||
DAGISelEmitter(Records).run(*Out);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user