[llvm] r199397 - Add an emitRawComment function and use it to simplify some uses of EmitRawText.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jan 16 08:28:37 PST 2014
Author: rafael
Date: Thu Jan 16 10:28:37 2014
New Revision: 199397
URL: http://llvm.org/viewvc/llvm-project?rev=199397&view=rev
Log:
Add an emitRawComment function and use it to simplify some uses of EmitRawText.
Modified:
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCStreamer.cpp
llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Jan 16 10:28:37 2014
@@ -217,6 +217,12 @@ public:
/// use this method.
virtual raw_ostream &GetCommentOS();
+ /// Print T and prefix it with the comment string (normally #) and optionally
+ /// a tab. This prints the comment immediately, not at the end of the
+ /// current line. It is basically a safe version of EmitRawText: since it
+ /// only prints comments, the object streamer ignores it instead of asserting.
+ virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
+
/// AddBlankLine - Emit a blank line to a .s file to pretty it up.
virtual void AddBlankLine() {}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Thu Jan 16 10:28:37 2014
@@ -579,7 +579,7 @@ static bool emitDebugValueComment(const
SmallString<128> Str;
raw_svector_ostream OS(Str);
- OS << '\t' << AP.MAI->getCommentString() << "DEBUG_VALUE: ";
+ OS << "DEBUG_VALUE: ";
DIVariable V(MI->getOperand(2).getMetadata());
if (V.getContext().isSubprogram()) {
@@ -627,7 +627,7 @@ static bool emitDebugValueComment(const
// Suppress offset, it is not meaningful here.
OS << "undef";
// NOTE: Want this comment at start of line, don't emit with AddComment.
- AP.OutStreamer.EmitRawText(OS.str());
+ AP.OutStreamer.emitRawComment(OS.str());
return true;
}
if (Deref)
@@ -639,7 +639,7 @@ static bool emitDebugValueComment(const
OS << '+' << Offset << ']';
// NOTE: Want this comment at start of line, don't emit with AddComment.
- AP.OutStreamer.EmitRawText(OS.str());
+ AP.OutStreamer.emitRawComment(OS.str());
return true;
}
@@ -2155,8 +2155,7 @@ void AsmPrinter::EmitBasicBlockStart(con
if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) {
if (isVerbose() && OutStreamer.hasRawTextSupport()) {
// NOTE: Want this comment at start of line, don't emit with AddComment.
- OutStreamer.EmitRawText(Twine(MAI->getCommentString()) + " BB#" +
- Twine(MBB->getNumber()) + ":");
+ OutStreamer.emitRawComment(" BB#" + Twine(MBB->getNumber()) + ":", false);
}
} else {
OutStreamer.EmitLabel(MBB->getSymbol());
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Thu Jan 16 10:28:37 2014
@@ -428,21 +428,14 @@ void AsmPrinter::EmitInlineAsm(const Mac
// If this asmstr is empty, just print the #APP/#NOAPP markers.
// These are useful to see where empty asm's wound up.
if (AsmStr[0] == 0) {
- // Don't emit the comments if writing to a .o file.
- if (!OutStreamer.hasRawTextSupport()) return;
-
- OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
- MAI->getInlineAsmStart());
- OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
- MAI->getInlineAsmEnd());
+ OutStreamer.emitRawComment(MAI->getInlineAsmStart());
+ OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
return;
}
// Emit the #APP start marker. This has to happen even if verbose-asm isn't
- // enabled, so we use EmitRawText.
- if (OutStreamer.hasRawTextSupport())
- OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
- MAI->getInlineAsmStart());
+ // enabled, so we use emitRawComment.
+ OutStreamer.emitRawComment(MAI->getInlineAsmStart());
// Get the !srcloc metadata node if we have it, and decode the loc cookie from
// it.
@@ -477,10 +470,8 @@ void AsmPrinter::EmitInlineAsm(const Mac
EmitInlineAsm(OS.str(), LocMD, MI->getInlineAsmDialect());
// Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
- // enabled, so we use EmitRawText.
- if (OutStreamer.hasRawTextSupport())
- OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
- MAI->getInlineAsmEnd());
+ // enabled, so we use emitRawComment.
+ OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
}
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Jan 16 10:28:37 2014
@@ -115,6 +115,8 @@ public:
return CommentStream;
}
+ void emitRawComment(const Twine &T, bool TabPrefix = true) LLVM_OVERRIDE;
+
/// AddBlankLine - Emit a blank line to a .s file to pretty it up.
virtual void AddBlankLine() {
EmitEOL();
@@ -311,6 +313,13 @@ static inline int64_t truncateToSize(int
return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
}
+void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
+ if (TabPrefix)
+ OS << '\t';
+ OS << MAI->getCommentString() << T;
+ EmitEOL();
+}
+
void MCAsmStreamer::ChangeSection(const MCSection *Section,
const MCExpr *Subsection) {
assert(Section && "Cannot switch to a null section!");
Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Thu Jan 16 10:28:37 2014
@@ -81,6 +81,8 @@ raw_ostream &MCStreamer::GetCommentOS()
return nulls();
}
+void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
+
void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
for (std::vector<MCDwarfFrameInfo>::iterator I = FrameInfos.begin(),
E = FrameInfos.end(); I != E; ++I)
Modified: llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=199397&r1=199396&r2=199397&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCInstLower.cpp Thu Jan 16 10:28:37 2014
@@ -783,8 +783,7 @@ void X86AsmPrinter::EmitInstruction(cons
// Emit nothing here but a comment if we can.
case X86::Int_MemBarrier:
- if (OutStreamer.hasRawTextSupport())
- OutStreamer.EmitRawText(StringRef("\t#MEMBARRIER"));
+ OutStreamer.emitRawComment("MEMBARRIER");
return;
More information about the llvm-commits
mailing list