+ errs() << " error opening file for writing!";
+ errs() << "\n";
+ return false;
+ }
+
+ void print(raw_ostream &OS, const Module* = nullptr) const override {}
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+ };
+}
+
+char CFGPrinter::ID = 0;
+INITIALIZE_PASS(CFGPrinter, "dot-cfg", "Print CFG of function to 'dot' file",
+ false, true)
+
+namespace {
+ struct CFGOnlyPrinter : public FunctionPass {
+ static char ID; // Pass identification, replacement for typeid
+ CFGOnlyPrinter() : FunctionPass(ID) {
+ initializeCFGOnlyPrinterPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnFunction(Function &F) override {
+ std::string Filename = "cfg." + F.getName().str() + ".dot";
+ errs() << "Writing '" << Filename << "'...";
+
+ std::string ErrorInfo;
+ raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
+
+ if (ErrorInfo.empty())
+ WriteGraph(File, (const Function*)&F, true);
+ else
+ errs() << " error opening file for writing!";
+ errs() << "\n";