MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
ds2cps.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/def.h>
4#include <mim/pass.h>
5
6namespace mim::plug::direct {
7
8/// Converts direct style function to cps functions.
9/// To do so, for each (non-type-level) ds function a corresponding cps function is created:
10/// ```
11/// f: [a: A] -> B
12/// f_cps: Cn [a: A, Cn B]
13/// ```
14/// Only the type signature of the function is changed and the body is wrapped in the newly added return continuation.
15/// (Technical detail: the arguments are substituted to fit the new function)
16///
17/// In a second distinct but connected step, the call sites are converted:
18/// For a direct style call `f args`, the call to the cps function `cps2ds_dep ... f_cps args` is introduced.
19/// The underlying substitution is `f` -> `cps2ds_dep ... f_cps`.
20class DS2CPS : public RWPass<DS2CPS, Lam> {
21public:
24
25 const Def* rewrite(const Def*) override;
26
27private:
28 Def2Def rewritten_;
29
30 const Def* rewrite_lam(Lam* lam);
31};
32
33} // namespace mim::plug::direct
Base class for all Defs.
Definition def.h:251
A function.
Definition lam.h:111
RWPass(World &world, std::string name)
Definition pass.h:295
World & world()
Definition pass.h:64
flags_t annex() const
Definition pass.h:68
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
DS2CPS(World &world, flags_t annex)
Definition ds2cps.h:22
const Def * rewrite(const Def *) override
Definition ds2cps.cpp:13
The direct style Plugin
Definition direct.h:7
DefMap< const Def * > Def2Def
Definition def.h:75
u64 flags_t
Definition types.h:45