Add an emitRawComment function and use it to simplify some uses of EmitRawText.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199397 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-01-16 16:28:37 +00:00
parent 1a6226f236
commit 640f8f65a7
6 changed files with 28 additions and 22 deletions

View File

@ -217,6 +217,12 @@ public:
/// use this method. /// use this method.
virtual raw_ostream &GetCommentOS(); 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. /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
virtual void AddBlankLine() {} virtual void AddBlankLine() {}

View File

@ -579,7 +579,7 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
SmallString<128> Str; SmallString<128> Str;
raw_svector_ostream OS(Str); raw_svector_ostream OS(Str);
OS << '\t' << AP.MAI->getCommentString() << "DEBUG_VALUE: "; OS << "DEBUG_VALUE: ";
DIVariable V(MI->getOperand(2).getMetadata()); DIVariable V(MI->getOperand(2).getMetadata());
if (V.getContext().isSubprogram()) { if (V.getContext().isSubprogram()) {
@ -627,7 +627,7 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
// Suppress offset, it is not meaningful here. // Suppress offset, it is not meaningful here.
OS << "undef"; OS << "undef";
// NOTE: Want this comment at start of line, don't emit with AddComment. // 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; return true;
} }
if (Deref) if (Deref)
@ -639,7 +639,7 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
OS << '+' << Offset << ']'; OS << '+' << Offset << ']';
// NOTE: Want this comment at start of line, don't emit with AddComment. // 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; return true;
} }
@ -2155,8 +2155,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) { if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) {
if (isVerbose() && OutStreamer.hasRawTextSupport()) { if (isVerbose() && OutStreamer.hasRawTextSupport()) {
// NOTE: Want this comment at start of line, don't emit with AddComment. // NOTE: Want this comment at start of line, don't emit with AddComment.
OutStreamer.EmitRawText(Twine(MAI->getCommentString()) + " BB#" + OutStreamer.emitRawComment(" BB#" + Twine(MBB->getNumber()) + ":", false);
Twine(MBB->getNumber()) + ":");
} }
} else { } else {
OutStreamer.EmitLabel(MBB->getSymbol()); OutStreamer.EmitLabel(MBB->getSymbol());

View File

@ -428,21 +428,14 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
// If this asmstr is empty, just print the #APP/#NOAPP markers. // If this asmstr is empty, just print the #APP/#NOAPP markers.
// These are useful to see where empty asm's wound up. // These are useful to see where empty asm's wound up.
if (AsmStr[0] == 0) { if (AsmStr[0] == 0) {
// Don't emit the comments if writing to a .o file. OutStreamer.emitRawComment(MAI->getInlineAsmStart());
if (!OutStreamer.hasRawTextSupport()) return; OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmStart());
OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmEnd());
return; return;
} }
// Emit the #APP start marker. This has to happen even if verbose-asm isn't // Emit the #APP start marker. This has to happen even if verbose-asm isn't
// enabled, so we use EmitRawText. // enabled, so we use emitRawComment.
if (OutStreamer.hasRawTextSupport()) OutStreamer.emitRawComment(MAI->getInlineAsmStart());
OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmStart());
// Get the !srcloc metadata node if we have it, and decode the loc cookie from // Get the !srcloc metadata node if we have it, and decode the loc cookie from
// it. // it.
@ -477,10 +470,8 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
EmitInlineAsm(OS.str(), LocMD, MI->getInlineAsmDialect()); EmitInlineAsm(OS.str(), LocMD, MI->getInlineAsmDialect());
// Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
// enabled, so we use EmitRawText. // enabled, so we use emitRawComment.
if (OutStreamer.hasRawTextSupport()) OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmEnd());
} }

View File

@ -115,6 +115,8 @@ public:
return CommentStream; 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. /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
virtual void AddBlankLine() { virtual void AddBlankLine() {
EmitEOL(); EmitEOL();
@ -311,6 +313,13 @@ static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8)); 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, void MCAsmStreamer::ChangeSection(const MCSection *Section,
const MCExpr *Subsection) { const MCExpr *Subsection) {
assert(Section && "Cannot switch to a null section!"); assert(Section && "Cannot switch to a null section!");

View File

@ -81,6 +81,8 @@ raw_ostream &MCStreamer::GetCommentOS() {
return nulls(); return nulls();
} }
void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
for (std::vector<MCDwarfFrameInfo>::iterator I = FrameInfos.begin(), for (std::vector<MCDwarfFrameInfo>::iterator I = FrameInfos.begin(),
E = FrameInfos.end(); I != E; ++I) E = FrameInfos.end(); I != E; ++I)

View File

@ -783,8 +783,7 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
// Emit nothing here but a comment if we can. // Emit nothing here but a comment if we can.
case X86::Int_MemBarrier: case X86::Int_MemBarrier:
if (OutStreamer.hasRawTextSupport()) OutStreamer.emitRawComment("MEMBARRIER");
OutStreamer.EmitRawText(StringRef("\t#MEMBARRIER"));
return; return;