diff options
author | Alan Phipps <a-phipps@ti.com> | 2020-12-28 11:20:48 -0600 |
---|---|---|
committer | Alan Phipps <a-phipps@ti.com> | 2021-01-05 09:51:51 -0600 |
commit | 9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 (patch) | |
tree | a29793dac7b81d67601905911a389a2cf2cdde2e /llvm/tools/llvm-cov/SourceCoverageView.h | |
parent | 53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0 (diff) | |
download | llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.zip llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.gz llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.bz2 |
[Coverage] Add support for Branch Coverage in LLVM Source-Based Code Coverage
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how
many times individual branch-generating conditions are taken (evaluate to TRUE)
and not taken (evaluate to FALSE). Individual conditions may comprise larger
boolean expressions using boolean logical operators. This functionality is
very similar to what is supported by GCOV except that it is very closely
anchored to the ASTs.
Differential Revision: https://reviews.llvm.org/D84467
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.h')
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageView.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h index 9ae9284..5a9fcdd 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.h +++ b/llvm/tools/llvm-cov/SourceCoverageView.h @@ -67,6 +67,23 @@ struct InstantiationView { } }; +/// A view that represents one or more branch regions on a given source line. +struct BranchView { + std::vector<CountedRegion> Regions; + std::unique_ptr<SourceCoverageView> View; + unsigned Line; + + BranchView(unsigned Line, ArrayRef<CountedRegion> Regions, + std::unique_ptr<SourceCoverageView> View) + : Regions(Regions), View(std::move(View)), Line(Line) {} + + unsigned getLine() const { return Line; } + + friend bool operator<(const BranchView &LHS, const BranchView &RHS) { + return LHS.Line < RHS.Line; + } +}; + /// A file manager that handles format-aware file creation. class CoveragePrinter { public: @@ -140,6 +157,9 @@ class SourceCoverageView { /// A container for all expansions (e.g macros) in the source on display. std::vector<ExpansionView> ExpansionSubViews; + /// A container for all branches in the source on display. + std::vector<BranchView> BranchSubViews; + /// A container for all instantiations (e.g template functions) in the source /// on display. std::vector<InstantiationView> InstantiationSubViews; @@ -209,6 +229,10 @@ protected: virtual void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, unsigned ViewDepth) = 0; + /// Render a branch view and any nested views. + virtual void renderBranchView(raw_ostream &OS, BranchView &BRV, + unsigned ViewDepth) = 0; + /// Render \p Title, a project title if one is available, and the /// created time. virtual void renderTitle(raw_ostream &OS, StringRef CellText) = 0; @@ -255,6 +279,10 @@ public: void addInstantiation(StringRef FunctionName, unsigned Line, std::unique_ptr<SourceCoverageView> View); + /// Add a branch subview to this view. + void addBranch(unsigned Line, ArrayRef<CountedRegion> Regions, + std::unique_ptr<SourceCoverageView> View); + /// Print the code coverage information for a specific portion of a /// source file to the output stream. void print(raw_ostream &OS, bool WholeFile, bool ShowSourceName, |