Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/spider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ set(SPIDER_TDL_ANTLR_GENERATED_SOURCES
)

set(SPIDER_TDL_SHARED_SOURCES
tdl/code_gen/python/PyGenerator.cpp
tdl/parser/ast/Node.cpp
tdl/parser/ast/node_impl/Function.cpp
tdl/parser/ast/node_impl/Identifier.cpp
Expand All @@ -227,12 +228,16 @@ set(SPIDER_TDL_SHARED_SOURCES
tdl/parser/ast/node_impl/type_impl/Struct.cpp
tdl/parser/ast/utils.cpp
tdl/parser/parse.cpp
tdl/pass/analysis/DetectStructCircularDependency.cpp
tdl/pass/analysis/DetectUndefinedStruct.cpp
tdl/pass/analysis/StructSpecDependencyGraph.cpp
CACHE INTERNAL
"spider task definition language shared source files"
)

set(SPIDER_TDL_SHARED_HEADERS
tdl/code_gen/python/PyGenerator.hpp
tdl/code_gen/Generator.hpp
tdl/Error.hpp
tdl/parser/ast/Node.hpp
tdl/parser/ast/FloatSpec.hpp
Expand All @@ -259,7 +264,11 @@ set(SPIDER_TDL_SHARED_HEADERS
tdl/parser/Exception.hpp
tdl/parser/parse.hpp
tdl/parser/SourceLocation.hpp
tdl/pass/analysis/DetectStructCircularDependency.hpp
tdl/pass/analysis/DetectUndefinedStruct.hpp
tdl/pass/analysis/StructSpecDependencyGraph.hpp
tdl/pass/Pass.hpp
tdl/pass/utils.hpp
CACHE INTERNAL
"spider task definition language shared header files"
)
Expand Down
65 changes: 65 additions & 0 deletions src/spider/tdl/code_gen/Generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef SPIDER_TDL_CODE_GEN_GENERATOR_HPP
#define SPIDER_TDL_CODE_GEN_GENERATOR_HPP

#include <memory>
#include <ostream>
#include <utility>

#include <boost/outcome/std_result.hpp>

#include <spider/tdl/Error.hpp>
#include <spider/tdl/parser/ast/nodes.hpp>
#include <spider/tdl/pass/analysis/StructSpecDependencyGraph.hpp>

namespace spider::tdl::code_gen {
/**
* Abstract base class for generating code from a translation unit to a target language.
*/
class Generator {
public:
// Constructor
Generator(
std::unique_ptr<parser::ast::TranslationUnit> translation_unit,
std::shared_ptr<pass::analysis::StructSpecDependencyGraph> struct_spec_dependency_graph
)
: m_translation_unit{std::move(translation_unit)},
m_struct_spec_dependency_graph{std::move(struct_spec_dependency_graph)} {}

// Delete copy constructor and copy assignment operator
Generator(Generator const&) = delete;
auto operator=(Generator const&) -> Generator& = delete;

// Default move constructor and move assignment operator
Generator(Generator&&) noexcept = default;
auto operator=(Generator&&) -> Generator& = delete;

// Destructor
virtual ~Generator() = default;

// Methods
/**
* Generates code from the translation unit to the target language.
* @param out_stream Output stream to write the generated code.
* @return A void result on success, or an error specified by an `Error` instance on failure.
*/
[[nodiscard]] virtual auto generate(std::ostream& out_stream)
-> boost::outcome_v2::std_checked<void, Error>
= 0;

protected:
[[nodiscard]] auto get_translation_unit() const -> parser::ast::TranslationUnit const* {
return m_translation_unit.get();
}

[[nodiscard]] auto get_struct_spec_dependency_graph() const
-> std::shared_ptr<pass::analysis::StructSpecDependencyGraph> {
return m_struct_spec_dependency_graph;
}

private:
std::unique_ptr<parser::ast::TranslationUnit const> m_translation_unit;
std::shared_ptr<pass::analysis::StructSpecDependencyGraph> m_struct_spec_dependency_graph;
};
} // namespace spider::tdl::code_gen

#endif // SPIDER_TDL_CODE_GEN_GENERATOR_HPP
Loading