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

Originally started out as a handler for additional source files, like hardware-accelerator kernels that are called from the main code, it has morphed more into a CodegenState That also includes library dependencies and header definitions that could be used with the existing arguments given to any dispatcher. More...

#include <sdfg/codegen/code_snippet_factory.h>

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

Public Member Functions

 CodeSnippetFactory (const std::pair< std::filesystem::path, std::filesystem::path > *config=nullptr)
virtual ~CodeSnippetFactory ()=default
virtual CodeSnippet & require (const std::string &name, const std::string &extension, bool as_file)
CodeSnippet & require (const std::string &name, const std::string &extension)
std::unordered_map< std::string, CodeSnippet >::iterator find (const std::string &name)
const std::unordered_map< std::string, CodeSnippet > & snippets () const
const std::filesystem::path & output_path () const
const std::filesystem::path & header_path () const
virtual void add_setup (const std::string &snippet)
virtual void add_teardown (const std::string &snippet)
virtual void add_global (const std::string &snippet)
virtual const std::unordered_set< std::string > & setup_snippets () const
virtual const std::unordered_set< std::string > & teardown_snippets () const
std::vector< const LibDependency * > get_used_lib_dependencies () const
const std::unordered_set< std::string > & globals_snippets () const
void add_available_dependency (const LibDependency *dependency)
 For the generation process to declare discovered runtime dependencies before the codegen starts.
bool is_available (const LibDependency *dependency) const
 The dependency is either already required or the system knows it is available.
std::optional< std::pair< const std::string &, const LibDependency * > > check_for_conflicts (const LibDependency *dependency) const
 Checks if this dependency would conflict with existing ones.
void require_no_conflicts (const LibDependency *dependency)
 Adds conflicts of this dependency to the list, throws if conflicts exist Warning: not transactional for now!
bool require_dependency (const LibDependency *dependency)
 Ensure that the given dependency is available or throw.

Protected Attributes

std::unordered_map< std::string, CodeSnippet > snippets_
const std::filesystem::path output_path_
const std::filesystem::path header_path_
std::unordered_set< std::string > setup_snippets_
std::unordered_set< std::string > teardown_snippets_
std::unordered_set< std::string > globals_snippets_
std::unordered_map< std::string, const LibDependency * > conflicting_ids_
std::unordered_map< const LibDependency *, DependencyState > dependencies_

Detailed Description

Originally started out as a handler for additional source files, like hardware-accelerator kernels that are called from the main code, it has morphed more into a CodegenState That also includes library dependencies and header definitions that could be used with the existing arguments given to any dispatcher.

Constructor & Destructor Documentation

◆ CodeSnippetFactory()

sdfg::codegen::CodeSnippetFactory::CodeSnippetFactory ( const std::pair< std::filesystem::path, std::filesystem::path > * config = nullptr)

◆ ~CodeSnippetFactory()

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

Member Function Documentation

◆ add_available_dependency()

void sdfg::codegen::CodeSnippetFactory::add_available_dependency ( const LibDependency * dependency)

For the generation process to declare discovered runtime dependencies before the codegen starts.

Reasons could be: user code requires that it exists, it has been found in the filesystem or the config says it is always available For example tenstorrent debug support, only available if compiled this way locally, then the headers of it may be relied upon. Otherwise it would crash

◆ add_global()

virtual void sdfg::codegen::CodeSnippetFactory::add_global ( const std::string & snippet)
virtual

◆ add_setup()

virtual void sdfg::codegen::CodeSnippetFactory::add_setup ( const std::string & snippet)
virtual

◆ add_teardown()

virtual void sdfg::codegen::CodeSnippetFactory::add_teardown ( const std::string & snippet)
virtual

◆ check_for_conflicts()

std::optional< std::pair< const std::string &, const LibDependency * > > sdfg::codegen::CodeSnippetFactory::check_for_conflicts ( const LibDependency * dependency) const

Checks if this dependency would conflict with existing ones.

Returns
conflict if any: {conflicting ID, source of that ID}

◆ find()

std::unordered_map< std::string, CodeSnippet >::iterator sdfg::codegen::CodeSnippetFactory::find ( const std::string & name)

◆ get_used_lib_dependencies()

std::vector< const LibDependency * > sdfg::codegen::CodeSnippetFactory::get_used_lib_dependencies ( ) const

◆ globals_snippets()

const std::unordered_set< std::string > & sdfg::codegen::CodeSnippetFactory::globals_snippets ( ) const

◆ header_path()

const std::filesystem::path & sdfg::codegen::CodeSnippetFactory::header_path ( ) const
inline

◆ is_available()

bool sdfg::codegen::CodeSnippetFactory::is_available ( const LibDependency * dependency) const

The dependency is either already required or the system knows it is available.

◆ output_path()

const std::filesystem::path & sdfg::codegen::CodeSnippetFactory::output_path ( ) const
inline

◆ require() [1/2]

CodeSnippet & sdfg::codegen::CodeSnippetFactory::require ( const std::string & name,
const std::string & extension )
inline

◆ require() [2/2]

virtual CodeSnippet & sdfg::codegen::CodeSnippetFactory::require ( const std::string & name,
const std::string & extension,
bool as_file )
virtual

◆ require_dependency()

bool sdfg::codegen::CodeSnippetFactory::require_dependency ( const LibDependency * dependency)

Ensure that the given dependency is available or throw.

Returns
true if the dependency is now newly used

◆ require_no_conflicts()

void sdfg::codegen::CodeSnippetFactory::require_no_conflicts ( const LibDependency * dependency)

Adds conflicts of this dependency to the list, throws if conflicts exist Warning: not transactional for now!

◆ setup_snippets()

virtual const std::unordered_set< std::string > & sdfg::codegen::CodeSnippetFactory::setup_snippets ( ) const
virtual

◆ snippets()

const std::unordered_map< std::string, CodeSnippet > & sdfg::codegen::CodeSnippetFactory::snippets ( ) const

◆ teardown_snippets()

virtual const std::unordered_set< std::string > & sdfg::codegen::CodeSnippetFactory::teardown_snippets ( ) const
virtual

Member Data Documentation

◆ conflicting_ids_

std::unordered_map<std::string, const LibDependency*> sdfg::codegen::CodeSnippetFactory::conflicting_ids_
protected

◆ dependencies_

std::unordered_map<const LibDependency*, DependencyState> sdfg::codegen::CodeSnippetFactory::dependencies_
protected

◆ globals_snippets_

std::unordered_set<std::string> sdfg::codegen::CodeSnippetFactory::globals_snippets_
protected

◆ header_path_

const std::filesystem::path sdfg::codegen::CodeSnippetFactory::header_path_
protected

◆ output_path_

const std::filesystem::path sdfg::codegen::CodeSnippetFactory::output_path_
protected

◆ setup_snippets_

std::unordered_set<std::string> sdfg::codegen::CodeSnippetFactory::setup_snippets_
protected

◆ snippets_

std::unordered_map<std::string, CodeSnippet> sdfg::codegen::CodeSnippetFactory::snippets_
protected

◆ teardown_snippets_

std::unordered_set<std::string> sdfg::codegen::CodeSnippetFactory::teardown_snippets_
protected

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