MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
1#include <mim/driver.h>
2#include <mim/world.h>
3
5
7
8const Def* normalize_is_loaded(const Def*, const Def*, const Def* arg) {
9 auto& world = arg->world();
10 auto& driver = world.driver();
11 if (auto str = tuple2str(arg); !str.empty()) return world.lit_bool(driver.is_loaded(driver.sym(str)));
12
13 return {};
14}
15
16/// `%compile.cond_phase name phase` ↦ `phase` if `name`'s plugin is loaded, else `%compile.null_phase`.
17const Def* normalize_cond_phase(const Def*, const Def* callee, const Def* phase) {
18 auto& world = phase->world();
19 auto& driver = world.driver();
20 auto name = callee->as<App>()->arg();
21 if (auto str = tuple2str(name); !str.empty() && driver.is_loaded(driver.sym(str))) return phase;
22 return world.annex(Annex::base<null_phase>());
23}
24
26
27} // namespace mim::plug::compile
Base class for all Defs.
Definition def.h:246
World & world() const noexcept
Definition def.cpp:444
const Driver & driver() const
Definition world.h:93
#define MIM_compile_NORMALIZER_IMPL
Definition autogen.h:233
The compile Plugin
const Def * normalize_cond_phase(const Def *, const Def *callee, const Def *phase)
compile.cond_phase name phase ↦ phase if name's plugin is loaded, else compile.null_phase.
const Def * normalize_is_loaded(const Def *, const Def *, const Def *arg)
std::string tuple2str(const Def *)
Definition tuple.cpp:83
static consteval flags_t base()
Definition plugin.h:150