AsmWriter: Extract writeStringField(), NFCI
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 28 Feb 2015 22:16:56 +0000 (22:16 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 28 Feb 2015 22:16:56 +0000 (22:16 +0000)
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`).

llvm-svn: 230873

llvm/lib/IR/AsmWriter.cpp

index 51be1b0..05aa3c5 100644 (file)
@@ -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;