diff options
author | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
commit | 06210ae42d418d50d8d9365d5c9419308ae9e7ee (patch) | |
tree | ab60b4cdd6e430dda1f292a46a77ddb744723f31 /contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp | |
parent | 2dd166267f53df1c3748b4325d294b9b839de74b (diff) | |
download | FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.zip FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.tar.gz |
MFC r309124:
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
release, and add lld 3.9.0. Also completely revamp the build system for
clang, llvm, lldb and their related tools.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld are available here:
<http://llvm.org/releases/3.9.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/clang/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Bryan Drewery, Andrew Turner, Antoine Brodin and Jan
Beich for their help.
Relnotes: yes
MFC r309147:
Pull in r282174 from upstream llvm trunk (by Krzysztof Parzyszek):
[PPC] Set SP after loading data from stack frame, if no red zone is
present
Follow-up to r280705: Make sure that the SP is only restored after
all data is loaded from the stack frame, if there is no red zone.
This completes the fix for
https://llvm.org/bugs/show_bug.cgi?id=26519.
Differential Revision: https://reviews.llvm.org/D24466
Reported by: Mark Millard
PR: 214433
MFC r309149:
Pull in r283060 from upstream llvm trunk (by Hal Finkel):
[PowerPC] Refactor soft-float support, and enable PPC64 soft float
This change enables soft-float for PowerPC64, and also makes
soft-float disable all vector instruction sets for both 32-bit and
64-bit modes. This latter part is necessary because the PPC backend
canonicalizes many Altivec vector types to floating-point types, and
so soft-float breaks scalarization support for many operations. Both
for embedded targets and for operating-system kernels desiring
soft-float support, it seems reasonable that disabling hardware
floating-point also disables vector instructions (embedded targets
without hardware floating point support are unlikely to have Altivec,
etc. and operating system kernels desiring not to use floating-point
registers to lower syscall cost are unlikely to want to use vector
registers either). If someone needs this to work, we'll need to
change the fact that we promote many Altivec operations to act on
v4f32. To make it possible to disable Altivec when soft-float is
enabled, hardware floating-point support needs to be expressed as a
positive feature, like the others, and not a negative feature,
because target features cannot have dependencies on the disabling of
some other feature. So +soft-float has now become -hard-float.
Fixes PR26970.
Pull in r283061 from upstream clang trunk (by Hal Finkel):
[PowerPC] Enable soft-float for PPC64, and +soft-float -> -hard-float
Enable soft-float support on PPC64, as the backend now supports it.
Also, the backend now uses -hard-float instead of +soft-float, so set
the target features accordingly.
Fixes PR26970.
Reported by: Mark Millard
PR: 214433
MFC r309212:
Add a few missed clang 3.9.0 files to OptionalObsoleteFiles.
MFC r309262:
Fix packaging for clang, lldb and lld 3.9.0
During the upgrade of clang/llvm etc to 3.9.0 in r309124, the PACKAGE
directive in the usr.bin/clang/*.mk files got dropped accidentally.
Restore it, with a few minor changes and additions:
* Correct license in clang.ucl to NCSA
* Add PACKAGE=clang for clang and most of the "ll" tools
* Put lldb in its own package
* Put lld in its own package
Reviewed by: gjb, jmallett
Differential Revision: https://reviews.freebsd.org/D8666
MFC r309656:
During the bootstrap phase, when building the minimal llvm library on
PowerPC, add lib/Support/Atomic.cpp. This is needed because upstream
llvm revision r271821 disabled the use of std::call_once, which causes
some fallback functions from Atomic.cpp to be used instead.
Reported by: Mark Millard
PR: 214902
MFC r309835:
Tentatively apply https://reviews.llvm.org/D18730 to work around gcc PR
70528 (bogus error: constructor required before non-static data member).
This should fix buildworld with the external gcc package.
Reported by: https://jenkins.freebsd.org/job/FreeBSD_HEAD_amd64_gcc/
MFC r310194:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
3.9.1 release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/3.9.1/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/lld/docs/ReleaseNotes.html>
Relnotes: yes
Diffstat (limited to 'contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp | 273 |
1 files changed, 121 insertions, 152 deletions
diff --git a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp index 58c8a67..baf7c14 100644 --- a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -6,80 +6,82 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This class implements rendering for code coverage of source code. -// +/// +/// \file This class implements rendering for code coverage of source code. +/// //===----------------------------------------------------------------------===// #include "SourceCoverageView.h" -#include "llvm/ADT/Optional.h" +#include "SourceCoverageViewHTML.h" +#include "SourceCoverageViewText.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/LineIterator.h" +#include "llvm/Support/Path.h" using namespace llvm; -void SourceCoverageView::renderLine( - raw_ostream &OS, StringRef Line, int64_t LineNumber, - const coverage::CoverageSegment *WrappedSegment, - ArrayRef<const coverage::CoverageSegment *> Segments, - unsigned ExpansionCol) { - Optional<raw_ostream::Colors> Highlight; - SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges; - - // The first segment overlaps from a previous line, so we treat it specially. - if (WrappedSegment && WrappedSegment->HasCount && WrappedSegment->Count == 0) - Highlight = raw_ostream::RED; - - // Output each segment of the line, possibly highlighted. - unsigned Col = 1; - for (const auto *S : Segments) { - unsigned End = std::min(S->Col, static_cast<unsigned>(Line.size()) + 1); - colored_ostream(OS, Highlight ? *Highlight : raw_ostream::SAVEDCOLOR, - Options.Colors && Highlight, /*Bold=*/false, /*BG=*/true) - << Line.substr(Col - 1, End - Col); - if (Options.Debug && Highlight) - HighlightedRanges.push_back(std::make_pair(Col, End)); - Col = End; - if (Col == ExpansionCol) - Highlight = raw_ostream::CYAN; - else if (S->HasCount && S->Count == 0) - Highlight = raw_ostream::RED; - else - Highlight = None; - } +void CoveragePrinter::StreamDestructor::operator()(raw_ostream *OS) const { + if (OS == &outs()) + return; + delete OS; +} - // Show the rest of the line - colored_ostream(OS, Highlight ? *Highlight : raw_ostream::SAVEDCOLOR, - Options.Colors && Highlight, /*Bold=*/false, /*BG=*/true) - << Line.substr(Col - 1, Line.size() - Col + 1); - OS << "\n"; - - if (Options.Debug) { - for (const auto &Range : HighlightedRanges) - errs() << "Highlighted line " << LineNumber << ", " << Range.first - << " -> " << Range.second << "\n"; - if (Highlight) - errs() << "Highlighted line " << LineNumber << ", " << Col << " -> ?\n"; - } +std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension, + bool InToplevel, bool Relative) { + assert(Extension.size() && "The file extension may not be empty"); + + SmallString<256> FullPath; + + if (!Relative) + FullPath.append(Opts.ShowOutputDirectory); + + if (!InToplevel) + sys::path::append(FullPath, getCoverageDir()); + + SmallString<256> ParentPath = sys::path::parent_path(Path); + sys::path::remove_dots(ParentPath, /*remove_dot_dots=*/true); + sys::path::append(FullPath, sys::path::relative_path(ParentPath)); + + auto PathFilename = (sys::path::filename(Path) + "." + Extension).str(); + sys::path::append(FullPath, PathFilename); + + return FullPath.str(); } -void SourceCoverageView::renderIndent(raw_ostream &OS, unsigned Level) { - for (unsigned I = 0; I < Level; ++I) - OS << " |"; +Expected<CoveragePrinter::OwnedStream> +CoveragePrinter::createOutputStream(StringRef Path, StringRef Extension, + bool InToplevel) { + if (!Opts.hasOutputDirectory()) + return OwnedStream(&outs()); + + std::string FullPath = getOutputPath(Path, Extension, InToplevel, false); + + auto ParentDir = sys::path::parent_path(FullPath); + if (auto E = sys::fs::create_directories(ParentDir)) + return errorCodeToError(E); + + std::error_code E; + raw_ostream *RawStream = new raw_fd_ostream(FullPath, E, sys::fs::F_RW); + auto OS = CoveragePrinter::OwnedStream(RawStream); + if (E) + return errorCodeToError(E); + return std::move(OS); } -void SourceCoverageView::renderViewDivider(unsigned Level, unsigned Length, - raw_ostream &OS) { - assert(Level != 0 && "Cannot render divider at top level"); - renderIndent(OS, Level - 1); - OS.indent(2); - for (unsigned I = 0; I < Length; ++I) - OS << "-"; +std::unique_ptr<CoveragePrinter> +CoveragePrinter::create(const CoverageViewOptions &Opts) { + switch (Opts.Format) { + case CoverageViewOptions::OutputFormat::Text: + return llvm::make_unique<CoveragePrinterText>(Opts); + case CoverageViewOptions::OutputFormat::HTML: + return llvm::make_unique<CoveragePrinterHTML>(Opts); + } + llvm_unreachable("Unknown coverage output format!"); } -/// Format a count using engineering notation with 3 significant digits. -static std::string formatCount(uint64_t N) { +std::string SourceCoverageView::formatCount(uint64_t N) { std::string Number = utostr(N); int Len = Number.size(); if (Len <= 3) @@ -94,63 +96,49 @@ static std::string formatCount(uint64_t N) { return Result; } -void -SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS, - const LineCoverageInfo &Line) { - if (!Line.isMapped()) { - OS.indent(LineCoverageColumnWidth) << '|'; - return; - } - std::string C = formatCount(Line.ExecutionCount); - OS.indent(LineCoverageColumnWidth - C.size()); - colored_ostream(OS, raw_ostream::MAGENTA, - Line.hasMultipleRegions() && Options.Colors) - << C; - OS << '|'; +bool SourceCoverageView::shouldRenderRegionMarkers( + bool LineHasMultipleRegions) const { + return getOptions().ShowRegionMarkers && + (!getOptions().ShowLineStatsOrRegionMarkers || LineHasMultipleRegions); } -void SourceCoverageView::renderLineNumberColumn(raw_ostream &OS, - unsigned LineNo) { - SmallString<32> Buffer; - raw_svector_ostream BufferOS(Buffer); - BufferOS << LineNo; - auto Str = BufferOS.str(); - // Trim and align to the right - Str = Str.substr(0, std::min(Str.size(), (size_t)LineNumberColumnWidth)); - OS.indent(LineNumberColumnWidth - Str.size()) << Str << '|'; +bool SourceCoverageView::hasSubViews() const { + return !ExpansionSubViews.empty() || !InstantiationSubViews.empty(); } -void SourceCoverageView::renderRegionMarkers( - raw_ostream &OS, ArrayRef<const coverage::CoverageSegment *> Segments) { - unsigned PrevColumn = 1; - for (const auto *S : Segments) { - if (!S->IsRegionEntry) - continue; - // Skip to the new region - if (S->Col > PrevColumn) - OS.indent(S->Col - PrevColumn); - PrevColumn = S->Col + 1; - std::string C = formatCount(S->Count); - PrevColumn += C.size(); - OS << '^' << C; +std::unique_ptr<SourceCoverageView> +SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File, + const CoverageViewOptions &Options, + coverage::CoverageData &&CoverageInfo) { + switch (Options.Format) { + case CoverageViewOptions::OutputFormat::Text: + return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options, + std::move(CoverageInfo)); + case CoverageViewOptions::OutputFormat::HTML: + return llvm::make_unique<SourceCoverageViewHTML>(SourceName, File, Options, + std::move(CoverageInfo)); } - OS << "\n"; + llvm_unreachable("Unknown coverage output format!"); +} + +void SourceCoverageView::addExpansion( + const coverage::CounterMappingRegion &Region, + std::unique_ptr<SourceCoverageView> View) { + ExpansionSubViews.emplace_back(Region, std::move(View)); +} - if (Options.Debug) - for (const auto *S : Segments) - errs() << "Marker at " << S->Line << ":" << S->Col << " = " - << formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n"); +void SourceCoverageView::addInstantiation( + StringRef FunctionName, unsigned Line, + std::unique_ptr<SourceCoverageView> View) { + InstantiationSubViews.emplace_back(FunctionName, Line, std::move(View)); } -void SourceCoverageView::render(raw_ostream &OS, bool WholeFile, - unsigned IndentLevel) { - // The width of the leading columns - unsigned CombinedColumnWidth = - (Options.ShowLineStats ? LineCoverageColumnWidth + 1 : 0) + - (Options.ShowLineNumbers ? LineNumberColumnWidth + 1 : 0); - // The width of the line that is used to divide between the view and the - // subviews. - unsigned DividerWidth = CombinedColumnWidth + 4; +void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, + bool ShowSourceName, unsigned ViewDepth) { + if (ShowSourceName) + renderSourceName(OS); + + renderViewHeader(OS); // We need the expansions and instantiations sorted so we can go through them // while we iterate lines. @@ -186,79 +174,60 @@ void SourceCoverageView::render(raw_ostream &OS, bool WholeFile, LineSegments.push_back(&*NextSegment++); // Calculate a count to be for the line as a whole. - LineCoverageInfo LineCount; + LineCoverageStats LineCount; if (WrappedSegment && WrappedSegment->HasCount) LineCount.addRegionCount(WrappedSegment->Count); for (const auto *S : LineSegments) if (S->HasCount && S->IsRegionEntry) - LineCount.addRegionStartCount(S->Count); + LineCount.addRegionStartCount(S->Count); - // Render the line prefix. - renderIndent(OS, IndentLevel); - if (Options.ShowLineStats) + renderLinePrefix(OS, ViewDepth); + if (getOptions().ShowLineStats) renderLineCoverageColumn(OS, LineCount); - if (Options.ShowLineNumbers) + if (getOptions().ShowLineNumbers) renderLineNumberColumn(OS, LI.line_number()); // If there are expansion subviews, we want to highlight the first one. unsigned ExpansionColumn = 0; if (NextESV != EndESV && NextESV->getLine() == LI.line_number() && - Options.Colors) + getOptions().Colors) ExpansionColumn = NextESV->getStartCol(); // Display the source code for the current line. - renderLine(OS, *LI, LI.line_number(), WrappedSegment, LineSegments, - ExpansionColumn); + renderLine(OS, {*LI, LI.line_number()}, WrappedSegment, LineSegments, + ExpansionColumn, ViewDepth); // Show the region markers. - if (Options.ShowRegionMarkers && (!Options.ShowLineStatsOrRegionMarkers || - LineCount.hasMultipleRegions()) && - !LineSegments.empty()) { - renderIndent(OS, IndentLevel); - OS.indent(CombinedColumnWidth); - renderRegionMarkers(OS, LineSegments); - } + if (shouldRenderRegionMarkers(LineCount.hasMultipleRegions())) + renderRegionMarkers(OS, LineSegments, ViewDepth); // Show the expansions and instantiations for this line. - unsigned NestedIndent = IndentLevel + 1; bool RenderedSubView = false; for (; NextESV != EndESV && NextESV->getLine() == LI.line_number(); ++NextESV) { - renderViewDivider(NestedIndent, DividerWidth, OS); - OS << "\n"; + renderViewDivider(OS, ViewDepth + 1); + + // Re-render the current line and highlight the expansion range for + // this subview. if (RenderedSubView) { - // Re-render the current line and highlight the expansion range for - // this subview. ExpansionColumn = NextESV->getStartCol(); - renderIndent(OS, IndentLevel); - OS.indent(CombinedColumnWidth + (IndentLevel == 0 ? 0 : 1)); - renderLine(OS, *LI, LI.line_number(), WrappedSegment, LineSegments, - ExpansionColumn); - renderViewDivider(NestedIndent, DividerWidth, OS); - OS << "\n"; + renderExpansionSite(OS, {*LI, LI.line_number()}, WrappedSegment, + LineSegments, ExpansionColumn, ViewDepth); + renderViewDivider(OS, ViewDepth + 1); } - // Render the child subview - if (Options.Debug) - errs() << "Expansion at line " << NextESV->getLine() << ", " - << NextESV->getStartCol() << " -> " << NextESV->getEndCol() - << "\n"; - NextESV->View->render(OS, false, NestedIndent); + + renderExpansionView(OS, *NextESV, ViewDepth + 1); RenderedSubView = true; } for (; NextISV != EndISV && NextISV->Line == LI.line_number(); ++NextISV) { - renderViewDivider(NestedIndent, DividerWidth, OS); - OS << "\n"; - renderIndent(OS, NestedIndent); - OS << ' '; - Options.colored_ostream(OS, raw_ostream::CYAN) << NextISV->FunctionName - << ":"; - OS << "\n"; - NextISV->View->render(OS, false, NestedIndent); + renderViewDivider(OS, ViewDepth + 1); + renderInstantiationView(OS, *NextISV, ViewDepth + 1); RenderedSubView = true; } - if (RenderedSubView) { - renderViewDivider(NestedIndent, DividerWidth, OS); - OS << "\n"; - } + if (RenderedSubView) + renderViewDivider(OS, ViewDepth + 1); + renderLineSuffix(OS, ViewDepth); } + + renderViewFooter(OS); } |