From d9ea85ab01fb0f2929ed50223d3758dceea8bcbd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 23 Aug 2009 08:43:55 +0000 Subject: [PATCH] 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 --- include/llvm/Support/Timer.h | 4 +- lib/Bitcode/Writer/Serialize.cpp | 9 +- lib/CodeGen/MachineInstr.cpp | 1 - lib/CodeGen/MachineModuleInfo.cpp | 1 - lib/CodeGen/SimpleRegisterCoalescing.cpp | 4 +- lib/CodeGen/VirtRegMap.cpp | 7 +- lib/CodeGen/VirtRegMap.h | 16 ---- lib/Debugger/ProgramInfo.cpp | 3 +- lib/Debugger/SourceLanguage-Unknown.cpp | 5 +- .../Interpreter/ExternalFunctions.cpp | 8 +- lib/ExecutionEngine/JIT/Intercept.cpp | 1 - lib/Support/CommandLine.cpp | 90 +++++++++---------- lib/Support/PluginLoader.cpp | 7 +- lib/Support/SlowOperationInformer.cpp | 11 +-- lib/Support/Statistic.cpp | 12 +-- lib/Support/Timer.cpp | 78 ++++++---------- 16 files changed, 103 insertions(+), 154 deletions(-) diff --git a/include/llvm/Support/Timer.h b/include/llvm/Support/Timer.h index 71b7ee58fd3..7240cb94ff9 100644 --- a/include/llvm/Support/Timer.h +++ b/include/llvm/Support/Timer.h @@ -19,12 +19,12 @@ #include "llvm/System/Mutex.h" #include #include -#include #include namespace llvm { class TimerGroup; +class raw_ostream; /// Timer - This class is used to track the amount of time spent between /// invocations of it's startTimer()/stopTimer() methods. Given appropriate OS @@ -112,7 +112,7 @@ public: /// print - Print the current timer to standard error, and reset the "Started" /// flag. - void print(const Timer &Total, std::ostream &OS); + void print(const Timer &Total, raw_ostream &OS); private: friend class TimerGroup; diff --git a/lib/Bitcode/Writer/Serialize.cpp b/lib/Bitcode/Writer/Serialize.cpp index 79464a61be4..a6beb1789e1 100644 --- a/lib/Bitcode/Writer/Serialize.cpp +++ b/lib/Bitcode/Writer/Serialize.cpp @@ -12,11 +12,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Bitcode/Serialize.h" -#include "string.h" - -#ifdef DEBUG_BACKPATCH -#include "llvm/Support/Streams.h" -#endif +#include "llvm/Support/raw_ostream.h" +#include using namespace llvm; @@ -86,7 +83,7 @@ SerializedPtrID Serializer::getPtrId(const void* ptr) { if (I == PtrMap.end()) { unsigned id = PtrMap.size()+1; #ifdef DEBUG_BACKPATCH - llvm::cerr << "Registered PTR: " << ptr << " => " << id << "\n"; + errs() << "Registered PTR: " << ptr << " => " << id << "\n"; #endif PtrMap[ptr] = id; return id; diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index f9c3d041750..792a2e03790 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -26,7 +26,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LeakDetector.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/FoldingSet.h" using namespace llvm; diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index df9d7cab095..08b126a13b1 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -24,7 +24,6 @@ #include "llvm/Module.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Streams.h" using namespace llvm; using namespace llvm::dwarf; diff --git a/lib/CodeGen/SimpleRegisterCoalescing.cpp b/lib/CodeGen/SimpleRegisterCoalescing.cpp index 2956e34a33d..1a7fc11c22c 100644 --- a/lib/CodeGen/SimpleRegisterCoalescing.cpp +++ b/lib/CodeGen/SimpleRegisterCoalescing.cpp @@ -2598,9 +2598,9 @@ SimpleRegisterCoalescing::lastRegisterUse(unsigned Start, unsigned End, void SimpleRegisterCoalescing::printRegName(unsigned reg) const { if (TargetRegisterInfo::isPhysicalRegister(reg)) - cerr << tri_->getName(reg); + errs() << tri_->getName(reg); else - cerr << "%reg" << reg; + errs() << "%reg" << reg; } void SimpleRegisterCoalescing::releaseMemory() { diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index 7ee4eeb6981..c78f35bdb13 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -259,11 +259,6 @@ bool VirtRegMap::FindUnusedRegisters(LiveIntervals* LIs) { return AnyUnused; } -void VirtRegMap::print(std::ostream &OS, const Module* M) const { - raw_os_ostream RawOS(OS); - print(RawOS, M); -} - void VirtRegMap::print(raw_ostream &OS, const Module* M) const { const TargetRegisterInfo* TRI = MF->getTarget().getRegisterInfo(); @@ -283,5 +278,5 @@ void VirtRegMap::print(raw_ostream &OS, const Module* M) const { } void VirtRegMap::dump() const { - print(cerr); + print(errs()); } diff --git a/lib/CodeGen/VirtRegMap.h b/lib/CodeGen/VirtRegMap.h index 7d1cf95fce0..482ba1bc29e 100644 --- a/lib/CodeGen/VirtRegMap.h +++ b/lib/CodeGen/VirtRegMap.h @@ -24,7 +24,6 @@ #include "llvm/ADT/IndexedMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Support/Streams.h" #include namespace llvm { @@ -482,25 +481,10 @@ namespace llvm { return 0; } - void print(std::ostream &OS, const Module* M = 0) const; - void print(std::ostream *OS) const { if (OS) print(*OS); } void print(raw_ostream &OS, const Module* M = 0) const; - void print(raw_ostream *OS) const { if (OS) print(*OS); } void dump() const; }; - inline std::ostream *operator<<(std::ostream *OS, const VirtRegMap &VRM) { - VRM.print(OS); - return OS; - } - inline std::ostream &operator<<(std::ostream &OS, const VirtRegMap &VRM) { - VRM.print(OS); - return OS; - } - inline raw_ostream *operator<<(raw_ostream *OS, const VirtRegMap &VRM) { - VRM.print(OS); - return OS; - } inline raw_ostream &operator<<(raw_ostream &OS, const VirtRegMap &VRM) { VRM.print(OS); return OS; diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp index 6e584bdcc31..f649ebe5813 100644 --- a/lib/Debugger/ProgramInfo.cpp +++ b/lib/Debugger/ProgramInfo.cpp @@ -23,7 +23,6 @@ #include "llvm/Debugger/SourceFile.h" #include "llvm/Debugger/SourceLanguage.h" #include "llvm/Support/SlowOperationInformer.h" -#include "llvm/Support/Streams.h" #include "llvm/ADT/STLExtras.h" using namespace llvm; @@ -184,7 +183,7 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo, if (SD) { // We found the first stop point! // This is just a sanity check. if (getSourceFile().getDescriptor() != SD) - cout << "WARNING: first line of function is not in the" + outs() << "WARNING: first line of function is not in the" << " file that the function descriptor claims it is in.\n"; break; } diff --git a/lib/Debugger/SourceLanguage-Unknown.cpp b/lib/Debugger/SourceLanguage-Unknown.cpp index b806fc779ef..d408866dea4 100644 --- a/lib/Debugger/SourceLanguage-Unknown.cpp +++ b/lib/Debugger/SourceLanguage-Unknown.cpp @@ -15,9 +15,8 @@ #include "llvm/Debugger/SourceLanguage.h" #include "llvm/Debugger/ProgramInfo.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" #include -#include using namespace llvm; //===----------------------------------------------------------------------===// @@ -132,7 +131,7 @@ SourceFunctionInfo *SLU::lookupFunction(const std::string &FunctionName, SourceFunctionInfo *Found = IP.first->second; ++IP.first; if (IP.first != IP.second) - cout << "Whoa, found multiple functions with the same name. I should" + outs() << "Whoa, found multiple functions with the same name. I should" << " ask the user which one to use: FIXME!\n"; return Found; } diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 92fd817cde0..12ca9cd1d34 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -24,7 +24,6 @@ #include "llvm/Module.h" #include "llvm/Config/config.h" // Detect libffi #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Streams.h" #include "llvm/System/DynamicLibrary.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/ManagedStatic.h" @@ -279,7 +278,7 @@ GenericValue Interpreter::callExternalFunction(Function *F, #endif // USE_LIBFFI if (F->getName() == "__main") - cerr << "Tried to execute an unknown external function: " + errs() << "Tried to execute an unknown external function: " << F->getType()->getDescription() << " __main\n"; else llvm_report_error("Tried to execute an unknown external function: " + @@ -393,7 +392,8 @@ GenericValue lle_X_sprintf(const FunctionType *FT, sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break; case 's': sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break; - default: cerr << ""; + default: + errs() << ""; ArgNo++; break; } strcpy(OutputBuffer, Buffer); @@ -414,7 +414,7 @@ GenericValue lle_X_printf(const FunctionType *FT, NewArgs.push_back(PTOGV((void*)&Buffer[0])); NewArgs.insert(NewArgs.end(), Args.begin(), Args.end()); GenericValue GV = lle_X_sprintf(FT, NewArgs); - cout << Buffer; + outs() << Buffer; return GV; } diff --git a/lib/ExecutionEngine/JIT/Intercept.cpp b/lib/ExecutionEngine/JIT/Intercept.cpp index f1e900f63b1..c00b60a276c 100644 --- a/lib/ExecutionEngine/JIT/Intercept.cpp +++ b/lib/ExecutionEngine/JIT/Intercept.cpp @@ -17,7 +17,6 @@ #include "JIT.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Streams.h" #include "llvm/System/DynamicLibrary.h" #include "llvm/Config/config.h" using namespace llvm; diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 7f85fac0cec..6b4354181a2 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -851,13 +851,12 @@ size_t basic_parser_impl::getOptionWidth(const Option &O) const { // 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 @@ void generic_parser_base::printOptionInfo(const Option &O, 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 @@ public: } 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 @@ public: 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::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 @@ namespace { 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"; - - std::vector > 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()); + stdout << ".\n"; + stdout << " Built " << __DATE__ << "(" << __TIME__ << ").\n"; + stdout << "\n"; + stdout << " Registered Targets:\n"; + + std::vector > 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 ea191ad739f..36caecffeed 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 #include using namespace llvm; @@ -28,8 +27,8 @@ void PluginLoader::operator=(const std::string &Filename) { sys::SmartScopedLock 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 d5ffff9d937..b4e9430e5fd 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 #include @@ -28,8 +28,8 @@ SlowOperationInformer::~SlowOperationInformer() { 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 @@ SlowOperationInformer::~SlowOperationInformer() { bool SlowOperationInformer::progress(unsigned Amount) { int status = sys::AlarmStatus(); if (status == -1) { - cout << "\n"; + outs() << "\n"; LastPrintAmount = 0; return true; } @@ -61,6 +61,7 @@ bool SlowOperationInformer::progress(unsigned Amount) { 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 06496fae91d..5ad569899ec 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 -#include #include 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 @@ StatisticInfo::~StatisticInfo() { 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 @@ StatisticInfo::~StatisticInfo() { } - 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 8eef2bd48d8..dd58d1f68b4 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 -#include #include #include 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 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name, // 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 @@ void Timer::print(const Timer &Total, std::ostream &OS) { 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 @@ void Timer::print(const Timer &Total, std::ostream &OS) { } // 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 @@ void TimerGroup::removeTimer() { 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 @@ void TimerGroup::removeTimer() { 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 @@ void TimerGroup::removeTimer() { 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... } } -- 2.34.1