MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
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
5
#include "
mim/plug/compile/compile.h
"
6
7
namespace
mim::plug::compile
{
8
9
const
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`.
18
const
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`.
26
const
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
34
MIM_compile_NORMALIZER_IMPL
35
36
}
// namespace mim::plug::compile
mim::App
Definition
lam.h:224
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Def::world
World & world() const noexcept
Definition
def.h:1097
mim::World::driver
Driver & driver()
Definition
world.h:103
MIM_compile_NORMALIZER_IMPL
#define MIM_compile_NORMALIZER_IMPL
Definition
autogen.h:129
compile.h
driver.h
mim::plug::compile
The compile Plugin
Definition
normalizers.cpp:7
mim::plug::compile::normalize_cond
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.
Definition
normalizers.cpp:26
mim::plug::compile::normalize_is_loaded
const Def * normalize_is_loaded(const Def *, const Def *, const Def *arg)
Definition
normalizers.cpp:9
mim::plug::compile::normalize_aggr
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.
Definition
normalizers.cpp:18
mim::tuple2str
std::string tuple2str(const Def *)
Definition
tuple.cpp:48
mim::arg_bool
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
plugin.h
mim::Annex::base
static consteval flags_t base()
Definition
plugin.h:250
world.h
src
mim
plug
compile
normalizers.cpp
Generated by
1.18.0