MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::Driver Class Reference

Some "global" variables needed all over the place. More...

#include <mim/driver.h>

Inheritance diagram for mim::Driver:
[legend]

Classes

struct  Names
class  Paths
 An ordered list of directories. More...
class  Imports

Public Member Functions

Construction
 Driver (std::string name={})
 Driver (const Driver &)=delete
 Driver (Driver &&)=delete
Driver & operator= (Driver)=delete
Getters
Flags & flags ()
const Flags & flags () const
fe::Log & log ()
const fe::Log & log () const
fe::Profiler & profiler ()
const fe::Profiler & profiler () const
World & world ()
const Version & version () const
 MimIR Version.
const Keys & keys () const
 Interned once here: every ast::Lexer borrows them.
Library
World * library ()
 nullptr before move_to_library().
const World * library () const
void move_to_library (World &world)
 Moves everything of world into library() and imports only its externals back.
Diagnostic Naming

Scratch state for PlainNames: which plain Def::sym each gid claimed while one message is formatted.

It lives here - not in a global - so that concurrent Drivers never share it.

Names & names () const
Manage Search Paths

A plain directory is probed as-is; a prefix root stands for an install tree and derives <root>/<libdir>/mim (plugins), <root>/<datadir>/mim (imports), and <root>/<libdir>/mim/rt (runtimes).

Each lookup starts with the empty path, which probes the current working directory without an absolute path. Within a list, paths added first are searched first; CLI paths precede the environment and derived ones.

void add_plugin_path (fs::path path)
void add_import_path (fs::path path)
void add_prefix_path (fs::path path)
fe::Vector< fs::path > plugin_paths () const
 Where Driver::load looks for libmim_<name>.
fe::Vector< fs::path > import_paths () const
 Where ast::Parser looks for <name>.mim; plugin directories are included, as a plugin ships both halves.
fe::Vector< fs::path > rt_paths () const
 Where a backend looks for its runtime modules.
Manage Imports

Tracks the distinct import or plugin directives that World::dump should emit again later.

const Imports & imports () const
Imports & imports ()
Manage Plugins

All these lookups yield nullptr if the key has not been found.

auto phase (flags_t flags)
const auto & phases () const
auto normalizer (flags_t flags) const
auto normalizer (plugin_t d, tag_t t, sub_t s) const
Plugin/Phase Arguments

Freeform command-line arguments addressed to a plugin/phase (-X <plugin>:<arg>).

A Phase reads its own arguments via Phase::args().

void add_arg (std::string_view plugin, std::string arg)
const fe::Vector< std::string > & args (std::string_view plugin) const
 Yields an empty fe::Vector if plugin has none.
std::optional< nat_t > arg_nat (std::string_view plugin, std::string_view key)
 The number passed as -X <plugin>:<key>=<n>, if any; warns about and ignores a non-number.
const auto & known_args () const
 The PluginArgs each loaded Plugin declares, in load order; only for listing them, see PluginArg.
const auto & known_envs () const
 The PluginEnvs each loaded Plugin declares, in load order; only for listing them, see PluginEnv.

Load Plugin

Finds and loads a shared object file that implements the MimIR Plugin name.

name may be a bare name (bar), a path (foo/bar), or a path to the shared object itself. Its directory part - if any - is prepended to every Driver::plugin_paths() entry, where libmim_<bar>.so (.dll on Windows) is searched for. A failure is reported at loc and bails.

void load (std::string_view name, Loc loc={})
bool is_loaded (std::string_view name) const
const fs::path * plugin_dir (std::string_view name) const
 Directory the Plugin was loaded from, so that its <name>.mim half cannot come from elsewhere.
void * get_fun_ptr (std::string_view plugin, const char *name)
template<class F>
auto get_fun_ptr (std::string_view plugin, const char *name)
static void add_static_plugin (const char *name, Plugin(*get_plugin)())
 Makes a Plugin linked into this binary available to Driver::load under name; see cmake/Mim.cmake.
static std::string plugin_name (std::string_view name)
 Bare plugin name of a possibly path-qualified name: foo/libmim_bar.so → bar.

Detailed Description

Some "global" variables needed all over the place.

Well, there are not really global - that's the point of this class.

Definition at line 64 of file driver.h.


Class Documentation

◆ mim::Driver::Names

struct mim::Driver::Names

Definition at line 102 of file driver.h.

Class Members
bool clashed = false
size_t depth = 0
SymMap< u32 > sym2gid

Constructor & Destructor Documentation

◆ Driver() [1/3]

mim::Driver::Driver ( std::string name = {})

◆ Driver() [2/3]

mim::Driver::Driver ( const Driver & )
delete

References Driver().

◆ Driver() [3/3]

mim::Driver::Driver ( Driver && )
delete

References Driver().

Member Function Documentation

◆ add_arg()

void mim::Driver::add_arg ( std::string_view plugin,
std::string arg )
inline

Definition at line 221 of file driver.h.

Referenced by main().

◆ add_import_path()

void mim::Driver::add_import_path ( fs::path path)
inline

Definition at line 136 of file driver.h.

Referenced by Driver(), and main().

◆ add_plugin_path()

void mim::Driver::add_plugin_path ( fs::path path)
inline

Definition at line 135 of file driver.h.

Referenced by Driver(), and main().

◆ add_prefix_path()

void mim::Driver::add_prefix_path ( fs::path path)
inline

Definition at line 137 of file driver.h.

Referenced by Driver(), and main().

◆ add_static_plugin()

void mim::Driver::add_static_plugin ( const char * name,
Plugin(* get_plugin )() )
static

Makes a Plugin linked into this binary available to Driver::load under name; see cmake/Mim.cmake.

Definition at line 148 of file driver.cpp.

◆ arg_nat()

std::optional< nat_t > mim::Driver::arg_nat ( std::string_view plugin,
std::string_view key )

The number passed as -X <plugin>:<key>=<n>, if any; warns about and ignores a non-number.

Definition at line 227 of file driver.cpp.

References mim::arg_value(), args(), and log().

◆ args()

const fe::Vector< std::string > & mim::Driver::args ( std::string_view plugin) const

Yields an empty fe::Vector if plugin has none.

Definition at line 221 of file driver.cpp.

References args().

Referenced by arg_nat(), args(), and mim::Phase::args().

◆ flags() [1/2]

Flags & mim::Driver::flags ( )
inline

◆ flags() [2/2]

const Flags & mim::Driver::flags ( ) const
inline

Definition at line 78 of file driver.h.

◆ get_fun_ptr() [1/2]

template<class F>
auto mim::Driver::get_fun_ptr ( std::string_view plugin,
const char * name )
inline

Definition at line 203 of file driver.h.

References get_fun_ptr().

◆ get_fun_ptr() [2/2]

void * mim::Driver::get_fun_ptr ( std::string_view plugin,
const char * name )

Definition at line 213 of file driver.cpp.

Referenced by get_fun_ptr().

◆ import_paths()

fe::Vector< fs::path > mim::Driver::import_paths ( ) const

Where ast::Parser looks for <name>.mim; plugin directories are included, as a plugin ships both halves.

Definition at line 110 of file driver.cpp.

References MIM_DATADIR, and MIM_LIBDIR.

Referenced by main().

◆ imports() [1/2]

Imports & mim::Driver::imports ( )
inline

Definition at line 178 of file driver.h.

◆ imports() [2/2]

const Imports & mim::Driver::imports ( ) const
inline

Definition at line 177 of file driver.h.

Referenced by mim::ast::Parser::import().

◆ is_loaded()

bool mim::Driver::is_loaded ( std::string_view name) const
inline

Definition at line 193 of file driver.h.

Referenced by mim::plug::ll::Emitter::Emitter(), and load().

◆ keys()

const Keys & mim::Driver::keys ( ) const
inline

Interned once here: every ast::Lexer borrows them.

Definition at line 85 of file driver.h.

◆ known_args()

const auto & mim::Driver::known_args ( ) const
inline

The PluginArgs each loaded Plugin declares, in load order; only for listing them, see PluginArg.

Definition at line 228 of file driver.h.

◆ known_envs()

const auto & mim::Driver::known_envs ( ) const
inline

The PluginEnvs each loaded Plugin declares, in load order; only for listing them, see PluginEnv.

Definition at line 231 of file driver.h.

◆ library() [1/2]

World * mim::Driver::library ( )
inline

nullptr before move_to_library().

Definition at line 90 of file driver.h.

◆ library() [2/2]

const World * mim::Driver::library ( ) const
inline

Definition at line 91 of file driver.h.

◆ load()

void mim::Driver::load ( std::string_view name,
Loc loc = {} )

◆ log() [1/2]

fe::Log & mim::Driver::log ( )
inline

◆ log() [2/2]

const fe::Log & mim::Driver::log ( ) const
inline

Definition at line 80 of file driver.h.

◆ move_to_library()

void mim::Driver::move_to_library ( World & world)

Moves everything of world into library() and imports only its externals back.

From then on, world imports an annex lazily when first looked up;

See also
World::import. Importing also resolves the Holes elaboration solved.

Definition at line 141 of file driver.cpp.

References mim::Def::as_mut(), mim::World::import(), mim::World::inherit(), and world().

Referenced by mim::optimize().

◆ names()

Names & mim::Driver::names ( ) const
inline

Definition at line 108 of file driver.h.

Referenced by mim::PlainNames::claim().

◆ normalizer() [1/2]

auto mim::Driver::normalizer ( flags_t flags) const
inline

Definition at line 213 of file driver.h.

References flags().

◆ normalizer() [2/2]

auto mim::Driver::normalizer ( plugin_t d,
tag_t t,
sub_t s ) const
inline

Definition at line 214 of file driver.h.

References mim::Annex::flags(), and normalizer().

Referenced by normalizer().

◆ operator=()

Driver & mim::Driver::operator= ( Driver )
delete

References Driver().

◆ phase()

auto mim::Driver::phase ( flags_t flags)
inline

Definition at line 211 of file driver.h.

References flags().

Referenced by mim::Phase::recreate(), and mim::plug::gpu::phase::run_stage().

◆ phases()

const auto & mim::Driver::phases ( ) const
inline

Definition at line 212 of file driver.h.

Referenced by mim::optimize().

◆ plugin_dir()

const fs::path * mim::Driver::plugin_dir ( std::string_view name) const
inline

Directory the Plugin was loaded from, so that its <name>.mim half cannot come from elsewhere.

nullptr if nothing pins it.

Definition at line 196 of file driver.h.

◆ plugin_name()

std::string mim::Driver::plugin_name ( std::string_view name)
static

Bare plugin name of a possibly path-qualified name: foo/libmim_bar.so → bar.

Definition at line 134 of file driver.cpp.

Referenced by mim::ast::Parser::import(), and load().

◆ plugin_paths()

fe::Vector< fs::path > mim::Driver::plugin_paths ( ) const

Where Driver::load looks for libmim_<name>.

Definition at line 100 of file driver.cpp.

References MIM_LIBDIR.

Referenced by load(), and main().

◆ profiler() [1/2]

fe::Profiler & mim::Driver::profiler ( )
inline

Definition at line 81 of file driver.h.

Referenced by mim::Phase::profile_count(), and mim::Phase::run().

◆ profiler() [2/2]

const fe::Profiler & mim::Driver::profiler ( ) const
inline

Definition at line 82 of file driver.h.

◆ rt_paths()

fe::Vector< fs::path > mim::Driver::rt_paths ( ) const

Where a backend looks for its runtime modules.

Definition at line 124 of file driver.cpp.

References MIM_LIBDIR.

Referenced by main().

◆ version()

const Version & mim::Driver::version ( ) const
inline

MimIR Version.

Definition at line 84 of file driver.h.

Referenced by load(), and main().

◆ world()

World & mim::Driver::world ( )
inline

Definition at line 83 of file driver.h.

Referenced by main(), and move_to_library().


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