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.aggr fallback` ↦ `tt`/`ff` if `-X compile:aggr=on`/`=off` was passed, else `fallback`.
17const Def* normalize_aggr(const Def*, const Def*, const Def* arg) {
18 auto& world = arg->world();
19 auto& driver = world.driver();
20 for (const auto& a : driver.args(driver.sym("compile"))) {
21 // clang-format off
22 if (a == "aggr=tt" || a == "aggr=on" || a == "aggr=true" || a == "aggr") return world.lit_tt();
23 if (a == "aggr=ff" || a == "aggr=off" || a == "aggr=false") return world.lit_ff();
24 // clang-format on
25 }
26 return arg;
27}
28
29/// `%compile.cond name phase` ↦ `phase` if `name`'s plugin is loaded, else `%compile.null`.
30const Def* normalize_cond(const Def*, const Def* callee, const Def* phase) {
31 auto& world = phase->world();
32 auto& driver = world.driver();
33 auto name = callee->as<App>()->arg();
34 if (auto str = tuple2str(name); !str.empty() && driver.is_loaded(driver.sym(str))) return phase;
35 return world.annex(Annex::base<null>());
36}
37
39
40} // namespace mim::plug::compile
Base class for all Defs.
Definition def.h:261
World & world() const noexcept
Definition def.cpp:483
const Driver & driver() const
Definition world.h:93
#define MIM_compile_NORMALIZER_IMPL
Definition autogen.h:136
The compile Plugin
const Def * normalize_cond(const Def *, const Def *callee, const Def *phase)
compile.cond name phase ↦ phase if name's plugin is loaded, else compile.null.
const Def * normalize_is_loaded(const Def *, const Def *, const Def *arg)
const Def * normalize_aggr(const Def *, const Def *, const Def *arg)
compile.aggr fallback ↦ tt/ff if -X compile:aggr=on/=off was passed, else fallback.
std::string tuple2str(const Def *)
Definition tuple.cpp:57
static consteval flags_t base()
Definition plugin.h:150