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
5#include <mim/pass/pass.h>
6
7namespace mim::plug::direct {
8
9/// Converts direct style function to cps functions.
10/// To do so, for each (non-type-level) ds function a corresponding cps function is created:
11/// ```
12/// f: [a: A] -> B
13/// f_cps: Cn [a: A, Cn B]
14/// ```
15/// Only the type signature of the function is changed and the body is wrapped in the newly added return continuation.
16/// (Technical detail: the arguments are substituted to fit the new function)
17///
18/// In a second distinct but connected step, the call sites are converted:
19/// For a direct style call `f args`, the call to the cps function `cps2ds_dep ... f_cps args` is introduced.
20/// The underlying substitution is `f` -> `cps2ds_dep ... f_cps`.
21class DS2CPS : public RWPass<DS2CPS, Lam> {
22public:
24 : RWPass(man, "ds2cps") {}
25
26 Ref rewrite(Ref) override;
27
28private:
29 Def2Def rewritten_;
30
31 Ref rewrite_lam(Lam* lam);
32};
33
34} // namespace mim::plug::direct
A function.
Definition lam.h:103
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:86
Converts direct style function to cps functions.
Definition ds2cps.h:21
Ref rewrite(Ref) override
Definition ds2cps.cpp:11
DS2CPS(PassMan &man)
Definition ds2cps.h:23
The direct style Plugin
Definition direct.h:7
DefMap< const Def * > Def2Def
Definition def.h:60