llvm.org GIT mirror llvm / d9ea85a
remove some uses of llvm/Support/Streams.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79842 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
16 changed file(s) with 113 addition(s) and 164 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/System/Mutex.h"
1919 #include
2020 #include
21 #include
2221 #include
2322
2423 namespace llvm {
2524
2625 class TimerGroup;
26 class raw_ostream;
2727
2828 /// Timer - This class is used to track the amount of time spent between
2929 /// invocations of it's startTimer()/stopTimer() methods. Given appropriate OS
111111
112112 /// print - Print the current timer to standard error, and reset the "Started"
113113 /// flag.
114 void print(const Timer &Total, std::ostream &OS);
114 void print(const Timer &Total, raw_ostream &OS);
115115
116116 private:
117117 friend class TimerGroup;
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Bitcode/Serialize.h"
14 #include "string.h"
15
16 #ifdef DEBUG_BACKPATCH
17 #include "llvm/Support/Streams.h"
18 #endif
14 #include "llvm/Support/raw_ostream.h"
15 #include
1916
2017 using namespace llvm;
2118
8582 if (I == PtrMap.end()) {
8683 unsigned id = PtrMap.size()+1;
8784 #ifdef DEBUG_BACKPATCH
88 llvm::cerr << "Registered PTR: " << ptr << " => " << id << "\n";
85 errs() << "Registered PTR: " << ptr << " => " << id << "\n";
8986 #endif
9087 PtrMap[ptr] = id;
9188 return id;
2525 #include "llvm/Support/ErrorHandling.h"
2626 #include "llvm/Support/LeakDetector.h"
2727 #include "llvm/Support/MathExtras.h"
28 #include "llvm/Support/Streams.h"
2928 #include "llvm/Support/raw_ostream.h"
3029 #include "llvm/ADT/FoldingSet.h"
3130 using namespace llvm;
2323 #include "llvm/Module.h"
2424 #include "llvm/Support/Dwarf.h"
2525 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/Streams.h"
2726 using namespace llvm;
2827 using namespace llvm::dwarf;
2928
25972597
25982598 void SimpleRegisterCoalescing::printRegName(unsigned reg) const {
25992599 if (TargetRegisterInfo::isPhysicalRegister(reg))
2600 cerr << tri_->getName(reg);
2600 errs() << tri_->getName(reg);
26012601 else
2602 cerr << "%reg" << reg;
2602 errs() << "%reg" << reg;
26032603 }
26042604
26052605 void SimpleRegisterCoalescing::releaseMemory() {
258258 return AnyUnused;
259259 }
260260
261 void VirtRegMap::print(std::ostream &OS, const Module* M) const {
262 raw_os_ostream RawOS(OS);
263 print(RawOS, M);
264 }
265
266261 void VirtRegMap::print(raw_ostream &OS, const Module* M) const {
267262 const TargetRegisterInfo* TRI = MF->getTarget().getRegisterInfo();
268263
282277 }
283278
284279 void VirtRegMap::dump() const {
285 print(cerr);
286 }
280 print(errs());
281 }
2323 #include "llvm/ADT/IndexedMap.h"
2424 #include "llvm/ADT/SmallPtrSet.h"
2525 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/Support/Streams.h"
2726 #include
2827
2928 namespace llvm {
481480 return 0;
482481 }
483482
484 void print(std::ostream &OS, const Module* M = 0) const;
485 void print(std::ostream *OS) const { if (OS) print(*OS); }
486483 void print(raw_ostream &OS, const Module* M = 0) const;
487 void print(raw_ostream *OS) const { if (OS) print(*OS); }
488484 void dump() const;
489485 };
490486
491 inline std::ostream *operator<<(std::ostream *OS, const VirtRegMap &VRM) {
492 VRM.print(OS);
493 return OS;
494 }
495 inline std::ostream &operator<<(std::ostream &OS, const VirtRegMap &VRM) {
496 VRM.print(OS);
497 return OS;
498 }
499 inline raw_ostream *operator<<(raw_ostream *OS, const VirtRegMap &VRM) {
500 VRM.print(OS);
501 return OS;
502 }
503487 inline raw_ostream &operator<<(raw_ostream &OS, const VirtRegMap &VRM) {
504488 VRM.print(OS);
505489 return OS;
2222 #include "llvm/Debugger/SourceFile.h"
2323 #include "llvm/Debugger/SourceLanguage.h"
2424 #include "llvm/Support/SlowOperationInformer.h"
25 #include "llvm/Support/Streams.h"
2625 #include "llvm/ADT/STLExtras.h"
2726 using namespace llvm;
2827
183182 if (SD) { // We found the first stop point!
184183 // This is just a sanity check.
185184 if (getSourceFile().getDescriptor() != SD)
186 cout << "WARNING: first line of function is not in the"
185 outs() << "WARNING: first line of function is not in the"
187186 << " file that the function descriptor claims it is in.\n";
188187 break;
189188 }
1414
1515 #include "llvm/Debugger/SourceLanguage.h"
1616 #include "llvm/Debugger/ProgramInfo.h"
17 #include "llvm/Support/Streams.h"
17 #include "llvm/Support/raw_ostream.h"
1818 #include
19 #include
2019 using namespace llvm;
2120
2221 //===----------------------------------------------------------------------===//
131130 SourceFunctionInfo *Found = IP.first->second;
132131 ++IP.first;
133132 if (IP.first != IP.second)
134 cout << "Whoa, found multiple functions with the same name. I should"
133 outs() << "Whoa, found multiple functions with the same name. I should"
135134 << " ask the user which one to use: FIXME!\n";
136135 return Found;
137136 }
2323 #include "llvm/Module.h"
2424 #include "llvm/Config/config.h" // Detect libffi
2525 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/Streams.h"
2726 #include "llvm/System/DynamicLibrary.h"
2827 #include "llvm/Target/TargetData.h"
2928 #include "llvm/Support/ManagedStatic.h"
278277 #endif // USE_LIBFFI
279278
280279 if (F->getName() == "__main")
281 cerr << "Tried to execute an unknown external function: "
280 errs() << "Tried to execute an unknown external function: "
282281 << F->getType()->getDescription() << " __main\n";
283282 else
284283 llvm_report_error("Tried to execute an unknown external function: " +
392391 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
393392 case 's':
394393 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
395 default: cerr << "";
394 default:
395 errs() << "";
396396 ArgNo++; break;
397397 }
398398 strcpy(OutputBuffer, Buffer);
413413 NewArgs.push_back(PTOGV((void*)&Buffer[0]));
414414 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
415415 GenericValue GV = lle_X_sprintf(FT, NewArgs);
416 cout << Buffer;
416 outs() << Buffer;
417417 return GV;
418418 }
419419
1616
1717 #include "JIT.h"
1818 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/Streams.h"
2019 #include "llvm/System/DynamicLibrary.h"
2120 #include "llvm/Config/config.h"
2221 using namespace llvm;
850850 //
851851 void basic_parser_impl::printOptionInfo(const Option &O,
852852 size_t GlobalWidth) const {
853 cout << " -" << O.ArgStr;
853 outs() << " -" << O.ArgStr;
854854
855855 if (const char *ValName = getValueName())
856 cout << "=<" << getValueStr(O, ValName) << ">";
857
858 cout << std::string(GlobalWidth-getOptionWidth(O), ' ') << " - "
859 << O.HelpStr << "\n";
856 outs() << "=<" << getValueStr(O, ValName) << '>';
857
858 outs().indent(GlobalWidth-getOptionWidth(O)) << " - " << O.HelpStr << '\n';
860859 }
861860
862861
989988 size_t GlobalWidth) const {
990989 if (O.hasArgStr()) {
991990 size_t L = std::strlen(O.ArgStr);
992 cout << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
993 << " - " << O.HelpStr << "\n";
991 outs() << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
992 << " - " << O.HelpStr << '\n';
994993
995994 for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
996995 size_t NumSpaces = GlobalWidth-strlen(getOption(i))-8;
997 cout << " =" << getOption(i) << std::string(NumSpaces, ' ')
998 << " - " << getDescription(i) << "\n";
996 outs() << " =" << getOption(i) << std::string(NumSpaces, ' ')
997 << " - " << getDescription(i) << '\n';
999998 }
1000999 } else {
10011000 if (O.HelpStr[0])
1002 cout << " " << O.HelpStr << "\n";
1001 outs() << " " << O.HelpStr << "\n";
10031002 for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
10041003 size_t L = std::strlen(getOption(i));
1005 cout << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
1006 << " - " << getDescription(i) << "\n";
1004 outs() << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
1005 << " - " << getDescription(i) << "\n";
10071006 }
10081007 }
10091008 }
10621061 }
10631062
10641063 if (ProgramOverview)
1065 cout << "OVERVIEW: " << ProgramOverview << "\n";
1066
1067 cout << "USAGE: " << ProgramName << " [options]";
1064 outs() << "OVERVIEW: " << ProgramOverview << "\n";
1065
1066 outs() << "USAGE: " << ProgramName << " [options]";
10681067
10691068 // Print out the positional options.
10701069 Option *CAOpt = 0; // The cl::ConsumeAfter option, if it exists...
10741073
10751074 for (size_t i = CAOpt != 0, e = PositionalOpts.size(); i != e; ++i) {
10761075 if (PositionalOpts[i]->ArgStr[0])
1077 cout << " --" << PositionalOpts[i]->ArgStr;
1078 cout << " " << PositionalOpts[i]->HelpStr;
1076 outs() << " --" << PositionalOpts[i]->ArgStr;
1077 outs() << " " << PositionalOpts[i]->HelpStr;
10791078 }
10801079
10811080 // Print the consume after option info if it exists...
1082 if (CAOpt) cout << " " << CAOpt->HelpStr;
1083
1084 cout << "\n\n";
1081 if (CAOpt) outs() << " " << CAOpt->HelpStr;
1082
1083 outs() << "\n\n";
10851084
10861085 // Compute the maximum argument length...
10871086 MaxArgLen = 0;
10881087 for (size_t i = 0, e = Opts.size(); i != e; ++i)
10891088 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
10901089
1091 cout << "OPTIONS:\n";
1090 outs() << "OPTIONS:\n";
10921091 for (size_t i = 0, e = Opts.size(); i != e; ++i)
10931092 Opts[i].second->printOptionInfo(MaxArgLen);
10941093
10951094 // Print any extra help the user has declared.
10961095 for (std::vector::iterator I = MoreHelp->begin(),
10971096 E = MoreHelp->end(); I != E; ++I)
1098 cout << *I;
1097 outs() << *I;
10991098 MoreHelp->clear();
11001099
11011100 // Halt the program since help information was printed
11241123 class VersionPrinter {
11251124 public:
11261125 void print() {
1127 cout << "Low Level Virtual Machine (http://llvm.org/):\n";
1128 cout << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
1126 raw_ostream &stdout = outs();
1127 stdout << "Low Level Virtual Machine (http://llvm.org/):\n";
1128 stdout << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
11291129 #ifdef LLVM_VERSION_INFO
1130 cout << LLVM_VERSION_INFO;
1130 stdout << LLVM_VERSION_INFO;
11311131 #endif
1132 cout << "\n ";
1132 stdout << "\n ";
11331133 #ifndef __OPTIMIZE__
1134 cout << "DEBUG build";
1134 stdout << "DEBUG build";
11351135 #else
1136 cout << "Optimized build";
1136 stdout << "Optimized build";
11371137 #endif
11381138 #ifndef NDEBUG
1139 cout << " with assertions";
1139 stdout << " with assertions";
11401140 #endif
1141 cout << ".\n";
1142 cout << " Built " << __DATE__ << "(" << __TIME__ << ").\n";
1143 cout << "\n";
1144 cout << " Registered Targets:\n";
1145
1146 std::vector > Targets;
1147 size_t Width = 0;
1148 for (TargetRegistry::iterator it = TargetRegistry::begin(),
1149 ie = TargetRegistry::end(); it != ie; ++it) {
1150 Targets.push_back(std::make_pair(it->getName(), &*it));
1151 Width = std::max(Width, ::strlen(it->getName()));
1152 }
1153 std::sort(Targets.begin(), Targets.end());
1154
1155 for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
1156 const Target *T = Targets[i].second;
1157 cout << " " << T->getName()
1141 stdout << ".\n";
1142 stdout << " Built " << __DATE__ << "(" << __TIME__ << ").\n";
1143 stdout << "\n";
1144 stdout << " Registered Targets:\n";
1145
1146 std::vector > Targets;
1147 size_t Width = 0;
1148 for (TargetRegistry::iterator it = TargetRegistry::begin(),
1149 ie = TargetRegistry::end(); it != ie; ++it) {
1150 Targets.push_back(std::make_pair(it->getName(), &*it));
1151 Width = std::max(Width, ::strlen(it->getName()));
1152 }
1153 std::sort(Targets.begin(), Targets.end());
1154
1155 for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
1156 const Target *T = Targets[i].second;
1157 stdout << " " << T->getName()
11581158 << std::string(Width - ::strlen(T->getName()), ' ') << " - "
11591159 << T->getShortDescription() << "\n";
1160 }
1161 if (Targets.empty())
1162 cout << " (none)\n";
1160 }
1161 if (Targets.empty())
1162 stdout << " (none)\n";
11631163 }
11641164 void operator=(bool OptionWasSpecified) {
11651165 if (OptionWasSpecified) {
1313 #define DONT_GET_PLUGIN_LOADER_OPTION
1414 #include "llvm/Support/ManagedStatic.h"
1515 #include "llvm/Support/PluginLoader.h"
16 #include "llvm/Support/Streams.h"
16 #include "llvm/Support/raw_ostream.h"
1717 #include "llvm/System/DynamicLibrary.h"
1818 #include "llvm/System/Mutex.h"
19 #include
2019 #include
2120 using namespace llvm;
2221
2726 sys::SmartScopedLock Lock(*PluginsLock);
2827 std::string Error;
2928 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
30 cerr << "Error opening '" << Filename << "': " << Error
31 << "\n -load request ignored.\n";
29 errs() << "Error opening '" << Filename << "': " << Error
30 << "\n -load request ignored.\n";
3231 } else {
3332 Plugins->push_back(Filename);
3433 }
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Support/SlowOperationInformer.h"
14 #include "llvm/Support/Streams.h"
14 #include "llvm/Support/raw_ostream.h"
1515 #include "llvm/System/Alarm.h"
1616 #include
1717 #include
2727 if (LastPrintAmount) {
2828 // If we have printed something, make _sure_ we print the 100% amount, and
2929 // also print a newline.
30 cout << std::string(LastPrintAmount, '\b') << "Progress "
31 << OperationName << ": 100% \n";
30 outs() << std::string(LastPrintAmount, '\b') << "Progress "
31 << OperationName << ": 100% \n";
3232 }
3333 }
3434
3939 bool SlowOperationInformer::progress(unsigned Amount) {
4040 int status = sys::AlarmStatus();
4141 if (status == -1) {
42 cout << "\n";
42 outs() << "\n";
4343 LastPrintAmount = 0;
4444 return true;
4545 }
6060 OS << "% ";
6161
6262 LastPrintAmount = OS.str().size();
63 cout << ToPrint+OS.str() << std::flush;
63 outs() << ToPrint+OS.str();
64 outs().flush();
6465 return false;
6566 }
2323 #include "llvm/ADT/Statistic.h"
2424 #include "llvm/Support/CommandLine.h"
2525 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/Streams.h"
26 #include "llvm/Support/raw_ostream.h"
2727 #include "llvm/System/Mutex.h"
2828 #include "llvm/ADT/StringExtras.h"
2929 #include
30 #include
3130 #include
3231 using namespace llvm;
3332
3433 // GetLibSupportInfoOutputFile - Return a file stream to print our output on.
35 namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
34 namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
3635
3736 /// -stats - Command line option to cause transformations to emit stats about
3837 /// what they did.
9594 if (Stats.empty()) return;
9695
9796 // Get the stream to write to.
98 std::ostream &OutStream = *GetLibSupportInfoOutputFile();
97 raw_ostream &OutStream = *GetLibSupportInfoOutputFile();
9998
10099 // Figure out how long the biggest Value and Name fields are.
101100 unsigned MaxNameLen = 0, MaxValLen = 0;
124123
125124 }
126125
127 OutStream << std::endl; // Flush the output stream...
126 OutStream << '\n'; // Flush the output stream...
127 OutStream.flush();
128128
129 if (&OutStream != cerr.stream() && &OutStream != cout.stream())
129 if (&OutStream != &outs() && &OutStream != &errs())
130130 delete &OutStream; // Close the file.
131131 }
1313 #include "llvm/Support/Timer.h"
1414 #include "llvm/Support/CommandLine.h"
1515 #include "llvm/Support/ManagedStatic.h"
16 #include "llvm/Support/Streams.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include "llvm/Support/Format.h"
1718 #include "llvm/System/Process.h"
1819 #include
19 #include
2020 #include
2121 #include
2222 using namespace llvm;
2323
2424 // GetLibSupportInfoOutputFile - Return a file stream to print our output on.
25 namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
25 namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
2626
2727 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
2828 // of constructor/destructor ordering being unspecified by C++. Basically the
268268 // TimerGroup Implementation
269269 //===----------------------------------------------------------------------===//
270270
271 // printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
272 // TotalWidth size, and B is the AfterDec size.
273 //
274 static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
275 std::ostream &OS) {
276 assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
277 OS.width(TotalWidth-AfterDec-1);
278 char OldFill = OS.fill();
279 OS.fill(' ');
280 OS << (int)Val; // Integer part;
281 OS << ".";
282 OS.width(AfterDec);
283 OS.fill('0');
284 unsigned ResultFieldSize = 1;
285 while (AfterDec--) ResultFieldSize *= 10;
286 OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
287 OS.fill(OldFill);
288 }
289
290 static void printVal(double Val, double Total, std::ostream &OS) {
271
272 static void printVal(double Val, double Total, raw_ostream &OS) {
291273 if (Total < 1e-7) // Avoid dividing by zero...
292274 OS << " ----- ";
293275 else {
294 OS << " ";
295 printAlignedFP(Val, 4, 7, OS);
296 OS << " (";
297 printAlignedFP(Val*100/Total, 1, 5, OS);
298 OS << "%)";
299 }
300 }
301
302 void Timer::print(const Timer &Total, std::ostream &OS) {
276 OS << " " << format("%7.4f", Val) << " (";
277 OS << format("%5.1f", Val*100/Total) << "%)";
278 }
279 }
280
281 void Timer::print(const Timer &Total, raw_ostream &OS) {
303282 if (&Total < this) {
304283 Total.Lock.acquire();
305284 Lock.acquire();
319298 OS << " ";
320299
321300 if (Total.MemUsed) {
322 OS.width(9);
323 OS << MemUsed << " ";
301 OS << format("%9lld", (long long)MemUsed) << " ";
324302 }
325303 if (Total.PeakMem) {
326304 if (PeakMem) {
327 OS.width(9);
328 OS << PeakMem << " ";
305 OS << format("%9lld", (long long)PeakMem) << " ";
329306 } else
330307 OS << " ";
331308 }
343320 }
344321
345322 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
346 std::ostream *
323 raw_ostream *
347324 llvm::GetLibSupportInfoOutputFile() {
348325 std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
349326 if (LibSupportInfoOutputFilename.empty())
350 return cerr.stream();
327 return &errs();
351328 if (LibSupportInfoOutputFilename == "-")
352 return cout.stream();
353
354 std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(),
355 std::ios::app);
356 if (!Result->good()) {
357 cerr << "Error opening info-output-file '"
329 return &outs();
330
331
332 std::string Error;
333 raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
334 Error, raw_fd_ostream::F_Append);
335 if (Error.empty())
336 return Result;
337
338 errs() << "Error opening info-output-file '"
358339 << LibSupportInfoOutputFilename << " for appending!\n";
359 delete Result;
360 return cerr.stream();
361 }
362 return Result;
340 delete Result;
341 return &errs();
363342 }
364343
365344
374353 unsigned Padding = (80-Name.length())/2;
375354 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
376355
377 std::ostream *OutStream = GetLibSupportInfoOutputFile();
356 raw_ostream *OutStream = GetLibSupportInfoOutputFile();
378357
379358 ++NumTimers;
380359 { // Scope to contain Total timer... don't allow total timer to drop us to
396375 if (this != DefaultTimerGroup) {
397376 *OutStream << " Total Execution Time: ";
398377
399 printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
400 *OutStream << " seconds (";
401 printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
402 *OutStream << " wall clock)\n";
378 *OutStream << format("%5.4f", Total.getProcessTime()) << " seconds (";
379 *OutStream << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
403380 }
404381 *OutStream << "\n";
405382
421398 TimersToPrint[i].print(Total, *OutStream);
422399
423400 Total.print(Total, *OutStream);
424 *OutStream << std::endl; // Flush output
401 *OutStream << '\n';
402 OutStream->flush();
425403 }
426404 --NumTimers;
427405
428406 TimersToPrint.clear();
429407
430 if (OutStream != cerr.stream() && OutStream != cout.stream())
408 if (OutStream != &errs() && OutStream != &outs())
431409 delete OutStream; // Close the file...
432410 }
433411 }