11 #include <string_view> 12 #include <unordered_map> 16 #include <hilti/rt/filesystem.h> 18 #include <hilti/base/logger.h> 19 #include <hilti/base/result.h> 20 #include <hilti/base/timing.h> 21 #include <hilti/compiler/context.h> 22 #include <hilti/compiler/unit.h> 32 enum class Dependencies {
44 bool include_linker =
false;
45 bool output_hilti =
false;
46 bool output_prototypes =
false;
47 bool output_cxx =
false;
49 bool output_linker =
false;
50 Dependencies output_dependencies = Dependencies::None;
51 bool execute_code =
false;
52 bool show_backtraces =
false;
53 bool abort_on_exceptions =
false;
54 bool keep_tmps =
false;
55 bool skip_dependencies =
false;
56 bool report_resource_usage =
false;
57 bool report_times =
false;
58 bool dump_code =
false;
59 bool global_optimizations =
true;
60 std::vector<hilti::rt::filesystem::path>
63 std::unique_ptr<Logger>
66 Options() { logger = std::make_unique<Logger>(); }
89 explicit Driver(std::string name);
98 Driver(std::string name,
const hilti::rt::filesystem::path& argv0);
149 return ! (_pending_units.empty() && _processed_units.empty() && _processed_paths.empty() &&
150 _libraries.empty() && _external_cxxs.empty());
197 const auto&
options()
const {
return _ctx->options(); }
288 result::Error error(std::string_view msg,
const hilti::rt::filesystem::path& p =
"");
308 Result<std::ofstream> openOutput(
const hilti::rt::filesystem::path& p,
bool binary =
false,
bool append =
false);
317 Result<Nothing> openInput(std::ifstream& in,
const hilti::rt::filesystem::path& p);
326 Result<Nothing> writeOutput(std::ifstream& in,
const hilti::rt::filesystem::path& p);
345 const std::string& extension =
"tmp");
348 void dumpUnit(
const Unit& unit);
426 enum Stage { UNINITIALIZED, INITIALIZED, COMPILED, CODEGENED, LINKED, JITTED } _stage = UNINITIALIZED;
429 void _addUnit(std::shared_ptr<Unit> unit);
432 Result<Nothing> _resolveUnitsWithPlugin(
const Plugin& plugin, std::vector<std::shared_ptr<Unit>> units,
int& round);
435 Result<Nothing> _transformUnitsWithPlugin(
const Plugin& plugin, std::vector<std::shared_ptr<Unit>> units);
448 const std::string& prefix,
int round);
451 void _dumpAST(std::shared_ptr<Unit> unit,
const logging::DebugStream& stream,
const std::string& prefix);
454 void _dumpAST(std::shared_ptr<Unit> unit, std::ostream& stream,
const Plugin& plugin,
const std::string& prefix,
458 void _dumpDeclarations(std::shared_ptr<Unit> unit,
const Plugin& plugin);
461 void _saveIterationAST(std::shared_ptr<Unit> unit,
const Plugin& plugin,
const std::string& prefix,
int round);
464 void _saveIterationAST(std::shared_ptr<Unit> unit,
const Plugin& plugin,
const std::string& prefix,
479 std::vector<std::shared_ptr<Unit>> _pending_units;
480 std::set<ID> _processed_units;
481 std::set<hilti::rt::filesystem::path> _processed_paths;
483 std::shared_ptr<Context> _ctx;
484 std::unique_ptr<hilti::JIT> _jit;
485 std::shared_ptr<const hilti::rt::Library> _library;
487 std::vector<CxxCode> _generated_cxxs;
488 std::unordered_map<std::string, Library> _libraries;
489 std::vector<hilti::rt::filesystem::path> _external_cxxs;
490 std::vector<linker::MetaData> _mds;
491 std::vector<std::shared_ptr<Unit>> _hlts;
493 bool _runtime_initialized =
false;
494 std::set<std::string> _tmp_files;
virtual void hookAddInput(const hilti::rt::filesystem::path &path)
Definition: driver.h:382
std::unique_ptr< Logger > logger
Definition: driver.h:64
const auto & driverOptions() const
Definition: driver.h:154
virtual std::string hookAugmentUsage()
Definition: driver.h:370
const auto & context() const
Definition: driver.h:194
virtual void hookInitRuntime()
Definition: driver.h:415
virtual bool hookProcessCommandLineOption(char opt, const char *optarg)
Definition: driver.h:364
bool hasInputs() const
Definition: driver.h:148
virtual void hookNewASTPreCompilation(std::shared_ptr< Unit > unit)
Definition: driver.h:389
virtual Result< Nothing > hookCompilationFinished(const Plugin &plugin)
Definition: driver.h:409
virtual void hookFinishRuntime()
Definition: driver.h:421
virtual void hookAddInput(std::shared_ptr< Unit > unit)
Definition: driver.h:376
hilti::rt::filesystem::path output_path
Definition: driver.h:62
virtual std::string hookAddCommandLineOptions()
Definition: driver.h:361
const auto & options() const
Definition: driver.h:197
const auto & hiltiOptions() const
Definition: driver.h:157
Definition: exception.h:21
std::string output_cxx_prefix
Definition: driver.h:48
virtual void hookNewASTPostCompilation(std::shared_ptr< Unit > unit)
Definition: driver.h:396
std::vector< hilti::rt::filesystem::path > inputs
Definition: driver.h:61