![]() |
Spicy
|
#include <unit.h>
Public Member Functions | |
NodeRef | module () |
auto | id () const |
auto | path () const |
Result< Nothing > | compile () |
Result< Nothing > | codegen () |
Result< Nothing > | print (std::ostream &out) const |
Result< Nothing > | createPrototypes (std::ostream &out) |
Result< CxxCode > | cxxCode () const |
Result< context::ModuleIndex > | import (const ID &id, const hilti::rt::filesystem::path &ext, std::optional< ID > scope={}, std::vector< hilti::rt::filesystem::path > search_dirs={}) |
Result< context::ModuleIndex > | import (const hilti::rt::filesystem::path &path) |
Node & | imported (const ID &id) const |
std::set< context::ModuleIndex > | allImported (bool code_only=false) const |
Result< bool > | requiresCompilation (const ID &id) |
Result< linker::MetaData > | linkerMetaData () const |
bool | isCompiledHILTI () const |
std::shared_ptr< Context > | context () const |
const Options & | options () const |
Static Public Member Functions | |
static Result< Unit > | fromModule (const std::shared_ptr< Context > &context, hilti::Module &&module, const hilti::rt::filesystem::path &path="") |
static Result< Unit > | fromSource (const std::shared_ptr< Context > &context, const hilti::rt::filesystem::path &path) |
static Result< Unit > | fromCache (const std::shared_ptr< Context > &context, const hilti::ID &id) |
static Result< Unit > | fromCache (const std::shared_ptr< Context > &context, const hilti::rt::filesystem::path &path) |
static Result< Unit > | fromCXX (std::shared_ptr< Context > context, detail::cxx::Unit cxx, const hilti::rt::filesystem::path &path="") |
static Result< Unit > | link (const std::shared_ptr< Context > &context, const std::vector< linker::MetaData > &mds) |
static std::pair< bool, std::optional< linker::MetaData > > | readLinkerMetaData (std::istream &input, const hilti::rt::filesystem::path &path="<input stream>") |
Container for a single HILTI code module. For each HILTI source file, one compiler unit gets instantiated. That unit then drives the process to compile module comp into C++ code. While that's in progress, the unit maintains state about the process, such as a cache of all external modules imported by the one that's being compiled.
std::set< context::ModuleIndex > Unit::allImported | ( | bool | code_only = false | ) | const |
Returns set of all imported modules so far.
code_only | if true include only dependencies that require independent compilation themselves |
Compiles the unit's module AST into its final internal representation.
|
inline |
Returns the compiler context in use.
Prints out C++ prototypes that host applications can use to interface with the generated C++ code. Must be called only after compile()
was successful.
out | stream to print the code to |
|
static |
Factory method that instantiates a unit from an existing HILTI module already cached by the global context.
context | global compiler context |
id | ID of the cached module |
|
static |
Factory method that instantiates a unit from an existing HILTI module already cached by the global context.
context | global compiler context |
path | path of the cached module |
|
static |
Factory method that instantiates a unit from existing C++ source code that's to compiled.
context | global compiler context |
path | path associated with the C++ code, if any |
|
static |
Factory method that instantiates a unit from an existing HILTI module that's be compiled.
This method also caches the module with the global context. Note that the module's ID or path must not exist with the context yet.
context | global compiler context |
module | HILTI module to compile, of which the unit will take ownership |
path | path associated with the module, if any |
|
static |
Factory method that instantiates a unit from an existing source file that it will parse.
This method also caches the module with the global context. Note that the module's ID or path must not exist with the context yet.
context | global compiler context |
path | path to parse the module from |
|
inline |
Returns the ID of the unit's top-level module (i.e., the one being compiled).
Result< ModuleIndex > Unit::import | ( | const ID & | id, |
const hilti::rt::filesystem::path & | ext, | ||
std::optional< ID > | scope = {} , |
||
std::vector< hilti::rt::filesystem::path > | search_dirs = {} |
||
) |
Makes an external HILTI module available to the one this unit is compiling. Essentially, this implements the HITLI's import
statement. Importing another module means that the compiled module will know how to access the other one's functionality. However, that external module will still need to be compiled itself as well; and then all the compiled modules need to be linked together.
This version of the import
method imports by module ID: it searches Configuration::hilti_library_paths
for a file with a corresponding name and extension.
id | ID of module to import |
ext | file name extension to search; .hlt is HILTI's standard extension, but plugins can add support for other extensions as well |
scope | if given, qualifies the ID with a path prefix to find the module (e.g., a scope of a.b.c will search the module in <search path>/a/b/c/<name> .) |
dirs | additional directories to search first |
Result< ModuleIndex > Unit::import | ( | const hilti::rt::filesystem::path & | path | ) |
Makes an external HILTI module available to the one this unit is compiling. See import(const ID, const hilti::rt::filesystem::path)
for more details on importing.
This version of the import
method imports directly from a given file.
path | to the file to import |
Returns the AST for an imported module.
id | module ID |
<tt>std::out_of_range</tt> | if no module of that name has been imported yet |
|
inline |
Returns true if this unit has been compiled from HILTI source. This is usually the case, but we also represent HILTI's linker output as a unit and there's no corresponding HILTI source code for that.
|
static |
Entry point for the HILTI linker, The linker combines meta data from several compiled HILTI modules and creates an additional unit from it, with its C++ code representing logic the HILTI runtime library will draw upon.
context | compiler context to use |
mds | set of meta data from modules to be linked together |
|
inline |
Returns the unit's meta data for the internal HILTI linker.
|
inline |
Returns the root node of the module AST's.
|
inline |
Returns the compiler options in use.
|
inline |
Returns the path associated with the unit's top-level module (i.e., the one being compiled).
Prints out a HILTI module by recreating its code from the internal AST. Must be called only after compile()
was successful.
out | stream to print the code to |
|
static |
Reads linker meta from a file. This expects the file to contain linker meta somewhere inside a appropriately marked block bracketed by C-style comments. When printing the generated C++ code for a compiled HILTI module, it will include that block. In other words, you can just save the C++ and reread the meta data with this method.
input | stream to read from |
path | file associated with the stream, for logging and error reporting |
Returns true if an imported module provides code that needs independent compilation to resolve references at link-time.