string_ostream is a safe and efficient string builder that combines opaque
stack storage with a built-in ostream interface.
small_string_ostream<bytes> additionally permits an explicit stack storage size
other than the default 128 bytes to be provided. Beyond that, storage is
transferred to the heap.
This convenient class can be used in most places an
std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair
would previously have been used, in order to guarantee consistent access
without byte truncation.
The patch also converts much of LLVM to use the new facility. These changes
include several probable bug fixes for truncated output, a programming error
that's no longer possible with the new interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749
91177308-0d34-0410-b5e6-
96231b3b80d8
57 files changed:
if (!Node->getName().empty())
return Node->getName().str();
if (!Node->getName().empty())
return Node->getName().str();
- std::string Str;
- raw_string_ostream OS(Str);
-
Node->printAsOperand(OS, false);
return OS.str();
}
Node->printAsOperand(OS, false);
return OS.str();
}
static std::string getCompleteNodeLabel(const BasicBlock *Node,
const Function *) {
enum { MaxColumns = 80 };
static std::string getCompleteNodeLabel(const BasicBlock *Node,
const Function *) {
enum { MaxColumns = 80 };
- std::string Str;
- raw_string_ostream OS(Str);
if (Node->getName().empty()) {
Node->printAsOperand(OS, false);
if (Node->getName().empty()) {
Node->printAsOperand(OS, false);
if (SuccNo == 0) return "def";
if (SuccNo == 0) return "def";
- std::string Str;
- raw_string_ostream OS(Str);
SwitchInst::ConstCaseIt Case =
SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
OS << Case.getCaseValue()->getValue();
SwitchInst::ConstCaseIt Case =
SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
OS << Case.getCaseValue()->getValue();
class ObjectBufferStream : public ObjectBuffer {
void anchor() override;
public:
class ObjectBufferStream : public ObjectBuffer {
void anchor() override;
public:
- ObjectBufferStream() : OS(SV) {}
+ ObjectBufferStream() {}
virtual ~ObjectBufferStream() {}
raw_ostream &getOStream() { return OS; }
void flush()
{
virtual ~ObjectBufferStream() {}
raw_ostream &getOStream() { return OS; }
void flush()
{
// Make the data accessible via the ObjectBuffer::Buffer
// Make the data accessible via the ObjectBuffer::Buffer
- Buffer.reset(MemoryBuffer::getMemBuffer(StringRef(SV.data(), SV.size()),
- "",
- false));
+ Buffer.reset(MemoryBuffer::getMemBuffer(OS.str(), "", false));
- SmallVector<char, 4096> SV; // Working buffer into which we JIT.
- raw_svector_ostream OS; // streaming wrapper
+ small_string_ostream<4096> OS; // Working buffer into which we JIT.
O << "|" << DOT::EscapeString(NodeDesc);
}
O << "|" << DOT::EscapeString(NodeDesc);
}
- std::string edgeSourceLabels;
- raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
+ string_ostream EdgeSourceLabels;
bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
if (hasEdgeSourceLabels) {
bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
if (hasEdgeSourceLabels) {
typename std::enable_if<has_ScalarTraits<T>::value,void>::type
yamlize(IO &io, T &Val, bool) {
if ( io.outputting() ) {
typename std::enable_if<has_ScalarTraits<T>::value,void>::type
yamlize(IO &io, T &Val, bool) {
if ( io.outputting() ) {
- std::string Storage;
- llvm::raw_string_ostream Buffer(Storage);
+ llvm::string_ostream Buffer;
ScalarTraits<T>::output(Val, io.getContext(), Buffer);
StringRef Str = Buffer.str();
io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
ScalarTraits<T>::output(Val, io.getContext(), Buffer);
StringRef Str = Buffer.str();
io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
#define LLVM_SUPPORT_RAW_OSTREAM_H
#include "llvm/ADT/StringRef.h"
#define LLVM_SUPPORT_RAW_OSTREAM_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
/// current_pos - Return the current position within the stream, not
/// counting the bytes currently in the buffer.
uint64_t current_pos() const override;
/// current_pos - Return the current position within the stream, not
/// counting the bytes currently in the buffer.
uint64_t current_pos() const override;
+
+protected:
+ // This constructor is specified not to access \p O provided for storage as it
+ // may not yet be initialized at construction time.
+ explicit raw_svector_ostream(SmallVectorImpl<char> &O, std::nullptr_t)
+ : OS(O){};
+ void init();
+
public:
/// Construct a new raw_svector_ostream.
///
public:
/// Construct a new raw_svector_ostream.
///
+/// string_ostream - A raw_ostream that builds a string. This is a
+/// raw_svector_ostream with storage.
+template <unsigned InternalLen>
+class small_string_ostream : public raw_svector_ostream {
+ SmallVector<char, InternalLen> Buffer;
+ // There's no need to flush explicitly.
+ using raw_svector_ostream::flush;
+
+public:
+ small_string_ostream() : raw_svector_ostream(Buffer, nullptr) { init(); }
+
+ void clear() {
+ flush();
+ Buffer.clear();
+ }
+};
+
+typedef small_string_ostream<128> string_ostream;
+
} // end llvm namespace
#endif
} // end llvm namespace
#endif
void EmitString(raw_ostream &O) {
// Escape the string.
void EmitString(raw_ostream &O) {
// Escape the string.
- SmallString<256> Str;
- raw_svector_ostream(Str).write_escaped(AggregateString);
+ small_string_ostream<256> Str;
+ Str.write_escaped(AggregateString);
AggregateString = Str.str();
O << " \"";
AggregateString = Str.str();
O << " \"";
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
char **OutMessages) {
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
char **OutMessages) {
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
- std::string Messages;
- raw_string_ostream MsgsOS(Messages);
LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
report_fatal_error("Broken module found, compilation aborted!");
if (OutMessages)
report_fatal_error("Broken module found, compilation aborted!");
if (OutMessages)
- *OutMessages = strdup(MsgsOS.str().c_str());
+ *OutMessages = strndup(MsgsOS.str().data(), MsgsOS.str().size());
std::string getNodeLabel(const BasicBlock *Node,
const BlockFrequencyInfo *Graph) {
std::string getNodeLabel(const BasicBlock *Node,
const BlockFrequencyInfo *Graph) {
- std::string Result;
- raw_string_ostream OS(Result);
- OS << Node->getName().str() << ":";
+ OS << Node->getName() << ":";
switch (ViewBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
switch (ViewBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
"never reach this point.");
}
"never reach this point.");
}
const DataLayout *DL;
TargetLibraryInfo *TLI;
const DataLayout *DL;
TargetLibraryInfo *TLI;
- std::string Messages;
- raw_string_ostream MessagesStr;
+ string_ostream MessagesStr;
static char ID; // Pass identification, replacement for typeid
static char ID; // Pass identification, replacement for typeid
- Lint() : FunctionPass(ID), MessagesStr(Messages) {
+ Lint() : FunctionPass(ID) {
initializeLintPass(*PassRegistry::getPassRegistry());
}
initializeLintPass(*PassRegistry::getPassRegistry());
}
TLI = &getAnalysis<TargetLibraryInfo>();
visit(F);
dbgs() << MessagesStr.str();
TLI = &getAnalysis<TargetLibraryInfo>();
visit(F);
dbgs() << MessagesStr.str();
using namespace llvm;
static std::string getTypeString(Type *T) {
using namespace llvm;
static std::string getTypeString(Type *T) {
- std::string Result;
- raw_string_ostream Tmp(Result);
- Tmp << *T;
- return Tmp.str();
+ string_ostream Result;
+ Result << *T;
+ return Result.str();
}
/// Run: module ::= toplevelentity*
}
/// Run: module ::= toplevelentity*
// Otherwise report the problem to the user.
{
// Otherwise report the problem to the user.
{
- std::string S;
- raw_string_ostream OS(S);
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
- std::string msg;
- raw_string_ostream Msg(msg);
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
- std::string msg;
- raw_string_ostream Msg(msg);
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
// Emit the inline asm to a temporary string so we can emit it through
// EmitInlineAsm.
// Emit the inline asm to a temporary string so we can emit it through
// EmitInlineAsm.
- SmallString<256> StringData;
- raw_svector_ostream OS(StringData);
+ small_string_ostream<256> OS;
// The variant of the current asmprinter.
int AsmPrinterVariant = MAI->getAssemblerDialect();
// The variant of the current asmprinter.
int AsmPrinterVariant = MAI->getAssemblerDialect();
}
OS << Counter;
} else {
}
OS << Counter;
} else {
- std::string msg;
- raw_string_ostream Msg(msg);
Msg << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
report_fatal_error(Msg.str());
Msg << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
report_fatal_error(Msg.str());
std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
- std::string Result;
- raw_string_ostream OS(Result);
- OS << Node->getName().str() << ":";
+ OS << Node->getName() << ":";
switch (ViewMachineBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
switch (ViewMachineBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
"never reach this point.");
}
"never reach this point.");
}
///
/// Only used by debug logging.
static std::string getBlockName(MachineBasicBlock *BB) {
///
/// Only used by debug logging.
static std::string getBlockName(MachineBasicBlock *BB) {
- std::string Result;
- raw_string_ostream OS(Result);
OS << "BB#" << BB->getNumber()
<< " (derived from LLVM BB '" << BB->getName() << "')";
OS << "BB#" << BB->getNumber()
<< " (derived from LLVM BB '" << BB->getName() << "')";
- OS.flush();
- return Result;
}
/// \brief Helper to print the number of a MBB.
///
/// Only used by debug logging.
static std::string getBlockNum(MachineBasicBlock *BB) {
}
/// \brief Helper to print the number of a MBB.
///
/// Only used by debug logging.
static std::string getBlockNum(MachineBasicBlock *BB) {
- std::string Result;
- raw_string_ostream OS(Result);
OS << "BB#" << BB->getNumber();
OS << "BB#" << BB->getNumber();
- OS.flush();
- return Result;
const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
DL->getPrivateGlobalPrefix();
const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
DL->getPrivateGlobalPrefix();
- SmallString<60> Name;
- raw_svector_ostream(Name)
- << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
+ small_string_ostream<60> Name;
+ Name << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
return Ctx.GetOrCreateSymbol(Name.str());
}
return Ctx.GetOrCreateSymbol(Name.str());
}
}
static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
}
static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
- std::string Str;
- raw_string_ostream SS(Str);
const ScheduleDAGMI *DAG = static_cast<const ScheduleDAGMI*>(G);
const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
static_cast<const ScheduleDAGMILive*>(G)->getDFSResult() : nullptr;
const ScheduleDAGMI *DAG = static_cast<const ScheduleDAGMI*>(G);
const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
static_cast<const ScheduleDAGMILive*>(G)->getDFSResult() : nullptr;
}
std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
}
std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
- std::string s;
- raw_string_ostream oss(s);
if (SU == &EntrySU)
oss << "<entry>";
else if (SU == &ExitSU)
if (SU == &EntrySU)
oss << "<entry>";
else if (SU == &ExitSU)
void SelectionDAGISel::CannotYetSelect(SDNode *N) {
void SelectionDAGISel::CannotYetSelect(SDNode *N) {
- std::string msg;
- raw_string_ostream Msg(msg);
Msg << "Cannot select: ";
if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
Msg << "Cannot select: ";
if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
}
std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
}
std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
- std::string s;
- raw_string_ostream O(s);
O << "SU(" << SU->NodeNum << "): ";
if (SU->getNode()) {
SmallVector<SDNode *, 4> GluedNodes;
O << "SU(" << SU->NodeNum << "): ";
if (SU->getNode()) {
SmallVector<SDNode *, 4> GluedNodes;
if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
&& !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
&& SchedModel.isComplete()) {
if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
&& !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
&& SchedModel.isComplete()) {
- std::string Err;
- raw_string_ostream ss(Err);
- ss << "DefIdx " << DefIdx << " exceeds machine model writes for "
- << *DefMI;
- report_fatal_error(ss.str());
+ string_ostream Err;
+ Err << "DefIdx " << DefIdx << " exceeds machine model writes for "
+ << *DefMI;
+ report_fatal_error(Err.str());
}
#endif
// FIXME: Automatically giving all implicit defs defaultDefLatency is
}
#endif
// FIXME: Automatically giving all implicit defs defaultDefLatency is
Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset);
if (Offset != EndStructureOffset) {
Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset);
if (Offset != EndStructureOffset) {
- std::string Str;
- raw_string_ostream OS(Str);
- OS << format("Parsing entry instructions at %lx failed", StartOffset);
- report_fatal_error(Str);
+ string_ostream Str;
+ Str << format("Parsing entry instructions at %lx failed", StartOffset);
+ report_fatal_error(Str.str());
/*===-- Error handling ----------------------------------------------------===*/
/*===-- Error handling ----------------------------------------------------===*/
+static char *LLVMCreateMessage(StringRef Message) {
+ assert(Message.find('\0') == Message.npos);
+ return strndup(Message.data(), Message.size());
+}
+
char *LLVMCreateMessage(const char *Message) {
return strdup(Message);
}
char *LLVMCreateMessage(const char *Message) {
return strdup(Message);
}
}
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
}
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
-
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
- Stream.flush();
-
- return LLVMCreateMessage(MsgStorage.c_str());
+ return LLVMCreateMessage(Msg.str());
}
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
}
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
}
char *LLVMPrintModuleToString(LLVMModuleRef M) {
}
char *LLVMPrintModuleToString(LLVMModuleRef M) {
- std::string buf;
- raw_string_ostream os(buf);
-
unwrap(M)->print(os, nullptr);
unwrap(M)->print(os, nullptr);
- os.flush();
-
- return strdup(buf.c_str());
+ return LLVMCreateMessage(os.str());
}
/*--.. Operations on inline assembler ......................................--*/
}
/*--.. Operations on inline assembler ......................................--*/
}
char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
}
char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
- std::string buf;
- raw_string_ostream os(buf);
if (unwrap(Ty))
unwrap(Ty)->print(os);
else
os << "Printing <null> Type";
if (unwrap(Ty))
unwrap(Ty)->print(os);
else
os << "Printing <null> Type";
- os.flush();
-
- return strdup(buf.c_str());
+ return strndup(os.str().data(), os.str().size());
}
/*--.. Operations on integer types .........................................--*/
}
/*--.. Operations on integer types .........................................--*/
}
char* LLVMPrintValueToString(LLVMValueRef Val) {
}
char* LLVMPrintValueToString(LLVMValueRef Val) {
- std::string buf;
- raw_string_ostream os(buf);
if (unwrap(Val))
unwrap(Val)->print(os);
else
os << "Printing <null> Value";
if (unwrap(Val))
unwrap(Val)->print(os);
else
os << "Printing <null> Value";
- os.flush();
-
- return strdup(buf.c_str());
+ return strndup(os.str().data(), os.str().size());
}
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
}
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
}
std::string DataLayout::getStringRepresentation() const {
}
std::string DataLayout::getStringRepresentation() const {
- std::string Result;
- raw_string_ostream OS(Result);
OS << (LittleEndian ? "e" : "E");
OS << (LittleEndian ? "e" : "E");
}
// Otherwise, print the message with a prefix based on the severity.
}
// Otherwise, print the message with a prefix based on the severity.
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
switch (DI.getSeverity()) {
case DS_Error:
switch (DI.getSeverity()) {
case DS_Error:
- errs() << "error: " << MsgStorage << "\n";
+ errs() << "error: " << Msg.str() << "\n";
exit(1);
case DS_Warning:
exit(1);
case DS_Warning:
- errs() << "warning: " << MsgStorage << "\n";
+ errs() << "warning: " << Msg.str() << "\n";
- errs() << "remark: " << MsgStorage << "\n";
+ errs() << "remark: " << Msg.str() << "\n";
- errs() << "note: " << MsgStorage << "\n";
+ errs() << "note: " << Msg.str() << "\n";
if(!*OutM) {
if (OutMessage) {
if(!*OutM) {
if (OutMessage) {
- std::string buf;
- raw_string_ostream os(buf);
-
Diag.print(nullptr, os, false);
Diag.print(nullptr, os, false);
- os.flush();
-
- *OutMessage = strdup(buf.c_str());
+ *OutMessage = strndup(os.str().data(), os.str().size());
break;
}
// Create the string that will be reported to the external diagnostic handler.
break;
}
// Create the string that will be reported to the external diagnostic handler.
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
+
+ // Null-terminate the C string.
+ Msg << '\0';
// If this method has been called it means someone has set up an external
// diagnostic handler. Assert on that.
assert(DiagHandler && "Invalid diagnostic handler");
// If this method has been called it means someone has set up an external
// diagnostic handler. Assert on that.
assert(DiagHandler && "Invalid diagnostic handler");
- (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
+ (*DiagHandler)(Severity, Msg.str().data(), DiagContext);
raw_ostream &OS = GetCommentOS();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
raw_ostream &OS = GetCommentOS();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
- VecOS.flush();
+ {
+ raw_svector_ostream VecOS(Code);
+ Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
+ }
// If we are showing fixups, create symbolic markers in the encoded
// representation. We do this by making a per-bit map to the fixup item index,
// If we are showing fixups, create symbolic markers in the encoded
// representation. We do this by making a per-bit map to the fixup item index,
}
MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
}
MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
- SmallString<128> NameSV;
- raw_svector_ostream(NameSV)
- << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
- return CreateSymbol(NameSV);
+ small_string_ostream<128> NameSV;
+ NameSV << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+ return CreateSymbol(NameSV.str());
}
MCSymbol *MCContext::CreateTempSymbol() {
}
MCSymbol *MCContext::CreateTempSymbol() {
- SmallString<128> NameSV;
- raw_svector_ostream(NameSV)
- << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
- return CreateSymbol(NameSV);
+ small_string_ostream<128> NameSV;
+ NameSV << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+ return CreateSymbol(NameSV.str());
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
const MCDisassembler *DisAsm = DC->getDisAsm();
MCInstPrinter *IP = DC->getIP();
MCDisassembler::DecodeStatus S;
const MCDisassembler *DisAsm = DC->getDisAsm();
MCInstPrinter *IP = DC->getIP();
MCDisassembler::DecodeStatus S;
- SmallVector<char, 64> InsnStr;
- raw_svector_ostream Annotations(InsnStr);
+ small_string_ostream<64> Annotations;
S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
/*REMOVE*/ nulls(), Annotations);
switch (S) {
S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
/*REMOVE*/ nulls(), Annotations);
switch (S) {
return 0;
case MCDisassembler::Success: {
return 0;
case MCDisassembler::Success: {
- Annotations.flush();
- StringRef AnnotationsStr = Annotations.str();
-
SmallVector<char, 64> InsnStr;
raw_svector_ostream OS(InsnStr);
formatted_raw_ostream FormattedOS(OS);
SmallVector<char, 64> InsnStr;
raw_svector_ostream OS(InsnStr);
formatted_raw_ostream FormattedOS(OS);
- IP->printInst(&Inst, FormattedOS, AnnotationsStr);
+ IP->printInst(&Inst, FormattedOS, Annotations.str());
if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
emitLatency(DC, Inst);
if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
emitLatency(DC, Inst);
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
uint64_t AddrDelta) {
MCContext &Context = MCOS->getContext();
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
uint64_t AddrDelta) {
MCContext &Context = MCOS->getContext();
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
MCOS->EmitBytes(OS.str());
}
MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
MCOS->EmitBytes(OS.str());
}
void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
uint64_t AddrDelta) {
MCContext &Context = Streamer.getContext();
void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
uint64_t AddrDelta) {
MCContext &Context = Streamer.getContext();
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
Streamer.EmitBytes(OS.str());
}
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
Streamer.EmitBytes(OS.str());
}
}
// Build the IR assembly string.
}
// Build the IR assembly string.
- std::string AsmStringIR;
- raw_string_ostream OS(AsmStringIR);
const char *AsmStart = SrcMgr.getMemoryBuffer(0)->getBufferStart();
const char *AsmEnd = SrcMgr.getMemoryBuffer(0)->getBufferEnd();
array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
const char *AsmStart = SrcMgr.getMemoryBuffer(0)->getBufferStart();
const char *AsmEnd = SrcMgr.getMemoryBuffer(0)->getBufferEnd();
array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
}
case AOK_DotOperator:
// Insert the dot if the user omitted it.
}
case AOK_DotOperator:
// Insert the dot if the user omitted it.
- OS.flush();
- if (AsmStringIR.back() != '.')
+ if (OS.str().back() != '.')
OS << '.';
OS << AR.Val;
break;
OS << '.';
OS << AR.Val;
break;
static void printRelocationTargetName(const MachOObjectFile *O,
const MachO::any_relocation_info &RE,
static void printRelocationTargetName(const MachOObjectFile *O,
const MachO::any_relocation_info &RE,
- raw_string_ostream &fmt) {
bool IsScattered = O->isRelocationScattered(RE);
// Target of a scattered relocation is an address. In the interest of
bool IsScattered = O->isRelocationScattered(RE);
// Target of a scattered relocation is an address. In the interest of
unsigned Arch = this->getArch();
unsigned Arch = this->getArch();
- std::string fmtbuf;
- raw_string_ostream fmt(fmtbuf);
unsigned Type = this->getAnyRelocationType(RE);
bool IsPCRel = this->getAnyRelocationPCRel(RE);
unsigned Type = this->getAnyRelocationType(RE);
bool IsPCRel = this->getAnyRelocationPCRel(RE);
} else
printRelocationTargetName(this, RE, fmt);
} else
printRelocationTargetName(this, RE, fmt);
+ StringRef fmtbuf = fmt.str();
Result.append(fmtbuf.begin(), fmtbuf.end());
return object_error::success;
}
Result.append(fmtbuf.begin(), fmtbuf.end());
return object_error::success;
}
}
std::string Arg::getAsString(const ArgList &Args) const {
}
std::string Arg::getAsString(const ArgList &Args) const {
- SmallString<256> Res;
- llvm::raw_svector_ostream OS(Res);
+ small_string_ostream<256> OS;
ArgStringList ASL;
render(Args, ASL);
ArgStringList ASL;
render(Args, ASL);
break;
case Option::RenderCommaJoinedStyle: {
break;
case Option::RenderCommaJoinedStyle: {
- SmallString<256> Res;
- llvm::raw_svector_ostream OS(Res);
+ small_string_ostream<256> OS;
OS << getSpelling();
for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
if (i) OS << ',';
OS << getSpelling();
for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
if (i) OS << ',';
// printOptionDiff - Specializations for printing basic value types.
//
// printOptionDiff - Specializations for printing basic value types.
//
-#define PRINT_OPT_DIFF(T) \
- void parser<T>:: \
- printOptionDiff(const Option &O, T V, OptionValue<T> D, \
- size_t GlobalWidth) const { \
- printOptionName(O, GlobalWidth); \
- std::string Str; \
- { \
- raw_string_ostream SS(Str); \
- SS << V; \
- } \
- outs() << "= " << Str; \
- size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\
- outs().indent(NumSpaces) << " (default: "; \
- if (D.hasValue()) \
- outs() << D.getValue(); \
- else \
- outs() << "*no default*"; \
- outs() << ")\n"; \
- } \
+#define PRINT_OPT_DIFF(T) \
+ void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
+ size_t GlobalWidth) const { \
+ printOptionName(O, GlobalWidth); \
+ string_ostream SS; \
+ SS << V; \
+ outs() << "= " << SS.str(); \
+ size_t NumSpaces = MaxOptWidth > SS.tell() ? MaxOptWidth - SS.tell() : 0; \
+ outs().indent(NumSpaces) << " (default: "; \
+ if (D.hasValue()) \
+ outs() << D.getValue(); \
+ else \
+ outs() << "*no default*"; \
+ outs() << ")\n"; \
+ }
PRINT_OPT_DIFF(bool)
PRINT_OPT_DIFF(boolOrDefault)
PRINT_OPT_DIFF(bool)
PRINT_OPT_DIFF(boolOrDefault)
// and we only need to set the vector size when the data is flushed.
raw_svector_ostream::raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {
// and we only need to set the vector size when the data is flushed.
raw_svector_ostream::raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {
+ init();
+}
+
+void raw_svector_ostream::init() {
// Set up the initial external buffer. We make sure that the buffer has at
// least 128 bytes free; raw_ostream itself only requires 64, but we want to
// make sure that we don't grow the buffer unnecessarily on destruction (when
// Set up the initial external buffer. We make sure that the buffer has at
// least 128 bytes free; raw_ostream itself only requires 64, but we want to
// make sure that we don't grow the buffer unnecessarily on destruction (when
break;
else if (Step < 0 && From < To)
break;
break;
else if (Step < 0 && From < To)
break;
- std::string Name;
- raw_string_ostream OS(Name);
- OS << format(Format.c_str(), unsigned(From));
- Record *Rec = Records.getDef(OS.str());
+ string_ostream Name;
+ Name << format(Format.c_str(), unsigned(From));
+ Record *Rec = Records.getDef(Name.str());
- PrintFatalError(Loc, "No def named '" + Name + "': " +
- Expr->getAsString());
+ PrintFatalError(Loc, "No def named '" + Name.str() + "': " +
+ Expr->getAsString());
// Try to reevaluate Rec in case it is a set.
if (const RecVec *Result = ST.expand(Rec))
Elts.insert(Result->begin(), Result->end());
// Try to reevaluate Rec in case it is a set.
if (const RecVec *Result = ST.expand(Rec))
Elts.insert(Result->begin(), Result->end());
if (ItemType) {
ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
if (!ListType) {
if (ItemType) {
ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
if (!ListType) {
- std::string s;
- raw_string_ostream ss(s);
ss << "Type mismatch for list, expected list type, got "
<< ItemType->getAsString();
TokError(ss.str());
ss << "Type mismatch for list, expected list type, got "
<< ItemType->getAsString();
TokError(ss.str());
// Otherwise report the problem to the user.
{
// Otherwise report the problem to the user.
{
- std::string S;
- raw_string_ostream OS(S);
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/ false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/ false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
LLVMModuleRef M, LLVMCodeGenFileType codegen, char** ErrorMessage,
LLVMMemoryBufferRef *OutMemBuf) {
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
LLVMModuleRef M, LLVMCodeGenFileType codegen, char** ErrorMessage,
LLVMMemoryBufferRef *OutMemBuf) {
- std::string CodeString;
- raw_string_ostream OStream(CodeString);
- formatted_raw_ostream Out(OStream);
+ string_ostream Code;
+ formatted_raw_ostream Out(Code);
bool Result = LLVMTargetMachineEmit(T, M, Out, codegen, ErrorMessage);
bool Result = LLVMTargetMachineEmit(T, M, Out, codegen, ErrorMessage);
- std::string &Data = OStream.str();
- *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Data.c_str(),
- Data.length(), "");
+ StringRef Buffer = Code.str();
+ *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Buffer.data(),
+ Buffer.size(), "");
if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
- SmallString<126> Msg;
- raw_svector_ostream OS(Msg);
+ small_string_ostream<128> OS;
OS << "ambiguous instructions require an explicit suffix (could be ";
for (unsigned i = 0; i != NumMatches; ++i) {
if (i != 0)
OS << "ambiguous instructions require an explicit suffix (could be ";
for (unsigned i = 0; i != NumMatches; ++i) {
if (i != 0)
unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
if (RelaxedOp == Inst.getOpcode()) {
unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
if (RelaxedOp == Inst.getOpcode()) {
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
Inst.dump_pretty(OS);
OS << "\n";
report_fatal_error("unexpected instruction to relax: " + OS.str());
Inst.dump_pretty(OS);
OS << "\n";
report_fatal_error("unexpected instruction to relax: " + OS.str());
}
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
}
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
- SmallString<128> Directive;
- raw_svector_ostream OS(Directive);
+ small_string_ostream<128> OS;
StringRef Name = Sym->getName();
if (Subtarget->isTargetKnownWindowsMSVC())
StringRef Name = Sym->getName();
if (Subtarget->isTargetKnownWindowsMSVC())
- OS.flush();
- OutStreamer.EmitBytes(Directive);
+ OutStreamer.EmitBytes(OS.str());
}
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
}
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
}
void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
}
void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
- SmallString<128> Str;
- raw_svector_ostream O(Str);
+ small_string_ostream<128> O;
switch (MI->getOpcode()) {
case XCore::DBG_VALUE:
switch (MI->getOpcode()) {
case XCore::DBG_VALUE:
}
std::string getTypeName(Type *T) {
}
std::string getTypeName(Type *T) {
- std::string TypeName;
- raw_string_ostream TypeStream(TypeName);
- TypeStream << "Printing <null> Type";
- TypeStream.flush();
- return TypeName;
+ OS << "Printing <null> Type";
+ return OS.str();
}
/// Returns the MDNode that represents type T if it is already created, or 0
}
/// Returns the MDNode that represents type T if it is already created, or 0
}
ReturnBlock = new GCOVBlock(i++, os);
}
ReturnBlock = new GCOVBlock(i++, os);
- std::string FunctionNameAndLine;
- raw_string_ostream FNLOS(FunctionNameAndLine);
- FNLOS << getFunctionName(SP) << SP.getLineNumber();
- FNLOS.flush();
- FuncChecksum = hash_value(FunctionNameAndLine);
+ string_ostream FnNameLine;
+ FnNameLine << getFunctionName(SP) << SP.getLineNumber();
+ FuncChecksum = hash_value(FnNameLine.str());
}
std::string getEdgeDestinations() {
}
std::string getEdgeDestinations() {
- std::string EdgeDestinations;
- raw_string_ostream EDOS(EdgeDestinations);
+ string_ostream EdgeDestinations;
Function *F = Blocks.begin()->first->getParent();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
GCOVBlock &Block = *Blocks[I];
for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
Function *F = Blocks.begin()->first->getParent();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
GCOVBlock &Block = *Blocks[I];
for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
- EDOS << Block.OutEdges[i]->Number;
+ EdgeDestinations << Block.OutEdges[i]->Number;
- return EdgeDestinations;
+ return EdgeDestinations.str();
}
uint32_t getFuncChecksum() {
}
uint32_t getFuncChecksum() {
if (PoisonStack && MS.TrackOrigins) {
setOrigin(&I, getCleanOrigin());
if (PoisonStack && MS.TrackOrigins) {
setOrigin(&I, getCleanOrigin());
- SmallString<2048> StackDescriptionStorage;
- raw_svector_ostream StackDescription(StackDescriptionStorage);
+ small_string_ostream<2048> StackDescription;
// We create a string with a description of the stack allocation and
// pass it into __msan_set_alloca_origin.
// It will be printed by the run-time if stack-originated UMR is found.
// We create a string with a description of the stack allocation and
// pass it into __msan_set_alloca_origin.
// It will be printed by the run-time if stack-originated UMR is found.
// of line at the module level and to provide a very simple format
// encoding the information herein. Both of these makes it simpler to
// parse the annotations by a simple external program.
// of line at the module level and to provide a very simple format
// encoding the information herein. Both of these makes it simpler to
// parse the annotations by a simple external program.
- std::string Str;
- raw_string_ostream os(Str);
os << "(" << Inst->getParent()->getParent()->getName() << ",%"
<< Inst->getName() << ")";
os << "(" << Inst->getParent()->getParent()->getName() << ",%"
<< Inst->getName() << ")";
Hash = cast<MDString>(Node->getOperand(0));
}
} else if (Argument *Arg = dyn_cast<Argument>(Ptr)) {
Hash = cast<MDString>(Node->getOperand(0));
}
} else if (Argument *Arg = dyn_cast<Argument>(Ptr)) {
- std::string str;
- raw_string_ostream os(str);
os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
<< ")";
Hash = MDString::get(Arg->getContext(), os.str());
os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
<< ")";
Hash = MDString::get(Arg->getContext(), os.str());
}
static std::string SequenceToString(Sequence A) {
}
static std::string SequenceToString(Sequence A) {
- std::string str;
- raw_string_ostream os(str);
os << A;
return os.str();
}
os << A;
return os.str();
}
Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
- SmallString<2048> StackDescriptionStorage;
- raw_svector_ostream StackDescription(StackDescriptionStorage);
+ small_string_ostream<2048> StackDescription;
StackDescription << NumVars;
Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);
StackDescription << NumVars;
Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);
/// Optimization analysis message produced during vectorization. Messages inform
/// the user why vectorization did not occur.
class Report {
/// Optimization analysis message produced during vectorization. Messages inform
/// the user why vectorization did not occur.
class Report {
- std::string Message;
- raw_string_ostream Out;
+ string_ostream Message;
Instruction *Instr;
public:
Instruction *Instr;
public:
- Report(Instruction *I = nullptr) : Out(Message), Instr(I) {
- Out << "loop not vectorized: ";
+ Report(Instruction *I = nullptr) : Instr(I) {
+ Message << "loop not vectorized: ";
}
template <typename A> Report &operator<<(const A &Value) {
}
template <typename A> Report &operator<<(const A &Value) {
return *this;
}
Instruction *getInstr() { return Instr; }
return *this;
}
Instruction *getInstr() { return Instr; }
- std::string &str() { return Out.str(); }
- operator Twine() { return Out.str(); }
+ StringRef str() { return Message.str(); }
+ operator Twine() { return Message.str(); }
};
/// InnerLoopVectorizer vectorizes loops which contain only one basic
};
/// InnerLoopVectorizer vectorizes loops which contain only one basic
#ifndef NDEBUG
/// \return string containing a file name and a line # for the given loop.
static std::string getDebugLocString(const Loop *L) {
#ifndef NDEBUG
/// \return string containing a file name and a line # for the given loop.
static std::string getDebugLocString(const Loop *L) {
- std::string Result;
- if (L) {
- raw_string_ostream OS(Result);
- const DebugLoc LoopDbgLoc = L->getStartLoc();
- if (!LoopDbgLoc.isUnknown())
- LoopDbgLoc.print(L->getHeader()->getContext(), OS);
- else
- // Just print the module name.
- OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
- OS.flush();
- }
- return Result;
+ if (!L)
+ return std::string();
+
+ string_ostream OS;
+ const DebugLoc LoopDbgLoc = L->getStartLoc();
+ if (!LoopDbgLoc.isUnknown())
+ LoopDbgLoc.print(L->getHeader()->getContext(), OS);
+ else
+ // Just print the module name.
+ OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
+ return OS.str();
std::vector<std::pair<unsigned, unsigned>> &MemberOffsetRefs) {
unsigned StartOffset = 0;
unsigned MemberNum = 0;
std::vector<std::pair<unsigned, unsigned>> &MemberOffsetRefs) {
unsigned StartOffset = 0;
unsigned MemberNum = 0;
- std::string NameBuf;
- raw_string_ostream NameOS(NameBuf);
unsigned NumSyms = 0;
LLVMContext &Context = getGlobalContext();
for (ArrayRef<NewArchiveIterator>::iterator I = Members.begin(),
unsigned NumSyms = 0;
LLVMContext &Context = getGlobalContext();
for (ArrayRef<NewArchiveIterator>::iterator I = Members.begin(),
Out << "<o>";
// Escape special chars and print the instruction in mnemonic form.
Out << "<o>";
// Escape special chars and print the instruction in mnemonic form.
- std::string Str;
- raw_string_ostream OS(Str);
IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
Out << DOT::EscapeString(OS.str());
}
IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
Out << DOT::EscapeString(OS.str());
}
if (Symbols.empty())
Symbols.push_back(std::make_pair(0, name));
if (Symbols.empty())
Symbols.push_back(std::make_pair(0, name));
-
- SmallString<40> Comments;
- raw_svector_ostream CommentStream(Comments);
+ small_string_ostream<40> Comments;
StringRef Bytes;
if (error(Section.getContents(Bytes)))
StringRef Bytes;
if (error(Section.getContents(Bytes)))
MCInst Inst;
if (DisAsm->getInstruction(Inst, Size, memoryObject,
MCInst Inst;
if (DisAsm->getInstruction(Inst, Size, memoryObject,
- SectionAddr + Index,
- DebugOut, CommentStream)) {
+ SectionAddr + Index, DebugOut, Comments)) {
outs() << format("%8" PRIx64 ":", SectionAddr + Index);
if (!NoShowRawInsn) {
outs() << "\t";
DumpBytes(StringRef(Bytes.data() + Index, Size));
}
IP->printInst(&Inst, outs(), "");
outs() << format("%8" PRIx64 ":", SectionAddr + Index);
if (!NoShowRawInsn) {
outs() << "\t";
DumpBytes(StringRef(Bytes.data() + Index, Size));
}
IP->printInst(&Inst, outs(), "");
- outs() << CommentStream.str();
+ outs() << Comments.str();
Comments.clear();
outs() << "\n";
} else {
Comments.clear();
outs() << "\n";
} else {
static std::string formatSymbol(StringRef Name, uint64_t Address,
uint64_t Offset = 0) {
static std::string formatSymbol(StringRef Name, uint64_t Address,
uint64_t Offset = 0) {
- std::string Buffer;
- raw_string_ostream OS(Buffer);
if (!Name.empty())
OS << Name << " ";
if (!Name.empty())
OS << Name << " ";
static std::string formatSymbol(const Dumper::Context &Ctx,
const coff_section *Section, uint64_t Offset,
uint32_t Displacement) {
static std::string formatSymbol(const Dumper::Context &Ctx,
const coff_section *Section, uint64_t Offset,
uint32_t Displacement) {
- std::string Buffer;
- raw_string_ostream OS(Buffer);
StringRef Name;
SymbolRef Symbol;
StringRef Name;
SymbolRef Symbol;
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
else
OS << format(" (0x%" PRIX64 ")", Offset);
OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
else
OS << format(" (0x%" PRIX64 ")", Offset);
}
std::string DumpFunction(const Function *F) {
}
std::string DumpFunction(const Function *F) {
- std::string Result;
- raw_string_ostream(Result) << "" << *F;
- return Result;
+ string_ostream Result;
+ Result << "" << *F;
+ return Result.str();
}
class RecordingJITMemoryManager : public JITMemoryManager {
}
class RecordingJITMemoryManager : public JITMemoryManager {
SMDiagnostic Error;
bool success =
nullptr != ParseAssemblyString(assembly, M, Error, M->getContext());
SMDiagnostic Error;
bool success =
nullptr != ParseAssemblyString(assembly, M, Error, M->getContext());
- std::string errMsg;
- raw_string_ostream os(errMsg);
- Error.print("", os);
- EXPECT_TRUE(success) << os.str();
+ string_ostream errMsg;
+ Error.print("", errMsg);
+ EXPECT_TRUE(success) << errMsg.str();
// variable values.
if (!VariableUses.empty()) {
for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
// variable values.
if (!VariableUses.empty()) {
for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
- SmallString<256> Msg;
- raw_svector_ostream OS(Msg);
+ small_string_ostream<256> OS;
StringRef Var = VariableUses[i].first;
if (Var[0] == '@') {
std::string Value;
StringRef Var = VariableUses[i].first;
if (Var[0] == '@') {
std::string Value;
// Default case: unhandled opcode
o << " default:\n"
// Default case: unhandled opcode
o << " default:\n"
- << " std::string msg;\n"
- << " raw_string_ostream Msg(msg);\n"
+ << " string_ostream Msg;\n"
<< " Msg << \"Not supported instr: \" << MI;\n"
<< " report_fatal_error(Msg.str());\n"
<< " }\n"
<< " Msg << \"Not supported instr: \" << MI;\n"
<< " report_fatal_error(Msg.str());\n"
<< " }\n"
}
static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
}
static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
- std::string JSONText;
- llvm::raw_string_ostream Stream(JSONText);
- Stream << "[\n";
+ llvm::string_ostream OS;
+ OS << "[\n";
size_t MemoryBytes = MemoryMB * 1024 * 1024;
size_t MemoryBytes = MemoryMB * 1024 * 1024;
- while (JSONText.size() < MemoryBytes) {
- Stream << " {\n"
- << " \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
- << " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
- << " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
- << " }";
- Stream.flush();
- if (JSONText.size() < MemoryBytes) Stream << ",";
- Stream << "\n";
+ while (OS.tell() < MemoryBytes) {
+ OS << " {\n"
+ << " \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
+ << " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
+ << " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
+ << " }";
+ if (OS.tell() < MemoryBytes)
+ OS << ",";
+ OS << "\n";
- Stream << "]\n";
- Stream.flush();
- return JSONText;
+ OS << "]\n";
+ return OS.str();
}
int main(int argc, char **argv) {
}
int main(int argc, char **argv) {