docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
library_node_dispatcher_base.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace sdfg::codegen {
6
7template<typename NodeType>
9public:
11 codegen::LanguageExtension& language_extension,
12 const Function& function,
13 const data_flow::DataFlowGraph& data_flow_graph,
14 const NodeType& node
15 )
16 : LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {
17 }
18
19 virtual ~LibraryNodeDispatcherBase() = default;
20
21 virtual bool begin_node(codegen::PrettyPrinter& stream) {
22 stream << "{" << std::endl;
23 stream.changeIndent(+4);
24 return true;
25 }
26
27 virtual void end_node(codegen::PrettyPrinter& stream, bool has_declaration) {
28 if (has_declaration) {
29 stream.changeIndent(-4);
30 stream << "}" << std::endl;
31 }
32 }
33
34protected:
36 codegen::PrettyPrinter& stream, const data_flow::AccessNode* node, const std::string& name
37 ) {
38 if (auto const_node = dynamic_cast<const data_flow::ConstantNode*>(node)) {
39 auto val = const_node->data();
40 stream << language_extension_.declaration(name, const_node->type()) << " = " << val << ";" << std::endl;
41 return name;
42 } else {
43 return node->data();
44 }
45 }
46};
47
48
49} // namespace sdfg::codegen
Dispatchers for dataflow blocks and library nodes.
Definition function.h:43
Definition language_extension.h:39
LibraryNodeDispatcherBase(codegen::LanguageExtension &language_extension, const Function &function, const data_flow::DataFlowGraph &data_flow_graph, const NodeType &node)
Definition library_node_dispatcher_base.h:10
virtual void end_node(codegen::PrettyPrinter &stream, bool has_declaration)
End code generation for the node.
Definition library_node_dispatcher_base.h:27
const std::string & require_param_as_var_equivalent(codegen::PrettyPrinter &stream, const data_flow::AccessNode *node, const std::string &name)
Definition library_node_dispatcher_base.h:35
virtual bool begin_node(codegen::PrettyPrinter &stream)
Begin code generation for the node.
Definition library_node_dispatcher_base.h:21
Base class for library node code generation dispatchers.
Definition block_dispatcher.h:163
LibraryNodeDispatcher(LanguageExtension &language_extension, const Function &function, const data_flow::DataFlowGraph &data_flow_graph, const data_flow::LibraryNode &node)
Construct a library node dispatcher.
LanguageExtension & language_extension_
Language extension for code generation.
Definition block_dispatcher.h:165
Definition utils.h:16
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
const std::string & data() const
Get the name of the data container.
Node representing a constant literal value in the dataflow graph.
Definition access_node.h:205
Definition data_flow_graph.h:29
Definition argument_registry.h:10