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
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 7f85fac..6b43541 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -851,13 +851,12 @@
//
void basic_parser_impl::printOptionInfo(const Option &O,
size_t GlobalWidth) const {
- cout << " -" << O.ArgStr;
+ outs() << " -" << O.ArgStr;
if (const char *ValName = getValueName())
- cout << "=<" << getValueStr(O, ValName) << ">";
+ outs() << "=<" << getValueStr(O, ValName) << '>';
- cout << std::string(GlobalWidth-getOptionWidth(O), ' ') << " - "
- << O.HelpStr << "\n";
+ outs().indent(GlobalWidth-getOptionWidth(O)) << " - " << O.HelpStr << '\n';
}
@@ -990,21 +989,21 @@
size_t GlobalWidth) const {
if (O.hasArgStr()) {
size_t L = std::strlen(O.ArgStr);
- cout << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
- << " - " << O.HelpStr << "\n";
+ outs() << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
+ << " - " << O.HelpStr << '\n';
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
size_t NumSpaces = GlobalWidth-strlen(getOption(i))-8;
- cout << " =" << getOption(i) << std::string(NumSpaces, ' ')
- << " - " << getDescription(i) << "\n";
+ outs() << " =" << getOption(i) << std::string(NumSpaces, ' ')
+ << " - " << getDescription(i) << '\n';
}
} else {
if (O.HelpStr[0])
- cout << " " << O.HelpStr << "\n";
+ outs() << " " << O.HelpStr << "\n";
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
size_t L = std::strlen(getOption(i));
- cout << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
- << " - " << getDescription(i) << "\n";
+ outs() << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
+ << " - " << getDescription(i) << "\n";
}
}
}
@@ -1063,9 +1062,9 @@
}
if (ProgramOverview)
- cout << "OVERVIEW: " << ProgramOverview << "\n";
+ outs() << "OVERVIEW: " << ProgramOverview << "\n";
- cout << "USAGE: " << ProgramName << " [options]";
+ outs() << "USAGE: " << ProgramName << " [options]";
// Print out the positional options.
Option *CAOpt = 0; // The cl::ConsumeAfter option, if it exists...
@@ -1075,28 +1074,28 @@
for (size_t i = CAOpt != 0, e = PositionalOpts.size(); i != e; ++i) {
if (PositionalOpts[i]->ArgStr[0])
- cout << " --" << PositionalOpts[i]->ArgStr;
- cout << " " << PositionalOpts[i]->HelpStr;
+ outs() << " --" << PositionalOpts[i]->ArgStr;
+ outs() << " " << PositionalOpts[i]->HelpStr;
}
// Print the consume after option info if it exists...
- if (CAOpt) cout << " " << CAOpt->HelpStr;
+ if (CAOpt) outs() << " " << CAOpt->HelpStr;
- cout << "\n\n";
+ outs() << "\n\n";
// Compute the maximum argument length...
MaxArgLen = 0;
for (size_t i = 0, e = Opts.size(); i != e; ++i)
MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
- cout << "OPTIONS:\n";
+ outs() << "OPTIONS:\n";
for (size_t i = 0, e = Opts.size(); i != e; ++i)
Opts[i].second->printOptionInfo(MaxArgLen);
// Print any extra help the user has declared.
for (std::vector<const char *>::iterator I = MoreHelp->begin(),
E = MoreHelp->end(); I != E; ++I)
- cout << *I;
+ outs() << *I;
MoreHelp->clear();
// Halt the program since help information was printed
@@ -1125,42 +1124,43 @@
class VersionPrinter {
public:
void print() {
- cout << "Low Level Virtual Machine (http://llvm.org/):\n";
- cout << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
+ raw_ostream &stdout = outs();
+ stdout << "Low Level Virtual Machine (http://llvm.org/):\n";
+ stdout << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
#ifdef LLVM_VERSION_INFO
- cout << LLVM_VERSION_INFO;
+ stdout << LLVM_VERSION_INFO;
#endif
- cout << "\n ";
+ stdout << "\n ";
#ifndef __OPTIMIZE__
- cout << "DEBUG build";
+ stdout << "DEBUG build";
#else
- cout << "Optimized build";
+ stdout << "Optimized build";
#endif
#ifndef NDEBUG
- cout << " with assertions";
+ stdout << " with assertions";
#endif
- cout << ".\n";
- cout << " Built " << __DATE__ << "(" << __TIME__ << ").\n";
- cout << "\n";
- cout << " Registered Targets:\n";
+ stdout << ".\n";
+ stdout << " Built " << __DATE__ << "(" << __TIME__ << ").\n";
+ stdout << "\n";
+ stdout << " Registered Targets:\n";
- std::vector<std::pair<std::string, const Target*> > Targets;
- size_t Width = 0;
- for (TargetRegistry::iterator it = TargetRegistry::begin(),
- ie = TargetRegistry::end(); it != ie; ++it) {
- Targets.push_back(std::make_pair(it->getName(), &*it));
- Width = std::max(Width, ::strlen(it->getName()));
- }
- std::sort(Targets.begin(), Targets.end());
+ std::vector<std::pair<std::string, const Target*> > Targets;
+ size_t Width = 0;
+ for (TargetRegistry::iterator it = TargetRegistry::begin(),
+ ie = TargetRegistry::end(); it != ie; ++it) {
+ Targets.push_back(std::make_pair(it->getName(), &*it));
+ Width = std::max(Width, ::strlen(it->getName()));
+ }
+ std::sort(Targets.begin(), Targets.end());
- for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
- const Target *T = Targets[i].second;
- cout << " " << T->getName()
+ for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
+ const Target *T = Targets[i].second;
+ stdout << " " << T->getName()
<< std::string(Width - ::strlen(T->getName()), ' ') << " - "
<< T->getShortDescription() << "\n";
- }
- if (Targets.empty())
- cout << " (none)\n";
+ }
+ if (Targets.empty())
+ stdout << " (none)\n";
}
void operator=(bool OptionWasSpecified) {
if (OptionWasSpecified) {
diff --git a/lib/Support/PluginLoader.cpp b/lib/Support/PluginLoader.cpp
index ea191ad..36caecf 100644
--- a/lib/Support/PluginLoader.cpp
+++ b/lib/Support/PluginLoader.cpp
@@ -14,10 +14,9 @@
#define DONT_GET_PLUGIN_LOADER_OPTION
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PluginLoader.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/DynamicLibrary.h"
#include "llvm/System/Mutex.h"
-#include <ostream>
#include <vector>
using namespace llvm;
@@ -28,8 +27,8 @@
sys::SmartScopedLock<true> Lock(*PluginsLock);
std::string Error;
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
- cerr << "Error opening '" << Filename << "': " << Error
- << "\n -load request ignored.\n";
+ errs() << "Error opening '" << Filename << "': " << Error
+ << "\n -load request ignored.\n";
} else {
Plugins->push_back(Filename);
}
diff --git a/lib/Support/SlowOperationInformer.cpp b/lib/Support/SlowOperationInformer.cpp
index d5ffff9..b4e9430 100644
--- a/lib/Support/SlowOperationInformer.cpp
+++ b/lib/Support/SlowOperationInformer.cpp
@@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/SlowOperationInformer.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Alarm.h"
#include <sstream>
#include <cassert>
@@ -28,8 +28,8 @@
if (LastPrintAmount) {
// If we have printed something, make _sure_ we print the 100% amount, and
// also print a newline.
- cout << std::string(LastPrintAmount, '\b') << "Progress "
- << OperationName << ": 100% \n";
+ outs() << std::string(LastPrintAmount, '\b') << "Progress "
+ << OperationName << ": 100% \n";
}
}
@@ -40,7 +40,7 @@
bool SlowOperationInformer::progress(unsigned Amount) {
int status = sys::AlarmStatus();
if (status == -1) {
- cout << "\n";
+ outs() << "\n";
LastPrintAmount = 0;
return true;
}
@@ -61,6 +61,7 @@
OS << "% ";
LastPrintAmount = OS.str().size();
- cout << ToPrint+OS.str() << std::flush;
+ outs() << ToPrint+OS.str();
+ outs().flush();
return false;
}
diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp
index 06496fa..5ad5698 100644
--- a/lib/Support/Statistic.cpp
+++ b/lib/Support/Statistic.cpp
@@ -24,16 +24,15 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Mutex.h"
#include "llvm/ADT/StringExtras.h"
#include <algorithm>
-#include <ostream>
#include <cstring>
using namespace llvm;
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
+namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
/// -stats - Command line option to cause transformations to emit stats about
/// what they did.
@@ -96,7 +95,7 @@
if (Stats.empty()) return;
// Get the stream to write to.
- std::ostream &OutStream = *GetLibSupportInfoOutputFile();
+ raw_ostream &OutStream = *GetLibSupportInfoOutputFile();
// Figure out how long the biggest Value and Name fields are.
unsigned MaxNameLen = 0, MaxValLen = 0;
@@ -125,8 +124,9 @@
}
- OutStream << std::endl; // Flush the output stream...
+ OutStream << '\n'; // Flush the output stream...
+ OutStream.flush();
- if (&OutStream != cerr.stream() && &OutStream != cout.stream())
+ if (&OutStream != &outs() && &OutStream != &errs())
delete &OutStream; // Close the file.
}
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 8eef2bd..dd58d1f 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -14,16 +14,16 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Format.h"
#include "llvm/System/Process.h"
#include <algorithm>
-#include <fstream>
#include <functional>
#include <map>
using namespace llvm;
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
+namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
// of constructor/destructor ordering being unspecified by C++. Basically the
@@ -269,38 +269,17 @@
// TimerGroup Implementation
//===----------------------------------------------------------------------===//
-// printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
-// TotalWidth size, and B is the AfterDec size.
-//
-static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
- std::ostream &OS) {
- assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
- OS.width(TotalWidth-AfterDec-1);
- char OldFill = OS.fill();
- OS.fill(' ');
- OS << (int)Val; // Integer part;
- OS << ".";
- OS.width(AfterDec);
- OS.fill('0');
- unsigned ResultFieldSize = 1;
- while (AfterDec--) ResultFieldSize *= 10;
- OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
- OS.fill(OldFill);
-}
-static void printVal(double Val, double Total, std::ostream &OS) {
+static void printVal(double Val, double Total, raw_ostream &OS) {
if (Total < 1e-7) // Avoid dividing by zero...
OS << " ----- ";
else {
- OS << " ";
- printAlignedFP(Val, 4, 7, OS);
- OS << " (";
- printAlignedFP(Val*100/Total, 1, 5, OS);
- OS << "%)";
+ OS << " " << format("%7.4f", Val) << " (";
+ OS << format("%5.1f", Val*100/Total) << "%)";
}
}
-void Timer::print(const Timer &Total, std::ostream &OS) {
+void Timer::print(const Timer &Total, raw_ostream &OS) {
if (&Total < this) {
Total.Lock.acquire();
Lock.acquire();
@@ -320,13 +299,11 @@
OS << " ";
if (Total.MemUsed) {
- OS.width(9);
- OS << MemUsed << " ";
+ OS << format("%9lld", (long long)MemUsed) << " ";
}
if (Total.PeakMem) {
if (PeakMem) {
- OS.width(9);
- OS << PeakMem << " ";
+ OS << format("%9lld", (long long)PeakMem) << " ";
} else
OS << " ";
}
@@ -344,23 +321,25 @@
}
// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
-std::ostream *
+raw_ostream *
llvm::GetLibSupportInfoOutputFile() {
std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
if (LibSupportInfoOutputFilename.empty())
- return cerr.stream();
+ return &errs();
if (LibSupportInfoOutputFilename == "-")
- return cout.stream();
+ return &outs();
- std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(),
- std::ios::app);
- if (!Result->good()) {
- cerr << "Error opening info-output-file '"
+
+ std::string Error;
+ raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
+ Error, raw_fd_ostream::F_Append);
+ if (Error.empty())
+ return Result;
+
+ errs() << "Error opening info-output-file '"
<< LibSupportInfoOutputFilename << " for appending!\n";
- delete Result;
- return cerr.stream();
- }
- return Result;
+ delete Result;
+ return &errs();
}
@@ -375,7 +354,7 @@
unsigned Padding = (80-Name.length())/2;
if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
- std::ostream *OutStream = GetLibSupportInfoOutputFile();
+ raw_ostream *OutStream = GetLibSupportInfoOutputFile();
++NumTimers;
{ // Scope to contain Total timer... don't allow total timer to drop us to
@@ -397,10 +376,8 @@
if (this != DefaultTimerGroup) {
*OutStream << " Total Execution Time: ";
- printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
- *OutStream << " seconds (";
- printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
- *OutStream << " wall clock)\n";
+ *OutStream << format("%5.4f", Total.getProcessTime()) << " seconds (";
+ *OutStream << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
}
*OutStream << "\n";
@@ -422,13 +399,14 @@
TimersToPrint[i].print(Total, *OutStream);
Total.print(Total, *OutStream);
- *OutStream << std::endl; // Flush output
+ *OutStream << '\n';
+ OutStream->flush();
}
--NumTimers;
TimersToPrint.clear();
- if (OutStream != cerr.stream() && OutStream != cout.stream())
+ if (OutStream != &errs() && OutStream != &outs())
delete OutStream; // Close the file...
}
}