Skip to content

Commit 43c275f

Browse files
committed
Use raw_ostream.
llvm-svn: 100615
1 parent 8586bfd commit 43c275f

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -438,58 +438,50 @@ static void EmitKill(const MachineInstr *MI, AsmPrinter &AP) {
438438
/// of DBG_VALUE, returning true if it was able to do so. A false return
439439
/// means the target will need to handle MI in EmitInstruction.
440440
static bool EmitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
441-
char buf[100];
442-
std::string Str = "\t";
443-
Str += AP.MAI->getCommentString();
444-
Str += "DEBUG_VALUE: ";
445441
// This code handles only the 3-operand target-independent form.
446442
if (MI->getNumOperands() != 3)
447443
return false;
448444

445+
SmallString<128> Str;
446+
raw_svector_ostream OS(Str);
447+
OS << '\t' << AP.MAI->getCommentString() << "DEBUG_VALUE: ";
448+
449449
// cast away const; DIetc do not take const operands for some reason.
450450
DIVariable V((MDNode*)(MI->getOperand(2).getMetadata()));
451-
Str += V.getName();
452-
Str += " <- ";
451+
OS << V.getName() << " <- ";
453452

454453
// Register or immediate value. Register 0 means undef.
455454
if (MI->getOperand(0).isFPImm()) {
456455
APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
457456
if (MI->getOperand(0).getFPImm()->getType()->isFloatTy()) {
458-
sprintf(buf, "%e", APF.convertToFloat());
459-
Str += buf;
457+
OS << (double)APF.convertToFloat();
460458
} else if (MI->getOperand(0).getFPImm()->getType()->isDoubleTy()) {
461-
sprintf(buf, "%e", APF.convertToDouble());
462-
Str += buf;
459+
OS << APF.convertToDouble();
463460
} else {
464461
// There is no good way to print long double. Convert a copy to
465462
// double. Ah well, it's only a comment.
466463
bool ignored;
467464
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
468465
&ignored);
469-
Str += "(long double) ";
470-
sprintf(buf, "%e", APF.convertToDouble());
471-
Str += buf;
466+
OS << "(long double) " << APF.convertToDouble();
472467
}
473468
} else if (MI->getOperand(0).isImm()) {
474-
sprintf(buf, "%lld", MI->getOperand(0).getImm());
475-
Str += buf;
469+
OS << MI->getOperand(0).getImm();
476470
} else if (MI->getOperand(0).isReg()) {
477471
if (MI->getOperand(0).getReg() == 0) {
478472
// Suppress offset, it is not meaningful here.
479-
Str += "undef";
473+
OS << "undef";
480474
// NOTE: Want this comment at start of line, don't emit with AddComment.
481-
AP.OutStreamer.EmitRawText(Twine(Str));
475+
AP.OutStreamer.EmitRawText(OS.str());
482476
return true;
483477
}
484-
Str += AP.TM.getRegisterInfo()->getName(MI->getOperand(0).getReg());
478+
OS << AP.TM.getRegisterInfo()->getName(MI->getOperand(0).getReg());
485479
} else
486480
llvm_unreachable("Unknown operand type");
487481

488-
Str += '+';
489-
sprintf(buf, "%lld", MI->getOperand(1).getImm());
490-
Str += buf;
482+
OS << '+' << MI->getOperand(1).getImm();
491483
// NOTE: Want this comment at start of line, don't emit with AddComment.
492-
AP.OutStreamer.EmitRawText(Twine(Str));
484+
AP.OutStreamer.EmitRawText(OS.str());
493485
return true;
494486
}
495487

0 commit comments

Comments
 (0)