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/plugin.h>
3#include <mim/world.h>
4
6
8
9const Def* normalize_is_loaded(const Def*, const Def*, const Def* arg) {
10 auto& world = arg->world();
11 auto& driver = world.driver();
12 if (auto str = tuple2str(arg); !str.empty()) return world.lit_bool(driver.is_loaded(str));
13
14 return {};
15}
16
17/// `compile.aggr fallback` ↦ `tt`/`ff` if `-X compile:aggr`/`:no-aggr` was passed, else `fallback`.
18const Def* normalize_aggr(const Def*, const Def*, const Def* arg) {
19 auto& world = arg->world();
20 auto& driver = world.driver();
21 if (auto b = arg_bool(driver.args("compile"), {"aggr"}, {"no-aggr"})) return world.lit_bool(*b);
22 return arg;
23}
24
25/// `compile.cond name phase` ↦ `phase` if `name`'s plugin is loaded, else `compile.null`.
26const Def* normalize_cond(const Def*, const Def* callee, const Def* phase) {
27 auto& world = phase->world();
28 auto& driver = world.driver();
29 auto name = callee->as<App>()->arg();
30 if (auto str = tuple2str(name); !str.empty() && driver.is_loaded(str)) return phase;
31 return world.annex(Annex::base<null>());
32}
33
35
36} // namespace mim::plug::compile
Base class for all Defs.
Definition def.h:273
World & world() const noexcept
Definition def.h:1097
Driver & driver()
Definition world.h:103
#define MIM_compile_NORMALIZER_IMPL
Definition autogen.h:129
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/:no-aggr was passed, else fallback.
std::string tuple2str(const Def *)
Definition tuple.cpp:48
std::optional< bool > arg_bool(fe::View< std::string > args, std::initializer_list< std::string_view > on, std::initializer_list< std::string_view > off)
An on key ↦ true, an off key ↦ false; std::nullopt if neither occurs.
Definition plugin.h:73
static consteval flags_t base()
Definition plugin.h:250