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/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:
23 : RWPass(man, "ds2cps") {}
24
25 Ref rewrite(Ref) override;
26
27private:
28 Def2Def rewritten_;
29
30 Ref rewrite_lam(Lam* lam);
31};
32
33} // namespace mim::plug::direct
A function.
Definition lam.h:96
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:107
PassMan & man()
Definition pass.h:30
Inherit from this class using CRTP, if your Pass does not need state and a fixed-point iteration.
Definition pass.h:220
Helper class to retrieve Infer::arg if present.
Definition def.h:85
Converts direct style function to cps functions.
Definition ds2cps.h:20
Ref rewrite(Ref) override
Definition ds2cps.cpp:11
DS2CPS(PassMan &man)
Definition ds2cps.h:22
The direct style Plugin
Definition direct.h:7
DefMap< const Def * > Def2Def
Definition def.h:59