MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower_regex.cpp
Go to the documentation of this file.
2
3#include <automaton/dfa.h>
4#include <automaton/dfamin.h>
5#include <automaton/nfa2dfa.h>
6
7#include <mim/def.h>
8
11#include <mim/plug/mem/mem.h>
12
17
18namespace mim::plug::regex {
19
20namespace {
21Ref wrap_in_cps2ds(Ref callee) { return direct::op_cps2ds_dep(callee); }
22} // namespace
23
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
Base class for all Defs.
Definition def.h:223
World & world() const
Definition def.cpp:415
Helper class to retrieve Infer::arg if present.
Definition def.h:86
MIM_EXPORT const mim::Def * dfa2matcher(mim::World &, const automaton::DFA &, mim::Ref)
You can dl::get this function.
std::unique_ptr< DFA > minimize_dfa(const DFA &dfa)
Definition dfamin.cpp:114
std::unique_ptr< DFA > nfa2dfa(const NFA &nfa)
Definition nfa2dfa.cpp:33
const Def * op_cps2ds_dep(const Def *f)
Definition direct.h:11
The regex Plugin
Definition lower_regex.h:5
std::unique_ptr< automaton::NFA > regex2nfa(Ref regex)
Definition regex2nfa.cpp:89
auto match(Ref def)
Definition axiom.h:112