From d46f580986360d5202c7d3b435021ae4951b6fbb Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 9 Oct 2018 04:30:23 +0000 Subject: [CFG Printer] Add support for writing the dot files with a custom prefix. Use this to direct these files to a specific location in the test suite so that we don't write files out to random directories (or fail if the working directory isn't writable). llvm-svn: 344014 --- llvm/lib/Analysis/CFGPrinter.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Analysis/CFGPrinter.cpp') diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp index 5b170dfa790..6d01e9d5d44 100644 --- a/llvm/lib/Analysis/CFGPrinter.cpp +++ b/llvm/lib/Analysis/CFGPrinter.cpp @@ -7,9 +7,10 @@ // //===----------------------------------------------------------------------===// // -// This file defines a '-dot-cfg' analysis pass, which emits the -// cfg..dot file for each function in the program, with a graph of the -// CFG for that function. +// This file defines a `-dot-cfg` analysis pass, which emits the +// `..dot` file for each function in the program, with a graph +// of the CFG for that function. The default value for `` is `cfg` but +// can be customized as needed. // // The other main feature of this file is that it implements the // Function::viewCFG method, which is useful for debugging passes which operate @@ -27,6 +28,10 @@ static cl::opt CFGFuncName( cl::desc("The name of a function (or its substring)" " whose CFG is viewed/printed.")); +static cl::opt CFGDotFilenamePrefix( + "cfg-dot-filename-prefix", cl::Hidden, + cl::desc("The prefix used for the CFG dot file names.")); + namespace { struct CFGViewerLegacyPass : public FunctionPass { static char ID; // Pass identifcation, replacement for typeid @@ -90,7 +95,8 @@ PreservedAnalyses CFGOnlyViewerPass::run(Function &F, static void writeCFGToDotFile(Function &F, bool CFGOnly = false) { if (!CFGFuncName.empty() && !F.getName().contains(CFGFuncName)) return; - std::string Filename = ("cfg." + F.getName() + ".dot").str(); + std::string Filename = + (CFGDotFilenamePrefix + "." + F.getName() + ".dot").str(); errs() << "Writing '" << Filename << "'..."; std::error_code EC; -- cgit v1.2.3