4 #ifndef CHI_CONTEXT_HPP 5 #define CHI_CONTEXT_HPP 10 #include <unordered_map> 15 #include "chi/Support/json.hpp" 17 #include <llvm/IR/LLVMContext.h> 18 #include <llvm/Support/CodeGen.h> 20 #include <boost/filesystem/path.hpp> 21 #include <boost/utility/string_view.hpp> 58 Context(
const boost::filesystem::path& workPath = {});
71 ChiModule* moduleByFullName(
const boost::filesystem::path& fullModuleName)
const noexcept;
76 GraphModule* newGraphModule(
const boost::filesystem::path& fullName);
81 std::vector<std::string> listModulesInWorkspace()
const noexcept;
89 Result loadModule(
const boost::filesystem::path& name,
ChiModule** toFill =
nullptr);
96 Result addModuleFromJson(
const boost::filesystem::path& fullName,
const nlohmann::json& json,
102 bool addModule(std::unique_ptr<ChiModule> modToAdd) noexcept;
107 bool unloadModule(
const boost::filesystem::path& fullName);
115 Result typeFromModule(
const boost::filesystem::path& module, boost::string_view name,
126 Result nodeTypeFromModule(
const boost::filesystem::path& moduleName,
127 boost::string_view typeName,
const nlohmann::json& data,
128 std::unique_ptr<NodeType>* toFill) noexcept;
134 std::unique_ptr<NodeType> createConverterNodeType(
const DataType& fromType,
const DataType& toType);
141 bool hasWorkspace() const noexcept {
return !workspacePath().empty(); }
152 std::unique_ptr<llvm::Module>* toFill);
162 std::unique_ptr<llvm::Module>* toFill);
168 std::vector<NodeInstance*> findInstancesOfType(
const boost::filesystem::path& moduleName,
169 boost::string_view typeName)
const;
182 std::vector<ChiModule*> ret;
184 for (
const auto& mod : mModules) { ret.push_back(mod.get()); }
199 void setModuleCache(std::unique_ptr<ModuleCache> newCache);
202 boost::filesystem::path mWorkspacePath;
204 llvm::LLVMContext mLLVMContext;
206 std::vector<std::unique_ptr<ChiModule>> mModules;
209 std::unordered_map<std::string , llvm::Module* >
214 std::unique_ptr<ModuleCache> mModuleCache;
216 std::unordered_map<std::string , std::unordered_map<std::string , std::unique_ptr<NodeType>>> mTypeConverters;
240 llvm::CodeGenOpt::Level optLevel = llvm::CodeGenOpt::Default,
241 const std::vector<llvm::GenericValue>& args = {},
242 llvm::Function* funcToRun =
nullptr, llvm::GenericValue* ret =
nullptr);
252 llvm::CodeGenOpt::Level optLevel = llvm::CodeGenOpt::Default,
253 const std::vector<std::string>& args = {},
254 llvm::Function* funcToRun =
nullptr,
int* ret =
nullptr);
257 #endif // CHI_CONTEXT_HPP LangModule * langModule() const
Get the LangModule, if it has been loaded.
Forward declares all the chigraph data types.
The module that provides built-in operations like literals, math operations, etc. ...
boost::filesystem::path workspacePath() const
Get the workspace path of the Context.
std::vector< ChiModule * > modules() const
Get the modules in the Context.
CompileSettings
Settings for compiling modules.
boost::filesystem::path workspaceFromChildPath(const boost::filesystem::path &path)
Get the workspace directory from a child of the workspace directory Example: say you have a workspace...
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Result interpretLLVMIRAsMain(std::unique_ptr< llvm::Module > mod, llvm::CodeGenOpt::Level optLevel=llvm::CodeGenOpt::Default, const std::vector< std::string > &args={}, llvm::Function *funcToRun=nullptr, int *ret=nullptr)
Interpret LLVM IR as if it were the main function.
ModuleCache & moduleCache()
Get the module cache.
Result interpretLLVMIR(std::unique_ptr< llvm::Module > mod, llvm::CodeGenOpt::Level optLevel=llvm::CodeGenOpt::Default, const std::vector< llvm::GenericValue > &args={}, llvm::Function *funcToRun=nullptr, llvm::GenericValue *ret=nullptr)
Interpret LLVM IR, just a convenience function.
A template class for type-safe flags.
llvm::LLVMContext & llvmContext()
Get the LLVMContext
const ModuleCache & moduleCache() const
Get the module cache.
This class provides an interface for creating module caches.
Module that holds graph functions.
bool hasWorkspace() const noexcept
Check if this context has a workspace bound to it – same as !workspacePath().empty() ...
The namespace where chigraph lives.
std::string stringifyLLVMType(llvm::Type *ty)
Turns a type into a string.
A type of data Loose wrapper around llvm::Type*, except it knows which ChiModule it's in and it embed...
Link in dependencies If this is set, it will be a ready to run module If not, it'll contain forward d...
The result object, used for identifiying errors with good diagnostics.