souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions
souffle::ram::transform::Transformer Class Referenceabstract

@Class Transformer @Brief abstract transformer class for a translation unit More...

#include <Transformer.h>

Inheritance diagram for souffle::ram::transform::Transformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::Transformer:
Collaboration graph

Public Member Functions

bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual std::string getName () const =0
 @Brief get name of the transformer More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

virtual bool transform (TranslationUnit &translationUnit)=0
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Detailed Description

@Class Transformer @Brief abstract transformer class for a translation unit

This is an abstract class to implement transformers. A transformer takes a translation unit and changes its state.

Transformers can be composed using other transformers.

For debugging purposes, a transformer has a name (this will show up in the debug report) and a protected method transform(), that performs the actual transformation.

The method apply is used to call transform() and does the reporting of the debug information.

Definition at line 50 of file Transformer.h.

Constructor & Destructor Documentation

◆ ~Transformer()

virtual souffle::ram::transform::Transformer::~Transformer ( )
virtualdefault

Member Function Documentation

◆ apply()

bool souffle::ram::transform::Transformer::apply ( TranslationUnit translationUnit)

@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Definition at line 39 of file Transformer.cpp.

44  {
45  translationUnit.invalidateAnalyses();
46  }
47 
48  // print runtime & change info for transformer in verbose mode
49  if (verbose && (!isA<MetaTransformer>(this))) {
50  std::string changedString = changed ? "changed" : "unchanged";
51  std::cout << getName() << " time: " << std::chrono::duration<double>(end - start).count() << "sec ["
52  << changedString << "]" << std::endl;
53  }
54 
55  // print program after transformation in debug report
56  if (debug) {
57  translationUnit.getDebugReport().startSection();
58  if (changed) {
59  translationUnit.getDebugReport().addCodeSection(getName(), "RAM Program after " + getName(),
60  "ram", ramProgStrOld, toString(translationUnit.getProgram()));
61 
62  translationUnit.getDebugReport().endSection(getName(), getName());
63  } else {
64  translationUnit.getDebugReport().endSection(getName(), getName() + " " + " (unchanged)");
65  }
66  }
67 
68  // abort evaluation of the program if errors were encountered
69  if (translationUnit.getErrorReport().getNumErrors() != 0) {
70  std::cerr << translationUnit.getErrorReport();
71  std::cerr << translationUnit.getErrorReport().getNumErrors()
72  << " errors generated, evaluation aborted" << std::endl;
73  exit(EXIT_FAILURE);
74  }
75 
76  return changed;
77 }
78 
79 } // namespace souffle::ram::transform

Referenced by souffle::ram::transform::HoistAggregateTransformer::hoistAggregate(), and souffle::ram::transform::ParallelTransformer::parallelizeOperations().

◆ getName()

virtual std::string souffle::ram::transform::Transformer::getName ( ) const
pure virtual

◆ transform()

virtual bool souffle::ram::transform::Transformer::transform ( TranslationUnit translationUnit)
protectedpure virtual

The documentation for this class was generated from the following files:
souffle::ram::transform::Transformer::getName
virtual std::string getName() const =0
@Brief get name of the transformer
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234