94 w.DLOG(
"dfa to match: {}", dfa);
100 auto matcher = w.mut_fun({w.call<mem::M>(0), w.call<mem::Ptr0>(w.arr(n, w.type_i8())), w.type_idx(n)},
101 {w.call<mem::M>(0), w.type_bool(), w.type_idx(n)});
102 matcher->debug_prefix(std::string(
"match_regex"));
103 auto [args, exit] = matcher->vars<2>();
104 exit->debug_prefix(std::string(
"exit"));
105 auto [mem, string, pos] = args->projs<3>();
106 mem->debug_prefix(std::string(
"mem"));
107 string->debug_prefix(std::string(
"string"));
108 pos->debug_prefix(std::string(
"pos"));
110 auto error = mem::mut_con(w.type_idx(n));
111 error->debug_prefix(
"error");
113 auto [mem, pos] =
error->vars<2>();
114 mem->debug_prefix(std::string(
"mem"));
115 pos->debug_prefix(std::string(
"pos"));
116 error->app(
false, exit, {mem, w.lit_ff(), pos});
119 auto accept = mem::mut_con(w.type_idx(n));
120 accept->debug_prefix(
"accept");
122 auto [mem, pos] = accept->vars<2>();
123 mem->debug_prefix(std::string(
"mem"));
124 pos->debug_prefix(std::string(
"pos"));
125 accept->app(
false, exit, {mem, w.lit_tt(), pos});
128 auto exiting = [
error, accept](
const DFANode* state) {
return state->is_accepting() ? accept :
error; };
130 for (
auto state : states) {
131 auto lam = mem::mut_con(w.type_idx(n));
132 lam->debug_prefix(state_to_name(state));
133 state2matcher.emplace(state, lam);
136 for (
auto [state, lam] : state2matcher) {
137 auto [mem, i] = lam->vars<2>();
139 if (state->is_erroring()) {
140 lam->app(
true,
error, {mem, i});
144 auto lea = w.call<mem::lea>(
Defs{string, i});
145 auto [mem2, c] = w.call<mem::load>(
Defs{mem, lea})->projs<2>();
147 auto is_end = w.call(core::icmp::e,
Defs({c, w.lit_i8(0)}));
148 auto not_end = mem::mut_con(w.type_idx(n));
149 not_end->debug_prefix(
"not_end_" + state_to_name(state));
151 auto new_i = w.call(core::wrap::add, core::Mode::nsuw, w.tuple({i, w.call(core::conv::u, n, w.lit_i64(1))}));
152 lam->app(
false, w.select(is_end, exiting(state), not_end), {mem2, i});
154 auto transitions = create_check_match_transitions_from(c, state);
155 auto next_check = exiting(state);
156 for (
auto [next_state, check] : transitions) {
157 auto next_lam = state2matcher[next_state];
158 auto checker = mem::mut_con(w.type_idx(n));
159 checker->debug_prefix(
"check_" + state_to_name(state) +
"_to_" + state_to_name(next_state));
160 auto [mem3, pos] = checker->vars<2>();
161 checker->app(
false, w.select(check, next_lam, next_check), {mem3, w.select(check, new_i, pos)});
162 next_check = checker;
165 auto [mem, pos] = not_end->vars<2>();
166 not_end->app(
true, next_check, {mem, pos});
170 matcher->app(
false, state2matcher[dfa.
get_start()], {mem, pos});