Spicy
Public Member Functions | Static Public Member Functions | List of all members
hilti::Unit Class Reference

#include <unit.h>

Public Member Functions

 ~Unit ()
 
declaration::Modulemodule () const
 
const auto & uid () const
 
void setUID (const declaration::module::UID &uid)
 
Result< Nothingcodegen ()
 
Result< Nothingprint (std::ostream &out) const
 
Result< NothingcreatePrototypes (std::ostream &out)
 
Result< CxxCodecxxCode () const
 
Result< linker::MetaDatalinkerMetaData () const
 
bool isCompiledHILTI () const
 
bool requiresCompilation ()
 
void setRequiresCompilation ()
 
std::shared_ptr< Contextcontext () const
 
const Optionsoptions () const
 

Static Public Member Functions

static Result< std::shared_ptr< Unit > > fromSource (const std::shared_ptr< Context > &context, Builder *builder, const hilti::rt::filesystem::path &path)
 
static Result< std::shared_ptr< Unit > > fromCXX (const std::shared_ptr< Context > &context, std::shared_ptr< detail::cxx::Unit > cxx, const hilti::rt::filesystem::path &path="")
 
static std::shared_ptr< UnitfromExistingUID (const std::shared_ptr< Context > &context, declaration::module::UID uid)
 
static Result< std::shared_ptr< Unit > > link (const std::shared_ptr< Context > &context, const std::vector< linker::MetaData > &mds)
 

Detailed Description

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 the module AST into C++ code. While that's in progress, the unit maintains state about the process, such as a list of dependencies this unit requires.

Constructor & Destructor Documentation

◆ ~Unit()

Unit::~Unit ( )

Destructor.

Member Function Documentation

◆ codegen()

Result< Nothing > Unit::codegen ( )

Triggers generation of C++ code from the compiled AST.

Returns
success if no error occurred, and an appropriate error otherwise

◆ context()

std::shared_ptr<Context> hilti::Unit::context ( ) const
inline

Returns the compiler context in use.

◆ createPrototypes()

Result< Nothing > Unit::createPrototypes ( std::ostream &  out)

Prints out C++ prototypes that host applications can use to interface with the generated C++ code. Must be called only after compile() was successful.

Parameters
outstream to print the code to
Returns
set if successful, or an appropriate error result

◆ cxxCode()

Result< CxxCode > Unit::cxxCode ( ) const

Returns the generated C++ code. Must be called only after compile() was successful.

Returns
code wrapped into the JIT's container class

◆ fromCXX()

Result< std::shared_ptr< Unit > > Unit::fromCXX ( const std::shared_ptr< Context > &  context,
std::shared_ptr< detail::cxx::Unit cxx,
const hilti::rt::filesystem::path &  path = "" 
)
static

Factory method that instantiates a unit from existing C++ source code that's to compiled.

Parameters
contextglobal compiler context
pathpath associated with the C++ code, if any
Returns
instantiated unit, or an appropriate error result if operation failed

◆ fromSource()

Result< std::shared_ptr< Unit > > Unit::fromSource ( const std::shared_ptr< Context > &  context,
Builder builder,
const hilti::rt::filesystem::path &  path 
)
static

Factory method that instantiates a unit from an existing source file that it will parse.

Parameters
contextglobal compiler context
pathpath to parse the module from
Returns
instantiated unit, or an appropriate error result if operation failed

◆ isCompiledHILTI()

bool Unit::isCompiledHILTI ( ) const

Returns true if this unit has HILTI source code available. 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.

◆ link()

Result< std::shared_ptr< Unit > > Unit::link ( const std::shared_ptr< Context > &  context,
const std::vector< linker::MetaData > &  mds 
)
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.

Parameters
contextcompiler context to use
mdsset of meta data from modules to be linked together
Returns
a unit representing additional C++ code that the modules need to function

◆ linkerMetaData()

Result<linker::MetaData> hilti::Unit::linkerMetaData ( ) const
inline

Returns the unit's meta data for the internal HILTI linker.

Returns
meta data, or an error if no code has been compiled yet

◆ module()

declaration::Module * Unit::module ( ) const

Returns the root node of the module's AST. Must only be called if isCompiledHilti() returns true.

◆ options()

const Options& hilti::Unit::options ( ) const
inline

Returns the compiler options in use.

◆ print()

Result< Nothing > Unit::print ( std::ostream &  out) const

Prints out a HILTI module by recreating its code from the internal AST. Must be called only after compile() was successful.

Parameters
outstream to print the code to
Returns
set if successful, or an appropriate error result

◆ requiresCompilation()

bool Unit::requiresCompilation ( )

Returns true if the AST has been determined to contain code that needs to be compiled as its own C++ module, rather than just declaration for other units.

◆ setRequiresCompilation()

void hilti::Unit::setRequiresCompilation ( )
inline

Explicitly marks the unit as requiring compilation down to C++, overriding any automatic determination.

◆ setUID()

void hilti::Unit::setUID ( const declaration::module::UID uid)
inline
  • Sets the unique module ID associated with the unit.

◆ uid()

const auto& hilti::Unit::uid ( ) const
inline

Returns the unique module ID associated with the unit.


The documentation for this class was generated from the following files: