1 //===--- SerializedDiagnosticPrinter.cpp - Serializer for diagnostics -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "llvm/Support/raw_ostream.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "clang/Basic/DiagnosticOptions.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "clang/Basic/FileManager.h"
18 #include "clang/Basic/Diagnostic.h"
19 #include "clang/Basic/Version.h"
20 #include "clang/Lex/Lexer.h"
21 #include "clang/Frontend/SerializedDiagnosticPrinter.h"
22 #include "clang/Frontend/DiagnosticRenderer.h"
24 using namespace clang;
25 using namespace clang::serialized_diags;
29 class AbbreviationMap {
30 llvm::DenseMap<unsigned, unsigned> Abbrevs;
34 void set(unsigned recordID, unsigned abbrevID) {
35 assert(Abbrevs.find(recordID) == Abbrevs.end()
36 && "Abbreviation already set.");
37 Abbrevs[recordID] = abbrevID;
40 unsigned get(unsigned recordID) {
41 assert(Abbrevs.find(recordID) != Abbrevs.end() &&
42 "Abbreviation not set.");
43 return Abbrevs[recordID];
47 typedef llvm::SmallVector<uint64_t, 64> RecordData;
48 typedef llvm::SmallVectorImpl<uint64_t> RecordDataImpl;
52 class SDiagsRenderer : public DiagnosticNoteRenderer {
55 SDiagsRenderer(SDiagsWriter &Writer, const LangOptions &LangOpts,
56 DiagnosticOptions *DiagOpts)
57 : DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {}
59 virtual ~SDiagsRenderer() {}
62 virtual void emitDiagnosticMessage(SourceLocation Loc,
64 DiagnosticsEngine::Level Level,
66 ArrayRef<CharSourceRange> Ranges,
67 const SourceManager *SM,
70 virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
71 DiagnosticsEngine::Level Level,
72 ArrayRef<CharSourceRange> Ranges,
73 const SourceManager &SM) {}
75 virtual void emitNote(SourceLocation Loc, StringRef Message,
76 const SourceManager *SM);
78 virtual void emitCodeContext(SourceLocation Loc,
79 DiagnosticsEngine::Level Level,
80 SmallVectorImpl<CharSourceRange>& Ranges,
81 ArrayRef<FixItHint> Hints,
82 const SourceManager &SM);
84 virtual void beginDiagnostic(DiagOrStoredDiag D,
85 DiagnosticsEngine::Level Level);
86 virtual void endDiagnostic(DiagOrStoredDiag D,
87 DiagnosticsEngine::Level Level);
90 class SDiagsWriter : public DiagnosticConsumer {
91 friend class SDiagsRenderer;
93 explicit SDiagsWriter(llvm::raw_ostream *os, DiagnosticOptions *diags)
94 : LangOpts(0), DiagOpts(diags), Stream(Buffer), OS(os),
95 EmittedAnyDiagBlocks(false) {
101 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
102 const Diagnostic &Info);
104 void BeginSourceFile(const LangOptions &LO,
105 const Preprocessor *PP) {
109 virtual void finish();
111 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
112 // It makes no sense to clone this.
117 /// \brief Emit the preamble for the serialized diagnostics.
120 /// \brief Emit the BLOCKINFO block.
121 void EmitBlockInfoBlock();
123 /// \brief Emit the META data block.
124 void EmitMetaBlock();
126 /// \brief Start a DIAG block.
127 void EnterDiagBlock();
129 /// \brief End a DIAG block.
130 void ExitDiagBlock();
132 /// \brief Emit a DIAG record.
133 void EmitDiagnosticMessage(SourceLocation Loc,
135 DiagnosticsEngine::Level Level,
137 const SourceManager *SM,
140 /// \brief Emit FIXIT and SOURCE_RANGE records for a diagnostic.
141 void EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges,
142 ArrayRef<FixItHint> Hints,
143 const SourceManager &SM);
145 /// \brief Emit a record for a CharSourceRange.
146 void EmitCharSourceRange(CharSourceRange R, const SourceManager &SM);
148 /// \brief Emit the string information for the category.
149 unsigned getEmitCategory(unsigned category = 0);
151 /// \brief Emit the string information for diagnostic flags.
152 unsigned getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
153 unsigned DiagID = 0);
155 /// \brief Emit (lazily) the file string and retrieved the file identifier.
156 unsigned getEmitFile(const char *Filename);
158 /// \brief Add SourceLocation information the specified record.
159 void AddLocToRecord(SourceLocation Loc, const SourceManager *SM,
160 PresumedLoc PLoc, RecordDataImpl &Record,
161 unsigned TokSize = 0);
163 /// \brief Add SourceLocation information the specified record.
164 void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record,
165 const SourceManager *SM,
166 unsigned TokSize = 0) {
167 AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(),
171 /// \brief Add CharSourceRange information the specified record.
172 void AddCharSourceRangeToRecord(CharSourceRange R, RecordDataImpl &Record,
173 const SourceManager &SM);
175 /// \brief The version of the diagnostics file.
176 enum { Version = 1 };
178 const LangOptions *LangOpts;
179 llvm::IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
181 /// \brief The byte buffer for the serialized content.
182 SmallString<1024> Buffer;
184 /// \brief The BitStreamWriter for the serialized diagnostics.
185 llvm::BitstreamWriter Stream;
187 /// \brief The name of the diagnostics file.
188 OwningPtr<llvm::raw_ostream> OS;
190 /// \brief The set of constructed record abbreviations.
191 AbbreviationMap Abbrevs;
193 /// \brief A utility buffer for constructing record content.
196 /// \brief A text buffer for rendering diagnostic text.
197 SmallString<256> diagBuf;
199 /// \brief The collection of diagnostic categories used.
200 llvm::DenseSet<unsigned> Categories;
202 /// \brief The collection of files used.
203 llvm::DenseMap<const char *, unsigned> Files;
205 typedef llvm::DenseMap<const void *, std::pair<unsigned, llvm::StringRef> >
208 /// \brief Map for uniquing strings.
209 DiagFlagsTy DiagFlags;
211 /// \brief Whether we have already started emission of any DIAG blocks. Once
212 /// this becomes \c true, we never close a DIAG block until we know that we're
213 /// starting another one or we're done.
214 bool EmittedAnyDiagBlocks;
216 } // end anonymous namespace
219 namespace serialized_diags {
220 DiagnosticConsumer *create(llvm::raw_ostream *OS,
221 DiagnosticOptions *diags) {
222 return new SDiagsWriter(OS, diags);
224 } // end namespace serialized_diags
225 } // end namespace clang
227 //===----------------------------------------------------------------------===//
228 // Serialization methods.
229 //===----------------------------------------------------------------------===//
231 /// \brief Emits a block ID in the BLOCKINFO block.
232 static void EmitBlockID(unsigned ID, const char *Name,
233 llvm::BitstreamWriter &Stream,
234 RecordDataImpl &Record) {
236 Record.push_back(ID);
237 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
239 // Emit the block name if present.
240 if (Name == 0 || Name[0] == 0)
246 Record.push_back(*Name++);
248 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
251 /// \brief Emits a record ID in the BLOCKINFO block.
252 static void EmitRecordID(unsigned ID, const char *Name,
253 llvm::BitstreamWriter &Stream,
254 RecordDataImpl &Record){
256 Record.push_back(ID);
259 Record.push_back(*Name++);
261 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
264 void SDiagsWriter::AddLocToRecord(SourceLocation Loc,
265 const SourceManager *SM,
267 RecordDataImpl &Record,
269 if (PLoc.isInvalid()) {
270 // Emit a "sentinel" location.
271 Record.push_back((unsigned)0); // File.
272 Record.push_back((unsigned)0); // Line.
273 Record.push_back((unsigned)0); // Column.
274 Record.push_back((unsigned)0); // Offset.
278 Record.push_back(getEmitFile(PLoc.getFilename()));
279 Record.push_back(PLoc.getLine());
280 Record.push_back(PLoc.getColumn()+TokSize);
281 Record.push_back(SM->getFileOffset(Loc));
284 void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range,
285 RecordDataImpl &Record,
286 const SourceManager &SM) {
287 AddLocToRecord(Range.getBegin(), Record, &SM);
288 unsigned TokSize = 0;
289 if (Range.isTokenRange())
290 TokSize = Lexer::MeasureTokenLength(Range.getEnd(),
293 AddLocToRecord(Range.getEnd(), Record, &SM, TokSize);
296 unsigned SDiagsWriter::getEmitFile(const char *FileName){
300 unsigned &entry = Files[FileName];
304 // Lazily generate the record for the file.
305 entry = Files.size();
307 Record.push_back(RECORD_FILENAME);
308 Record.push_back(entry);
309 Record.push_back(0); // For legacy.
310 Record.push_back(0); // For legacy.
311 StringRef Name(FileName);
312 Record.push_back(Name.size());
313 Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FILENAME), Record, Name);
318 void SDiagsWriter::EmitCharSourceRange(CharSourceRange R,
319 const SourceManager &SM) {
321 Record.push_back(RECORD_SOURCE_RANGE);
322 AddCharSourceRangeToRecord(R, Record, SM);
323 Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_SOURCE_RANGE), Record);
326 /// \brief Emits the preamble of the diagnostics file.
327 void SDiagsWriter::EmitPreamble() {
328 // Emit the file header.
329 Stream.Emit((unsigned)'D', 8);
330 Stream.Emit((unsigned)'I', 8);
331 Stream.Emit((unsigned)'A', 8);
332 Stream.Emit((unsigned)'G', 8);
334 EmitBlockInfoBlock();
338 static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
339 using namespace llvm;
340 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // File ID.
341 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Line.
342 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Column.
343 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Offset;
346 static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
347 AddSourceLocationAbbrev(Abbrev);
348 AddSourceLocationAbbrev(Abbrev);
351 void SDiagsWriter::EmitBlockInfoBlock() {
352 Stream.EnterBlockInfoBlock(3);
354 using namespace llvm;
356 // ==---------------------------------------------------------------------==//
357 // The subsequent records and Abbrevs are for the "Meta" block.
358 // ==---------------------------------------------------------------------==//
360 EmitBlockID(BLOCK_META, "Meta", Stream, Record);
361 EmitRecordID(RECORD_VERSION, "Version", Stream, Record);
362 BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
363 Abbrev->Add(BitCodeAbbrevOp(RECORD_VERSION));
364 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
365 Abbrevs.set(RECORD_VERSION, Stream.EmitBlockInfoAbbrev(BLOCK_META, Abbrev));
367 // ==---------------------------------------------------------------------==//
368 // The subsequent records and Abbrevs are for the "Diagnostic" block.
369 // ==---------------------------------------------------------------------==//
371 EmitBlockID(BLOCK_DIAG, "Diag", Stream, Record);
372 EmitRecordID(RECORD_DIAG, "DiagInfo", Stream, Record);
373 EmitRecordID(RECORD_SOURCE_RANGE, "SrcRange", Stream, Record);
374 EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
375 EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
376 EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
377 EmitRecordID(RECORD_FIXIT, "FixIt", Stream, Record);
379 // Emit abbreviation for RECORD_DIAG.
380 Abbrev = new BitCodeAbbrev();
381 Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG));
382 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Diag level.
383 AddSourceLocationAbbrev(Abbrev);
384 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Category.
385 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID.
386 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
387 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Diagnostc text.
388 Abbrevs.set(RECORD_DIAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
390 // Emit abbrevation for RECORD_CATEGORY.
391 Abbrev = new BitCodeAbbrev();
392 Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY));
393 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Category ID.
394 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // Text size.
395 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Category text.
396 Abbrevs.set(RECORD_CATEGORY, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
398 // Emit abbrevation for RECORD_SOURCE_RANGE.
399 Abbrev = new BitCodeAbbrev();
400 Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_RANGE));
401 AddRangeLocationAbbrev(Abbrev);
402 Abbrevs.set(RECORD_SOURCE_RANGE,
403 Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
405 // Emit the abbreviation for RECORD_DIAG_FLAG.
406 Abbrev = new BitCodeAbbrev();
407 Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG_FLAG));
408 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID.
409 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
410 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Flag name text.
411 Abbrevs.set(RECORD_DIAG_FLAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
414 // Emit the abbreviation for RECORD_FILENAME.
415 Abbrev = new BitCodeAbbrev();
416 Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME));
417 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped file ID.
418 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Size.
419 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modifcation time.
420 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
421 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text.
422 Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
425 // Emit the abbreviation for RECORD_FIXIT.
426 Abbrev = new BitCodeAbbrev();
427 Abbrev->Add(BitCodeAbbrevOp(RECORD_FIXIT));
428 AddRangeLocationAbbrev(Abbrev);
429 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
430 Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // FixIt text.
431 Abbrevs.set(RECORD_FIXIT, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
437 void SDiagsWriter::EmitMetaBlock() {
438 Stream.EnterSubblock(BLOCK_META, 3);
440 Record.push_back(RECORD_VERSION);
441 Record.push_back(Version);
442 Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
446 unsigned SDiagsWriter::getEmitCategory(unsigned int category) {
447 if (Categories.count(category))
450 Categories.insert(category);
452 // We use a local version of 'Record' so that we can be generating
453 // another record when we lazily generate one for the category entry.
455 Record.push_back(RECORD_CATEGORY);
456 Record.push_back(category);
457 StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
458 Record.push_back(catName.size());
459 Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_CATEGORY), Record, catName);
464 unsigned SDiagsWriter::getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
466 if (DiagLevel == DiagnosticsEngine::Note)
467 return 0; // No flag for notes.
469 StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(DiagID);
470 if (FlagName.empty())
473 // Here we assume that FlagName points to static data whose pointer
474 // value is fixed. This allows us to unique by diagnostic groups.
475 const void *data = FlagName.data();
476 std::pair<unsigned, StringRef> &entry = DiagFlags[data];
477 if (entry.first == 0) {
478 entry.first = DiagFlags.size();
479 entry.second = FlagName;
481 // Lazily emit the string in a separate record.
483 Record.push_back(RECORD_DIAG_FLAG);
484 Record.push_back(entry.first);
485 Record.push_back(FlagName.size());
486 Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG_FLAG),
493 void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
494 const Diagnostic &Info) {
495 // Enter the block for a non-note diagnostic immediately, rather than waiting
496 // for beginDiagnostic, in case associated notes are emitted before we get
498 if (DiagLevel != DiagnosticsEngine::Note) {
499 if (EmittedAnyDiagBlocks)
503 EmittedAnyDiagBlocks = true;
506 // Compute the diagnostic text.
508 Info.FormatDiagnostic(diagBuf);
510 if (Info.getLocation().isInvalid()) {
511 // Special-case diagnostics with no location. We may not have entered a
512 // source file in this case, so we can't use the normal DiagnosticsRenderer
514 EmitDiagnosticMessage(SourceLocation(), PresumedLoc(), DiagLevel,
519 assert(Info.hasSourceManager() && LangOpts &&
520 "Unexpected diagnostic with valid location outside of a source file");
521 SDiagsRenderer Renderer(*this, *LangOpts, &*DiagOpts);
522 Renderer.emitDiagnostic(Info.getLocation(), DiagLevel,
525 llvm::makeArrayRef(Info.getFixItHints(),
526 Info.getNumFixItHints()),
527 &Info.getSourceManager(),
531 void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc,
533 DiagnosticsEngine::Level Level,
535 const SourceManager *SM,
536 DiagOrStoredDiag D) {
537 // Emit the RECORD_DIAG record.
539 Record.push_back(RECORD_DIAG);
540 Record.push_back(Level);
541 AddLocToRecord(Loc, SM, PLoc, Record);
543 if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) {
544 // Emit the category string lazily and get the category ID.
545 unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID());
546 Record.push_back(getEmitCategory(DiagID));
547 // Emit the diagnostic flag string lazily and get the mapped ID.
548 Record.push_back(getEmitDiagnosticFlag(Level, Info->getID()));
550 Record.push_back(getEmitCategory());
551 Record.push_back(getEmitDiagnosticFlag(Level));
554 Record.push_back(Message.size());
555 Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Message);
559 SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc,
561 DiagnosticsEngine::Level Level,
563 ArrayRef<clang::CharSourceRange> Ranges,
564 const SourceManager *SM,
565 DiagOrStoredDiag D) {
566 Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, SM, D);
569 void SDiagsWriter::EnterDiagBlock() {
570 Stream.EnterSubblock(BLOCK_DIAG, 4);
573 void SDiagsWriter::ExitDiagBlock() {
577 void SDiagsRenderer::beginDiagnostic(DiagOrStoredDiag D,
578 DiagnosticsEngine::Level Level) {
579 if (Level == DiagnosticsEngine::Note)
580 Writer.EnterDiagBlock();
583 void SDiagsRenderer::endDiagnostic(DiagOrStoredDiag D,
584 DiagnosticsEngine::Level Level) {
585 // Only end note diagnostics here, because we can't be sure when we've seen
586 // the last note associated with a non-note diagnostic.
587 if (Level == DiagnosticsEngine::Note)
588 Writer.ExitDiagBlock();
591 void SDiagsWriter::EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges,
592 ArrayRef<FixItHint> Hints,
593 const SourceManager &SM) {
594 // Emit Source Ranges.
595 for (ArrayRef<CharSourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
598 EmitCharSourceRange(*I, SM);
601 for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end();
603 const FixItHint &Fix = *I;
607 Record.push_back(RECORD_FIXIT);
608 AddCharSourceRangeToRecord(Fix.RemoveRange, Record, SM);
609 Record.push_back(Fix.CodeToInsert.size());
610 Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FIXIT), Record,
615 void SDiagsRenderer::emitCodeContext(SourceLocation Loc,
616 DiagnosticsEngine::Level Level,
617 SmallVectorImpl<CharSourceRange> &Ranges,
618 ArrayRef<FixItHint> Hints,
619 const SourceManager &SM) {
620 Writer.EmitCodeContext(Ranges, Hints, SM);
623 void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message,
624 const SourceManager *SM) {
625 Writer.EnterDiagBlock();
626 PresumedLoc PLoc = SM ? SM->getPresumedLoc(Loc) : PresumedLoc();
627 Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note,
628 Message, SM, DiagOrStoredDiag());
629 Writer.ExitDiagBlock();
632 void SDiagsWriter::finish() {
633 // Finish off any diagnostic we were in the process of emitting.
634 if (EmittedAnyDiagBlocks)
637 // Write the generated bitstream to "Out".
638 OS->write((char *)&Buffer.front(), Buffer.size());