add a twine form of MCStreamer::EmitRawText, and mc'ize

a few more things in AsmPrinter.cpp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100294 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-04-03 22:12:35 +00:00
parent d5928dcd78
commit 58bc4dd4a9
3 changed files with 29 additions and 16 deletions

View File

@@ -286,6 +286,7 @@ class TargetAsmBackend;
/// the specified string in the output .s file. This capability is /// the specified string in the output .s file. This capability is
/// indicated by the hasRawTextSupport() predicate. By default this aborts. /// indicated by the hasRawTextSupport() predicate. By default this aborts.
virtual void EmitRawText(StringRef String); virtual void EmitRawText(StringRef String);
void EmitRawText(const Twine &String);
/// Finish - Finish emission of machine code and flush any output. /// Finish - Finish emission of machine code and flush any output.
virtual void Finish() = 0; virtual void Finish() = 0;

View File

@@ -164,7 +164,7 @@ void AsmPrinter::EmitLinkage(unsigned Linkage, MCSymbol *GVSym) const {
// .linkonce discard // .linkonce discard
// FIXME: It would be nice to use .linkonce samesize for non-common // FIXME: It would be nice to use .linkonce samesize for non-common
// globals. // globals.
O << LinkOnce; OutStreamer.EmitRawText(LinkOnce);
} else { } else {
// .weak _foo // .weak _foo
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak); OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
@@ -1386,9 +1386,9 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
if (AsmStr[0] == 0) { if (AsmStr[0] == 0) {
if (!OutStreamer.hasRawTextSupport()) return; if (!OutStreamer.hasRawTextSupport()) return;
OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+ OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmStart()); MAI->getInlineAsmStart());
OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+ OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmEnd()); MAI->getInlineAsmEnd());
return; return;
} }
@@ -1396,7 +1396,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
// 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 EmitRawText.
if (OutStreamer.hasRawTextSupport()) if (OutStreamer.hasRawTextSupport())
OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+ OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmStart()); MAI->getInlineAsmStart());
// Emit the inline asm to a temporary string so we can emit it through // Emit the inline asm to a temporary string so we can emit it through
@@ -1584,7 +1584,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
// 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 EmitRawText.
if (OutStreamer.hasRawTextSupport()) if (OutStreamer.hasRawTextSupport())
OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+ OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
MAI->getInlineAsmEnd()); MAI->getInlineAsmEnd());
} }
@@ -1592,21 +1592,24 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
/// that is an implicit def. /// that is an implicit def.
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const { void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
if (!VerboseAsm) return; if (!VerboseAsm) return;
O.PadToColumn(MAI->getCommentColumn()); OutStreamer.AddComment(Twine("implicit-def: ") +
O << MAI->getCommentString() << " implicit-def: " TRI->getName(MI->getOperand(0).getReg()));
<< TRI->getName(MI->getOperand(0).getReg());
OutStreamer.AddBlankLine(); OutStreamer.AddBlankLine();
} }
void AsmPrinter::printKill(const MachineInstr *MI) const { void AsmPrinter::printKill(const MachineInstr *MI) const {
if (!VerboseAsm) return; if (!VerboseAsm) return;
O.PadToColumn(MAI->getCommentColumn()); O.PadToColumn(MAI->getCommentColumn());
O << MAI->getCommentString() << " kill:";
std::string Str = "kill:";
for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) { for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
const MachineOperand &op = MI->getOperand(n); const MachineOperand &Op = MI->getOperand(n);
assert(op.isReg() && "KILL instruction must have only register operands"); assert(Op.isReg() && "KILL instruction must have only register operands");
O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>"); Str += ' ';
Str += TRI->getName(Op.getReg());
Str += (Op.isDef() ? "<def>" : "<kill>");
} }
OutStreamer.AddComment(Str);
OutStreamer.AddBlankLine(); OutStreamer.AddBlankLine();
} }
@@ -1772,15 +1775,16 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
// Print the main label for the block. // Print the main label for the block.
if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) { if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) {
if (VerboseAsm) { if (VerboseAsm && OutStreamer.hasRawTextSupport()) {
// NOTE: Want this comment at start of line.
O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
if (const BasicBlock *BB = MBB->getBasicBlock()) if (const BasicBlock *BB = MBB->getBasicBlock())
if (BB->hasName()) if (BB->hasName())
OutStreamer.AddComment("%" + BB->getName()); OutStreamer.AddComment("%" + BB->getName());
PrintBasicBlockLoopComments(*MBB, LI, *this); PrintBasicBlockLoopComments(*MBB, LI, *this);
OutStreamer.AddBlankLine();
// NOTE: Want this comment at start of line, don't emit with AddComment.
OutStreamer.EmitRawText(Twine(MAI->getCommentString()) + " BB#" +
Twine(MBB->getNumber()) + ":");
} }
} else { } else {
if (VerboseAsm) { if (VerboseAsm) {

View File

@@ -10,6 +10,8 @@
#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCExpr.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include <cstdlib> #include <cstdlib>
using namespace llvm; using namespace llvm;
@@ -54,3 +56,9 @@ void MCStreamer::EmitRawText(StringRef String) {
" something must not be fully mc'ized\n"; " something must not be fully mc'ized\n";
abort(); abort();
} }
void MCStreamer::EmitRawText(const Twine &T) {
SmallString<128> Str;
T.toVector(Str);
EmitRawText(Str.str());
}