| 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
chi::GraphModule::saveToDisk
Result saveToDisk() const
Serialize to disk in the context.
Definition: GraphModule.cpp:514
chi::GraphFunction
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
Definition: GraphFunction.hpp:23
chi::GraphModule::generateModule
Result generateModule(llvm::Module &module) override
Generate a llvm::Module from the module.
Definition: GraphModule.cpp:435
Fwd.hpp
Forward declares all the chigraph data types.
chi::GraphModule::pathToCSources
boost::filesystem::path pathToCSources() const
Get the path to the .c directory. It is not garunteed to exist, even if cEnabled() is true...
Definition: GraphModule.hpp:150
chi::GraphStruct
A class holding a compound type defined in a GraphModule.
Definition: GraphStruct.hpp:18
chi::GraphModule::createLineNumberAssoc
boost::bimap< unsigned, NodeInstance * > createLineNumberAssoc() const
Create the associations from line number and function in debug info.
Definition: GraphModule.cpp:794
chi::GraphModule::functions
const std::vector< std::unique_ptr< GraphFunction > > & functions() const
Get functions.
Definition: GraphModule.hpp:95
chi::GraphModule::functionFromName
GraphFunction * functionFromName(boost::string_view name) const
Get a function from the name.
Definition: GraphModule.cpp:598
chi::GraphModule::structFromName
GraphStruct * structFromName(boost::string_view name) const
Get a struct by name.
Definition: GraphModule.cpp:817
chi::GraphModule::setCEnabled
void setCEnabled(bool newValue)
Set if C support is enabled.
Definition: GraphModule.hpp:132
chi::GraphModule::removeStruct
bool removeStruct(boost::string_view name)
Remove a struct from the module by name.
Definition: GraphModule.cpp:840
chi::GraphModule::getOrCreateFunction
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.
Definition: GraphModule.cpp:545
chi::ChiModule::fullName
std::string fullName() const
Get the full name of the module.
Definition: ChiModule.hpp:61
chi::Context
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
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::GraphModule::sourceFilePath
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...
Definition: GraphModule.cpp:862
chi::GraphModule::cEnabled
bool cEnabled() const
Gets if C support is enabled.
Definition: GraphModule.hpp:136
chi::GraphModule::nodeTypeNames
std::vector< std::string > nodeTypeNames() const override
Get the possible node type names.
Definition: GraphModule.cpp:779
chi::GraphModule::getOrCreateStruct
GraphStruct * getOrCreateStruct(std::string name, bool *inserted=nullptr)
Create a new struct in the module.
Definition: GraphModule.cpp:824
chi::ChiModule::dependencies
const std::set< boost::filesystem::path > & dependencies() const
Get the dependencies.
Definition: ChiModule.hpp:83
chi::GraphModule::addForwardDeclarations
Result addForwardDeclarations(llvm::Module &module) const override
Adds forward declartions for the functions in this module.
Definition: GraphModule.cpp:425
chi::GraphModule::typeNames
std::vector< std::string > typeNames() const override
Get the possible DataType names.
Definition: GraphModule.cpp:416
chi::GraphModule::nodeTypeFromName
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.
Definition: GraphModule.cpp:606
chi::GraphModule::GraphModule
GraphModule(Context &cont, boost::filesystem::path fullName, const std::vector< boost::filesystem::path > &dependencies={})
Construct a GraphModule.
Definition: GraphModule.cpp:409
ChiModule.hpp
Defines the ChiModule class.
chi::GraphModule::typeFromName
DataType typeFromName(boost::string_view name) override
Get a DataType from the name.
Definition: GraphModule.cpp:771
chi::GraphModule
Module that holds graph functions.
Definition: GraphModule.hpp:16
chi
The namespace where chigraph lives.
Definition: BitcodeParser.hpp:12
chi::DataType
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
chi::ChiModule::shortName
std::string shortName() const
Get the short name of the module (the last bit)
Definition: ChiModule.hpp:58
chi::Result
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
chi::GraphModule::createNodeTypeFromCCode
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.
Definition: GraphModule.cpp:866
chi::GraphModule::removeFunction
bool removeFunction(boost::string_view name, bool deleteReferences=true)
Remove a function from the module.
Definition: GraphModule.cpp:568