12#include "llvm/Support/WithColor.h"
17 struct NullLogger final :
Logger {};
18 static auto *Instance =
new NullLogger();
23struct TextualLogger final :
Logger {
24 llvm::raw_ostream &OS;
33 TextualLogger(llvm::raw_ostream &OS)
34 : OS(OS),
ShowColors(
llvm::WithColor::defaultAutoDetectFunction()(OS)) {}
36 virtual void beginAnalysis(
const ControlFlowContext &CFG,
37 TypeErasedDataflowAnalysis &
Analysis)
override {
39 llvm::WithColor Header(OS, llvm::raw_ostream::Colors::RED,
true);
40 OS <<
"=== Beginning data flow analysis ===\n";
42 if (
auto *D = CFG.getDecl()) {
51 virtual void endAnalysis()
override {
52 llvm::WithColor Header(OS, llvm::raw_ostream::Colors::RED,
true);
53 unsigned Blocks = 0, Steps = 0;
54 for (
const auto &E : VisitCount) {
58 llvm::errs() <<
"=== Finished analysis: " << Blocks <<
" blocks in "
59 << Steps <<
" total steps ===\n";
61 virtual void enterBlock(
const CFGBlock &
Block)
override {
64 llvm::WithColor Header(OS, llvm::raw_ostream::Colors::RED,
true);
65 OS <<
"=== Entering block B" <<
Block.getBlockID() <<
" (iteration "
66 << Count <<
") ===\n";
74 virtual void enterElement(
const CFGElement &Element)
override {
78 llvm::WithColor Subheader(OS, llvm::raw_ostream::Colors::CYAN,
80 OS <<
"Processing element B" <<
CurrentBlock->getBlockID() <<
"."
82 Element.dumpToStream(OS);
85 void recordState(TypeErasedDataflowAnalysisState &State)
override {
87 llvm::WithColor Subheader(OS, llvm::raw_ostream::Colors::CYAN,
89 OS <<
"Computed state for B" <<
CurrentBlock->getBlockID() <<
"."
97 void blockConverged()
override {
98 OS <<
"B" <<
CurrentBlock->getBlockID() <<
" has converged!\n";
100 virtual void logText(llvm::StringRef S)
override { OS << S <<
"\n"; }
105 return std::make_unique<TextualLogger>(OS);
llvm::DenseMap< const CFGBlock *, unsigned > VisitCount
const CFGElement * CurrentElement
const CFGBlock * CurrentBlock
TypeErasedDataflowAnalysis * CurrentAnalysis
unsigned CurrentElementIndex
TypeErasedDataflowAnalysis & Analysis
The analysis to be run.
A logger is notified as the analysis progresses.
static std::unique_ptr< Logger > textual(llvm::raw_ostream &)
A logger that simply writes messages to the specified ostream in real time.
static Logger & null()
Returns a dummy logger that does nothing.
Dataflow Directional Tag Classes.
YAML serialization mapping.