aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/SourceCoverageView.h
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-06-28 02:09:39 +0000
committerVedant Kumar <vsk@apple.com>2016-06-28 02:09:39 +0000
commit7937ef37969f7d46d8626e2b61a6ae8361afbea6 (patch)
treeda524077905d16803c53d68fc50823be5f352880 /llvm/tools/llvm-cov/SourceCoverageView.h
parent9980075133ceec5746318ba133a1b09cffebd6ee (diff)
downloadllvm-7937ef37969f7d46d8626e2b61a6ae8361afbea6.zip
llvm-7937ef37969f7d46d8626e2b61a6ae8361afbea6.tar.gz
llvm-7937ef37969f7d46d8626e2b61a6ae8361afbea6.tar.bz2
Reapply "[llvm-cov] Add an -output-dir option for the show sub-command""
Passing -output-dir path/to/dir to llvm-cov show creates path/to/dir if it doesn't already exist, and prints reports into that directory. In function view mode, all views are written into path/to/dir/functions.$EXTENSION. In file view mode, all views are written into path/to/dir/coverage/$PATH.$EXTENSION. Changes since the initial commit: - Avoid accidentally closing stdout twice. llvm-svn: 273985
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.h')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.h27
1 files changed, 26 insertions, 1 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index 03c0742..def5c6a 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -101,7 +101,7 @@ struct LineCoverageStats {
///
/// A source coverage view and its nested sub-views form a file-oriented
/// representation of code coverage data. This view can be printed out by a
-/// renderer which implements the Rendering Interface.
+/// renderer which implements both the File Creation and Rendering interfaces.
class SourceCoverageView {
/// A function or file name.
StringRef SourceName;
@@ -122,6 +122,25 @@ class SourceCoverageView {
/// on display.
std::vector<InstantiationView> InstantiationSubViews;
+public:
+ struct StreamDestructor {
+ void operator()(raw_ostream *OS) const;
+ };
+
+ using OwnedStream = std::unique_ptr<raw_ostream, StreamDestructor>;
+
+ /// @name File Creation Interface
+ /// @{
+
+ /// \brief Create a file to print a coverage view into.
+ virtual Expected<OwnedStream> createOutputFile(StringRef Path,
+ bool InToplevel) = 0;
+
+ /// \brief Close a file which has been used to print a coverage view.
+ virtual void closeOutputFile(OwnedStream OS) = 0;
+
+ /// @}
+
protected:
struct LineRef {
StringRef Line;
@@ -183,6 +202,12 @@ protected:
/// digits.
static std::string formatCount(uint64_t N);
+ /// \brief If directory output is enabled, create a file with \p Path as the
+ /// suffix. Otherwise, return stdout.
+ static Expected<OwnedStream>
+ createOutputStream(const CoverageViewOptions &Opts, StringRef Path,
+ StringRef Extension, bool InToplevel);
+
SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
const CoverageViewOptions &Options,
coverage::CoverageData &&CoverageInfo)