void llvm::PrintStatistics(raw_ostream &OS) { StatisticInfo &Stats = *StatInfo; // Figure out how long the biggest Value and Name fields are. unsigned MaxNameLen = 0, MaxValLen = 0; for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) { MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stats.Stats[i]->getValue()).size()); MaxNameLen = std::max(MaxNameLen, (unsigned)std::strlen(Stats.Stats[i]->getName())); } // Sort the fields by name. std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(), NameCompare()); // Print out the statistics header... OS << "===" << std::string(73, '-') << "===\n" << " ... Statistics Collected ...\n" << "===" << std::string(73, '-') << "===\n\n"; // Print all of the statistics. for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) { std::string CountStr = utostr(Stats.Stats[i]->getValue()); OS << std::string(MaxValLen-CountStr.size(), ' ') << CountStr << " " << Stats.Stats[i]->getName() << std::string(MaxNameLen-std::strlen(Stats.Stats[i]->getName()), ' ') << " - " << Stats.Stats[i]->getDesc() << "\n"; } OS << '\n'; // Flush the output stream. OS.flush(); }
bool ide::getDocumentationCommentAsXML(const Decl *D, raw_ostream &OS) { auto MaybeClangNode = D->getClangNode(); if (MaybeClangNode) { if (auto *CD = MaybeClangNode.getAsDecl()) { std::string S; llvm::raw_string_ostream SS(S); if (getClangDocumentationCommentAsXML(CD, SS)) { replaceObjcDeclarationsWithSwiftOnes(D, SS.str(), OS); return true; } } return false; } swift::markup::MarkupContext MC; auto DC = getCascadingDocComment(MC, D); if (!DC.hasValue()) return false; CommentToXMLConverter Converter(OS); Converter.visitDocComment(DC.getValue()); OS.flush(); return true; }
void UnifiedStatsReporter::printAlwaysOnStatsAndTimers(raw_ostream &OS) { // Adapted from llvm::PrintStatisticsJSON OS << "{\n"; const char *delim = ""; if (FrontendCounters) { auto &C = getFrontendCounters(); #define FRONTEND_STATISTIC(TY, NAME) \ do { \ OS << delim << "\t\"" #TY "." #NAME "\": " << C.NAME; \ delim = ",\n"; \ } while (0); #include "swift/Basic/Statistics.def" #undef FRONTEND_STATISTIC } if (DriverCounters) { auto &C = getDriverCounters(); #define DRIVER_STATISTIC(NAME) \ do { \ OS << delim << "\t\"Driver." #NAME "\": " << C.NAME; \ delim = ",\n"; \ } while (0); #include "swift/Basic/Statistics.def" #undef DRIVER_STATISTIC } // Print timers. TimerGroup::printAllJSONValues(OS, delim); OS << "\n}\n"; OS.flush(); }
void AMDGPUInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI) { OS.flush(); printInstruction(MI, OS); printAnnotation(OS, Annot); }
void llvm::PrintStatistics(raw_ostream &OS) { StatisticInfo &Stats = *StatInfo; // Figure out how long the biggest Value and Name fields are. unsigned MaxDebugTypeLen = 0, MaxValLen = 0; for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) { MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stats.Stats[i]->getValue()).size()); MaxDebugTypeLen = std::max(MaxDebugTypeLen, (unsigned)std::strlen(Stats.Stats[i]->getDebugType())); } Stats.sort(); // Print out the statistics header... OS << "===" << std::string(73, '-') << "===\n" << " ... Statistics Collected ...\n" << "===" << std::string(73, '-') << "===\n\n"; // Print all of the statistics. for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) OS << format("%*u %-*s - %s\n", MaxValLen, Stats.Stats[i]->getValue(), MaxDebugTypeLen, Stats.Stats[i]->getDebugType(), Stats.Stats[i]->getDesc()); OS << '\n'; // Flush the output stream. OS.flush(); }
bool FixItRewriter::WriteFixedFile(FileID ID, raw_ostream &OS) { const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(ID); if (!RewriteBuf) return true; RewriteBuf->write(OS); OS.flush(); return false; }
void CallGraph::print(raw_ostream &OS) const { OS << " --- Call graph Dump --- \n"; // We are going to print the graph in reverse post order, partially, to make // sure the output is deterministic. llvm::ReversePostOrderTraversal<const clang::CallGraph*> RPOT(this); for (llvm::ReversePostOrderTraversal<const clang::CallGraph*>::rpo_iterator I = RPOT.begin(), E = RPOT.end(); I != E; ++I) { const CallGraphNode *N = *I; OS << " Function: "; if (N == Root) OS << "< root >"; else N->print(OS); OS << " calls: "; for (CallGraphNode::const_iterator CI = N->begin(), CE = N->end(); CI != CE; ++CI) { assert(*CI != Root && "No one can call the root node."); (*CI)->print(OS); OS << " "; } OS << '\n'; } OS.flush(); }
/// PrintCurStackTrace - Print the current stack trace to the specified stream. static void PrintCurStackTrace(raw_ostream &OS) { // Don't print an empty trace. if (!PrettyStackTraceHead) return; // If there are pretty stack frames registered, walk and emit them. OS << "Stack dump:\n"; PrintStack(PrettyStackTraceHead, OS); OS.flush(); }
void write(raw_ostream &OS) { OS.flush(); // length = length + "aeabi\0" + TagFile + ByteSize + Tag + Value; // length = 17 bytes OS << 'A' << (uint8_t)17 << (uint8_t)0 << (uint8_t)0 << (uint8_t)0; OS << "aeabi" << '\0'; OS << (uint8_t)1 << (uint8_t)7 << (uint8_t)0 << (uint8_t)0 << (uint8_t)0; OS << (uint8_t)Tag << (uint8_t)Value; }
void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const { OS << "OVERVIEW: " << Title << "\n"; OS << '\n'; OS << "USAGE: " << Name << " [options] <inputs>\n"; OS << '\n'; // Render help text into a map of group-name to a list of (option, help) // pairs. using helpmap_ty = std::map<std::string, std::vector<OptionInfo>>; helpmap_ty GroupedOptionHelp; for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { unsigned Id = i + 1; // FIXME: Split out option groups. if (getOptionKind(Id) == Option::GroupClass) continue; unsigned Flags = getInfo(Id).Flags; if (FlagsToInclude && !(Flags & FlagsToInclude)) continue; if (Flags & FlagsToExclude) continue; // If an alias doesn't have a help text, show a help text for the aliased // option instead. const char *HelpText = getOptionHelpText(Id); if (!HelpText && ShowAllAliases) { const Option Alias = getOption(Id).getAlias(); if (Alias.isValid()) HelpText = getOptionHelpText(Alias.getID()); } if (HelpText) { const char *HelpGroup = getOptionHelpGroup(*this, Id); const std::string &OptName = getOptionHelpName(*this, Id); GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText}); } } for (helpmap_ty::iterator it = GroupedOptionHelp .begin(), ie = GroupedOptionHelp.end(); it != ie; ++it) { if (it != GroupedOptionHelp .begin()) OS << "\n"; PrintHelpOptionList(OS, it->first, it->second); } OS.flush(); }
void TimerGroup::PrintQueuedTimers(raw_ostream &OS) { // Sort the timers in descending order by amount of time taken. std::sort(TimersToPrint.begin(), TimersToPrint.end()); TimeRecord Total; for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) Total += TimersToPrint[i].first; // Print out timing header. OS << "===" << std::string(73, '-') << "===\n"; // Figure out how many spaces to indent TimerGroup name. unsigned Padding = (80-Name.length())/2; if (Padding > 80) Padding = 0; // Don't allow "negative" numbers OS.indent(Padding) << Name << '\n'; OS << "===" << std::string(73, '-') << "===\n"; // If this is not an collection of ungrouped times, print the total time. // Ungrouped timers don't really make sense to add up. We still print the // TOTAL line to make the percentages make sense. if (this != DefaultTimerGroup) OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n", Total.getProcessTime(), Total.getWallTime()); OS << '\n'; if (Total.getUserTime()) OS << " ---User Time---"; if (Total.getSystemTime()) OS << " --System Time--"; if (Total.getProcessTime()) OS << " --User+System--"; OS << " ---Wall Time---"; if (Total.getMemUsed()) OS << " ---Mem---"; OS << " --- Name ---\n"; // Loop through all of the timing data, printing it out. for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) { const std::pair<TimeRecord, std::string> &Entry = TimersToPrint[e-i-1]; Entry.first.print(Total, OS); OS << Entry.second << '\n'; } Total.print(Total, OS); OS << "Total\n\n"; OS.flush(); TimersToPrint.clear(); }
void TimerGroup::PrintQueuedTimers(raw_ostream &OS) { // Sort the timers in descending order by amount of time taken. llvm::sort(TimersToPrint); TimeRecord Total; for (const PrintRecord &Record : TimersToPrint) Total += Record.Time; // Print out timing header. OS << "===" << std::string(73, '-') << "===\n"; // Figure out how many spaces to indent TimerGroup name. unsigned Padding = (80-Description.length())/2; if (Padding > 80) Padding = 0; // Don't allow "negative" numbers OS.indent(Padding) << Description << '\n'; OS << "===" << std::string(73, '-') << "===\n"; // If this is not an collection of ungrouped times, print the total time. // Ungrouped timers don't really make sense to add up. We still print the // TOTAL line to make the percentages make sense. if (this != getDefaultTimerGroup()) OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n", Total.getProcessTime(), Total.getWallTime()); OS << '\n'; if (Total.getUserTime()) OS << " ---User Time---"; if (Total.getSystemTime()) OS << " --System Time--"; if (Total.getProcessTime()) OS << " --User+System--"; OS << " ---Wall Time---"; if (Total.getMemUsed()) OS << " ---Mem---"; OS << " --- Name ---\n"; // Loop through all of the timing data, printing it out. for (const PrintRecord &Record : make_range(TimersToPrint.rbegin(), TimersToPrint.rend())) { Record.Time.print(Total, OS); OS << Record.Description << '\n'; } Total.print(Total, OS); OS << "Total\n\n"; OS.flush(); TimersToPrint.clear(); }
bool ide::convertMarkupToXML(StringRef Text, raw_ostream &OS) { std::string Comment; { llvm::raw_string_ostream OS(Comment); OS << "/**\n" << Text << "\n" << "*/"; } SourceManager SourceMgr; MarkupContext MC; LineList LL = getLineListFromComment(SourceMgr, MC, Comment); if (auto *Doc = swift::markup::parseDocument(MC, LL)) { CommentToXMLConverter Converter(OS); Converter.visitCommentParts(extractCommentParts(MC, Doc)); OS.flush(); return false; } return true; }
void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude) const { OS << "OVERVIEW: " << Title << "\n"; OS << '\n'; OS << "USAGE: " << Name << " [options] <inputs>\n"; OS << '\n'; // Render help text into a map of group-name to a list of (option, help) // pairs. typedef std::map<std::string, std::vector<std::pair<std::string, const char*> > > helpmap_ty; helpmap_ty GroupedOptionHelp; for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { unsigned Id = i + 1; // FIXME: Split out option groups. if (getOptionKind(Id) == Option::GroupClass) continue; unsigned Flags = getInfo(Id).Flags; if (FlagsToInclude && !(Flags & FlagsToInclude)) continue; if (Flags & FlagsToExclude) continue; if (const char *Text = getOptionHelpText(Id)) { const char *HelpGroup = getOptionHelpGroup(*this, Id); const std::string &OptName = getOptionHelpName(*this, Id); GroupedOptionHelp[HelpGroup].push_back(std::make_pair(OptName, Text)); } } for (helpmap_ty::iterator it = GroupedOptionHelp .begin(), ie = GroupedOptionHelp.end(); it != ie; ++it) { if (it != GroupedOptionHelp .begin()) OS << "\n"; PrintHelpOptionList(OS, it->first, it->second); } OS.flush(); }
//adapted from LLVM's C interface "LLVMTargetMachineEmitToFile" bool llvmutil_emitobjfile(Module * Mod, TargetMachine * TM, raw_ostream & dest, std::string * ErrorMessage) { PassManager pass; llvmutil_addtargetspecificpasses(&pass, TM); TargetMachine::CodeGenFileType ft = TargetMachine::CGFT_ObjectFile; formatted_raw_ostream destf(dest); if (TM->addPassesToEmitFile(pass, destf, ft)) { *ErrorMessage = "addPassesToEmitFile"; return true; } pass.run(*Mod); destf.flush(); dest.flush(); return false; }
void llvm::PrintStatisticsJSON(raw_ostream &OS) { StatisticInfo &Stats = *StatInfo; Stats.sort(); // Print all of the statistics. OS << "{\n"; const char *delim = ""; for (const Statistic *Stat : Stats.Stats) { OS << delim; assert(!yaml::needsQuotes(Stat->getDebugType()) && "Statistic group/type name is simple."); assert(!yaml::needsQuotes(Stat->getName()) && "Statistic name is simple"); OS << "\t\"" << Stat->getDebugType() << '.' << Stat->getName() << "\": " << Stat->getValue(); delim = ",\n"; } // Print timers. TimerGroup::printAllJSONValues(OS, delim); OS << "\n}\n"; OS.flush(); }
void HandleTranslationUnit(ASTContext &Ctx) override { auto &SerializedAST = Buffer->Data; OS->write(SerializedAST.data(), SerializedAST.size()); OS->flush(); }