From 9973291e83bebe731132a0f7645ead7426dbc10c Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 28 Feb 2015 22:16:56 +0000 Subject: [PATCH] AsmWriter: Extract writeStringField(), NFCI Extract logic for escaping a string field in the new debug info hierarchy from `GenericDebugNode`. A follow-up commit will use it far more widely (hence the dead code for `ShouldSkipEmpty`). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230873 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/AsmWriter.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 51be1b00f21..05aa3c5c6d9 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1306,17 +1306,24 @@ static void writeTag(raw_ostream &Out, FieldSeparator &FS, const DebugNode *N) { Out << N->getTag(); } +static void writeStringField(raw_ostream &Out, FieldSeparator &FS, + StringRef Name, StringRef Value, + bool ShouldSkipEmpty = true) { + if (ShouldSkipEmpty && Value.empty()) + return; + + Out << FS << Name << ": \""; + PrintEscapedString(Value, Out); + Out << "\""; +} + static void writeGenericDebugNode(raw_ostream &Out, const GenericDebugNode *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context) { Out << "!GenericDebugNode("; FieldSeparator FS; writeTag(Out, FS, N); - if (!N->getHeader().empty()) { - Out << FS << "header: \""; - PrintEscapedString(N->getHeader(), Out); - Out << "\""; - } + writeStringField(Out, FS, "header", N->getHeader()); if (N->getNumDwarfOperands()) { Out << FS << "operands: {"; FieldSeparator IFS; -- 2.34.1