docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg::codegen::CodeGenerator Class Referenceabstract

Base class for code generators. More...

#include <sdfg/codegen/code_generator.h>

Inheritance diagram for sdfg::codegen::CodeGenerator:
[legend]

Public Member Functions

 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="")
virtual ~CodeGenerator ()=default
const StructuredSDFG & sdfg () const
virtual bool generate ()=0
 Generate the code.
virtual std::string function_definition ()=0
 Generate a function definition for the SDFG.
virtual bool emit_header (PrettyPrinter &out)=0
 write the contents of the main header into out
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.
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.
virtual void append_function_source (std::ostream &ofs_source)=0
 Generate only the function source code and append it to the source file.
const PrettyPrinter & includes () const
 Get the includes.
const PrettyPrinter & classes () const
 Get the classes.
const PrettyPrinter & globals () const
 Get the globals.
const std::unordered_map< std::string, CodeSnippet > & library_snippets () const
 all created library snippets
const PrettyPrinter & main () const
 Get the main stream.

Protected Attributes

StructuredSDFG & sdfg_
 Reference to the schedule.
analysis::AnalysisManager & analysis_manager_
 Analysis manager for the SDFG.
InstrumentationPlan & instrumentation_plan_
 Instrumentation strategy.
ArgCapturePlan & arg_capture_plan_
PrettyPrinter includes_stream_
 Stream for includes.
PrettyPrinter classes_stream_
 Stream for classes.
PrettyPrinter globals_stream_
 Stream for global variables and functions.
std::shared_ptr< CodeSnippetFactory > library_snippet_factory_
 Stream for library functions.
PrettyPrinter main_stream_
 Main stream.
std::string externals_prefix_
 Prefix to use for external functions.

Detailed Description

Base class for code generators.

This class provides the basic structure for code generators. It contains the streams for the includes, classes, globals, library functions and main code.

Constructor & Destructor Documentation

◆ CodeGenerator()

sdfg::codegen::CodeGenerator::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 = "" )
inline

◆ ~CodeGenerator()

virtual sdfg::codegen::CodeGenerator::~CodeGenerator ( )
virtualdefault

Member Function Documentation

◆ append_function_source()

virtual void sdfg::codegen::CodeGenerator::append_function_source ( std::ostream & ofs_source)
pure virtual

Generate only the function source code and append it to the source file.

as_source generates this into source_path after includes, globals and structs

Implemented in sdfg::codegen::CStyleBaseCodeGenerator.

◆ as_source()

virtual bool sdfg::codegen::CodeGenerator::as_source ( const std::filesystem::path & header_path,
const std::filesystem::path & source_path )
pure virtual

Generate the SDFG's code into source files.

Deprecated
this requires generate() being run manually prior and will output directly into filepaths for header and source at the same time. Which is quite restrictive. New parallel builder require [emit_header] and [emit_main_source] instead

Implemented in sdfg::codegen::CStyleBaseCodeGenerator.

◆ classes()

const PrettyPrinter & sdfg::codegen::CodeGenerator::classes ( ) const
inline

Get the classes.

◆ emit_header()

virtual bool sdfg::codegen::CodeGenerator::emit_header ( PrettyPrinter & out)
pure virtual

write the contents of the main header into out

Implemented in sdfg::codegen::CStyleBaseCodeGenerator.

◆ emit_main_source()

virtual bool sdfg::codegen::CodeGenerator::emit_main_source ( std::ostream & out,
const std::filesystem::path & header_path )
pure virtual

write the contents of the main source file into out.

Can also generate additional source files (snippets) that also depend on the header

Implemented in sdfg::codegen::CStyleBaseCodeGenerator.

◆ function_definition()

virtual std::string sdfg::codegen::CodeGenerator::function_definition ( )
pure virtual

Generate a function definition for the SDFG.

Implemented in sdfg::codegen::CCodeGenerator, and sdfg::codegen::CPPCodeGenerator.

◆ generate()

virtual bool sdfg::codegen::CodeGenerator::generate ( )
pure virtual

Generate the code.

Returns
true if the code was generated successfully

Implemented in sdfg::codegen::CStyleBaseCodeGenerator.

◆ globals()

const PrettyPrinter & sdfg::codegen::CodeGenerator::globals ( ) const
inline

Get the globals.

◆ includes()

const PrettyPrinter & sdfg::codegen::CodeGenerator::includes ( ) const
inline

Get the includes.

◆ library_snippets()

const std::unordered_map< std::string, CodeSnippet > & sdfg::codegen::CodeGenerator::library_snippets ( ) const
inline

all created library snippets

◆ main()

const PrettyPrinter & sdfg::codegen::CodeGenerator::main ( ) const
inline

Get the main stream.

◆ sdfg()

const StructuredSDFG & sdfg::codegen::CodeGenerator::sdfg ( ) const
inlinenodiscard

Member Data Documentation

◆ analysis_manager_

analysis::AnalysisManager& sdfg::codegen::CodeGenerator::analysis_manager_
protected

Analysis manager for the SDFG.

◆ arg_capture_plan_

ArgCapturePlan& sdfg::codegen::CodeGenerator::arg_capture_plan_
protected

◆ classes_stream_

PrettyPrinter sdfg::codegen::CodeGenerator::classes_stream_
protected

Stream for classes.

◆ externals_prefix_

std::string sdfg::codegen::CodeGenerator::externals_prefix_
protected

Prefix to use for external functions.

◆ globals_stream_

PrettyPrinter sdfg::codegen::CodeGenerator::globals_stream_
protected

Stream for global variables and functions.

◆ includes_stream_

PrettyPrinter sdfg::codegen::CodeGenerator::includes_stream_
protected

Stream for includes.

◆ instrumentation_plan_

InstrumentationPlan& sdfg::codegen::CodeGenerator::instrumentation_plan_
protected

Instrumentation strategy.

◆ library_snippet_factory_

std::shared_ptr<CodeSnippetFactory> sdfg::codegen::CodeGenerator::library_snippet_factory_
protected

Stream for library functions.

◆ main_stream_

PrettyPrinter sdfg::codegen::CodeGenerator::main_stream_
protected

Main stream.

◆ sdfg_

StructuredSDFG& sdfg::codegen::CodeGenerator::sdfg_
protected

Reference to the schedule.


The documentation for this class was generated from the following file: