souffle  2.0.2-371-g6315b36
DebugReporter.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file DebugReporter.h
12  *
13  * Defines an adaptor transformer to capture debug output from other transformers
14  *
15  ***********************************************************************/
16 #pragma once
17 
18 #include "ast/TranslationUnit.h"
19 #include "ast/transform/Meta.h"
20 #include "ast/transform/Null.h"
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ast::transform {
31 
32 /**
33  * Transformation pass which wraps another transformation pass and generates
34  * a debug report section for the stage after applying the wrapped transformer,
35  * and adds it to the translation unit's debug report.
36  */
37 class DebugReporter : public MetaTransformer {
38 public:
40 
41  std::vector<Transformer*> getSubtransformers() const override {
42  return {wrappedTransformer.get()};
43  }
44 
45  void setDebugReport() override {}
46 
47  void setVerbosity(bool verbose) override {
48  this->verbose = verbose;
49  if (auto* mt = dynamic_cast<MetaTransformer*>(wrappedTransformer.get())) {
50  mt->setVerbosity(verbose);
51  }
52  }
53 
54  void disableTransformers(const std::set<std::string>& transforms) override {
55  if (auto* mt = dynamic_cast<MetaTransformer*>(wrappedTransformer.get())) {
56  mt->disableTransformers(transforms);
57  } else if (transforms.find(wrappedTransformer->getName()) != transforms.end()) {
58  wrappedTransformer = mk<NullTransformer>();
59  }
60  }
61 
62  std::string getName() const override {
63  return "DebugReporter";
64  }
65 
66  DebugReporter* clone() const override {
68  }
69 
70 private:
72 
73  bool transform(TranslationUnit& translationUnit) override;
74 
75  void generateDebugReport(TranslationUnit& tu, const std::string& preTransformDatalog);
76 };
77 
78 } // namespace souffle::ast::transform
souffle::ast::transform::DebugReporter::DebugReporter
DebugReporter(Own< Transformer > wrappedTransformer)
Definition: DebugReporter.h:51
souffle::ast::transform::DebugReporter::setDebugReport
void setDebugReport() override
Definition: DebugReporter.h:57
souffle::ast::transform::DebugReporter::getSubtransformers
std::vector< Transformer * > getSubtransformers() const override
Definition: DebugReporter.h:53
TranslationUnit.h
souffle::ast::transform::MetaTransformer
Transformer that coordinates other sub-transformations.
Definition: Meta.h:36
souffle::ast::transform::DebugReporter::clone
DebugReporter * clone() const override
Definition: DebugReporter.h:78
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
MiscUtil.h
Transformer.h
Null.h
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
ContainerUtil.h
souffle::ast::transform::MetaTransformer::verbose
bool verbose
Definition: Meta.h:44
souffle::ast::transform::DebugReporter::generateDebugReport
void generateDebugReport(TranslationUnit &tu, const std::string &preTransformDatalog)
Definition: DebugReporter.cpp:49
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::transform
Definition: Program.h:45
souffle::ast::transform::DebugReporter::getName
std::string getName() const override
Definition: DebugReporter.h:74
std
Definition: Brie.h:3053
souffle::ast::transform::DebugReporter
Transformation pass which wraps another transformation pass and generates a debug report section for ...
Definition: DebugReporter.h:43
souffle::ast::transform::DebugReporter::wrappedTransformer
Own< Transformer > wrappedTransformer
Definition: DebugReporter.h:83
souffle::ast::transform::DebugReporter::setVerbosity
void setVerbosity(bool verbose) override
Definition: DebugReporter.h:59
souffle::ast::transform::DebugReporter::disableTransformers
void disableTransformers(const std::set< std::string > &transforms) override
Definition: DebugReporter.h:66
Meta.h
souffle::ast::transform::DebugReporter::transform
bool transform(TranslationUnit &translationUnit) override
Definition: DebugReporter.cpp:32