serialized diagnostics: serialize the version info in a separate meta block.

llvm-svn: 144115
This commit is contained in:
Ted Kremenek 2011-11-08 20:27:29 +00:00
parent 0d58033bdb
commit cc88d264eb
2 changed files with 40 additions and 23 deletions

View File

@ -23,12 +23,18 @@ class DiagnosticsEngine;
namespace serialized_diags {
enum BlockIDs {
/// \brief The DIAG block, which acts as a container around a diagnostic.
BLOCK_DIAG = llvm::bitc::FIRST_APPLICATION_BLOCKID
/// \brief A top-level block which represents any meta data associated
/// with the diagostics, including versioning of the format.
BLOCK_META = llvm::bitc::FIRST_APPLICATION_BLOCKID,
/// \brief The this block acts as a container for all the information
/// for a specific diagnostic.
BLOCK_DIAG
};
enum RecordIDs {
RECORD_DIAG = 1,
RECORD_VERSION = 1,
RECORD_DIAG,
RECORD_SOURCE_RANGE,
RECORD_DIAG_FLAG,
RECORD_CATEGORY,

View File

@ -22,20 +22,6 @@ using namespace clang;
using namespace clang::serialized_diags;
namespace {
/// \brief A utility class for entering and exiting bitstream blocks.
class BlockEnterExit {
llvm::BitstreamWriter &Stream;
public:
BlockEnterExit(llvm::BitstreamWriter &stream, unsigned blockID,
unsigned codelen = 3)
: Stream(stream) {
Stream.EnterSubblock(blockID, codelen);
}
~BlockEnterExit() {
Stream.ExitBlock();
}
};
class AbbreviationMap {
llvm::DenseMap<unsigned, unsigned> Abbrevs;
@ -85,6 +71,9 @@ private:
/// \brief Emit the BLOCKINFO block.
void EmitBlockInfoBlock();
/// \brief Emit the META data block.
void EmitMetaBlock();
/// \brief Emit a record for a CharSourceRange.
void EmitCharSourceRange(CharSourceRange R);
@ -257,9 +246,12 @@ void SDiagsWriter::EmitCharSourceRange(CharSourceRange R) {
void SDiagsWriter::EmitPreamble() {
// Emit the file header.
Stream.Emit((unsigned)'D', 8);
Stream.Emit((unsigned) Version, 32 - 8);
Stream.Emit((unsigned)'I', 8);
Stream.Emit((unsigned)'A', 8);
Stream.Emit((unsigned)'G', 8);
EmitBlockInfoBlock();
EmitMetaBlock();
}
static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
@ -277,7 +269,20 @@ static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
void SDiagsWriter::EmitBlockInfoBlock() {
Stream.EnterBlockInfoBlock(3);
using namespace llvm;
// ==---------------------------------------------------------------------==//
// The subsequent records and Abbrevs are for the "Meta" block.
// ==---------------------------------------------------------------------==//
EmitBlockID(BLOCK_META, "Meta", Stream, Record);
EmitRecordID(RECORD_VERSION, "Version", Stream, Record);
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(RECORD_VERSION));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
Abbrevs.set(RECORD_VERSION, Stream.EmitBlockInfoAbbrev(BLOCK_META, Abbrev));
// ==---------------------------------------------------------------------==//
// The subsequent records and Abbrevs are for the "Diagnostic" block.
// ==---------------------------------------------------------------------==//
@ -290,11 +295,8 @@ void SDiagsWriter::EmitBlockInfoBlock() {
EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
EmitRecordID(RECORD_FIXIT, "FixIt", Stream, Record);
// Emit Abbrevs.
using namespace llvm;
// Emit abbreviation for RECORD_DIAG.
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Diag level.
AddSourceLocationAbbrev(Abbrev);
@ -351,6 +353,15 @@ void SDiagsWriter::EmitBlockInfoBlock() {
Stream.ExitBlock();
}
void SDiagsWriter::EmitMetaBlock() {
Stream.EnterSubblock(BLOCK_META, 3);
Record.clear();
Record.push_back(RECORD_VERSION);
Record.push_back(Version);
Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
Stream.ExitBlock();
}
unsigned SDiagsWriter::getEmitCategory(unsigned int DiagID) {
unsigned category = DiagnosticIDs::getCategoryNumberForDiag(DiagID);