llvm.org GIT mirror llvm / 8dd8d5c
Revert "Introduce a string_ostream string builder facilty" Temporarily back out commits r211749, r211752 and r211754. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211814 91177308-0d34-0410-b5e6-96231b3b80d8 Alp Toker 5 years ago
57 changed file(s) with 291 addition(s) and 229 deletion(s). Raw diff Collapse all Expand all
3535 if (!Node->getName().empty())
3636 return Node->getName().str();
3737
38 string_ostream OS;
38 std::string Str;
39 raw_string_ostream OS(Str);
40
3941 Node->printAsOperand(OS, false);
4042 return OS.str();
4143 }
4345 static std::string getCompleteNodeLabel(const BasicBlock *Node,
4446 const Function *) {
4547 enum { MaxColumns = 80 };
46 string_ostream OS;
48 std::string Str;
49 raw_string_ostream OS(Str);
4750
4851 if (Node->getName().empty()) {
4952 Node->printAsOperand(OS, false);
105108
106109 if (SuccNo == 0) return "def";
107110
108 string_ostream OS;
111 std::string Str;
112 raw_string_ostream OS(Str);
109113 SwitchInst::ConstCaseIt Case =
110114 SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
111115 OS << Case.getCaseValue()->getValue();
5757 class ObjectBufferStream : public ObjectBuffer {
5858 void anchor() override;
5959 public:
60 ObjectBufferStream() {}
60 ObjectBufferStream() : OS(SV) {}
6161 virtual ~ObjectBufferStream() {}
6262
6363 raw_ostream &getOStream() { return OS; }
6464 void flush()
6565 {
66 OS.flush();
67
6668 // Make the data accessible via the ObjectBuffer::Buffer
67 Buffer.reset(MemoryBuffer::getMemBuffer(OS.str(), "", false));
69 Buffer.reset(MemoryBuffer::getMemBuffer(StringRef(SV.data(), SV.size()),
70 "",
71 false));
6872 }
6973
7074 protected:
71 small_string_ostream<4096> OS; // Working buffer into which we JIT.
75 SmallVector SV; // Working buffer into which we JIT.
76 raw_svector_ostream OS; // streaming wrapper
7277 };
7378
7479 } // namespace llvm
183183 O << "|" << DOT::EscapeString(NodeDesc);
184184 }
185185
186 string_ostream EdgeSourceLabels;
186 std::string edgeSourceLabels;
187 raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
187188 bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
188189
189190 if (hasEdgeSourceLabels) {
611611 typename std::enable_if::value,void>::type
612612 yamlize(IO &io, T &Val, bool) {
613613 if ( io.outputting() ) {
614 llvm::string_ostream Buffer;
614 std::string Storage;
615 llvm::raw_string_ostream Buffer(Storage);
615616 ScalarTraits::output(Val, io.getContext(), Buffer);
616617 StringRef Str = Buffer.str();
617618 io.scalarString(Str, ScalarTraits::mustQuote(Str));
1414 #define LLVM_SUPPORT_RAW_OSTREAM_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/SmallVector.h"
1817 #include "llvm/Support/Compiler.h"
1918 #include "llvm/Support/DataTypes.h"
2019
2120 namespace llvm {
2221 class format_object_base;
22 template
23 class SmallVectorImpl;
2324
2425 namespace sys {
2526 namespace fs {
459460 /// current_pos - Return the current position within the stream, not
460461 /// counting the bytes currently in the buffer.
461462 uint64_t current_pos() const override;
462
463 protected:
464 // This constructor is specified not to access \p O provided for storage as it
465 // may not yet be initialized at construction time.
466 explicit raw_svector_ostream(SmallVectorImpl &O, std::nullptr_t)
467 : OS(O){};
468 void init();
469
470463 public:
471464 /// Construct a new raw_svector_ostream.
472465 ///
499492 ~raw_null_ostream();
500493 };
501494
502 /// string_ostream - A raw_ostream that builds a string. This is a
503 /// raw_svector_ostream with storage.
504 template
505 class small_string_ostream : public raw_svector_ostream {
506 SmallVector Buffer;
507 // There's no need to flush explicitly.
508 using raw_svector_ostream::flush;
509
510 public:
511 small_string_ostream() : raw_svector_ostream(Buffer, nullptr) { init(); }
512
513 void clear() {
514 flush();
515 Buffer.clear();
516 }
517 };
518
519 typedef small_string_ostream<128> string_ostream;
520
521495 } // end llvm namespace
522496
523497 #endif
4141
4242 void EmitString(raw_ostream &O) {
4343 // Escape the string.
44 small_string_ostream<256> Str;
45 Str.write_escaped(AggregateString);
44 SmallString<256> Str;
45 raw_svector_ostream(Str).write_escaped(AggregateString);
4646 AggregateString = Str.str();
4747
4848 O << " \"";
7474 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
7575 char **OutMessages) {
7676 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
77 string_ostream MsgsOS;
77 std::string Messages;
78 raw_string_ostream MsgsOS(Messages);
7879
7980 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
8081
8586 if (Action == LLVMAbortProcessAction && Result)
8687 report_fatal_error("Broken module found, compilation aborted!");
8788
88 if (OutMessages) {
89 MsgsOS << '\0';
90 *OutMessages = strdup(MsgsOS.str().data());
91 }
89 if (OutMessages)
90 *OutMessages = strdup(MsgsOS.str().c_str());
9291
9392 return Result;
9493 }
8181
8282 std::string getNodeLabel(const BasicBlock *Node,
8383 const BlockFrequencyInfo *Graph) {
84 string_ostream OS;
84 std::string Result;
85 raw_string_ostream OS(Result);
8586
86 OS << Node->getName() << ":";
87 OS << Node->getName().str() << ":";
8788 switch (ViewBlockFreqPropagationDAG) {
8889 case GVDT_Fraction:
8990 Graph->printBlockFreq(OS, Node);
9697 "never reach this point.");
9798 }
9899
99 return OS.str();
100 return Result;
100101 }
101102 };
102103
104104 const DataLayout *DL;
105105 TargetLibraryInfo *TLI;
106106
107 string_ostream MessagesStr;
107 std::string Messages;
108 raw_string_ostream MessagesStr;
108109
109110 static char ID; // Pass identification, replacement for typeid
110 Lint() : FunctionPass(ID) {
111 Lint() : FunctionPass(ID), MessagesStr(Messages) {
111112 initializeLintPass(*PassRegistry::getPassRegistry());
112113 }
113114
179180 TLI = &getAnalysis();
180181 visit(F);
181182 dbgs() << MessagesStr.str();
182 MessagesStr.clear();
183 Messages.clear();
183184 return false;
184185 }
185186
2727 using namespace llvm;
2828
2929 static std::string getTypeString(Type *T) {
30 string_ostream Result;
31 Result << *T;
32 return Result.str();
30 std::string Result;
31 raw_string_ostream Tmp(Result);
32 Tmp << *T;
33 return Tmp.str();
3334 }
3435
3536 /// Run: module ::= toplevelentity*
15841584
15851585 // Otherwise report the problem to the user.
15861586 {
1587 string_ostream OS;
1587 std::string S;
1588 raw_string_ostream OS(S);
15881589 OS << "Unsupported expression in static initializer: ";
15891590 CE->printAsOperand(OS, /*PrintType=*/false,
15901591 !AP.MF ? nullptr : AP.MF->getFunction()->getParent());
240240 }
241241 }
242242 if (Error) {
243 string_ostream Msg;
243 std::string msg;
244 raw_string_ostream Msg(msg);
244245 Msg << "invalid operand in inline asm: '" << AsmStr << "'";
245246 MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
246247 }
411412 }
412413 }
413414 if (Error) {
414 string_ostream Msg;
415 std::string msg;
416 raw_string_ostream Msg(msg);
415417 Msg << "invalid operand in inline asm: '" << AsmStr << "'";
416418 MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
417419 }
468470
469471 // Emit the inline asm to a temporary string so we can emit it through
470472 // EmitInlineAsm.
471 small_string_ostream<256> OS;
473 SmallString<256> StringData;
474 raw_svector_ostream OS(StringData);
472475
473476 // The variant of the current asmprinter.
474477 int AsmPrinterVariant = MAI->getAssemblerDialect();
513516 }
514517 OS << Counter;
515518 } else {
516 string_ostream Msg;
519 std::string msg;
520 raw_string_ostream Msg(msg);
517521 Msg << "Unknown special formatter '" << Code
518522 << "' for machine instr: " << *MI;
519523 report_fatal_error(Msg.str());
8888
8989 std::string getNodeLabel(const MachineBasicBlock *Node,
9090 const MachineBlockFrequencyInfo *Graph) {
91 string_ostream OS;
91 std::string Result;
92 raw_string_ostream OS(Result);
9293
93 OS << Node->getName() << ":";
94 OS << Node->getName().str() << ":";
9495 switch (ViewMachineBlockFreqPropagationDAG) {
9596 case GVDT_Fraction:
9697 Graph->printBlockFreq(OS, Node);
103104 "never reach this point.");
104105 }
105106
106 return OS.str();
107 return Result;
107108 }
108109 };
109110
263263 ///
264264 /// Only used by debug logging.
265265 static std::string getBlockName(MachineBasicBlock *BB) {
266 string_ostream OS;
266 std::string Result;
267 raw_string_ostream OS(Result);
267268 OS << "BB#" << BB->getNumber()
268269 << " (derived from LLVM BB '" << BB->getName() << "')";
269 return OS.str();
270 OS.flush();
271 return Result;
270272 }
271273
272274 /// \brief Helper to print the number of a MBB.
273275 ///
274276 /// Only used by debug logging.
275277 static std::string getBlockNum(MachineBasicBlock *BB) {
276 string_ostream OS;
278 std::string Result;
279 raw_string_ostream OS(Result);
277280 OS << "BB#" << BB->getNumber();
278 return OS.str();
281 OS.flush();
282 return Result;
279283 }
280284 #endif
281285
464464
465465 const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
466466 DL->getPrivateGlobalPrefix();
467 small_string_ostream<60> Name;
468 Name << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
467 SmallString<60> Name;
468 raw_svector_ostream(Name)
469 << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
469470 return Ctx.GetOrCreateSymbol(Name.str());
470471 }
471472
32343234 }
32353235
32363236 static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
3237 string_ostream SS;
3237 std::string Str;
3238 raw_string_ostream SS(Str);
32383239 const ScheduleDAGMI *DAG = static_cast(G);
32393240 const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
32403241 static_cast(G)->getDFSResult() : nullptr;
11961196 }
11971197
11981198 std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
1199 string_ostream oss;
1199 std::string s;
1200 raw_string_ostream oss(s);
12001201 if (SU == &EntrySU)
12011202 oss << "";
12021203 else if (SU == &ExitSU)
32443244
32453245
32463246 void SelectionDAGISel::CannotYetSelect(SDNode *N) {
3247 string_ostream Msg;
3247 std::string msg;
3248 raw_string_ostream Msg(msg);
32483249 Msg << "Cannot select: ";
32493250
32503251 if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
267267 }
268268
269269 std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
270 string_ostream O;
270 std::string s;
271 raw_string_ostream O(s);
271272 O << "SU(" << SU->NodeNum << "): ";
272273 if (SU->getNode()) {
273274 SmallVector GluedNodes;
211211 if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
212212 && !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
213213 && SchedModel.isComplete()) {
214 string_ostream Err;
215 Err << "DefIdx " << DefIdx << " exceeds machine model writes for "
216 << *DefMI;
217 report_fatal_error(Err.str());
214 std::string Err;
215 raw_string_ostream ss(Err);
216 ss << "DefIdx " << DefIdx << " exceeds machine model writes for "
217 << *DefMI;
218 report_fatal_error(ss.str());
218219 }
219220 #endif
220221 // FIXME: Automatically giving all implicit defs defaultDefLatency is
352352 Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset);
353353
354354 if (Offset != EndStructureOffset) {
355 string_ostream Str;
356 Str << format("Parsing entry instructions at %lx failed", StartOffset);
357 report_fatal_error(Str.str());
355 std::string Str;
356 raw_string_ostream OS(Str);
357 OS << format("Parsing entry instructions at %lx failed", StartOffset);
358 report_fatal_error(Str);
358359 }
359360 }
360361 }
6161
6262 /*===-- Error handling ----------------------------------------------------===*/
6363
64 static char *LLVMCreateMessage(string_ostream &OS) {
65 OS << '\0';
66 return strdup(OS.str().data());
67 }
68
6964 char *LLVMCreateMessage(const char *Message) {
7065 return strdup(Message);
7166 }
114109 }
115110
116111 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
117 string_ostream Msg;
118 DiagnosticPrinterRawOStream DP(Msg);
112 std::string MsgStorage;
113 raw_string_ostream Stream(MsgStorage);
114 DiagnosticPrinterRawOStream DP(Stream);
115
119116 unwrap(DI)->print(DP);
120 return LLVMCreateMessage(Msg);
117 Stream.flush();
118
119 return LLVMCreateMessage(MsgStorage.c_str());
121120 }
122121
123122 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
201200 }
202201
203202 char *LLVMPrintModuleToString(LLVMModuleRef M) {
204 string_ostream os;
203 std::string buf;
204 raw_string_ostream os(buf);
205
205206 unwrap(M)->print(os, nullptr);
206 return LLVMCreateMessage(os);
207 os.flush();
208
209 return strdup(buf.c_str());
207210 }
208211
209212 /*--.. Operations on inline assembler ......................................--*/
274277 }
275278
276279 char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
277 string_ostream os;
280 std::string buf;
281 raw_string_ostream os(buf);
278282
279283 if (unwrap(Ty))
280284 unwrap(Ty)->print(os);
281285 else
282286 os << "Printing Type";
283287
284 return LLVMCreateMessage(os);
288 os.flush();
289
290 return strdup(buf.c_str());
285291 }
286292
287293 /*--.. Operations on integer types .........................................--*/
525531 }
526532
527533 char* LLVMPrintValueToString(LLVMValueRef Val) {
528 string_ostream os;
534 std::string buf;
535 raw_string_ostream os(buf);
529536
530537 if (unwrap(Val))
531538 unwrap(Val)->print(os);
532539 else
533540 os << "Printing Value";
534541
535 return LLVMCreateMessage(os);
542 os.flush();
543
544 return strdup(buf.c_str());
536545 }
537546
538547 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
518518 }
519519
520520 std::string DataLayout::getStringRepresentation() const {
521 string_ostream OS;
521 std::string Result;
522 raw_string_ostream OS(Result);
522523
523524 OS << (LittleEndian ? "e" : "E");
524525
163163 }
164164
165165 // Otherwise, print the message with a prefix based on the severity.
166 string_ostream Msg;
167 DiagnosticPrinterRawOStream DP(Msg);
166 std::string MsgStorage;
167 raw_string_ostream Stream(MsgStorage);
168 DiagnosticPrinterRawOStream DP(Stream);
168169 DI.print(DP);
169
170 Stream.flush();
170171 switch (DI.getSeverity()) {
171172 case DS_Error:
172 errs() << "error: " << Msg.str() << "\n";
173 errs() << "error: " << MsgStorage << "\n";
173174 exit(1);
174175 case DS_Warning:
175 errs() << "warning: " << Msg.str() << "\n";
176 errs() << "warning: " << MsgStorage << "\n";
176177 break;
177178 case DS_Remark:
178 errs() << "remark: " << Msg.str() << "\n";
179 errs() << "remark: " << MsgStorage << "\n";
179180 break;
180181 case DS_Note:
181 errs() << "note: " << Msg.str() << "\n";
182 errs() << "note: " << MsgStorage << "\n";
182183 break;
183184 }
184185 }
107107
108108 if(!*OutM) {
109109 if (OutMessage) {
110 string_ostream os;
110 std::string buf;
111 raw_string_ostream os(buf);
112
111113 Diag.print(nullptr, os, false);
112 os << '\0';
113 *OutMessage = strdup(os.str().data());
114 os.flush();
115
116 *OutMessage = strdup(buf.c_str());
114117 }
115118 return 1;
116119 }
548548 break;
549549 }
550550 // Create the string that will be reported to the external diagnostic handler.
551 string_ostream Msg;
552 DiagnosticPrinterRawOStream DP(Msg);
551 std::string MsgStorage;
552 raw_string_ostream Stream(MsgStorage);
553 DiagnosticPrinterRawOStream DP(Stream);
553554 DI.print(DP);
554
555 // Null-terminate the C string.
556 Msg << '\0';
555 Stream.flush();
557556
558557 // If this method has been called it means someone has set up an external
559558 // diagnostic handler. Assert on that.
560559 assert(DiagHandler && "Invalid diagnostic handler");
561 (*DiagHandler)(Severity, Msg.str().data(), DiagContext);
560 (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
562561 }
563562
564563 void
11741174 raw_ostream &OS = GetCommentOS();
11751175 SmallString<256> Code;
11761176 SmallVector Fixups;
1177 {
1178 raw_svector_ostream VecOS(Code);
1179 Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
1180 }
1177 raw_svector_ostream VecOS(Code);
1178 Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
1179 VecOS.flush();
11811180
11821181 // If we are showing fixups, create symbolic markers in the encoded
11831182 // representation. We do this by making a per-bit map to the fixup item index,
139139 }
140140
141141 MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
142 small_string_ostream<128> NameSV;
143 NameSV << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
144 return CreateSymbol(NameSV.str());
142 SmallString<128> NameSV;
143 raw_svector_ostream(NameSV)
144 << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
145 return CreateSymbol(NameSV);
145146 }
146147
147148 MCSymbol *MCContext::CreateTempSymbol() {
148 small_string_ostream<128> NameSV;
149 NameSV << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
150 return CreateSymbol(NameSV.str());
149 SmallString<128> NameSV;
150 raw_svector_ostream(NameSV)
151 << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
152 return CreateSymbol(NameSV);
151153 }
152154
153155 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
269269 const MCDisassembler *DisAsm = DC->getDisAsm();
270270 MCInstPrinter *IP = DC->getIP();
271271 MCDisassembler::DecodeStatus S;
272 small_string_ostream<64> Annotations;
272 SmallVector InsnStr;
273 raw_svector_ostream Annotations(InsnStr);
273274 S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
274275 /*REMOVE*/ nulls(), Annotations);
275276 switch (S) {
279280 return 0;
280281
281282 case MCDisassembler::Success: {
283 Annotations.flush();
284 StringRef AnnotationsStr = Annotations.str();
285
282286 SmallVector InsnStr;
283287 raw_svector_ostream OS(InsnStr);
284288 formatted_raw_ostream FormattedOS(OS);
285 IP->printInst(&Inst, FormattedOS, Annotations.str());
289 IP->printInst(&Inst, FormattedOS, AnnotationsStr);
286290
287291 if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
288292 emitLatency(DC, Inst);
419419 void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
420420 uint64_t AddrDelta) {
421421 MCContext &Context = MCOS->getContext();
422 small_string_ostream<256> OS;
422 SmallString<256> Tmp;
423 raw_svector_ostream OS(Tmp);
423424 MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
424425 MCOS->EmitBytes(OS.str());
425426 }
16451646 void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
16461647 uint64_t AddrDelta) {
16471648 MCContext &Context = Streamer.getContext();
1648 small_string_ostream<256> OS;
1649 SmallString<256> Tmp;
1650 raw_svector_ostream OS(Tmp);
16491651 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
16501652 Streamer.EmitBytes(OS.str());
16511653 }
45794579 }
45804580
45814581 // Build the IR assembly string.
4582 string_ostream OS;
4582 std::string AsmStringIR;
4583 raw_string_ostream OS(AsmStringIR);
45834584 const char *AsmStart = SrcMgr.getMemoryBuffer(0)->getBufferStart();
45844585 const char *AsmEnd = SrcMgr.getMemoryBuffer(0)->getBufferEnd();
45854586 array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
46444645 }
46454646 case AOK_DotOperator:
46464647 // Insert the dot if the user omitted it.
4647 if (OS.str().back() != '.')
4648 OS.flush();
4649 if (AsmStringIR.back() != '.')
46484650 OS << '.';
46494651 OS << AR.Val;
46504652 break;
300300
301301 static void printRelocationTargetName(const MachOObjectFile *O,
302302 const MachO::any_relocation_info &RE,
303 raw_ostream &fmt) {
303 raw_string_ostream &fmt) {
304304 bool IsScattered = O->isRelocationScattered(RE);
305305
306306 // Target of a scattered relocation is an address. In the interest of
10091009
10101010 unsigned Arch = this->getArch();
10111011
1012 string_ostream fmt;
1012 std::string fmtbuf;
1013 raw_string_ostream fmt(fmtbuf);
10131014 unsigned Type = this->getAnyRelocationType(RE);
10141015 bool IsPCRel = this->getAnyRelocationPCRel(RE);
10151016
11721173 } else
11731174 printRelocationTargetName(this, RE, fmt);
11741175
1175 StringRef fmtbuf = fmt.str();
1176 fmt.flush();
11761177 Result.append(fmtbuf.begin(), fmtbuf.end());
11771178 return object_error::success;
11781179 }
6161 }
6262
6363 std::string Arg::getAsString(const ArgList &Args) const {
64 small_string_ostream<256> OS;
64 SmallString<256> Res;
65 llvm::raw_svector_ostream OS(Res);
6566
6667 ArgStringList ASL;
6768 render(Args, ASL);
9394 break;
9495
9596 case Option::RenderCommaJoinedStyle: {
96 small_string_ostream<256> OS;
97 SmallString<256> Res;
98 llvm::raw_svector_ostream OS(Res);
9799 OS << getSpelling();
98100 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
99101 if (i) OS << ',';
13411341
13421342 // printOptionDiff - Specializations for printing basic value types.
13431343 //
1344 #define PRINT_OPT_DIFF(T) \
1345 void parser::printOptionDiff(const Option &O, T V, OptionValue D, \
1346 size_t GlobalWidth) const { \
1347 printOptionName(O, GlobalWidth); \
1348 string_ostream SS; \
1349 SS << V; \
1350 outs() << "= " << SS.str(); \
1351 size_t NumSpaces = MaxOptWidth > SS.tell() ? MaxOptWidth - SS.tell() : 0; \
1352 outs().indent(NumSpaces) << " (default: "; \
1353 if (D.hasValue()) \
1354 outs() << D.getValue(); \
1355 else \
1356 outs() << "*no default*"; \
1357 outs() << ")\n"; \
1358 }
1344 #define PRINT_OPT_DIFF(T) \
1345 void parser:: \
1346 printOptionDiff(const Option &O, T V, OptionValue D, \
1347 size_t GlobalWidth) const { \
1348 printOptionName(O, GlobalWidth); \
1349 std::string Str; \
1350 { \
1351 raw_string_ostream SS(Str); \
1352 SS << V; \
1353 } \
1354 outs() << "= " << Str; \
1355 size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\
1356 outs().indent(NumSpaces) << " (default: "; \
1357 if (D.hasValue()) \
1358 outs() << D.getValue(); \
1359 else \
1360 outs() << "*no default*"; \
1361 outs() << ")\n"; \
1362 } \
13591363
13601364 PRINT_OPT_DIFF(bool)
13611365 PRINT_OPT_DIFF(boolOrDefault)
703703 // and we only need to set the vector size when the data is flushed.
704704
705705 raw_svector_ostream::raw_svector_ostream(SmallVectorImpl &O) : OS(O) {
706 init();
707 }
708
709 void raw_svector_ostream::init() {
710706 // Set up the initial external buffer. We make sure that the buffer has at
711707 // least 128 bytes free; raw_ostream itself only requires 64, but we want to
712708 // make sure that we don't grow the buffer unnecessarily on destruction (when
208208 break;
209209 else if (Step < 0 && From < To)
210210 break;
211 string_ostream Name;
212 Name << format(Format.c_str(), unsigned(From));
213 Record *Rec = Records.getDef(Name.str());
211 std::string Name;
212 raw_string_ostream OS(Name);
213 OS << format(Format.c_str(), unsigned(From));
214 Record *Rec = Records.getDef(OS.str());
214215 if (!Rec)
215 PrintFatalError(Loc, "No def named '" + Name.str() + "': " +
216 Expr->getAsString());
216 PrintFatalError(Loc, "No def named '" + Name + "': " +
217 Expr->getAsString());
217218 // Try to reevaluate Rec in case it is a set.
218219 if (const RecVec *Result = ST.expand(Rec))
219220 Elts.insert(Result->begin(), Result->end());
13061306 if (ItemType) {
13071307 ListRecTy *ListType = dyn_cast(ItemType);
13081308 if (!ListType) {
1309 string_ostream ss;
1309 std::string s;
1310 raw_string_ostream ss(s);
13101311 ss << "Type mismatch for list, expected list type, got "
13111312 << ItemType->getAsString();
13121313 TokError(ss.str());
145145
146146 // Otherwise report the problem to the user.
147147 {
148 string_ostream OS;
148 std::string S;
149 raw_string_ostream OS(S);
149150 OS << "Unsupported expression in static initializer: ";
150151 CE->printAsOperand(OS, /*PrintType=*/ false,
151152 !AP.MF ? nullptr : AP.MF->getFunction()->getParent());
236236 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
237237 LLVMModuleRef M, LLVMCodeGenFileType codegen, char** ErrorMessage,
238238 LLVMMemoryBufferRef *OutMemBuf) {
239 string_ostream Code;
240 formatted_raw_ostream Out(Code);
239 std::string CodeString;
240 raw_string_ostream OStream(CodeString);
241 formatted_raw_ostream Out(OStream);
241242 bool Result = LLVMTargetMachineEmit(T, M, Out, codegen, ErrorMessage);
242
243 StringRef Buffer = Code.str();
244 *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Buffer.data(),
245 Buffer.size(), "");
243 OStream.flush();
244
245 std::string &Data = OStream.str();
246 *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Data.c_str(),
247 Data.length(), "");
246248 return Result;
247249 }
248250
24112411 if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
24122412 if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
24132413
2414 small_string_ostream<128> OS;
2414 SmallString<126> Msg;
2415 raw_svector_ostream OS(Msg);
24152416 OS << "ambiguous instructions require an explicit suffix (could be ";
24162417 for (unsigned i = 0; i != NumMatches; ++i) {
24172418 if (i != 0)
280280 unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
281281
282282 if (RelaxedOp == Inst.getOpcode()) {
283 small_string_ostream<256> OS;
283 SmallString<256> Tmp;
284 raw_svector_ostream OS(Tmp);
284285 Inst.dump_pretty(OS);
285286 OS << "\n";
286287 report_fatal_error("unexpected instruction to relax: " + OS.str());
549549 }
550550
551551 void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
552 small_string_ostream<128> OS;
552 SmallString<128> Directive;
553 raw_svector_ostream OS(Directive);
553554 StringRef Name = Sym->getName();
554555
555556 if (Subtarget->isTargetKnownWindowsMSVC())
570571 OS << ",data";
571572 }
572573
573 OutStreamer.EmitBytes(OS.str());
574 OS.flush();
575 OutStreamer.EmitBytes(Directive);
574576 }
575577
576578 void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
266266 }
267267
268268 void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
269 small_string_ostream<128> O;
269 SmallString<128> Str;
270 raw_svector_ostream O(Str);
270271
271272 switch (MI->getOpcode()) {
272273 case XCore::DBG_VALUE:
351351 }
352352
353353 std::string getTypeName(Type *T) {
354 string_ostream OS;
354 std::string TypeName;
355 raw_string_ostream TypeStream(TypeName);
355356 if (T)
356 T->print(OS);
357 T->print(TypeStream);
357358 else
358 OS << "Printing Type";
359 return OS.str();
359 TypeStream << "Printing Type";
360 TypeStream.flush();
361 return TypeName;
360362 }
361363
362364 /// Returns the MDNode that represents type T if it is already created, or 0
315315 }
316316 ReturnBlock = new GCOVBlock(i++, os);
317317
318 string_ostream FnNameLine;
319 FnNameLine << getFunctionName(SP) << SP.getLineNumber();
320 FuncChecksum = hash_value(FnNameLine.str());
318 std::string FunctionNameAndLine;
319 raw_string_ostream FNLOS(FunctionNameAndLine);
320 FNLOS << getFunctionName(SP) << SP.getLineNumber();
321 FNLOS.flush();
322 FuncChecksum = hash_value(FunctionNameAndLine);
321323 }
322324
323325 ~GCOVFunction() {
334336 }
335337
336338 std::string getEdgeDestinations() {
337 string_ostream EdgeDestinations;
339 std::string EdgeDestinations;
340 raw_string_ostream EDOS(EdgeDestinations);
338341 Function *F = Blocks.begin()->first->getParent();
339342 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
340343 GCOVBlock &Block = *Blocks[I];
341344 for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
342 EdgeDestinations << Block.OutEdges[i]->Number;
343 }
344 return EdgeDestinations.str();
345 EDOS << Block.OutEdges[i]->Number;
346 }
347 return EdgeDestinations;
345348 }
346349
347350 uint32_t getFuncChecksum() {
24232423
24242424 if (PoisonStack && MS.TrackOrigins) {
24252425 setOrigin(&I, getCleanOrigin());
2426 small_string_ostream<2048> StackDescription;
2426 SmallString<2048> StackDescriptionStorage;
2427 raw_svector_ostream StackDescription(StackDescriptionStorage);
24272428 // We create a string with a description of the stack allocation and
24282429 // pass it into __msan_set_alloca_origin.
24292430 // It will be printed by the run-time if stack-originated UMR is found.
834834 // of line at the module level and to provide a very simple format
835835 // encoding the information herein. Both of these makes it simpler to
836836 // parse the annotations by a simple external program.
837 string_ostream os;
837 std::string Str;
838 raw_string_ostream os(Str);
838839 os << "(" << Inst->getParent()->getParent()->getName() << ",%"
839840 << Inst->getName() << ")";
840841
847848 Hash = cast(Node->getOperand(0));
848849 }
849850 } else if (Argument *Arg = dyn_cast(Ptr)) {
850 string_ostream os;
851 std::string str;
852 raw_string_ostream os(str);
851853 os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
852854 << ")";
853855 Hash = MDString::get(Arg->getContext(), os.str());
857859 }
858860
859861 static std::string SequenceToString(Sequence A) {
860 string_ostream os;
862 std::string str;
863 raw_string_ostream os(str);
861864 os << A;
862865 return os.str();
863866 }
6464 Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
6565
6666 std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
67 small_string_ostream<2048> StackDescription;
67 SmallString<2048> StackDescriptionStorage;
68 raw_svector_ostream StackDescription(StackDescriptionStorage);
6869 StackDescription << NumVars;
6970 Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
7071 SmallVector &SB(Layout->ShadowBytes);
211211 /// Optimization analysis message produced during vectorization. Messages inform
212212 /// the user why vectorization did not occur.
213213 class Report {
214 string_ostream Message;
214 std::string Message;
215 raw_string_ostream Out;
215216 Instruction *Instr;
216217
217218 public:
218 Report(Instruction *I = nullptr) : Instr(I) {
219 Message << "loop not vectorized: ";
219 Report(Instruction *I = nullptr) : Out(Message), Instr(I) {
220 Out << "loop not vectorized: ";
220221 }
221222
222223 template Report &operator<<(const A &Value) {
223 Message << Value;
224 Out << Value;
224225 return *this;
225226 }
226227
227228 Instruction *getInstr() { return Instr; }
228229
229 StringRef str() { return Message.str(); }
230 operator Twine() { return Message.str(); }
230 std::string &str() { return Out.str(); }
231 operator Twine() { return Out.str(); }
231232 };
232233
233234 /// InnerLoopVectorizer vectorizes loops which contain only one basic
501502 #ifndef NDEBUG
502503 /// \return string containing a file name and a line # for the given loop.
503504 static std::string getDebugLocString(const Loop *L) {
504 if (!L)
505 return std::string();
506
507 string_ostream OS;
508 const DebugLoc LoopDbgLoc = L->getStartLoc();
509 if (!LoopDbgLoc.isUnknown())
510 LoopDbgLoc.print(L->getHeader()->getContext(), OS);
511 else
512 // Just print the module name.
513 OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
514 return OS.str();
505 std::string Result;
506 if (L) {
507 raw_string_ostream OS(Result);
508 const DebugLoc LoopDbgLoc = L->getStartLoc();
509 if (!LoopDbgLoc.isUnknown())
510 LoopDbgLoc.print(L->getHeader()->getContext(), OS);
511 else
512 // Just print the module name.
513 OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
514 OS.flush();
515 }
516 return Result;
515517 }
516518 #endif
517519
688688 std::vector> &MemberOffsetRefs) {
689689 unsigned StartOffset = 0;
690690 unsigned MemberNum = 0;
691 string_ostream NameOS;
691 std::string NameBuf;
692 raw_string_ostream NameOS(NameBuf);
692693 unsigned NumSyms = 0;
693694 LLVMContext &Context = getGlobalContext();
694695 for (ArrayRef::iterator I = Members.begin(),
221221 Out << "";
222222
223223 // Escape special chars and print the instruction in mnemonic form.
224 string_ostream OS;
224 std::string Str;
225 raw_string_ostream OS(Str);
225226 IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
226227 Out << DOT::EscapeString(OS.str());
227228 }
471472 if (Symbols.empty())
472473 Symbols.push_back(std::make_pair(0, name));
473474
474 small_string_ostream<40> Comments;
475
476 SmallString<40> Comments;
477 raw_svector_ostream CommentStream(Comments);
475478
476479 StringRef Bytes;
477480 if (error(Section.getContents(Bytes)))
509512 MCInst Inst;
510513
511514 if (DisAsm->getInstruction(Inst, Size, memoryObject,
512 SectionAddr + Index, DebugOut, Comments)) {
515 SectionAddr + Index,
516 DebugOut, CommentStream)) {
513517 outs() << format("%8" PRIx64 ":", SectionAddr + Index);
514518 if (!NoShowRawInsn) {
515519 outs() << "\t";
516520 DumpBytes(StringRef(Bytes.data() + Index, Size));
517521 }
518522 IP->printInst(&Inst, outs(), "");
519 outs() << Comments.str();
523 outs() << CommentStream.str();
520524 Comments.clear();
521525 outs() << "\n";
522526 } else {
9494
9595 static std::string formatSymbol(StringRef Name, uint64_t Address,
9696 uint64_t Offset = 0) {
97 string_ostream OS;
97 std::string Buffer;
98 raw_string_ostream OS(Buffer);
9899
99100 if (!Name.empty())
100101 OS << Name << " ";
114114 static std::string formatSymbol(const Dumper::Context &Ctx,
115115 const coff_section *Section, uint64_t Offset,
116116 uint32_t Displacement) {
117 string_ostream OS;
117 std::string Buffer;
118 raw_string_ostream OS(Buffer);
118119
119120 StringRef Name;
120121 SymbolRef Symbol;
129130 OS << format(" +0x%X (0x%" PRIX64 ")", Displacement, Offset);
130131 else
131132 OS << format(" (0x%" PRIX64 ")", Offset);
132
133133 return OS.str();
134134 }
135135
6969 }
7070
7171 std::string DumpFunction(const Function *F) {
72 string_ostream Result;
73 Result << "" << *F;
74 return Result.str();
72 std::string Result;
73 raw_string_ostream(Result) << "" << *F;
74 return Result;
7575 }
7676
7777 class RecordingJITMemoryManager : public JITMemoryManager {
169169 SMDiagnostic Error;
170170 bool success =
171171 nullptr != ParseAssemblyString(assembly, M, Error, M->getContext());
172 string_ostream errMsg;
173 Error.print("", errMsg);
174 EXPECT_TRUE(success) << errMsg.str();
172 std::string errMsg;
173 raw_string_ostream os(errMsg);
174 Error.print("", os);
175 EXPECT_TRUE(success) << os.str();
175176 return success;
176177 }
177178
457457 // variable values.
458458 if (!VariableUses.empty()) {
459459 for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
460 small_string_ostream<256> OS;
460 SmallString<256> Msg;
461 raw_svector_ostream OS(Msg);
461462 StringRef Var = VariableUses[i].first;
462463 if (Var[0] == '@') {
463464 std::string Value;
318318
319319 // Default case: unhandled opcode
320320 o << " default:\n"
321 << " string_ostream Msg;\n"
321 << " std::string msg;\n"
322 << " raw_string_ostream Msg(msg);\n"
322323 << " Msg << \"Not supported instr: \" << MI;\n"
323324 << " report_fatal_error(Msg.str());\n"
324325 << " }\n"
165165 }
166166
167167 static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
168 llvm::string_ostream OS;
169 OS << "[\n";
168 std::string JSONText;
169 llvm::raw_string_ostream Stream(JSONText);
170 Stream << "[\n";
170171 size_t MemoryBytes = MemoryMB * 1024 * 1024;
171 while (OS.tell() < MemoryBytes) {
172 OS << " {\n"
173 << " \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
174 << " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
175 << " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
176 << " }";
177 if (OS.tell() < MemoryBytes)
178 OS << ",";
179 OS << "\n";
180 }
181 OS << "]\n";
182 return OS.str();
172 while (JSONText.size() < MemoryBytes) {
173 Stream << " {\n"
174 << " \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
175 << " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
176 << " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
177 << " }";
178 Stream.flush();
179 if (JSONText.size() < MemoryBytes) Stream << ",";
180 Stream << "\n";
181 }
182 Stream << "]\n";
183 Stream.flush();
184 return JSONText;
183185 }
184186
185187 int main(int argc, char **argv) {