99 w.DLOG(
"dfa to match: {}", dfa);
105 auto matcher = w.mut_fun({w.call<mem::M>(0), w.call<mem::Ptr0>(w.arr(n, w.type_i8())), w.type_idx(n)},
106 {w.call<mem::M>(0), w.type_bool(), w.type_idx(n)});
107 matcher->debug_prefix(std::string(
"match_regex"));
108 auto [args, exit] = matcher->vars<2>();
109 exit->debug_prefix(std::string(
"exit"));
110 auto [mem, string, pos] = args->projs<3>();
111 mem->debug_prefix(std::string(
"mem"));
112 string->debug_prefix(std::string(
"string"));
113 pos->debug_prefix(std::string(
"pos"));
115 auto error = mem::mut_con(w.type_idx(n));
116 error->debug_prefix(
"error");
118 auto [mem, pos] =
error->vars<2>();
119 mem->debug_prefix(std::string(
"mem"));
120 pos->debug_prefix(std::string(
"pos"));
121 error->app(
false, exit, {mem, w.lit_ff(), pos});
124 auto accept = mem::mut_con(w.type_idx(n));
125 accept->debug_prefix(
"accept");
127 auto [mem, pos] = accept->vars<2>();
128 mem->debug_prefix(std::string(
"mem"));
129 pos->debug_prefix(std::string(
"pos"));
130 accept->app(
false, exit, {mem, w.lit_tt(), pos});
133 auto exiting = [
error, accept](
const DFANode* state) {
return state->is_accepting() ? accept :
error; };
135 for (
auto state : states) {
136 auto lam = mem::mut_con(w.type_idx(n));
137 lam->debug_prefix(state_to_name(state));
138 state2matcher.emplace(state, lam);
141 for (
auto [state, lam] : state2matcher) {
142 auto [mem, i] = lam->vars<2>();
144 if (state->is_erroring()) {
145 lam->app(
true,
error, {mem, i});
149 auto lea = w.call<mem::lea>(
Defs{string, i});
150 auto [mem2, c] = w.call<mem::load>(
Defs{mem, lea})->projs<2>();
152 auto is_end = w.call(core::icmp::e,
Defs({c, w.lit_i8(0)}));
153 auto not_end = mem::mut_con(w.type_idx(n));
154 not_end->debug_prefix(
"not_end_" + state_to_name(state));
156 auto new_i = w.call(core::wrap::add, core::Mode::nsuw, w.tuple({i, w.call(core::conv::u, n, w.lit_i64(1))}));
157 lam->app(
false, w.select(is_end, exiting(state), not_end), {mem2, i});
159 auto transitions = create_check_match_transitions_from(c, state);
160 auto next_check = exiting(state);
161 for (
auto [next_state, check] : transitions) {
162 auto next_lam = state2matcher[next_state];
163 auto checker = mem::mut_con(w.type_idx(n));
164 checker->debug_prefix(
"check_" + state_to_name(state) +
"_to_" + state_to_name(next_state));
165 auto [mem3, pos] = checker->vars<2>();
166 checker->app(
false, w.select(check, next_lam, next_check), {mem3, w.select(check, new_i, pos)});
167 next_check = checker;
170 auto [mem, pos] = not_end->vars<2>();
171 not_end->app(
true, next_check, {mem, pos});
175 matcher->app(
false, state2matcher[dfa.
get_start()], {mem, pos});