[llvm] r274086 - [llvm-cov] Minor cleanups to prepare for the html format patch

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 17:38:22 PDT 2016


Author: vedantk
Date: Tue Jun 28 19:38:21 2016
New Revision: 274086

URL: http://llvm.org/viewvc/llvm-project?rev=274086&view=rev
Log:
[llvm-cov] Minor cleanups to prepare for the html format patch

- Add renderView{Header,Footer}, renderLineSuffix, and hasSubViews to
  support creating tables with nested views.

- Move the 'Format' cl::opt to make it easier to extend.

- Just create one function view file, instead of overwriting the same
  file for every new function. Add a regression test for this.

Modified:
    llvm/trunk/test/tools/llvm-cov/report.cpp
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h

Modified: llvm/trunk/test/tools/llvm-cov/report.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/report.cpp?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/report.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/report.cpp Tue Jun 28 19:38:21 2016
@@ -33,3 +33,10 @@ int main() {
   bar();
   return 0;
 }
+
+// Test that listing multiple functions in a function view works.
+// RUN: llvm-cov show -o %t.dir %S/Inputs/report.covmapping -instr-profile=%S/Inputs/report.profdata -filename-equivalence -name-regex=".*" %s
+// RUN: FileCheck -check-prefix=FUNCTIONS -input-file %t.dir/functions.txt %s
+// FUNCTIONS: _Z3foob
+// FUNCTIONS: _Z3barv
+// FUNCTIONS: _Z4func

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Tue Jun 28 19:38:21 2016
@@ -268,6 +268,13 @@ int CodeCoverageTool::run(Command Cmd, i
   cl::opt<bool> DebugDump("dump", cl::Optional,
                           cl::desc("Show internal debug dump"));
 
+  cl::opt<CoverageViewOptions::OutputFormat> Format(
+      "format", cl::desc("Output format for line-based coverage reports"),
+      cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
+                            "Text output"),
+                 clEnumValEnd),
+      cl::init(CoverageViewOptions::OutputFormat::Text));
+
   cl::opt<bool> FilenameEquivalence(
       "filename-equivalence", cl::Optional,
       cl::desc("Treat source files as equivalent to paths in the coverage data "
@@ -319,9 +326,14 @@ int CodeCoverageTool::run(Command Cmd, i
     ViewOpts.Debug = DebugDump;
     CompareFilenamesOnly = FilenameEquivalence;
 
-    ViewOpts.Colors = UseColor == cl::BOU_UNSET
-                          ? sys::Process::StandardOutHasColors()
-                          : UseColor == cl::BOU_TRUE;
+    ViewOpts.Format = Format;
+    switch (ViewOpts.Format) {
+    case CoverageViewOptions::OutputFormat::Text:
+      ViewOpts.Colors = UseColor == cl::BOU_UNSET
+                            ? sys::Process::StandardOutHasColors()
+                            : UseColor == cl::BOU_TRUE;
+      break;
+    }
 
     // Create the function filters
     if (!NameFilters.empty() || !NameRegexFilters.empty()) {
@@ -410,13 +422,6 @@ int CodeCoverageTool::show(int argc, con
                                    cl::desc("Show function instantiations"),
                                    cl::cat(ViewCategory));
 
-  cl::opt<CoverageViewOptions::OutputFormat> Format(
-      "format", cl::desc("Output format for line-based coverage reports"),
-      cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
-                            "Text output"),
-                 clEnumValEnd),
-      cl::init(CoverageViewOptions::OutputFormat::Text));
-
   cl::opt<std::string> ShowOutputDirectory(
       "output-dir", cl::init(""),
       cl::desc("Directory in which coverage information is written out"));
@@ -434,7 +439,6 @@ int CodeCoverageTool::show(int argc, con
   ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
   ViewOpts.ShowExpandedRegions = ShowExpansions;
   ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
-  ViewOpts.Format = Format;
   ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
 
   if (ViewOpts.hasOutputDirectory()) {
@@ -451,7 +455,14 @@ int CodeCoverageTool::show(int argc, con
   auto Printer = CoveragePrinter::create(ViewOpts);
 
   if (!Filters.empty()) {
-    // Show functions
+    auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true);
+    if (Error E = OSOrErr.takeError()) {
+      error(toString(std::move(E)));
+      return 1;
+    }
+    auto OS = std::move(OSOrErr.get());
+
+    // Show functions.
     for (const auto &Function : Coverage->getCoveredFunctions()) {
       if (!Filters.matches(Function))
         continue;
@@ -464,15 +475,10 @@ int CodeCoverageTool::show(int argc, con
         continue;
       }
 
-      auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true);
-      if (Error E = OSOrErr.takeError()) {
-        error(toString(std::move(E)));
-        return 1;
-      }
-      auto OS = std::move(OSOrErr.get());
       mainView->print(*OS.get(), /*WholeFile=*/false, /*ShowSourceName=*/true);
-      Printer->closeViewFile(std::move(OS));
     }
+
+    Printer->closeViewFile(std::move(OS));
     return 0;
   }
 

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Tue Jun 28 19:38:21 2016
@@ -88,6 +88,16 @@ std::string SourceCoverageView::formatCo
   return Result;
 }
 
+bool SourceCoverageView::shouldRenderRegionMarkers(
+    bool LineHasMultipleRegions) const {
+  return getOptions().ShowRegionMarkers &&
+         (!getOptions().ShowLineStatsOrRegionMarkers || LineHasMultipleRegions);
+}
+
+bool SourceCoverageView::hasSubViews() const {
+  return !ExpansionSubViews.empty() || !InstantiationSubViews.empty();
+}
+
 std::unique_ptr<SourceCoverageView>
 SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File,
                            const CoverageViewOptions &Options,
@@ -117,6 +127,8 @@ void SourceCoverageView::print(raw_ostre
   if (ShowSourceName)
     renderSourceName(OS);
 
+  renderViewHeader(OS);
+
   // We need the expansions and instantiations sorted so we can go through them
   // while we iterate lines.
   std::sort(ExpansionSubViews.begin(), ExpansionSubViews.end());
@@ -175,12 +187,8 @@ void SourceCoverageView::print(raw_ostre
                ExpansionColumn, ViewDepth);
 
     // Show the region markers.
-    if (getOptions().ShowRegionMarkers &&
-        (!getOptions().ShowLineStatsOrRegionMarkers ||
-         LineCount.hasMultipleRegions()) &&
-        !LineSegments.empty()) {
+    if (shouldRenderRegionMarkers(LineCount.hasMultipleRegions()))
       renderRegionMarkers(OS, LineSegments, ViewDepth);
-    }
 
     // Show the expansions and instantiations for this line.
     bool RenderedSubView = false;
@@ -192,9 +200,8 @@ void SourceCoverageView::print(raw_ostre
       // this subview.
       if (RenderedSubView) {
         ExpansionColumn = NextESV->getStartCol();
-        renderExpansionSite(
-            OS, *NextESV, {*LI, LI.line_number()}, WrappedSegment, LineSegments,
-            ExpansionColumn, ViewDepth);
+        renderExpansionSite(OS, {*LI, LI.line_number()}, WrappedSegment,
+                            LineSegments, ExpansionColumn, ViewDepth);
         renderViewDivider(OS, ViewDepth + 1);
       }
 
@@ -208,5 +215,8 @@ void SourceCoverageView::print(raw_ostre
     }
     if (RenderedSubView)
       renderViewDivider(OS, ViewDepth + 1);
+    renderLineSuffix(OS, ViewDepth);
   }
+
+  renderViewFooter(OS);
 }

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Tue Jun 28 19:38:21 2016
@@ -183,12 +183,21 @@ protected:
   /// @name Rendering Interface
   /// @{
 
+  /// \brief Render a header for the view.
+  virtual void renderViewHeader(raw_ostream &OS) = 0;
+
+  /// \brief Render a footer for the view.
+  virtual void renderViewFooter(raw_ostream &OS) = 0;
+
   /// \brief Render the source name for the view.
   virtual void renderSourceName(raw_ostream &OS) = 0;
 
   /// \brief Render the line prefix at the given \p ViewDepth.
   virtual void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) = 0;
 
+  /// \brief Render the line suffix at the given \p ViewDepth.
+  virtual void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) = 0;
+
   /// \brief Render a view divider at the given \p ViewDepth.
   virtual void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) = 0;
 
@@ -212,7 +221,7 @@ protected:
 
   /// \brief Render the site of an expansion.
   virtual void
-  renderExpansionSite(raw_ostream &OS, ExpansionView &ESV, LineRef L,
+  renderExpansionSite(raw_ostream &OS, LineRef L,
                       const coverage::CoverageSegment *WrappedSegment,
                       CoverageSegmentArray Segments, unsigned ExpansionCol,
                       unsigned ViewDepth) = 0;
@@ -231,6 +240,12 @@ protected:
   /// digits.
   static std::string formatCount(uint64_t N);
 
+  /// \brief Check if region marker output is expected for a line.
+  bool shouldRenderRegionMarkers(bool LineHasMultipleRegions) const;
+
+  /// \brief Check if there are any sub-views attached to this view.
+  bool hasSubViews() const;
+
   SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
                      const CoverageViewOptions &Options,
                      coverage::CoverageData &&CoverageInfo)

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp Tue Jun 28 19:38:21 2016
@@ -59,6 +59,10 @@ unsigned getDividerWidth(const CoverageV
 
 } // anonymous namespace
 
+void SourceCoverageViewText::renderViewHeader(raw_ostream &OS) { (void)OS; }
+
+void SourceCoverageViewText::renderViewFooter(raw_ostream &OS) { (void)OS; }
+
 void SourceCoverageViewText::renderSourceName(raw_ostream &OS) {
   getOptions().colored_ostream(OS, raw_ostream::CYAN) << getSourceName()
                                                       << ":\n";
@@ -70,6 +74,12 @@ void SourceCoverageViewText::renderLineP
     OS << "  |";
 }
 
+void SourceCoverageViewText::renderLineSuffix(raw_ostream &OS,
+                                              unsigned ViewDepth) {
+  (void)OS;
+  (void)ViewDepth;
+}
+
 void SourceCoverageViewText::renderViewDivider(raw_ostream &OS,
                                                unsigned ViewDepth) {
   assert(ViewDepth != 0 && "Cannot render divider at top level");
@@ -180,8 +190,7 @@ void SourceCoverageViewText::renderRegio
 }
 
 void SourceCoverageViewText::renderExpansionSite(
-    raw_ostream &OS, ExpansionView &ESV, LineRef L,
-    const coverage::CoverageSegment *WrappedSegment,
+    raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment,
     CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) {
   renderLinePrefix(OS, ViewDepth);
   OS.indent(getCombinedColumnWidth(getOptions()) + (ViewDepth == 0 ? 0 : 1));

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h?rev=274086&r1=274085&r2=274086&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h Tue Jun 28 19:38:21 2016
@@ -34,10 +34,16 @@ public:
 
 /// \brief A code coverage view which supports text-based rendering.
 class SourceCoverageViewText : public SourceCoverageView {
+  void renderViewHeader(raw_ostream &OS) override;
+
+  void renderViewFooter(raw_ostream &OS) override;
+
   void renderSourceName(raw_ostream &OS) override;
 
   void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override;
 
+  void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override;
+
   void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override;
 
   void renderLine(raw_ostream &OS, LineRef L,
@@ -45,7 +51,7 @@ class SourceCoverageViewText : public So
                   CoverageSegmentArray Segments, unsigned ExpansionCol,
                   unsigned ViewDepth) override;
 
-  void renderExpansionSite(raw_ostream &OS, ExpansionView &ESV, LineRef L,
+  void renderExpansionSite(raw_ostream &OS, LineRef L,
                            const coverage::CoverageSegment *WrappedSegment,
                            CoverageSegmentArray Segments, unsigned ExpansionCol,
                            unsigned ViewDepth) override;




More information about the llvm-commits mailing list