souffle  2.0.2-371-g6315b36
DebugReporter.cpp
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.cpp
12  *
13  * Defines class for adapting other transformers to produce debug output
14  *
15  ***********************************************************************/
16 
18 #include "ast/Program.h"
19 #include "ast/TranslationUnit.h"
20 #include "ast/utility/Utils.h"
21 #include "reports/DebugReport.h"
22 #include <chrono>
23 
24 namespace souffle::ast::transform {
25 
26 bool DebugReporter::transform(TranslationUnit& translationUnit) {
27  translationUnit.getDebugReport().startSection();
28  auto datalogSpecOriginal = pprint(translationUnit.getProgram());
30  bool changed = applySubtransformer(translationUnit, wrappedTransformer.get());
32 
33  if (changed) {
34  generateDebugReport(translationUnit, datalogSpecOriginal);
35  }
36 
37  auto elapsed = std::to_string(std::chrono::duration<double>(end - start).count());
38  translationUnit.getDebugReport().endSection(wrappedTransformer->getName(),
39  wrappedTransformer->getName() + " (" + elapsed + "s)" + (changed ? "" : " (unchanged)"));
40  return changed;
41 }
42 
43 void DebugReporter::generateDebugReport(TranslationUnit& tu, const std::string& preTransformDatalog) {
45  "dl", "Datalog", "souffle", preTransformDatalog, pprint(tu.getProgram()));
46 }
47 
48 } // namespace souffle::ast::transform
TranslationUnit.h
DebugReport.h
souffle::ast::pprint
std::string pprint(const Node &node)
Definition: Utils.cpp:59
Utils.h
souffle::now
time_point now()
Definition: MiscUtil.h:89
souffle::DebugReport::addCodeSection
void addCodeSection(std::string id, std::string title, std::string_view language, std::string_view prev, std::string_view curr)
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::test::count
int count(const C &c)
Definition: table_test.cpp:40
souffle::ast::transform
Definition: Program.h:45
souffle::ast::TranslationUnit::getDebugReport
DebugReport & getDebugReport()
Return debug report.
Definition: TranslationUnit.h:100
DebugReporter.h
Program.h
souffle::ast::transform::DebugReporter::wrappedTransformer
Own< Transformer > wrappedTransformer
Definition: DebugReporter.h:83
souffle::ast::TranslationUnit::getProgram
Program & getProgram() const
Return the program.
Definition: TranslationUnit.h:84
souffle::ast::transform::MetaTransformer::applySubtransformer
bool applySubtransformer(TranslationUnit &translationUnit, Transformer *transformer)
Definition: Meta.cpp:30
souffle::ast::transform::DebugReporter::transform
bool transform(TranslationUnit &translationUnit) override
Definition: DebugReporter.cpp:32