MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
lower_regex.cpp
Go to the documentation of this file.
1
#include "
mim/plug/regex/phase/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/cps/cps.h
>
11
#include <
mim/plug/mem/mem.h
>
12
13
#include "
mim/plug/regex/dfa2matcher.h
"
14
#include "
mim/plug/regex/regex.h
"
15
#include "
mim/plug/regex/regex2nfa.h
"
16
17
#ifndef DOXYGEN
// clang-format off
18
template
<>
struct
std::formatter<
automaton
::DFA> : fe::ostream_formatter {};
19
template
<>
struct
std::formatter<
automaton
::NFA> : fe::ostream_formatter {};
20
#endif
// clang-format on
21
22
namespace
mim::plug::regex
{
23
24
const
Def
*
LowerRegex::rewrite_imm_App
(
const
App
* app) {
25
auto
callee = app->
callee
();
26
if
(
Axm::isa<regex::conj>
(callee) ||
Axm::isa<regex::disj>
(callee) ||
Axm::isa<regex::not_>
(callee)
27
||
Axm::isa<regex::neg_lookahead>
(callee) ||
Axm::isa<regex::range>
(callee) ||
Axm::isa<regex::any>
(callee)
28
||
Axm::isa<quant>
(callee) ||
Axm::isa<regex::empty>
(callee)) {
29
// The NFA is derived from the old callee's structure; only the argument needs rewriting.
30
auto
new_n =
rewrite
(app->
arg
());
31
auto
nfa =
regex2nfa
(callee);
32
log
().d(
"NFA: {}"
, *nfa);
33
34
auto
dfa =
automaton::nfa2dfa
(*nfa);
35
log
().d(
"DFA: {}"
, *dfa);
36
37
auto
min_dfa =
automaton::minimize_dfa
(*dfa);
38
return
cps::op_cps2ds_dep
(
dfa2matcher
(
new_world
(), *min_dfa, new_n));
39
}
40
41
return
RWPhase::rewrite_imm_App
(app);
42
}
43
44
}
// namespace mim::plug::regex
mim::App
Definition
lam.h:215
mim::App::callee
const Def * callee() const
Definition
lam.h:237
mim::App::arg
const Def * arg() const
Definition
lam.h:251
mim::Axm::isa
static auto isa(const Def *def)
Definition
axm.h:112
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Phase::log
const fe::Log & log() const
Definition
phase.h:60
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:379
mim::RWPhase::rewrite_imm_App
const Def * rewrite_imm_App(const App *) override
Definition
phase.cpp:223
mim::Rewriter::rewrite
virtual const Def * rewrite(const Def *)
Definition
rewrite.cpp:62
mim::plug::regex::LowerRegex::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
lower_regex.cpp:24
core.h
cps.h
def.h
dfa2matcher.h
dfa2matcher
const mim::Def * dfa2matcher(mim::World &, const automaton::DFA &, const mim::Def *)
You can fe::dl::get this function.
Definition
dfa2matcher.cpp:84
dfa.h
dfamin.h
lower_regex.h
mem.h
automaton
Definition
automaton.h:15
automaton::minimize_dfa
std::unique_ptr< DFA > minimize_dfa(const DFA &dfa)
Definition
dfamin.cpp:102
automaton::nfa2dfa
std::unique_ptr< DFA > nfa2dfa(const NFA &nfa)
Definition
nfa2dfa.cpp:39
mim::plug::cps::op_cps2ds_dep
const Def * op_cps2ds_dep(const Def *k)
Definition
cps.h:16
mim::plug::regex
The regex Plugin
Definition
lower_regex.h:5
mim::plug::regex::regex2nfa
std::unique_ptr< automaton::NFA > regex2nfa(const Def *regex)
Definition
regex2nfa.cpp:129
nfa2dfa.h
regex2nfa.h
regex.h
src
mim
plug
regex
phase
lower_regex.cpp
Generated by
1.18.0