![]() |
chigraph
master
Systems programming language written for beginners in LLVM
|
The class that handles the loading, creation, storing, and compilation of modules It also stores a LLVMContext
object to be used everywhere.
More...
#include <chi/Context.hpp>
Public Member Functions | |
Context (const boost::filesystem::path &workPath={}) | |
Creates a context with just the lang module. More... | |
Context (const Context &context)=delete | |
Context (Context &&)=delete | |
~Context () | |
Destructor. | |
bool | addModule (std::unique_ptr< ChiModule > modToAdd) noexcept |
Adds a custom module to the Context. More... | |
Result | addModuleFromJson (const boost::filesystem::path &fullName, const nlohmann::json &json, GraphModule **toFill=nullptr) |
Load a module from JSON – avoid this use the string overload. More... | |
Result | compileModule (const boost::filesystem::path &fullName, Flags< CompileSettings > settings, std::unique_ptr< llvm::Module > *toFill) |
Compile a module to a llvm::Module . More... | |
Result | compileModule (ChiModule &mod, Flags< CompileSettings > settings, std::unique_ptr< llvm::Module > *toFill) |
Compile a module to a llvm::Module . More... | |
std::unique_ptr< NodeType > | createConverterNodeType (const DataType &fromType, const DataType &toType) |
Create a converter node. More... | |
std::vector< NodeInstance * > | findInstancesOfType (const boost::filesystem::path &moduleName, boost::string_view typeName) const |
Find all uses of a node type in all the loaded modules. More... | |
bool | hasWorkspace () const noexcept |
Check if this context has a workspace bound to it – same as !workspacePath().empty() More... | |
LangModule * | langModule () const |
Get the LangModule , if it has been loaded. More... | |
std::vector< std::string > | listModulesInWorkspace () const noexcept |
Get the list of modules in the workspace. More... | |
llvm::LLVMContext & | llvmContext () |
Get the LLVMContext More... | |
Result | loadModule (const boost::filesystem::path &name, ChiModule **toFill=nullptr) |
Load a module from disk, also loads dependencies. More... | |
ChiModule * | moduleByFullName (const boost::filesystem::path &fullModuleName) const noexcept |
Gets the module by the full name. More... | |
const ModuleCache & | moduleCache () const |
Get the module cache. More... | |
ModuleCache & | moduleCache () |
Get the module cache. More... | |
std::vector< ChiModule * > | modules () const |
Get the modules in the Context. More... | |
GraphModule * | newGraphModule (const boost::filesystem::path &fullName) |
Create a new GraphModule with the given full name. More... | |
Result | nodeTypeFromModule (const boost::filesystem::path &moduleName, boost::string_view typeName, const nlohmann::json &data, std::unique_ptr< NodeType > *toFill) noexcept |
Gets a NodeType from the JSON and name. More... | |
void | setModuleCache (std::unique_ptr< ModuleCache > newCache) |
Set the module cache. More... | |
Result | typeFromModule (const boost::filesystem::path &module, boost::string_view name, DataType *toFill) noexcept |
Gets a DataType from a module. More... | |
bool | unloadModule (const boost::filesystem::path &fullName) |
Unloads a module. More... | |
boost::filesystem::path | workspacePath () const |
Get the workspace path of the Context. More... | |
The class that handles the loading, creation, storing, and compilation of modules It also stores a LLVMContext
object to be used everywhere.
It stores all the modules and allows for compilation of them. Basic use looks like this:
Definition at line 55 of file Context.hpp.
chi::Context::Context | ( | const boost::filesystem::path & | workPath = {} | ) |
Creates a context with just the lang module.
workPath | Path to the workspace, or a subdirectory of the workspace |
Definition at line 40 of file Context.cpp.
References chi::workspaceFromChildPath(), and ~Context().
|
noexcept |
Adds a custom module to the Context.
modToAdd | The module to add. The context will take excluseive ownership of it. |
Definition at line 185 of file Context.cpp.
References moduleByFullName(), and chi::LangModule::nodeTypeFromName().
Referenced by loadModule(), and newGraphModule().
Result chi::Context::addModuleFromJson | ( | const boost::filesystem::path & | fullName, |
const nlohmann::json & | json, | ||
GraphModule ** | toFill = nullptr |
||
) |
Load a module from JSON – avoid this use the string overload.
[in] | fullName | The full path of the module, including URL |
[in] | json | The JSON data |
[out] | toFill | The GraphModule* to fill into, optional |
Definition at line 156 of file Context.cpp.
References chi::Result::addScopedContext(), chi::ChiModule::fullName(), chi::jsonToGraphModule(), moduleByFullName(), and unloadModule().
Referenced by loadModule().
Result chi::Context::compileModule | ( | const boost::filesystem::path & | fullName, |
Flags< CompileSettings > | settings, | ||
std::unique_ptr< llvm::Module > * | toFill | ||
) |
Compile a module to a llvm::Module
.
[in] | fullName | The full name of the module to compile. If moduleByFullName(fullName) == nullptr , this function has no side-effects |
[in] | settings | The settings. See CompileSettings for more info |
[out] | toFill | The llvm::Module to fill – this can be nullptr it will be replaced |
Result
Definition at line 284 of file Context.cpp.
References chi::Result::addEntry(), and moduleByFullName().
Referenced by compileModule(), and chi::Debugger::start().
Result chi::Context::compileModule | ( | ChiModule & | mod, |
Flags< CompileSettings > | settings, | ||
std::unique_ptr< llvm::Module > * | toFill | ||
) |
Compile a module to a llvm::Module
.
[in] | mod | The module to compile |
[in] | settings | The settings. See CompileSettings for more details |
[out] | toFill | The llvm::Module to fill – this can be nullptr it will be replaced |
toFill != nullptr
(the value the unique_ptr
points to be can be null, but not the pointer to the unique_ptr
) Result
Definition at line 298 of file Context.cpp.
References chi::Result::addEntry(), chi::Result::addScopedContext(), chi::ModuleCache::cacheModule(), compileModule(), chi::ChiModule::dependencies(), chi::executablePath(), chi::ChiModule::fullName(), chi::ChiModule::fullNamePath(), chi::ChiModule::generateModule(), chi::ChiModule::lastEditTime(), chi::LinkDependencies, llvmContext(), moduleByFullName(), moduleCache(), chi::parseBitcodeFile(), chi::ModuleCache::retrieveFromCache(), chi::ChiModule::shortName(), and chi::UseCache.
std::unique_ptr< NodeType > chi::Context::createConverterNodeType | ( | const DataType & | fromType, |
const DataType & | toType | ||
) |
Create a converter node.
[in] | fromType | The type to convert from |
[in] | toType | The type to convert to |
Definition at line 269 of file Context.cpp.
References chi::DataType::qualifiedName().
std::vector< NodeInstance * > chi::Context::findInstancesOfType | ( | const boost::filesystem::path & | moduleName, |
boost::string_view | typeName | ||
) | const |
Find all uses of a node type in all the loaded modules.
moduleName | The name of the module that the type being search for is in |
typeName | The name of the type in module to search for |
NodeInstance
s that are of that type Definition at line 444 of file Context.cpp.
Referenced by chi::GraphStruct::dataType(), chi::GraphModule::removeFunction(), chi::GraphStruct::setName(), and chi::GraphFunction::setName().
|
inlinenoexcept |
Check if this context has a workspace bound to it – same as !workspacePath().empty()
Definition at line 141 of file Context.hpp.
|
inline |
Get the LangModule
, if it has been loaded.
LangModule
Definition at line 177 of file Context.hpp.
Referenced by chi::FunctionCompiler::createSubroutineType(), and loadModule().
|
noexcept |
Get the list of modules in the workspace.
Definition at line 68 of file Context.cpp.
References workspacePath().
|
inline |
Get the LLVMContext
LLVMContext
Definition at line 173 of file Context.hpp.
Referenced by compileModule(), chi::GraphStruct::dataType(), chi::LangModule::LangModule(), and chi::LangModule::typeFromName().
Result chi::Context::loadModule | ( | const boost::filesystem::path & | name, |
ChiModule ** | toFill = nullptr |
||
) |
Load a module from disk, also loads dependencies.
[in] | name | The name of the moudle |
!name.empty()
to fetch all dependencies as well. Leave as default to only use local modules. [out] | toFill | The module that was loaded, optional |
Definition at line 91 of file Context.cpp.
References addModule(), addModuleFromJson(), chi::Result::addScopedContext(), langModule(), moduleByFullName(), chi::ChiModule::updateLastEditTime(), and workspacePath().
Referenced by chi::ChiModule::addDependency().
|
noexcept |
Gets the module by the full name.
fullModuleName | The name of the module to find |
fullModuleName
, nullptr if none were found Definition at line 48 of file Context.cpp.
Referenced by addModule(), addModuleFromJson(), compileModule(), loadModule(), chi::Debugger::nodeFromFrame(), nodeTypeFromModule(), and typeFromModule().
|
inline |
Get the module cache.
Definition at line 191 of file Context.hpp.
Referenced by compileModule().
|
inline |
Get the module cache.
Definition at line 194 of file Context.hpp.
References chi::interpretLLVMIR(), chi::interpretLLVMIRAsMain(), chi::stringifyLLVMType(), and chi::workspaceFromChildPath().
|
inline |
GraphModule * chi::Context::newGraphModule | ( | const boost::filesystem::path & | fullName | ) |
Create a new GraphModule with the given full name.
fullName | The new name |
Definition at line 55 of file Context.cpp.
References addModule().
Referenced by chi::jsonToGraphModule().
|
noexcept |
Gets a NodeType from the JSON and name.
[in] | moduleName | The full module name. |
[in] | typeName | The name of the node type |
[in] | data | The JSON data that is used to construct the NodeType. |
[out] | toFill | The point to fill |
toFill != nullptr
(the value the unique_ptr
points to be can be null, but not the pointer to the unique_ptr
) Definition at line 253 of file Context.cpp.
References chi::Result::addEntry(), and moduleByFullName().
Referenced by chi::GraphFunction::createEntryNodeType(), chi::GraphFunction::createExitNodeType(), chi::GraphFunction::insertNode(), chi::jsonToGraphFunction(), and chi::GraphFunction::setName().
void chi::Context::setModuleCache | ( | std::unique_ptr< ModuleCache > | newCache | ) |
Set the module cache.
newCache | The new module cache |
newCache != nullptr
Definition at line 599 of file Context.cpp.
|
noexcept |
Gets a DataType from a module.
[in] | module | The full name of the module |
[in] | name | The name of the type, required |
[out] | toFill | The type to fill |
toFill != nullptr
Definition at line 232 of file Context.cpp.
References chi::Result::addEntry(), moduleByFullName(), and chi::ChiModule::typeFromName().
Referenced by chi::createGraphFunctionDeclarationFromJson(), chi::GraphModule::createNodeTypeFromCCode(), chi::jsonToGraphFunction(), chi::jsonToGraphStruct(), chi::LangModule::LangModule(), and chi::GraphModule::nodeTypeFromName().
bool chi::Context::unloadModule | ( | const boost::filesystem::path & | fullName | ) |
Unloads a module.
fullName | The full name of the module to unload |
Definition at line 219 of file Context.cpp.
Referenced by addModuleFromJson().
|
inline |
Get the workspace path of the Context.
Definition at line 138 of file Context.hpp.
Referenced by chi::DefaultModuleCache::cachePathForModule(), chi::jsonToGraphModule(), listModulesInWorkspace(), loadModule(), and chi::GraphModule::sourceFilePath().