MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
branch_normalize.cpp
Go to the documentation of this file.
2
3#include "mim/lam.h"
4
5namespace mim {
6
8 if (lam->is_set()) {
9 if (auto br = Branch(lam->body())) {
10 auto tt = br.tt()->isa<Lam>() ? br.tt() : Lam::eta_expand(br.tt());
11 auto ff = br.ff()->isa<Lam>() ? br.ff() : Lam::eta_expand(br.ff());
12
13 if (tt != br.tt() || ff != br.ff()) {
14 DLOG("branch-noramlize: tt: `{} -> `{}` - ff: `{}` -> `{}`", br.tt(), tt, br.ff(), ff);
15 lam->branch(lam->filter(), br.cond(), tt, ff, br.arg());
16 // if we have this pattern nested, it will work recursively due to the rewrite of the new stuff below
17 }
18 }
19 }
20
21 return Rewriter::rewrite_mut_Lam(lam);
22}
23
24} // namespace mim
const Def * rewrite_mut_Lam(Lam *) final
Matches (ff, tt)#cond arg.
Definition tuple.h:283
Base class for all Defs.
Definition def.h:251
bool is_set() const
Yields true if empty or the last op is set.
Definition def.cpp:295
A function.
Definition lam.h:111
const Def * filter() const
Definition lam.h:123
static Lam * eta_expand(Filter, const Def *f)
Definition lam.cpp:51
Lam * branch(Filter filter, const Def *cond, const Def *t, const Def *f, const Def *arg=nullptr)
Set body to an App of (f, t)#cond mem or (f, t)#cond () if mem is nullptr.
Definition lam.cpp:35
const Def * body() const
Definition lam.h:124
#define DLOG(...)
Vaporizes to nothingness in Debug build.
Definition log.h:95
Definition ast.h:14