![]() |
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) |
| void | registerUnit (const std::shared_ptr< Unit > &unit) |
| Unit * | lookupUnit (const declaration::module::UID &uid) const |
| void | updateProcessExtension (const declaration::module::UID &uid, const hilti::rt::filesystem::path &ext) |
| Result< Nothing > | addInput (const hilti::rt::filesystem::path &path) |
| Result< Nothing > | addInput (declaration::module::UID uid) |
| 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 () |
| const auto & | context () const |
| auto * | builder () const |
| const auto & | options () const |
| Result< Nothing > | initRuntime () |
| Result< Nothing > | executeMain () |
| Result< Nothing > | finishRuntime () |
| void | fatalError (const std::string &msg) |
| void | fatalError (const hilti::result::Error &error) |
| 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::unique_ptr< Builder > | createBuilder (ASTContext *ctx) const |
| virtual std::string | hookAddCommandLineOptions () |
| virtual bool | hookProcessCommandLineOption (int opt, const char *optarg) |
| virtual std::string | hookAugmentUsage () |
| virtual void | hookAddInput (std::shared_ptr< Unit > unit) |
| virtual void | hookAddInput (const hilti::rt::filesystem::path &path) |
| virtual void | hookNewASTPreCompilation (const Plugin &plugin, ASTRoot *root) |
| virtual bool | hookNewASTPostCompilation (const Plugin &plugin, ASTRoot *root) |
| virtual Result< Nothing > | hookCompilationFinished (ASTRoot *root) |
| virtual void | hookInitRuntime () |
| virtual void | hookFinishRuntime () |
Friends | |
| class | ASTContext |
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 executable, which will change the path's that the global options instance returns if it's inside HILTI build directory. |
Schedules a source file for compilation. The file will be parsed immediately, and then compiled later when compile() is called. If the same source unit has been added previously, this method will have no effect.
The hookAddInput() and hookNewASTPreCompilation() hooks will be called immediately for the new module.
| path | source code to compile |
| Result< Nothing > Driver::addInput | ( | declaration::module::UID | uid | ) |
Schedules an already existing module for compilation. This is useful when input modules are generated in-memory on the fly. The module must have already been added to the AST. It will now be registered as a source unit for full processing (compilation to C++; JIT) just as any on-disk source files added with addInput(<path>).
| uid | UID of the existing module |
|
protected |
Helper function to augment 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 |
|
inline |
Returns the current builder. Valid only once compilation has started, otherwise null.
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.
|
protectedvirtual |
Instantiates a new builder tied to a given context. Derived class can override this to create a builder own their own type (as long as that's derived from hilti::Builder).
| ctx | context to create builder for |
Reimplemented in spicy::Driver.
|
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.
| void Driver::fatalError | ( | const hilti::result::Error & | error | ) |
Reports the given error and stops execution.
| error | the error to report |
| void Driver::fatalError | ( | const std::string & | msg | ) |
Reports the given message and stops execution.
| msg | the error message |
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 code file is being added as an input file.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when a new unit 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.
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when the AST has been fully processed and transformed to its final state.
|
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 an HILTI AST been finalized by a plugin. This hook will run after the AST has been fully processed by that plugin, but before it's being transformed.
The hook may modify the AST further, including adding new modules. If it does indicate so with its return value, AST processing will start over again to fully resolve the modified AST. Once that's done, this hook will execute again. Note, however, that the hook cannot add anything to the AST that depends on previous plugins, as they won't execute again.
| plugin | the plugin that has processed the AST |
| root | the AST that has been processed |
|
inlineprotectedvirtual |
Hook for derived classes to execute custom code when an HILTI AST has been initially set up for processing by a plugin. This hook will run before the AST has been processed any further by that plugin.
|
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.
|
inline |
Looks up a previously registered by its UID.
| uid | UID to look up |
|
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 |
|
inline |
Shortcut to return the current context's options.
Writes out generated code if requested by driver options.
Frontend for parsing command line options into driver::Options and hilti::Options. See the output ofhiltic –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 |
|
inline |
Registers a unit with the driver for compilation. If a unit with the same UID is already known, this is a no-op.
| unit | unit to register |
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 |
| void Driver::updateProcessExtension | ( | const declaration::module::UID & | uid, |
| const hilti::rt::filesystem::path & | ext | ||
| ) |
Changes the process extension of an existing unit.
This also updates the unit's module by changing its UID accordingly.
| uid | UID of the unit to change, which must correspond to a known unit |
| ext | new process extension; no other unit of the same name must exist yet with that extension |
|
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 |