chigraph  master
Systems programming language written for beginners in LLVM
GraphModule.hpp
Go to the documentation of this file.
1 
4 #ifndef CHI_GRAPH_MODULE_HPP
5 #define CHI_GRAPH_MODULE_HPP
6 
7 #pragma once
8 
9 #include <chi/ChiModule.hpp>
10 #include <chi/Fwd.hpp>
11 
12 #include <boost/bimap.hpp>
13 
14 namespace chi {
16 struct GraphModule : public ChiModule {
21  GraphModule(Context& cont, boost::filesystem::path fullName,
22  const std::vector<boost::filesystem::path>& dependencies = {});
23 
24  // No copy or move -- pointer only
25  GraphModule(const GraphModule&) = delete;
26  GraphModule(GraphModule&&) = delete;
27  GraphModule& operator=(const GraphModule&) = delete;
28  GraphModule& operator=(GraphModule&&) = delete;
29 
30  // ChiModule interface
32 
33  Result nodeTypeFromName(boost::string_view name, const nlohmann::json& jsonData,
34  std::unique_ptr<NodeType>* toFill) override;
35 
36  DataType typeFromName(boost::string_view name) override;
37  std::vector<std::string> nodeTypeNames() const override;
38 
39  std::vector<std::string> typeNames() const override;
40 
41  Result addForwardDeclarations(llvm::Module& module) const override;
42 
43  Result generateModule(llvm::Module& module) override;
44 
46 
49  boost::bimap<unsigned, NodeInstance*> createLineNumberAssoc() const;
50 
53  Result saveToDisk() const;
54 
58  boost::filesystem::path sourceFilePath() const;
59 
62 
72  GraphFunction* getOrCreateFunction(std::string name, std::vector<NamedDataType> dataIns,
73  std::vector<NamedDataType> dataOuts,
74  std::vector<std::string> execIns,
75  std::vector<std::string> execOuts, bool* inserted = nullptr);
76 
81  bool removeFunction(boost::string_view name, bool deleteReferences = true);
82 
86  void removeFunction(GraphFunction& func, bool deleteReferences = true);
87 
91  GraphFunction* functionFromName(boost::string_view name) const;
92 
95  const std::vector<std::unique_ptr<GraphFunction>>& functions() const { return mFunctions; }
96 
98 
101 
102  const std::vector<std::unique_ptr<GraphStruct>>& structs() const { return mStructs; }
103 
107  GraphStruct* structFromName(boost::string_view name) const;
108 
113  GraphStruct* getOrCreateStruct(std::string name, bool* inserted = nullptr);
114 
118  bool removeStruct(boost::string_view name);
119 
123  void removeStruct(GraphStruct& tyToDel);
124 
126 
129 
132  void setCEnabled(bool newValue) { mCEnabled = newValue; }
133 
136  bool cEnabled() const { return mCEnabled; }
137 
145  Result createNodeTypeFromCCode(boost::string_view code, boost::string_view functionName,
146  std::vector<std::string> clangArgs,
147  std::unique_ptr<NodeType>* toFill);
148 
150  boost::filesystem::path pathToCSources() const {
151  return sourceFilePath().parent_path() / (shortName() + ".c");
152  }
153 
155 
156 private:
157  std::vector<std::unique_ptr<GraphFunction>> mFunctions;
158  std::vector<std::unique_ptr<GraphStruct>> mStructs;
159 
160  bool mCEnabled = false;
161 };
162 } // namespace chi
163 
164 #endif // CHI_GRAPH_MODULE_HPP
Result saveToDisk() const
Serialize to disk in the context.
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
Result generateModule(llvm::Module &module) override
Generate a llvm::Module from the module.
Forward declares all the chigraph data types.
boost::filesystem::path pathToCSources() const
Get the path to the .c directory. It is not garunteed to exist, even if cEnabled() is true...
A class holding a compound type defined in a GraphModule.
Definition: GraphStruct.hpp:18
boost::bimap< unsigned, NodeInstance * > createLineNumberAssoc() const
Create the associations from line number and function in debug info.
const std::vector< std::unique_ptr< GraphFunction > > & functions() const
Get functions.
Definition: GraphModule.hpp:95
GraphFunction * functionFromName(boost::string_view name) const
Get a function from the name.
GraphStruct * structFromName(boost::string_view name) const
Get a struct by name.
void setCEnabled(bool newValue)
Set if C support is enabled.
bool removeStruct(boost::string_view name)
Remove a struct from the module by name.
GraphFunction * getOrCreateFunction(std::string name, std::vector< NamedDataType > dataIns, std::vector< NamedDataType > dataOuts, std::vector< std::string > execIns, std::vector< std::string > execOuts, bool *inserted=nullptr)
Create a new function if it does&#39;t already exist.
std::string fullName() const
Get the full name of the module.
Definition: ChiModule.hpp:61
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
boost::filesystem::path sourceFilePath() const
Get the path to the source file It&#39;s not garunteed to exist, because it could have not been saved...
bool cEnabled() const
Gets if C support is enabled.
std::vector< std::string > nodeTypeNames() const override
Get the possible node type names.
GraphStruct * getOrCreateStruct(std::string name, bool *inserted=nullptr)
Create a new struct in the module.
const std::set< boost::filesystem::path > & dependencies() const
Get the dependencies.
Definition: ChiModule.hpp:83
Result addForwardDeclarations(llvm::Module &module) const override
Adds forward declartions for the functions in this module.
std::vector< std::string > typeNames() const override
Get the possible DataType names.
Result nodeTypeFromName(boost::string_view name, const nlohmann::json &jsonData, std::unique_ptr< NodeType > *toFill) override
Create a node type that is in the module from the name and json.
GraphModule(Context &cont, boost::filesystem::path fullName, const std::vector< boost::filesystem::path > &dependencies={})
Construct a GraphModule.
Defines the ChiModule class.
DataType typeFromName(boost::string_view name) override
Get a DataType from the name.
Module that holds graph functions.
Definition: GraphModule.hpp:16
The namespace where chigraph lives.
A type of data Loose wrapper around llvm::Type*, except it knows which ChiModule it&#39;s in and it embed...
Definition: DataType.hpp:17
std::string shortName() const
Get the short name of the module (the last bit)
Definition: ChiModule.hpp:58
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
Result createNodeTypeFromCCode(boost::string_view code, boost::string_view functionName, std::vector< std::string > clangArgs, std::unique_ptr< NodeType > *toFill)
From C code, create a NodeType.
bool removeFunction(boost::string_view name, bool deleteReferences=true)
Remove a function from the module.