MimIR
0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower_regex.cpp
Go to the documentation of this file.
1
#include "
mim/plug/regex/pass/lower_regex.h
"
2
3
#include <
automaton/dfa.h
>
4
#include <
automaton/dfamin.h
>
5
#include <
automaton/nfa2dfa.h
>
6
7
#include <
mim/def.h
>
8
9
#include <
mim/plug/core/core.h
>
10
#include <
mim/plug/direct/direct.h
>
11
#include <
mim/plug/mem/mem.h
>
12
13
#include "
mim/plug/regex/autogen.h
"
14
#include "
mim/plug/regex/dfa2matcher.h
"
15
#include "
mim/plug/regex/regex.h
"
16
#include "
mim/plug/regex/regex2nfa.h
"
17
18
namespace
mim::plug::regex
{
19
20
namespace
{
21
Ref wrap_in_cps2ds(Ref callee) {
return
direct::op_cps2ds_dep
(callee); }
22
}
// namespace
23
24
Ref
LowerRegex::rewrite
(
Ref
def) {
25
const
Def
* new_app = def;
26
27
if
(
auto
app = def->isa<
App
>()) {
28
auto
callee = app->callee();
29
if
(
match<regex::conj>
(callee) ||
match<regex::disj>
(callee) ||
match<regex::not_>
(callee)
30
||
match<regex::range>
(callee) ||
match<regex::any>
(callee) ||
match<quant>
(callee)) {
31
const
auto
n = app->arg();
32
auto
nfa =
regex2nfa
(callee);
33
def->
world
().DLOG(
"nfa: {}"
, *nfa);
34
35
auto
dfa =
automaton::nfa2dfa
(*nfa);
36
def->
world
().DLOG(
"dfa: {}"
, *dfa);
37
38
auto
min_dfa =
automaton::minimize_dfa
(*dfa);
39
new_app = wrap_in_cps2ds(
dfa2matcher
(def->
world
(), *min_dfa, n));
40
}
41
}
42
43
return
new_app;
44
}
45
46
}
// namespace mim::plug::regex
mim::App
Definition
lam.h:204
mim::Def
Base class for all Defs.
Definition
def.h:223
mim::Def::world
World & world() const
Definition
def.cpp:415
mim::Ref
Helper class to retrieve Infer::arg if present.
Definition
def.h:86
mim::plug::regex::LowerRegex::rewrite
Ref rewrite(Ref) override
Definition
lower_regex.cpp:24
core.h
def.h
dfa2matcher.h
dfa2matcher
MIM_EXPORT const mim::Def * dfa2matcher(mim::World &, const automaton::DFA &, mim::Ref)
You can dl::get this function.
Definition
dfa2matcher.cpp:95
dfa.h
dfamin.h
direct.h
lower_regex.h
mem.h
automaton::minimize_dfa
std::unique_ptr< DFA > minimize_dfa(const DFA &dfa)
Definition
dfamin.cpp:114
automaton::nfa2dfa
std::unique_ptr< DFA > nfa2dfa(const NFA &nfa)
Definition
nfa2dfa.cpp:33
mim::plug::direct::op_cps2ds_dep
const Def * op_cps2ds_dep(const Def *f)
Definition
direct.h:11
mim::plug::regex
The regex Plugin
Definition
lower_regex.h:5
mim::plug::regex::regex2nfa
std::unique_ptr< automaton::NFA > regex2nfa(Ref regex)
Definition
regex2nfa.cpp:89
mim::match
auto match(Ref def)
Definition
axiom.h:112
nfa2dfa.h
regex2nfa.h
autogen.h
regex.h
src
mim
plug
regex
pass
lower_regex.cpp
Generated by
1.12.0