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
16
17namespace mim::plug::regex {
18
19namespace {
20const Def* wrap_in_cps2ds(const Def* callee) { return direct::op_cps2ds_dep(callee); }
21} // namespace
22
23const Def* LowerRegex::rewrite(const Def* def) {
24 const Def* new_app = def;
25
26 if (auto app = def->isa<App>()) {
27 auto callee = app->callee();
29 || Axm::isa<regex::range>(callee) || Axm::isa<regex::any>(callee) || Axm::isa<quant>(callee)) {
30 const auto n = app->arg();
31 auto nfa = regex2nfa(callee);
32 DLOG("nfa: {}", *nfa);
33
34 auto dfa = automaton::nfa2dfa(*nfa);
35 DLOG("dfa: {}", *dfa);
36
37 auto min_dfa = automaton::minimize_dfa(*dfa);
38 new_app = wrap_in_cps2ds(dfa2matcher(world(), *min_dfa, n));
39 }
40 }
41
42 return new_app;
43}
44
45} // namespace mim::plug::regex
static auto isa(const Def *def)
Definition axm.h:107
Base class for all Defs.
Definition def.h:251
World & world()
Definition pass.h:64
const Def * rewrite(const Def *) override
const mim::Def * dfa2matcher(mim::World &, const automaton::DFA &, const mim::Def *)
You can dl::get this function.
#define DLOG(...)
Vaporizes to nothingness in Debug build.
Definition log.h:95
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 *k)
Definition direct.h:16
The regex Plugin
Definition lower_regex.h:5
std::unique_ptr< automaton::NFA > regex2nfa(const Def *regex)
Definition regex2nfa.cpp:90