4 #ifndef CHI_GRAPH_FUNCTION_HPP 5 #define CHI_GRAPH_FUNCTION_HPP 11 #include "chi/Support/json.hpp" 13 #include <unordered_map> 15 #include <boost/filesystem.hpp> 16 #include <boost/utility/string_view.hpp> 17 #include <boost/uuid/random_generator.hpp> 18 #include <boost/uuid/uuid.hpp> 32 std::vector<NamedDataType> dataOuts, std::vector<std::string> execIns,
33 std::vector<std::string> execOuts);
51 std::unordered_map<boost::uuids::uuid, std::unique_ptr<NodeInstance>>&
nodes() {
55 const std::unordered_map<boost::uuids::uuid, std::unique_ptr<NodeInstance>>&
nodes()
const {
78 boost::uuids::uuid
id = boost::uuids::random_generator()(),
86 boost::string_view name)
const noexcept;
97 Result insertNode(
const boost::filesystem::path& moduleName, boost::string_view typeName,
98 const nlohmann::json& typeJSON,
float x,
float y,
99 boost::uuids::uuid
id = boost::uuids::random_generator()(),
116 boost::uuids::uuid
id = boost::uuids::random_generator()(),
145 const std::vector<NamedDataType>&
dataInputs()
const {
return mDataInputs; }
151 size_t addBefore = (std::numeric_limits<size_t>::max)());
180 const std::vector<NamedDataType>&
dataOutputs()
const {
return mDataOutputs; }
186 size_t addBefore = (std::numeric_limits<size_t>::max)());
216 const std::vector<std::string>&
execInputs()
const {
return mExecInputs; }
220 void addExecInput(std::string name,
size_t addBefore = (std::numeric_limits<size_t>::max)());
241 const std::vector<std::string>&
execOutputs()
const {
return mExecOutputs; }
245 void addExecOutput(std::string name,
size_t addBefore = (std::numeric_limits<size_t>::max)());
265 const std::vector<NamedDataType>&
localVariables()
const {
return mLocalVariables; }
278 bool* inserted =
nullptr);
313 std::string
name()
const {
return mName; }
324 std::vector<NodeInstance*>
setName(boost::string_view newName,
bool updateReferences =
true);
331 void updateEntries();
337 std::string mDescription;
339 std::vector<NamedDataType> mDataInputs;
340 std::vector<NamedDataType> mDataOutputs;
342 std::vector<std::string> mExecInputs;
343 std::vector<std::string> mExecOutputs;
345 std::vector<NamedDataType> mLocalVariables;
347 std::unordered_map<boost::uuids::uuid, std::unique_ptr<NodeInstance>>
355 inline std::pair<std::string, std::string>
parseColonPair(
const std::string& in) {
356 size_t colonID = in.find(
':');
357 if (colonID == std::string::npos) {
return {}; }
358 std::string
module = in.substr(0, in.find(
':'));
359 std::string
name = in.substr(in.find(
':') + 1);
365 #endif // CHI_GRAPH_FUNCTION_HPP void addDataOutput(const DataType &type, std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)())
Add an data output to the end of the argument list.
GraphFunction(GraphModule &mod, std::string name, std::vector< NamedDataType > dataIns, std::vector< NamedDataType > dataOuts, std::vector< std::string > execIns, std::vector< std::string > execOuts)
Construct a graph–don't call this directly use GraphModule::getorCreateFunction. ...
void addDataInput(const DataType &type, std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)())
Add an input to the end of the argument list.
Result getOrInsertEntryNode(float x, float y, boost::uuids::uuid id=boost::uuids::random_generator()(), NodeInstance **toFill=nullptr)
Creates an entry node if it doesn't already exist, else just return it.
const std::vector< NamedDataType > & dataOutputs() const
Get the function data outputs in the format {type, docstring}.
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
Forward declares all the chigraph data types.
Result removeNode(NodeInstance &nodeToRemove)
Remove a node from the function.
Result createEntryNodeType(std::unique_ptr< NodeType > *toFill) const
Create a fresh NodeType for an entry.
void retypeDataInput(size_t idx, DataType newType)
Change the type of a data input This also updates the entry node and disconnects invalid connections...
const std::vector< std::string > & execInputs() const
Get the function exec inputs.
std::pair< std::string, std::string > parseColonPair(const std::string &in)
Parse a colonated pair Example: lang:i32 would turn into {lang, i32}.
Result insertNode(std::unique_ptr< NodeType > type, float x, float y, boost::uuids::uuid id=boost::uuids::random_generator()(), NodeInstance **toFill=nullptr)
Add a node to the graph.
NamedDataType localVariableFromName(boost::string_view name) const
Get a local varaible by name.
const std::vector< std::string > & execOutputs() const
Get the function exec outputs.
~GraphFunction()=default
Destructor.
void removeDataInput(size_t idx)
Remove an input from the argument list Also removes invalid connections If idx is out of range...
Context & context() const
Get the context.
void retypeLocalVariable(boost::string_view name, DataType newType)
Set a new type to a local variable.
std::string qualifiedName() const
Get the qualified name of the function Same as module().fullName() + ":" + name();.
void removeExecOutput(size_t idx)
Remove an exec output from the argument list If idx is out of range, this function does nothing...
void setDescription(std::string newDesc)
Set the description of the function.
GraphModule & module() const
Get the GraphModule that contains this GraphFunction.
void removeDataOutput(size_t idx)
Remove an data output from the argument list Also removes invalid connections If idx is out of range...
Result createExitNodeType(std::unique_ptr< NodeType > *toFill) const
Create a fresh NodeType for an exit.
std::string name() const
Get the name of the function.
Basicaly a std::pair<std::string, DataType>, except it has nicer names.
const std::unordered_map< boost::uuids::uuid, std::unique_ptr< NodeInstance > > & nodes() const
Get the nodes in the function Usually called by connectData or connectExec or GraphFunction.
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
void removeExecInput(size_t idx)
Remove an exec input from the argument list If idx is out of range, this function does nothing...
void renameExecInput(size_t idx, std::string name)
Change the name for an exec input If idx is out of range, this function does nothing.
NodeInstance * nodeByID(const boost::uuids::uuid &id) const
Get a node with a given ID.
std::vector< NodeInstance * > setName(boost::string_view newName, bool updateReferences=true)
Set the name of the function.
NodeInstance * entryNode() const noexcept
Gets the node with type lang:entry returns nullptr on failure Also returns nullptr if there are two e...
void renameExecOutput(size_t idx, std::string name)
Rename an exec output If idx is out of range, this function does nothing.
std::unordered_map< boost::uuids::uuid, std::unique_ptr< NodeInstance > > & nodes()
Get the nodes in the function Usually called by connectData or connectExec or GraphFunction.
void retypeDataOutput(size_t idx, DataType newType)
Change the type of a data output This also updates all exit nodes and disconnects invalid connections...
void renameLocalVariable(std::string oldName, std::string newName)
Rename a local variable.
bool removeLocalVariable(boost::string_view name)
Remove a local variable from the function by name.
std::vector< NodeInstance * > nodesWithType(const boost::filesystem::path &module, boost::string_view name) const noexcept
Gets the nodes with a given type.
const std::vector< NamedDataType > & localVariables() const
Get the local variables.
Module that holds graph functions.
void renameDataOutput(size_t idx, std::string newName)
Modify an data output (change it's type and docstring)
The namespace where chigraph lives.
void addExecOutput(std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)())
Add an exec output to the end of the argument list.
void addExecInput(std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)())
Add an exec input to the end of the argument list.
A type of data Loose wrapper around llvm::Type*, except it knows which ChiModule it's in and it embed...
const std::vector< NamedDataType > & dataInputs() const
Get the function data inputs in the format {type, docstring}.
llvm::FunctionType * functionType() const
Get the LLVM function type for the function.
The result object, used for identifiying errors with good diagnostics.
NamedDataType getOrCreateLocalVariable(std::string name, DataType type, bool *inserted=nullptr)
Create a new local varaible in the module.
void renameDataInput(size_t idx, std::string newName)
Rename a data input This also updates the entry node If idx is out of range, this function does nothi...
const std::string & description() const
Get the description of the function.