8#include <absl/container/flat_hash_map.h>
9#include <absl/container/node_hash_map.h>
12#include <fe/profile.h>
22namespace fs = std::filesystem;
27using Keys = fe::SymTab<ast::Tok::Tag, ast::Num_Keys + ast::Num_Subst>;
43 static bool claim(
const Driver&, Sym sym, uint32_t gid);
50class Diag :
public fe::CodeDiag {
55 std::string
render(
const std::function<std::string()>&)
const override;
67 Driver(std::string name = {});
78 fe::Log&
log() {
return log_; }
79 const fe::Log&
log()
const {
return log_; }
81 const fe::Profiler&
profiler()
const {
return profiler_; }
104 if (fs::exists(path) && fs::is_directory(path)) paths_.insert(insert_, std::move(path));
108 void seal() { insert_ = paths_.begin(); }
110 auto begin()
const {
return paths_.cbegin(); }
111 auto end()
const {
return paths_.cend(); }
114 std::list<fs::path> paths_;
115 std::list<fs::path>::iterator insert_ = paths_.end();
133 fe::Vector<fs::path>
rt_paths()
const;
150 const auto&
entries()
const {
return entries_; }
155 auto begin()
const {
return entries_.cbegin(); }
156 auto end()
const {
return entries_.cend(); }
163 std::deque<Entry> entries_;
176 void load(std::string_view name);
177 bool is_loaded(std::string_view name)
const {
return fe::lookup(plugins_, name); }
179 const fs::path*
plugin_dir(std::string_view name)
const {
return fe::lookup(plugin2dir_, name); }
180 void*
get_fun_ptr(std::string_view plugin,
const char* name);
184 return reinterpret_cast<F*
>(
get_fun_ptr(plugin, name));
192 const auto&
phases()
const {
return phases_; }
201 void add_arg(std::string_view plugin, std::string arg) { plugin_args_[plugin].emplace_back(std::move(arg)); }
203 const fe::Vector<std::string>&
args(std::string_view plugin)
const;
214 absl::node_hash_map<std::string, Plugin::Handle> plugins_;
218 mutable Names names_;
219 fe::Profiler profiler_;
221 Paths plugin_dirs_, import_dirs_, prefixes_;
222 absl::flat_hash_map<std::string, fs::path> plugin2dir_;
225 absl::flat_hash_map<std::string, fe::Vector<std::string>> plugin_args_;
226 std::vector<std::pair<std::string, fe::View<PluginArg>>> known_args_;
227 std::vector<std::pair<std::string, fe::View<PluginEnv>>> known_envs_;
232#define GET_FUN_PTR(plugin, f) get_fun_ptr<decltype(f)>(plugin, #f)
Diag(const Driver &driver)
std::string render(const std::function< std::string()> &) const override
void add(const fe::Src *src, Sym, ast::Tok::Tag, bool path)
Remembers the directive that pulled in src; a repeated import of the same file adds nothing.
const auto & entries() const
bool path
The directive spelled a path (import "a/b.mim") rather than a name.
An ordered list of directories.
void seal()
Later Paths::add calls insert in front of everything added so far.
Some "global" variables needed all over the place.
const auto & known_envs() const
The PluginEnvs each loaded Plugin declares, in load order; only for listing them, see PluginEnv.
void add_prefix_path(fs::path path)
const Imports & imports() const
auto get_fun_ptr(std::string_view plugin, const char *name)
Driver(std::string name={})
void add_import_path(fs::path path)
void load(std::string_view name)
const Version & version() const
MimIR Version.
const auto & known_args() const
The PluginArgs each loaded Plugin declares, in load order; only for listing them, see PluginArg.
auto normalizer(plugin_t d, tag_t t, sub_t s) const
const Flags & flags() const
fe::Vector< fs::path > import_paths() const
Where ast::Parser looks for <name>.mim; plugin directories are included, as a plugin ships both halve...
bool is_loaded(std::string_view name) const
Driver & operator=(Driver)=delete
const fe::Profiler & profiler() const
const fs::path * plugin_dir(std::string_view name) const
Directory libmim_<name> was loaded from, so that its <name>.mim half cannot come from elsewhere.
void add_arg(std::string_view plugin, std::string arg)
auto normalizer(flags_t flags) const
fe::Vector< fs::path > rt_paths() const
Where a backend looks for its runtime modules.
absl::flat_hash_map< Sym, u32 > sym2gid
Driver(const Driver &)=delete
const fe::Vector< std::string > & args(std::string_view plugin) const
Yields an empty fe::Vector if plugin has none.
void add_plugin_path(fs::path path)
fe::Vector< fs::path > plugin_paths() const
Where Driver::load looks for libmim_<name>.
void * get_fun_ptr(std::string_view plugin, const char *name)
fe::Profiler & profiler()
const auto & phases() const
const Keys & keys() const
Interned once here: every ast::Lexer borrows them.
auto phase(flags_t flags)
const fe::Log & log() const
PlainNames(const Driver *driver)
Activates plain naming on driver until this guard dies; a null driver leaves it off.
static bool claim(const Driver &, Sym sym, uint32_t gid)
Registers that gid renders as sym and reports whether the plain sym may be used.
The World represents the whole program and manages creation of MimIR nodes (Defs).
absl::flat_hash_map< flags_t, std::function< std::unique_ptr< Phase >(World &)> > Flags2Phases
Maps an axiom of a Phase to a function that creates one.
absl::flat_hash_map< flags_t, NormalizeFn > Normalizers
fe::SymTab< ast::Tok::Tag, ast::Num_Keys+ast::Num_Subst > Keys
The reserved words the ast::Lexer looks up, keyed by the Sym it has just interned.
static constexpr flags_t flags(plugin_t p, tag_t t, sub_t s=0)
Assembles the full flags from its plugin, tag, and sub fields.
Compiler switches that must be saved and looked up in later phases of compilation.