| chigraph master Systems programming language written for beginners in LLVM

NodeType.hpp
Go to the documentation of this file.
1
4 #ifndef CHI_NODE_TYPE_HPP
5 #define CHI_NODE_TYPE_HPP
6
7 #pragma once
8
9 #include <memory>
10 #include <unordered_map>
11 #include <vector>
12
13 #include "chi/Fwd.hpp"
14 #include "chi/Support/json.hpp"
15
16 namespace chi {
19 struct NodeType {
20 private:
21 friend NodeInstance;
22
23 public:
28 NodeType(ChiModule& mod, std::string name = {}, std::string description = {});
30 virtual ~NodeType();
31
34 std::string qualifiedName() const;
35
47 virtual Result codegen(NodeCompiler& compiler, llvm::BasicBlock& codegenInto,
48 size_t execInputID, const llvm::DebugLoc& nodeLocation,
49 const std::vector<llvm::Value*>& io,
50 const std::vector<llvm::BasicBlock*>& outputBlocks) = 0;
51
54 virtual nlohmann::json toJSON() const { return {}; }
57 virtual std::unique_ptr<NodeType> clone() const = 0;
58
61 std::string name() const { return mName; }
64 std::string description() const { return mDescription; }
67 ChiModule& module() const { return *mModule; }
70 Context& context() const { return *mContext; }
73 const std::vector<NamedDataType>& dataInputs() const { return mDataInputs; }
76 const std::vector<NamedDataType>& dataOutputs() const { return mDataOutputs; }
79 const std::vector<std::string>& execInputs() const { return mExecInputs; }
82 const std::vector<std::string>& execOutputs() const { return mExecOutputs; }
83
86 bool pure() { return mPure; }
87
89 bool converter() { return mConverter; }
90
91 protected:
94 void setDataInputs(std::vector<NamedDataType> newInputs);
97 void setDataOutputs(std::vector<NamedDataType> newOutputs);
100 void setExecInputs(std::vector<std::string> newInputs);
103 void setExecOutputs(std::vector<std::string> newOutputs);
104
107 void setName(std::string newName);
108
111 void setDescription(std::string newDesc);
112
120 void makePure();
121
125 void makeConverter();
126
129 NodeInstance* nodeInstance() const;
130
131 private:
132 ChiModule* mModule;
133 Context* mContext;
134 std::string mName, mDescription;
135
136 NodeInstance* mNodeInstance = nullptr;
137
138 std::vector<NamedDataType> mDataInputs;
139 std::vector<NamedDataType> mDataOutputs;
140
141 std::vector<std::string> mExecInputs;
142 std::vector<std::string> mExecOutputs;
143
144 bool mPure = false;
145 bool mConverter = false;
146 };
147 } // namespace chi
148
149 #endif // CHI_NODE_TYPE_HPP
chi::NodeType::execInputs
const std::vector< std::string > & execInputs() const
Get the execution inputs for the node.
Definition: NodeType.hpp:79
chi::NodeType::module
ChiModule & module() const
Get the ChiModule this NodeType belongs to.
Definition: NodeType.hpp:67
Fwd.hpp
Forward declares all the chigraph data types.
chi::NodeType::context
Context & context() const
Get the Context this NodeType belongs to.
Definition: NodeType.hpp:70
chi::NodeType::dataOutputs
const std::vector< NamedDataType > & dataOutputs() const
Get the data outputs for the node.
Definition: NodeType.hpp:76
chi::NodeInstance
An instance of a node.
Definition: NodeInstance.hpp:19
chi::NodeType::makeConverter
void makeConverter()
Make this a converter node.
Definition: NodeType.cpp:44
chi::NodeType::setDescription
void setDescription(std::string newDesc)
Set the description of the node.
Definition: NodeType.cpp:56
chi::NodeType::converter
bool converter()
Get if this node is a converter.
Definition: NodeType.hpp:89
chi::NodeType::name
std::string name() const
Get the name of the NodeType in the ChiModule.
Definition: NodeType.hpp:61
chi::NodeType::toJSON
virtual nlohmann::json toJSON() const
Create the JSON necessary to store the object.
Definition: NodeType.hpp:54
chi::NodeType::execOutputs
const std::vector< std::string > & execOutputs() const
Get the execution outputs for the node.
Definition: NodeType.hpp:82
chi::NodeType::makePure
void makePure()
Make this node pure For more info on what this means, see https://en.wikipedia.org/wiki/Pure_function...
Definition: NodeType.cpp:37
chi::NodeType::description
std::string description() const
Get the description of the NodeType.
Definition: NodeType.hpp:64
chi::NodeCompiler
Helper to compile nodes.
Definition: NodeCompiler.hpp:24
chi::NodeType
A generic node type.
Definition: NodeType.hpp:19
chi::NodeType::nodeInstance
NodeInstance * nodeInstance() const
Get the node instance.
Definition: NodeType.cpp:52
chi::Context
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
chi::NodeType::NodeType
NodeType(ChiModule &mod, std::string name={}, std::string description={})
Constructor.
Definition: NodeType.cpp:9
chi::ChiModule
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
chi::NodeType::setExecOutputs
void setExecOutputs(std::vector< std::string > newOutputs)
Set the exec outputs for the NodeType.
Definition: NodeType.cpp:33
chi::NodeType::setDataOutputs
void setDataOutputs(std::vector< NamedDataType > newOutputs)
Set the data outputs for the NodeType.
Definition: NodeType.cpp:24
chi::NodeType::setExecInputs
void setExecInputs(std::vector< std::string > newInputs)
Set the exec inputs for the NodeType.
Definition: NodeType.cpp:29
chi::NodeType::pure
bool pure()
Get if this node is pure.
Definition: NodeType.hpp:86
chi::NodeType::setName
void setName(std::string newName)
Set the name of the type.
Definition: NodeType.cpp:54
chi::NodeType::~NodeType
virtual ~NodeType()
Destructor.
chi::NodeType::dataInputs
const std::vector< NamedDataType > & dataInputs() const
Get the data inputs for the node.
Definition: NodeType.hpp:73
chi
The namespace where chigraph lives.
Definition: BitcodeParser.hpp:12
chi::NodeType::qualifiedName
std::string qualifiedName() const
Get the qualified name of the node type, like module.name():name()
Definition: NodeType.cpp:17
chi::NodeType::clone
virtual std::unique_ptr< NodeType > clone() const =0
Clones the type.
chi::Result
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
chi::NodeType::codegen
virtual Result codegen(NodeCompiler &compiler, llvm::BasicBlock &codegenInto, size_t execInputID, const llvm::DebugLoc &nodeLocation, const std::vector< llvm::Value *> &io, const std::vector< llvm::BasicBlock *> &outputBlocks)=0
A virtual function that is called when this node needs to be called.
chi::NodeType::setDataInputs
void setDataInputs(std::vector< NamedDataType > newInputs)
Set the data inputs for the NodeType.
Definition: NodeType.cpp:19