![]() |
Spicy
|
#include <driver.h>
Public Member Functions | |
Driver (std::string name) | |
Driver (std::string name, const hilti::rt::filesystem::path &argv0) | |
Driver (const Driver &)=delete | |
Driver (Driver &&) noexcept=delete | |
Driver & | operator= (const Driver &)=delete |
Driver & | operator= (Driver &&) noexcept=delete |
Result< Nothing > | parseOptions (int argc, char **argv) |
Result< Nothing > | addInput (hilti::Module &&m, const hilti::rt::filesystem::path &path="") |
Result< Nothing > | addInput (const hilti::rt::filesystem::path &path) |
bool | hasInputs () const |
const auto & | driverOptions () const |
const auto & | hiltiOptions () const |
void | setDriverOptions (driver::Options options) |
void | setCompilerOptions (hilti::Options options) |
Result< Nothing > | initialize () |
Result< Nothing > | compile () |
Result< Nothing > | transformUnits () |
auto | context () const |
Result< Nothing > | initRuntime () |
Result< Nothing > | executeMain () |
Result< Nothing > | finishRuntime () |
Result< Nothing > | run () |
Protected Member Functions | |
void | usage () |
Result< Nothing > | compileUnits () |
Result< Nothing > | codegenUnits () |
Result< Nothing > | linkUnits () |
Result< Nothing > | outputUnits () |
Result< Nothing > | jitUnits () |
result::Error | error (std::string_view msg, const hilti::rt::filesystem::path &p="") |
result::Error | augmentError (const result::Error &err, const hilti::rt::filesystem::path &p="") |
Result< std::ofstream > | openOutput (const hilti::rt::filesystem::path &p, bool binary=false, bool append=false) |
Result< Nothing > | openInput (std::ifstream &in, const hilti::rt::filesystem::path &p) |
Result< Nothing > | writeOutput (std::ifstream &in, const hilti::rt::filesystem::path &p) |
Result< std::stringstream > | readInput (const hilti::rt::filesystem::path &p) |
Result< hilti::rt::filesystem::path > | writeToTemp (std::ifstream &in, const std::string &name_hint, const std::string &extension="tmp") |
void | dumpUnit (const Unit &unit) |
void | printHiltiException (const hilti::rt::Exception &e) |
virtual std::string | hookAddCommandLineOptions () |
virtual bool | hookProcessCommandLineOption (char opt, const char *optarg) |
virtual std::string | hookAugmentUsage () |
virtual void | hookAddInput (const hilti::rt::filesystem::path &path) |
virtual void | hookAddInput (const hilti::Module &m, const hilti::rt::filesystem::path &path) |
virtual void | hookNewASTPreCompilation (const ID &name, const std::optional< hilti::rt::filesystem::path > &path, const Node &root) |
virtual void | hookNewASTPostCompilation (const ID &name, const std::optional< hilti::rt::filesystem::path > &path, const Node &root) |
virtual Result< Nothing > | hookCompilationFinished () |
virtual void | hookInitRuntime () |
virtual void | hookFinishRuntime () |
Compiler driver.
The driver is a high-level building block for writing command-line tools compiling HILTI source files (and more). hiltic
is just a tiny wrapper around this class.
Classes can drive from the driver to expand its functionality, including for adding support for additional types of source files (e.g., Spicy code).
|
explicit |
name | descriptive name for the tool using the driver, which will be used in usage and error messages. |
Driver::Driver | ( | std::string | name, |
const hilti::rt::filesystem::path & | argv0 | ||
) |
name | descriptive name for the tool using the driver, which will be used in usage and error messages. |
argv0 | the current exectuable, which will change the path's that the global options instance returns if it's inside HILTI build directory. |
Result< Nothing > Driver::addInput | ( | hilti::Module && | m, |
const hilti::rt::filesystem::path & | path = "" |
||
) |
Schedules a HILTI module for compilation. The unit will take ownership and compile the module once compile()
is called. If module of the same ID or path has been added previously, this will have no effect.
hookNewASTPreCompilation()
hook will be called immediately for the new module.
m | HILTI module to schedule for compilation |
path | path associated with the module, if any |
Schedules a HILTI source file for compilation. The file will be parsed immediately, and then compiled later when compile()
is called. If the same file/module has been added previously, this method will have no effect.
hookNewASTPreCompilation()
hook will be called immediately for the new module after it has been parsed.
input | source of HILTI module to compile |
|
protected |
Helper function to augment an result::Error
with a message that includig driver name and, optionally, a file the error refers to.
msg | error message |
p | file to associate with the error, empty for none |
Compiles all registered input files to C++ code.
This function can only be invoked after compileUnits
.
Loads, compiles, and links the source files. This must be called only after driver and compiler options have been set. Internally, it chains the various *Modules()
methods.
Compiles all registered input files to HILTI code.
|
inline |
Returns the current HILTI context. Valid only once compilation has started, otherwise null.
|
inline |
Returns the driver options currently in effect.
|
protected |
Save a unit's final HILTI and C++ code to disk for debugging.
|
protected |
Helper function to create an result::Error
with a message that including driver name and, optionally, a file the error refers to.
msg | error message |
p | file to associate with the error, empty for none |
Executes the hilti_main
entry function in compiled code. This must be called only after initRuntime()
has run already.
Shuts down HILT's runtime library after execution has concluded, cleaning up resources.
|
inline |
Returns true if at least one input file has been added.
|
inline |
Returns the HILTI compiler options currently in effect.
|
inlineprotectedvirtual |
Hook for derived classes to add more options to the getopt() option string.
Reimplemented in spicy::Driver.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when a new source path is being added as an input file.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when a new AST module is being added as an input file.
|
inlineprotectedvirtual |
Hook for derived classes for adding content to the driver's usage message (--help
).
Reimplemented in spicy::Driver.
Hook for derived classes to execute custom code when all input files have been compiled to HILTI & Spicy code (but not yet linked). If the hook return an error that will abort all further processing. The hook may add further inputs files through the add()
methods, which will then be compiled next. If so, this hook will execute again once all new inputs have likewise been compiled.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code just before the HILTI runtime is being shut down.
Reimplemented in Spicyc.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when the HILTI runtime has been initialized.
Reimplemented in Spicyc.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when a HILTI AST has been finalized. This hook will run after the AST has been compiled (and hence it'll be fully processed).
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when an HILTI AST has been loaded. This hook will run before the AST has been compiled (and hence it'll be fully unprocessed).
|
inlineprotectedvirtual |
Hook for derived classes for parsing additional options.
Reimplemented in spicy::Driver.
Initializes the compilation process. Must be called after options have been set, and before any inputs are added.
Initializes HILTI's runtime system to prepare for execution of compiled code. This will already trigger execution of all module-specific initialization code (initialization of globals; module-level statements). The method must be called only after compile()
has run already.
JIT all code compiled so far.
Runs the HILTI-side linker on all available C++ code.
|
protected |
Helper function to open a file for reading.
in | input stream to open with file with |
p | input file |
|
protected |
Helper function to open a file for writing.
p | output file |
binary | true to open in binary mode |
append | true to append to existing file |
Writes out generated code if requested by driver options.
Frontend for parsing command line options into driver::Options
and hilti::Options
. See the outout of
hiltic –help` for a list.
setDriverOptions()
and setCompilerOptions()
provide alternative ways to set the options directly.
argc,argv | command line arguments to parse |
|
protected |
Prints an uncaught HILTI exception to stderr.
e | exception to print |
|
protected |
Helper function to read data from an input file.
p | input file |
Compile and executes all source files. This is a convenience wrapper around the stages of the process provided by other methods. It executes all of compile()
, initRuntime()
, executeMain()
, and finishRuntime()
in that order.
void Driver::setCompilerOptions | ( | hilti::Options | options | ) |
Sets HILTI's compiler options.
options | the options |
void Driver::setDriverOptions | ( | driver::Options | options | ) |
Sets the driver's options and arguments.
options | the options |
|
protected |
Prints a usage message to stderr. The message summarizes the options understood by parseOptions()
.
|
protected |
Helper function to write data into an output file.
in | stream to read data to write from |
p | output file |
|
protected |
Copies an input stream into a temporary file on disk
in | stream to read from |
name_hint | a string to include into the temporary file's name |
extension | extension for the temporary file's name |