souffle  2.0.2-371-g6315b36
Pipeline.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. 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 Pipeline.h
12  *
13  * Transformer that holds an arbitrary number of sub-transformations
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/TranslationUnit.h"
21 #include "ast/transform/Meta.h"
22 #include "ast/transform/Null.h"
26 #include <algorithm>
27 #include <memory>
28 #include <set>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace souffle::ast::transform {
34 
35 /**
36  * Transformer that holds an arbitrary number of sub-transformations
37  */
38 class PipelineTransformer : public MetaTransformer {
39 public:
40  template <typename... Args>
41  PipelineTransformer(Args... args) {
42  Own<Transformer> tmp[] = {std::move(args)...};
43  for (auto& cur : tmp) {
44  pipeline.push_back(std::move(cur));
45  }
46  }
47 
49 
50  std::vector<Transformer*> getSubtransformers() const override {
51  return toPtrVector(pipeline);
52  }
53 
54  void setDebugReport() override {
55  for (auto& i : pipeline) {
56  if (auto* mt = dynamic_cast<MetaTransformer*>(i.get())) {
57  mt->setDebugReport();
58  } else {
59  i = mk<DebugReporter>(std::move(i));
60  }
61  }
62  }
63 
64  void setVerbosity(bool verbose) override {
65  this->verbose = verbose;
66  for (auto& cur : pipeline) {
67  if (auto* mt = dynamic_cast<MetaTransformer*>(cur.get())) {
68  mt->setVerbosity(verbose);
69  }
70  }
71  }
72 
73  void disableTransformers(const std::set<std::string>& transforms) override {
74  for (auto& i : pipeline) {
75  if (auto* mt = dynamic_cast<MetaTransformer*>(i.get())) {
76  mt->disableTransformers(transforms);
77  } else if (transforms.find(i->getName()) != transforms.end()) {
78  i = mk<NullTransformer>();
79  }
80  }
81  }
82 
83  std::string getName() const override {
84  return "PipelineTransformer";
85  }
86 
87  PipelineTransformer* clone() const override {
88  VecOwn<Transformer> transformers;
89  for (const auto& transformer : pipeline) {
90  transformers.push_back(souffle::clone(transformer));
91  }
92  return new PipelineTransformer(std::move(transformers));
93  }
94 
95 protected:
97  bool transform(TranslationUnit& translationUnit) override {
98  bool changed = false;
99  for (auto& transformer : pipeline) {
100  changed |= applySubtransformer(translationUnit, transformer.get());
101  }
102  return changed;
103  }
104 };
105 
106 } // namespace souffle::ast::transform
TranslationUnit.h
souffle::ast::transform::PipelineTransformer
Transformer that holds an arbitrary number of sub-transformations.
Definition: Pipeline.h:44
souffle::ast::transform::PipelineTransformer::clone
PipelineTransformer * clone() const override
Definition: Pipeline.h:99
souffle::ast::transform::PipelineTransformer::transform
bool transform(TranslationUnit &translationUnit) override
Definition: Pipeline.h:109
souffle::ast::transform::PipelineTransformer::PipelineTransformer
PipelineTransformer(Args... args)
Definition: Pipeline.h:53
souffle::ast::transform::MetaTransformer
Transformer that coordinates other sub-transformations.
Definition: Meta.h:36
souffle::ast::transform::PipelineTransformer::disableTransformers
void disableTransformers(const std::set< std::string > &transforms) override
Definition: Pipeline.h:85
MiscUtil.h
Transformer.h
Null.h
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
i
size_t i
Definition: json11.h:663
ContainerUtil.h
souffle::ast::transform::PipelineTransformer::setDebugReport
void setDebugReport() override
Definition: Pipeline.h:66
souffle::ast::transform::MetaTransformer::verbose
bool verbose
Definition: Meta.h:44
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::transform
Definition: Program.h:45
souffle::ast::transform::PipelineTransformer::getSubtransformers
std::vector< Transformer * > getSubtransformers() const override
Definition: Pipeline.h:62
DebugReporter.h
std
Definition: Brie.h:3053
souffle::ast::transform::PipelineTransformer::setVerbosity
void setVerbosity(bool verbose) override
Definition: Pipeline.h:76
souffle::ast::transform::PipelineTransformer::getName
std::string getName() const override
Definition: Pipeline.h:95
souffle::ast::transform::PipelineTransformer::pipeline
VecOwn< Transformer > pipeline
Definition: Pipeline.h:108
souffle::toPtrVector
std::vector< T * > toPtrVector(const std::vector< std::unique_ptr< T >> &v)
A utility function enabling the creation of a vector of pointers.
Definition: ContainerUtil.h:146
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45
souffle::ast::transform::MetaTransformer::applySubtransformer
bool applySubtransformer(TranslationUnit &translationUnit, Transformer *transformer)
Definition: Meta.cpp:30
Meta.h