docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
code_generator.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <string>
5#include <utility>
6
10#include "sdfg/codegen/utils.h"
12#include "sdfg/types/type.h"
13
14namespace sdfg {
15namespace codegen {
16
24protected:
27
30
34
37
40
43
45 std::shared_ptr<CodeSnippetFactory> library_snippet_factory_;
46
49
51 std::string externals_prefix_;
52
53public:
56 analysis::AnalysisManager& analysis_manager,
57 InstrumentationPlan& instrumentation_plan,
58 ArgCapturePlan& arg_capture_plan,
59 std::shared_ptr<CodeSnippetFactory> library_snippet_factory = std::make_shared<CodeSnippetFactory>(),
60 const std::string& externals_prefix = ""
61 )
62 : sdfg_(sdfg), analysis_manager_(analysis_manager), instrumentation_plan_(instrumentation_plan),
63 arg_capture_plan_(arg_capture_plan), library_snippet_factory_(std::move(library_snippet_factory)),
64 externals_prefix_(externals_prefix) {};
65
66
67 virtual ~CodeGenerator() = default;
68
69 [[nodiscard]] const StructuredSDFG& sdfg() const {
70 return this->sdfg_;
71 };
72
78 virtual bool generate() = 0;
79
81 virtual std::string function_definition() = 0;
82
84 virtual bool emit_header(PrettyPrinter& out) = 0;
85
88 virtual bool emit_main_source(std::ostream& out, const std::filesystem::path& header_path) = 0;
89
94 virtual bool as_source(const std::filesystem::path& header_path, const std::filesystem::path& source_path) = 0;
95
98 virtual void append_function_source(std::ostream& ofs_source) = 0;
99
101 const PrettyPrinter& includes() const {
102 return this->includes_stream_;
103 };
104
106 const PrettyPrinter& classes() const {
107 return this->classes_stream_;
108 };
109
111 const PrettyPrinter& globals() const {
112 return this->globals_stream_;
113 };
114
116 const std::unordered_map<std::string, CodeSnippet>& library_snippets() const {
117 return this->library_snippet_factory_->snippets();
118 };
119
121 const PrettyPrinter& main() const {
122 return this->main_stream_;
123 };
124};
125
126} // namespace codegen
127} // namespace sdfg
Definition structured_sdfg.h:30
Definition analysis.h:53
Definition arg_capture_plan.h:36
std::shared_ptr< CodeSnippetFactory > library_snippet_factory_
Stream for library functions.
Definition code_generator.h:45
const PrettyPrinter & classes() const
Get the classes.
Definition code_generator.h:106
PrettyPrinter globals_stream_
Stream for global variables and functions.
Definition code_generator.h:42
ArgCapturePlan & arg_capture_plan_
Definition code_generator.h:33
CodeGenerator(StructuredSDFG &sdfg, analysis::AnalysisManager &analysis_manager, InstrumentationPlan &instrumentation_plan, ArgCapturePlan &arg_capture_plan, std::shared_ptr< CodeSnippetFactory > library_snippet_factory=std::make_shared< CodeSnippetFactory >(), const std::string &externals_prefix="")
Definition code_generator.h:54
PrettyPrinter classes_stream_
Stream for classes.
Definition code_generator.h:39
analysis::AnalysisManager & analysis_manager_
Analysis manager for the SDFG.
Definition code_generator.h:29
const PrettyPrinter & main() const
Get the main stream.
Definition code_generator.h:121
virtual bool generate()=0
Generate the code.
std::string externals_prefix_
Prefix to use for external functions.
Definition code_generator.h:51
const PrettyPrinter & globals() const
Get the globals.
Definition code_generator.h:111
PrettyPrinter main_stream_
Main stream.
Definition code_generator.h:48
virtual bool emit_main_source(std::ostream &out, const std::filesystem::path &header_path)=0
write the contents of the main source file into out.
InstrumentationPlan & instrumentation_plan_
Instrumentation strategy.
Definition code_generator.h:32
const StructuredSDFG & sdfg() const
Definition code_generator.h:69
virtual ~CodeGenerator()=default
virtual void append_function_source(std::ostream &ofs_source)=0
Generate only the function source code and append it to the source file.
StructuredSDFG & sdfg_
Reference to the schedule.
Definition code_generator.h:26
const PrettyPrinter & includes() const
Get the includes.
Definition code_generator.h:101
virtual std::string function_definition()=0
Generate a function definition for the SDFG.
PrettyPrinter includes_stream_
Stream for includes.
Definition code_generator.h:36
virtual bool as_source(const std::filesystem::path &header_path, const std::filesystem::path &source_path)=0
Generate the SDFG's code into source files.
const std::unordered_map< std::string, CodeSnippet > & library_snippets() const
all created library snippets
Definition code_generator.h:116
virtual bool emit_header(PrettyPrinter &out)=0
write the contents of the main header into out
Definition instrumentation_plan.h:26
Definition utils.h:16
Definition argument_registry.h:10
Definition analysis.h:7
Core type system definitions for sdfglib.