Thorin 1.9.0
The Higher ORder 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 <thorin/def.h>
8
11#include <thorin/plug/mem/mem.h>
12
17
18namespace thorin::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 thorin::plug::regex
Base class for all Defs.
Definition def.h:222
World & world() const
Definition def.cpp:421
Helper class to retrieve Infer::arg if present.
Definition def.h:87
THORIN_EXPORT const thorin::Def * dfa2matcher(thorin::World &, const automaton::DFA &, thorin::Ref)
You can dl::get this function.
std::unique_ptr< DFA > minimize_dfa(const DFA &dfa)
Definition dfamin.cpp:115
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