MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
ds2cps.cpp
Go to the documentation of this file.
1
#include "
mim/phase/ds2cps.h
"
2
3
namespace
mim
{
4
5
std::array<const Def*, 2>
DS2CPS::rewrite_filter_body
(
Lam
* old_lam,
Lam
* new_lam) {
6
auto
scope =
Scope
(*
this
,
Lam::isa_cn
(new_lam));
7
auto
[filter, body] =
RWPhase::rewrite_filter_body
(old_lam, new_lam);
8
return
{filter,
wire
(scope.base(), body)};
9
}
10
11
const
Def
*
DS2CPS::lift
(
const
Def
* k,
Defs
new_args,
const
Def
* new_type,
bool
filter, Sym
name
) {
12
auto
& w =
new_world
();
13
auto
cont = w.mut_con(new_type)->set_filter(filter);
14
auto
res = cont->var();
15
cont->set(
name
?
name
: w.append_suffix(k->
sym
(),
"_cont"
));
16
bind_new
(cont->has_var());
17
pending_.emplace_back(k,
DefVec
(new_args.begin(), new_args.end()), cont);
18
log
().d(
"lift {} ({}, {})"
, k, fe::Join(new_args,
", "
), cont);
19
return
res;
20
}
21
22
const
Def
*
DS2CPS::wire
(
size_t
base,
const
Def
* body) {
23
auto
& w =
new_world
();
24
while
(pending_.size() > base) {
25
auto
[callee,
args
, cont] = std::move(pending_.back());
26
pending_.pop_back();
27
cont->set_body(body);
28
args
.emplace_back(cont);
29
body = w.app(callee,
args
);
30
}
31
return
body;
32
}
33
34
}
// namespace mim
mim::DS2CPS::Scope::Scope
Scope(DS2CPS &phase, bool liftable)
Definition
ds2cps.h:37
mim::DS2CPS::lift
const Def * lift(const Def *k, Defs new_args, const Def *new_type, bool filter=false, Sym name={})
Records the call k (new_args..., cont) as pending and returns the Var of cont: Cn new_type as its res...
Definition
ds2cps.cpp:11
mim::DS2CPS::wire
const Def * wire(size_t base, const Def *body)
Wires all pending calls above base around body and returns the new body.
Definition
ds2cps.cpp:22
mim::DS2CPS::rewrite_filter_body
std::array< const Def *, 2 > rewrite_filter_body(Lam *, Lam *) override
The rewritten filter and body of old_lam for its stub new_lam, before the body is coerce()d.
Definition
ds2cps.cpp:5
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Def::sym
Sym sym() const
Definition
def.h:629
mim::Lam
A function.
Definition
lam.h:91
mim::Lam::isa_cn
static const Lam * isa_cn(const Def *d)
Definition
lam.h:125
mim::Phase::log
const fe::Log & log() const
Definition
phase.h:62
mim::Phase::args
const fe::Vector< std::string > & args()
Command-line arguments passed to this Phase's plugin via -X <plugin>:<arg>.
Definition
phase.cpp:23
mim::Phase::name
std::string_view name() const
Definition
phase.h:63
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:418
mim::RWPhase::rewrite_filter_body
virtual std::array< const Def *, 2 > rewrite_filter_body(Lam *old_lam, Lam *)
The rewritten filter and body of old_lam for its stub new_lam, before the body is coerce()d.
Definition
phase.h:434
mim::Rewriter::bind_new
void bind_new(const Var *var)
Adds the new var - if any - to the innermost scope.
Definition
rewrite.cpp:44
ds2cps.h
mim
Definition
ast.h:16
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:94
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:96
src
mim
phase
ds2cps.cpp
Generated by
1.18.0