Debian Codegraph @

minimize.c

raw symbols SCIP
1 /* Foma: a finite-state toolkit and library. */cxx . . $ `<file>/minimize.c`/
2 /* Copyright © 2008-2021 Mans Hulden */
3
4 /* This file is part of foma. */
5
6 /* Licensed under the Apache License, Version 2.0 (the "License"); */
7 /* you may not use this file except in compliance with the License. */
8 /* You may obtain a copy of the License at */
9
10 /* http://www.apache.org/licenses/LICENSE-2.0 */
11
12 /* Unless required by applicable law or agreed to in writing, software */
13 /* distributed under the License is distributed on an "AS IS" BASIS, */
14 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
15 /* See the License for the specific language governing permissions and */
16 /* limitations under the License. */
17
18 #include <stdlib.h>
19 #include <assert.h>
20 #include <limits.h>
21 #include <stdint.h>
22 #include "foma.h"cxx . . $ `<file>/foma.h`/
23
24 static struct fsmcxx . . $ fsm# *fsm_minimize_brzcxx . . $ fsm_minimize_brz(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net);
25 static struct fsmcxx . . $ fsm# *fsm_minimize_hopcxx . . $ fsm_minimize_hop(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net);
26 static struct fsmcxx . . $ fsm# *rebuild_machinecxx . . $ rebuild_machine(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net);
27
28 static int *single_sigma_arraycxx . . $ single_sigma_array., *double_sigma_arraycxx . . $ double_sigma_array., *memo_tablecxx . . $ memo_table., *temp_movecxx . . $ temp_move., *temp_groupcxx . . $ temp_group., maxsigmacxx . . $ maxsigma., epsilon_symbolcxx . . $ epsilon_symbol., num_statescxx . . $ num_states., num_symbolscxx . . $ num_symbols., num_finalscxx . . $ num_finals., mainloopcxx . . $ mainloop., total_statescxx . . $ total_states.;
29
30 static _Boolcxx . . $ `fomalib.h:31:11`! *finalscxx . . $ finals.;
31
32 struct statesymcxx . . $ statesym# {
33 int targetcxx . . $ statesym#target.;
34 unsigned short int symbolcxx . . $ statesym#symbol.;
35 struct state_listcxx . . $ state_list# *statescxx . . $ statesym#states.;
36 struct statesymcxx . . $ statesym# *nextcxx . . $ statesym#next.;
37 };
38
39 struct state_listcxx . . $ state_list# {
40 int statecxx . . $ state_list#state.;
41 struct state_listcxx . . $ state_list# *nextcxx . . $ state_list#next.;
42 };
43
44 struct pcxx . . $ p# {
45 struct ecxx . . $ e# *first_ecxx . . $ p#first_e.;
46 struct ecxx . . $ e# *last_ecxx . . $ p#last_e.;
47 struct pcxx . . $ p# *current_splitcxx . . $ p#current_split.;
48 struct pcxx . . $ p# *nextcxx . . $ p#next.;
49 struct agendacxx . . $ agenda# *agendacxx . . $ p#agenda.;
50 int countcxx . . $ p#count.;
51 int t_countcxx . . $ p#t_count.;
52 int inv_countcxx . . $ p#inv_count.;
53 int inv_t_countcxx . . $ p#inv_t_count.;
54 };
55
56 struct ecxx . . $ e# {
57 struct pcxx . . $ p# *groupcxx . . $ e#group.;
58 struct ecxx . . $ e# *leftcxx . . $ e#left.;
59 struct ecxx . . $ e# *rightcxx . . $ e#right.;
60 int inv_countcxx . . $ e#inv_count.;
61 };
62
63 struct agendacxx . . $ agenda# {
64 struct pcxx . . $ p# *pcxx . . $ agenda#p.;
65 struct agendacxx . . $ agenda# *nextcxx . . $ agenda#next.;
66 _Boolcxx . . $ `fomalib.h:31:11`! indexcxx . . $ agenda#index.;
67 };
68
69 struct trans_listcxx . . $ trans_list# {
70 int inoutcxx . . $ trans_list#inout.;
71 int sourcecxx . . $ trans_list#source.;
72 } *trans_list_minimizecxx . . $ trans_list_minimize.;
73
74 struct trans_arraycxx . . $ trans_array# {
75 struct trans_listcxx . . $ trans_list# *transitionscxx . . $ trans_array#transitions.;
76 unsigned int sizecxx . . $ trans_array#size.;
77 unsigned int tailcxx . . $ trans_array#tail.;
78 } *trans_array_minimizecxx . . $ trans_array_minimize.;
79
80
81
82 static struct pcxx . . $ p# *Pcxx . . $ P., *Pheadcxx . . $ Phead., *Pnextcxx . . $ Pnext., *current_wcxx . . $ current_w.;
83 static struct ecxx . . $ e# *Ecxx . . $ E.;
84 static struct agendacxx . . $ agenda# *Agenda_headcxx . . $ Agenda_head., *Agenda_topcxx . . $ Agenda_top., *Agenda_nextcxx . . $ Agenda_next., *Agendacxx . . $ Agenda.;
85
86 static INLINEcxx . . $ `fomalib.h:34:9`! int refine_statescxx . . $ refine_states(7864480464b09eea).(int sym);
87 static void init_PEcxx . . $ init_PE(49f6e7a06ebc5aa8).();
88 static void agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(struct pcxx . . $ p# *pptr, int start);
89 static void sigma_to_pairscxx . . $ sigma_to_pairs(1a8333acb2d82ae1).(struct fsmcxx . . $ fsm# *net);
90 /* static void single_symbol_to_symbol_pair(int symbol, int *symbol_in, int *symbol_out); */
91 static INLINEcxx . . $ `fomalib.h:34:9`! int symbol_pair_to_single_symbolcxx . . $ symbol_pair_to_single_symbol(9b79fb6aee4c0440).(int in, int out);
92 static void generate_inversecxx . . $ generate_inverse(1a8333acb2d82ae1).(struct fsmcxx . . $ fsm# *net);
93
94 struct fsmcxx . . $ fsm# *fsm_minimizecxx . . $ fsm_minimize(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net) {
95 extern int g_minimalcxx . . $ g_minimal.;
96 extern int g_minimize_hopcroftcxx . . $ g_minimize_hopcroft.;
97
98 if (net == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; }
99 /* The network needs to be deterministic and trim before we minimize */
100 if (net->is_deterministiccxx . . $ fsm#is_deterministic. != YEScxx . . $ `fomalib.h:84:9`!)
101 net = fsm_determinizecxx . . $ fsm_determinize(af08066b5a2430ab).(net);
102 if (net->is_prunedcxx . . $ fsm#is_pruned. != YEScxx . . $ `fomalib.h:84:9`!)
103 net = fsm_coaccessiblecxx . . $ fsm_coaccessible(af08066b5a2430ab).(net);
104 if (net->is_minimizedcxx . . $ fsm#is_minimized. != YEScxx . . $ `fomalib.h:84:9`! && g_minimalcxx . . $ g_minimal. == 1) {
105 if (g_minimize_hopcroftcxx . . $ g_minimize_hopcroft. != 0) {
106 net = fsm_minimize_hopcxx . . $ fsm_minimize_hop(af08066b5a2430ab).(net);
107 }
108 else
109 net = fsm_minimize_brzcxx . . $ fsm_minimize_brz(af08066b5a2430ab).(net);
110 fsm_update_flagscxx . . $ fsm_update_flags(a3a070c1c18f185a).(net,YEScxx . . $ `fomalib.h:84:9`!,YEScxx . . $ `fomalib.h:84:9`!,YEScxx . . $ `fomalib.h:84:9`!,YEScxx . . $ `fomalib.h:84:9`!,UNKcxx . . $ `fomalib.h:85:9`!,UNKcxx . . $ `fomalib.h:85:9`!);
111 }
112 return(net);
113 }
114
115 static struct fsmcxx . . $ fsm# *fsm_minimize_brzcxx . . $ fsm_minimize_brz(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net) {
116 return(fsm_determinizecxx . . $ fsm_determinize(af08066b5a2430ab).(fsm_reversecxx . . $ fsm_reverse(af08066b5a2430ab).(fsm_determinizecxx . . $ fsm_determinize(af08066b5a2430ab).(fsm_reversecxx . . $ fsm_reverse(af08066b5a2430ab).(net)))));
117 }
118
119 static struct fsmcxx . . $ fsm# *fsm_minimize_hopcxx . . $ fsm_minimize_hop(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net) {
120
121 struct ecxx . . $ e# *temp_E;
122 struct trans_arraycxx . . $ trans_array# *tptr;
123 struct trans_listcxx . . $ trans_list# *transitions;
124 int i,j,minsym,next_minsym,current_i, stateno, thissize, source;
125 unsigned int tail;
126
127 fsm_countcxx . . $ fsm_count(1a8333acb2d82ae1).(net);
128 if (net->finalcountcxx . . $ fsm#finalcount. == 0) {
129 fsm_destroycxx . . $ fsm_destroy(45dd8c66b239e273).(net);
130 return(fsm_empty_setcxx . . $ fsm_empty_set(ca05114fe4ed2883).());
131 }
132
133 num_statescxx . . $ num_states. = net->statecountcxx . . $ fsm#statecount.;
134
135 Pcxx . . $ P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
136
137 /*
138 1. generate the inverse lookup table
139 2. generate P and E (partitions, states linked list)
140 3. Init Agenda = {Q, Q-F}
141 4. Split until Agenda is empty
142 */
143
144 sigma_to_pairscxx . . $ sigma_to_pairs(1a8333acb2d82ae1).(net);
145
146 init_PEcxx . . $ init_PE(49f6e7a06ebc5aa8).();
147
148 if (total_statescxx . . $ total_states. == num_statescxx . . $ num_states.) {
149 goto bail;
150 }
151
152 generate_inversecxx . . $ generate_inverse(1a8333acb2d82ae1).(net);
153
154
155 Agenda_headcxx . . $ Agenda_head.->indexcxx . . $ agenda#index. = 0;
156 if (Agenda_headcxx . . $ Agenda_head.->nextcxx . . $ agenda#next. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
157 Agenda_headcxx . . $ Agenda_head.->nextcxx . . $ agenda#next.->indexcxx . . $ agenda#index. = 0;
158
159 for (Agendacxx . . $ Agenda. = Agenda_headcxx . . $ Agenda_head.; Agendacxx . . $ Agenda. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; ) {
160 /* Remove current_w from agenda */
161 current_wcxx . . $ current_w. = Agendacxx . . $ Agenda.->pcxx . . $ agenda#p.;
162 current_i = Agendacxx . . $ Agenda.->indexcxx . . $ agenda#index.;
163 Agendacxx . . $ Agenda.->pcxx . . $ agenda#p.->agendacxx . . $ p#agenda. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
164 Agendacxx . . $ Agenda. = Agendacxx . . $ Agenda.->nextcxx . . $ agenda#next.;
165
166 /* Store current group state number in tmp_group */
167 /* And figure out minsym */
168 /* If index is 0 we start splitting from the first symbol */
169 /* Otherwise we split from where we left off last time */
170
171 thissize = 0;
172 minsym = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
173 for (temp_E = current_wcxx . . $ current_w.->first_ecxx . . $ p#first_e.; temp_E != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; temp_E = temp_E->rightcxx . . $ e#right.) {
174 stateno = temp_E - Ecxx . . $ E.;
175 *(temp_groupcxx . . $ temp_group.+thissize) = stateno;
176 thissize++;
177 tptr = trans_array_minimizecxx . . $ trans_array_minimize.+stateno;
178 /* Clear tails if symloop should start from 0 */
179 if (current_i == 0)
180 tptr->tailcxx . . $ trans_array#tail. = 0;
181
182 tail = tptr->tailcxx . . $ trans_array#tail.;
183 transitions = (tptr->transitionscxx . . $ trans_array#transitions.)+tail;
184 if (tail < tptr->sizecxx . . $ trans_array#size. && transitions->inoutcxx . . $ trans_list#inout. < minsym) {
185 minsym = transitions->inoutcxx . . $ trans_list#inout.;
186 }
187 }
188
189 for (next_minsym = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!; minsym != INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`! ; minsym = next_minsym, next_minsym = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!) {
190
191 /* Add states to temp_move */
192 for (i = 0, j = 0; i < thissize; i++) {
193 tptr = trans_array_minimizecxx . . $ trans_array_minimize.+*(temp_groupcxx . . $ temp_group.+i);
194 tail = tptr->tailcxx . . $ trans_array#tail.;
195 transitions = (tptr->transitionscxx . . $ trans_array#transitions.)+tail;
196 while (tail < tptr->sizecxx . . $ trans_array#size. && transitions->inoutcxx . . $ trans_list#inout. == minsym) {
197 source = transitions->sourcecxx . . $ trans_list#source.;
198 if (*(memo_tablecxx . . $ memo_table.+(source)) != mainloopcxx . . $ mainloop.) {
199 *(memo_tablecxx . . $ memo_table.+(source)) = mainloopcxx . . $ mainloop.;
200 *(temp_movecxx . . $ temp_move.+j) = source;
201 j++;
202 }
203 tail++;
204 transitions++;
205 }
206 tptr->tailcxx . . $ trans_array#tail. = tail;
207 if (tail < tptr->sizecxx . . $ trans_array#size. && transitions->inoutcxx . . $ trans_list#inout. < next_minsym) {
208 next_minsym = transitions->inoutcxx . . $ trans_list#inout.;
209 }
210 }
211 if (j == 0) {
212 continue;
213 }
214 mainloopcxx . . $ mainloop.++;
215 if (refine_statescxx . . $ refine_states(7864480464b09eea).(j) == 1) {
216 break; /* break loop if we split current_w */
217 }
218 }
219 if (total_statescxx . . $ total_states. == num_statescxx . . $ num_states.) {
220 break;
221 }
222 }
223
224 net = rebuild_machinecxx . . $ rebuild_machine(af08066b5a2430ab).(net);
225
226 freecxx . . $ free(5d22bdacc48458e8).(trans_array_minimizecxx . . $ trans_array_minimize.);
227 freecxx . . $ free(5d22bdacc48458e8).(trans_list_minimizecxx . . $ trans_list_minimize.);
228
229 bail:
230
231 freecxx . . $ free(5d22bdacc48458e8).(Agenda_topcxx . . $ Agenda_top.);
232
233 freecxx . . $ free(5d22bdacc48458e8).(memo_tablecxx . . $ memo_table.);
234 freecxx . . $ free(5d22bdacc48458e8).(temp_movecxx . . $ temp_move.);
235 freecxx . . $ free(5d22bdacc48458e8).(temp_groupcxx . . $ temp_group.);
236
237
238 freecxx . . $ free(5d22bdacc48458e8).(finalscxx . . $ finals.);
239 freecxx . . $ free(5d22bdacc48458e8).(Ecxx . . $ E.);
240 freecxx . . $ free(5d22bdacc48458e8).(Pheadcxx . . $ Phead.);
241 freecxx . . $ free(5d22bdacc48458e8).(single_sigma_arraycxx . . $ single_sigma_array.);
242 freecxx . . $ free(5d22bdacc48458e8).(double_sigma_arraycxx . . $ double_sigma_array.);
243
244 return(net);
245 }
246
247 static struct fsmcxx . . $ fsm# *rebuild_machinecxx . . $ rebuild_machine(af08066b5a2430ab).(struct fsmcxx . . $ fsm# *net) {
248 int i,j, group_num, source, target, new_linecount = 0, arccount = 0;
249 struct fsm_statecxx . . $ fsm_state# *fsm;
250 struct pcxx . . $ p# *myp;
251 struct ecxx . . $ e# *thise;
252
253 if (net->statecountcxx . . $ fsm#statecount. == total_statescxx . . $ total_states.) {
254 return(net);
255 }
256 fsm = net->statescxx . . $ fsm#states.;
257
258 /* We need to make sure state 0 is first in its group */
259 /* to get the proper numbering of states */
260
261 if (Ecxx . . $ E.->groupcxx . . $ e#group.->first_ecxx . . $ p#first_e. != Ecxx . . $ E.) {
262 Ecxx . . $ E.->groupcxx . . $ e#group.->first_ecxx . . $ p#first_e. = Ecxx . . $ E.;
263 }
264
265 /* Recycling t_count for group numbering use here */
266
267 group_num = 1;
268 myp = Pcxx . . $ P.;
269 while (myp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
270 myp->countcxx . . $ p#count. = 0;
271 myp = myp->nextcxx . . $ p#next.;
272 }
273
274 for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) {
275 thise = Ecxx . . $ E.+((fsm+i)->state_nocxx . . $ fsm_state#state_no.);
276 if (thise->groupcxx . . $ e#group.->first_ecxx . . $ p#first_e. == thise) {
277 new_linecount++;
278 if ((fsm+i)->start_statecxx . . $ fsm_state#start_state. == 1) {
279 thise->groupcxx . . $ e#group.->t_countcxx . . $ p#t_count. = 0;
280 thise->groupcxx . . $ e#group.->countcxx . . $ p#count. = 1;
281 } else if (thise->groupcxx . . $ e#group.->countcxx . . $ p#count. == 0) {
282 thise->groupcxx . . $ e#group.->t_countcxx . . $ p#t_count. = group_num++;
283 thise->groupcxx . . $ e#group.->countcxx . . $ p#count. = 1;
284 }
285 }
286 }
287
288 for (i=0, j=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) {
289 thise = Ecxx . . $ E.+((fsm+i)->state_nocxx . . $ fsm_state#state_no.);
290 if (thise->groupcxx . . $ e#group.->first_ecxx . . $ p#first_e. == thise) {
291 source = thise->groupcxx . . $ e#group.->t_countcxx . . $ p#t_count.;
292 target = ((fsm+i)->targetcxx . . $ fsm_state#target. == -1) ? -1 : (Ecxx . . $ E.+((fsm+i)->targetcxx . . $ fsm_state#target.))->groupcxx . . $ e#group.->t_countcxx . . $ p#t_count.;
293 add_fsm_arccxx . . $ add_fsm_arc(ca4c73e59b5dbf52).(fsm, j, source, (fsm+i)->incxx . . $ fsm_state#in., (fsm+i)->outcxx . . $ fsm_state#out., target, finalscxx . . $ finals.[(fsm+i)->state_nocxx . . $ fsm_state#state_no.], (fsm+i)->start_statecxx . . $ fsm_state#start_state.);
294 arccount = ((fsm+i)->targetcxx . . $ fsm_state#target. == -1) ? arccount : arccount+1;
295 j++;
296 }
297 }
298
299 add_fsm_arccxx . . $ add_fsm_arc(ca4c73e59b5dbf52).(fsm, j, -1, -1, -1, -1, -1, -1);
300 fsm = realloccxx . . $ realloc(417ab160f6baadc6).(fsm,sizeof(struct fsm_statecxx . . $ fsm_state#)*(new_linecount+1));
301 net->statescxx . . $ fsm#states. = fsm;
302 net->linecountcxx . . $ fsm#linecount. = j+1;
303 net->arccountcxx . . $ fsm#arccount. = arccount;
304 net->statecountcxx . . $ fsm#statecount. = total_statescxx . . $ total_states.;
305 return(net);
306 }
307
308 static INLINEcxx . . $ `fomalib.h:34:9`! int refine_statescxx . . $ refine_states(7864480464b09eea).(int invstates) {
309 int i, selfsplit;
310 struct ecxx . . $ e# *thise;
311 struct pcxx . . $ p# *tP, *newP = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
312
313 /*
314 1. add inverse(P,a) to table of inverses, disallowing duplicates
315 2. first pass on S, touch each state once, increasing P->t_count
316 3. for each P where counter != count, split and add to agenda
317 */
318
319 /* Inverse to table of inverses */
320 selfsplit = 0;
321
322 /* touch and increase P->counter */
323 for (i=0; i < invstates; i++) {
324 ((Ecxx . . $ E.+(*(temp_movecxx . . $ temp_move.+i)))->groupcxx . . $ e#group.)->t_countcxx . . $ p#t_count.++;
325 ((Ecxx . . $ E.+(*(temp_movecxx . . $ temp_move.+i)))->groupcxx . . $ e#group.)->inv_t_countcxx . . $ p#inv_t_count. += ((Ecxx . . $ E.+(*(temp_movecxx . . $ temp_move.+i)))->inv_countcxx . . $ e#inv_count.);
326 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!((E+(*(temp_move+i)))->group->t_count <= (E+(*(temp_move+i)))->group->count);
327 }
328
329 /* Split (this is the tricky part) */
330
331 for (i=0; i < invstates; i++) {
332
333 thise = Ecxx . . $ E.+*(temp_movecxx . . $ temp_move.+i);
334 tP = thise->groupcxx . . $ e#group.;
335
336 /* Do we need to split?
337 if we've touched as many states as there are in the partition
338 we don't split */
339
340 if (tP->t_countcxx . . $ p#t_count. == tP->countcxx . . $ p#count.) {
341 tP->t_countcxx . . $ p#t_count. = 0;
342 tP->inv_t_countcxx . . $ p#inv_t_count. = 0;
343 continue;
344 }
345
346 if ((tP->t_countcxx . . $ p#t_count. != tP->countcxx . . $ p#count.) && (tP->countcxx . . $ p#count. > 1) && (tP->t_countcxx . . $ p#t_count. > 0)) {
347
348 /* Check if we already split this */
349 newP = tP->current_splitcxx . . $ p#current_split.;
350 if (newP == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
351 /* printf("tP [%i] newP [%i]\n",tP->inv_count,tP->inv_t_count); */
352 /* Create new group newP */
353 total_statescxx . . $ total_states.++;
354 if (total_statescxx . . $ total_states. == num_statescxx . . $ num_states.)
355 return(1); /* Abort now, machine is already minimal */
356 tP->current_splitcxx . . $ p#current_split. = Pnextcxx . . $ Pnext.++;
357 newP = tP->current_splitcxx . . $ p#current_split.;
358 newP->first_ecxx . . $ p#first_e. = newP->last_ecxx . . $ p#last_e. = thise;
359 newP->countcxx . . $ p#count. = 0;
360 newP->inv_countcxx . . $ p#inv_count. = tP->inv_t_countcxx . . $ p#inv_t_count.;
361 newP->inv_t_countcxx . . $ p#inv_t_count. = 0;
362 newP->t_countcxx . . $ p#t_count. = 0;
363 newP->current_splitcxx . . $ p#current_split. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
364 newP->agendacxx . . $ p#agenda. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
365
366 /* Add to agenda */
367
368 /* If the current block (tP) is on the agenda, we add both back */
369 /* to the agenda */
370 /* In practice we need only add newP since tP stays where it is */
371 /* However, we mark the larger one as not starting the symloop */
372 /* from zero */
373 if (tP->agendacxx . . $ p#agenda. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
374 /* Is tP smaller */
375 if (tP->inv_countcxx . . $ p#inv_count. < tP->inv_t_countcxx . . $ p#inv_t_count.) {
376 agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(newP, 1);
377 tP->agendacxx . . $ p#agenda.->indexcxx . . $ agenda#index. = 0;
378 }
379 else {
380 agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(newP, 0);
381 }
382 /* In the event that we're splitting the partition we're currently */
383 /* splitting with, we can simply add both new partitions to the agenda */
384 /* and break out of the entire sym loop after we're */
385 /* done with the current sym and move on with the agenda */
386 /* We process the larger one for all symbols */
387 /* and the smaller one for only the ones remaining in this symloop */
388
389 } else if (tP == current_wcxx . . $ current_w.) {
390 agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(((tP->inv_countcxx . . $ p#inv_count. < tP->inv_t_countcxx . . $ p#inv_t_count.) ? tP : newP),0);
391 agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(((tP->inv_countcxx . . $ p#inv_count. >= tP->inv_t_countcxx . . $ p#inv_t_count.) ? tP : newP),1);
392 selfsplit = 1;
393 } else {
394 /* If the block is not on the agenda, we add */
395 /* the smaller of tP, newP and start the symloop from 0 */
396 agenda_addcxx . . $ agenda_add(ea1864ceabae1298).((tP->inv_countcxx . . $ p#inv_count. < tP->inv_t_countcxx . . $ p#inv_t_count. ? tP : newP),0);
397 }
398 /* Add to middle of P-chain */
399 newP->nextcxx . . $ p#next. = Pcxx . . $ P.->nextcxx . . $ p#next.;
400 Pcxx . . $ P.->nextcxx . . $ p#next. = newP;
401 }
402
403 thise->groupcxx . . $ e#group. = newP;
404 newP->countcxx . . $ p#count.++;
405
406 /* need to make tP->last_e point to the last untouched e */
407 if (thise == tP->last_ecxx . . $ p#last_e.)
408 tP->last_ecxx . . $ p#last_e. = thise->leftcxx . . $ e#left.;
409 if (thise == tP->first_ecxx . . $ p#first_e.)
410 tP->first_ecxx . . $ p#first_e. = thise->rightcxx . . $ e#right.;
411
412 /* Adjust links */
413 if (thise->leftcxx . . $ e#left. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
414 thise->leftcxx . . $ e#left.->rightcxx . . $ e#right. = thise->rightcxx . . $ e#right.;
415 if (thise->rightcxx . . $ e#right. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
416 thise->rightcxx . . $ e#right.->leftcxx . . $ e#left. = thise->leftcxx . . $ e#left.;
417
418 if (newP->last_ecxx . . $ p#last_e. != thise) {
419 newP->last_ecxx . . $ p#last_e.->rightcxx . . $ e#right. = thise;
420 thise->leftcxx . . $ e#left. = newP->last_ecxx . . $ p#last_e.;
421 newP->last_ecxx . . $ p#last_e. = thise;
422 }
423
424 thise->rightcxx . . $ e#right. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
425 if (newP->first_ecxx . . $ p#first_e. == thise)
426 thise->leftcxx . . $ e#left. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
427
428 /* Are we done for this block? Adjust counters */
429 if (newP->countcxx . . $ p#count. == tP->t_countcxx . . $ p#t_count.) {
430 tP->countcxx . . $ p#count. = tP->countcxx . . $ p#count. - newP->countcxx . . $ p#count.;
431 tP->inv_countcxx . . $ p#inv_count. = tP->inv_countcxx . . $ p#inv_count. - tP->inv_t_countcxx . . $ p#inv_t_count.;
432 tP->current_splitcxx . . $ p#current_split. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
433 tP->t_countcxx . . $ p#t_count. = 0;
434 tP->inv_t_countcxx . . $ p#inv_t_count. = 0;
435 }
436 }
437 }
438 /* We return 1 if we just split the partition we were working with */
439 return (selfsplit);
440 }
441
442 static void agenda_addcxx . . $ agenda_add(ea1864ceabae1298).(struct pcxx . . $ p# *pptr, int start) {
443
444 /* Use FILO strategy here */
445
446 struct agendacxx . . $ agenda# *ag;
447 //ag = malloc(sizeof(struct agenda));
448 ag = Agenda_nextcxx . . $ Agenda_next.++;
449 if (Agendacxx . . $ Agenda. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
450 ag->nextcxx . . $ agenda#next. = Agendacxx . . $ Agenda.;
451 else
452 ag->nextcxx . . $ agenda#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
453 ag->pcxx . . $ agenda#p. = pptr;
454 ag->indexcxx . . $ agenda#index. = start;
455 Agendacxx . . $ Agenda. = ag;
456 pptr->agendacxx . . $ p#agenda. = ag;
457 }
458
459 static void init_PEcxx . . $ init_PE(49f6e7a06ebc5aa8).() {
460 /* Create two members of P
461 (nonfinals,finals)
462 and put both of them on the agenda
463 */
464
465 int i;
466 struct ecxx . . $ e# *last_f, *last_nonf;
467 struct pcxx . . $ p# *nonFP, *FP;
468 struct agendacxx . . $ agenda# *ag;
469
470 mainloopcxx . . $ mainloop. = 1;
471 memo_tablecxx . . $ memo_table. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.,sizeof(int));
472 temp_movecxx . . $ temp_move. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.,sizeof(int));
473 temp_groupcxx . . $ temp_group. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.,sizeof(int));
474 Pheadcxx . . $ Phead. = Pcxx . . $ P. = Pnextcxx . . $ Pnext. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.+1, sizeof(struct pcxx . . $ p#));
475 nonFP = Pnextcxx . . $ Pnext.++;
476 FP = Pnextcxx . . $ Pnext.++;
477 nonFP->nextcxx . . $ p#next. = FP;
478 nonFP->countcxx . . $ p#count. = num_statescxx . . $ num_states.-num_finalscxx . . $ num_finals.;
479 FP->nextcxx . . $ p#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
480 FP->countcxx . . $ p#count. = num_finalscxx . . $ num_finals.;
481 FP->t_countcxx . . $ p#t_count. = 0;
482 nonFP->t_countcxx . . $ p#t_count. = 0;
483 FP->current_splitcxx . . $ p#current_split. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
484 nonFP->current_splitcxx . . $ p#current_split. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
485 FP->inv_countcxx . . $ p#inv_count. = nonFP->inv_countcxx . . $ p#inv_count. = FP->inv_t_countcxx . . $ p#inv_t_count. = nonFP->inv_t_countcxx . . $ p#inv_t_count. = 0;
486
487 /* How many groups can we put on the agenda? */
488 Agenda_topcxx . . $ Agenda_top. = Agenda_nextcxx . . $ Agenda_next. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.*2, sizeof(struct agendacxx . . $ agenda#));
489 Agenda_headcxx . . $ Agenda_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
490
491 Pcxx . . $ P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
492 total_statescxx . . $ total_states. = 0;
493
494 if (num_finalscxx . . $ num_finals. > 0) {
495 ag = Agenda_nextcxx . . $ Agenda_next.++;
496 FP->agendacxx . . $ p#agenda. = ag;
497 Pcxx . . $ P. = FP;
498 Pcxx . . $ P.->nextcxx . . $ p#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
499 ag->pcxx . . $ agenda#p. = FP;
500 Agenda_headcxx . . $ Agenda_head. = ag;
501 ag->nextcxx . . $ agenda#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
502 total_statescxx . . $ total_states.++;
503 }
504 if (num_statescxx . . $ num_states. - num_finalscxx . . $ num_finals. > 0) {
505 ag = Agenda_nextcxx . . $ Agenda_next.++;
506 nonFP->agendacxx . . $ p#agenda. = ag;
507 ag->pcxx . . $ agenda#p. = nonFP;
508 ag->nextcxx . . $ agenda#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
509 total_statescxx . . $ total_states.++;
510 if (Agenda_headcxx . . $ Agenda_head. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
511 Agenda_headcxx . . $ Agenda_head.->nextcxx . . $ agenda#next. = ag;
512 Pcxx . . $ P.->nextcxx . . $ p#next. = nonFP;
513 Pcxx . . $ P.->nextcxx . . $ p#next.->nextcxx . . $ p#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
514 } else {
515 Pcxx . . $ P. = nonFP;
516 Pcxx . . $ P.->nextcxx . . $ p#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
517 Agenda_headcxx . . $ Agenda_head. = ag;
518 }
519 }
520
521 /* Initialize doubly linked list E */
522 Ecxx . . $ E. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states.,sizeof(struct ecxx . . $ e#));
523
524 last_f = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
525 last_nonf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
526
527 for (i=0; i < num_statescxx . . $ num_states.; i++) {
528 if (finalscxx . . $ finals.[i]) {
529 (Ecxx . . $ E.+i)->groupcxx . . $ e#group. = FP;
530 (Ecxx . . $ E.+i)->leftcxx . . $ e#left. = last_f;
531 if (i > 0 && last_f != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
532 last_f->rightcxx . . $ e#right. = (Ecxx . . $ E.+i);
533 if (last_f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
534 FP->first_ecxx . . $ p#first_e. = (Ecxx . . $ E.+i);
535 last_f = (Ecxx . . $ E.+i);
536 FP->last_ecxx . . $ p#last_e. = (Ecxx . . $ E.+i);
537 } else {
538 (Ecxx . . $ E.+i)->groupcxx . . $ e#group. = nonFP;
539 (Ecxx . . $ E.+i)->leftcxx . . $ e#left. = last_nonf;
540 if (i > 0 && last_nonf != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
541 last_nonf->rightcxx . . $ e#right. = (Ecxx . . $ E.+i);
542 if (last_nonf == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
543 nonFP->first_ecxx . . $ p#first_e. = (Ecxx . . $ E.+i);
544 last_nonf = (Ecxx . . $ E.+i);
545 nonFP->last_ecxx . . $ p#last_e. = (Ecxx . . $ E.+i);
546 }
547 (Ecxx . . $ E.+i)->inv_countcxx . . $ e#inv_count. = 0;
548 }
549
550 if (last_f != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
551 last_f->rightcxx . . $ e#right. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
552 if (last_nonf != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
553 last_nonf->rightcxx . . $ e#right. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
554 }
555
556 static int trans_sort_cmpcxx . . $ trans_sort_cmp(9148c8c3ff42c9d8).(const void *a, const void *b) {
557 return (((const struct trans_listcxx . . $ trans_list# *)a)->inoutcxx . . $ trans_list#inout. - ((const struct trans_listcxx . . $ trans_list# *)b)->inoutcxx . . $ trans_list#inout.);
558 }
559
560 static void generate_inversecxx . . $ generate_inverse(1a8333acb2d82ae1).(struct fsmcxx . . $ fsm# *net) {
561
562 struct fsm_statecxx . . $ fsm_state# *fsm;
563 struct trans_arraycxx . . $ trans_array# *tptr;
564 struct trans_listcxx . . $ trans_list# *listptr;
565
566 int i, source, target, offsetcount, symbol, size;
567 fsm = net->statescxx . . $ fsm#states.;
568 trans_array_minimizecxx . . $ trans_array_minimize. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(net->statecountcxx . . $ fsm#statecount., sizeof(struct trans_arraycxx . . $ trans_array#));
569 trans_list_minimizecxx . . $ trans_list_minimize. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(net->arccountcxx . . $ fsm#arccount., sizeof(struct trans_listcxx . . $ trans_list#));
570
571 /* Figure out the number of transitions each one has */
572 for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) {
573 if ((fsm+i)->targetcxx . . $ fsm_state#target. == -1) {
574 continue;
575 }
576 target = (fsm+i)->targetcxx . . $ fsm_state#target.;
577 (Ecxx . . $ E.+target)->inv_countcxx . . $ e#inv_count.++;
578 (Ecxx . . $ E.+target)->groupcxx . . $ e#group.->inv_countcxx . . $ p#inv_count.++;
579 (trans_array_minimizecxx . . $ trans_array_minimize.+target)->sizecxx . . $ trans_array#size.++;
580 }
581 offsetcount = 0;
582 for (i=0; i < net->statecountcxx . . $ fsm#statecount.; i++) {
583 (trans_array_minimizecxx . . $ trans_array_minimize.+i)->transitionscxx . . $ trans_array#transitions. = trans_list_minimizecxx . . $ trans_list_minimize. + offsetcount;
584 offsetcount += (trans_array_minimizecxx . . $ trans_array_minimize.+i)->sizecxx . . $ trans_array#size.;
585 }
586 for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) {
587 if ((fsm+i)->targetcxx . . $ fsm_state#target. == -1) {
588 continue;
589 }
590 symbol = symbol_pair_to_single_symbolcxx . . $ symbol_pair_to_single_symbol(9b79fb6aee4c0440).((fsm+i)->incxx . . $ fsm_state#in.,(fsm+i)->outcxx . . $ fsm_state#out.);
591 source = (fsm+i)->state_nocxx . . $ fsm_state#state_no.;
592 target = (fsm+i)->targetcxx . . $ fsm_state#target.;
593 tptr = trans_array_minimizecxx . . $ trans_array_minimize. + target;
594 ((tptr->transitionscxx . . $ trans_array#transitions.)+(tptr->tailcxx . . $ trans_array#tail.))->inoutcxx . . $ trans_list#inout. = symbol;
595 ((tptr->transitionscxx . . $ trans_array#transitions.)+(tptr->tailcxx . . $ trans_array#tail.))->sourcecxx . . $ trans_list#source. = source;
596 tptr->tailcxx . . $ trans_array#tail.++;
597 }
598 /* Sort arcs */
599 for (i=0; i < net->statecountcxx . . $ fsm#statecount.; i++) {
600 listptr = (trans_array_minimizecxx . . $ trans_array_minimize.+i)->transitionscxx . . $ trans_array#transitions.;
601 size = (trans_array_minimizecxx . . $ trans_array_minimize.+i)->sizecxx . . $ trans_array#size.;
602 if (size > 1)
603 qsortcxx . . $ qsort(ebb60b13a65e77d7).(listptr, size, sizeof(struct trans_listcxx . . $ trans_list#), trans_sort_cmpcxx . . $ trans_sort_cmp(9148c8c3ff42c9d8).);
604 }
605 }
606
607 static void sigma_to_pairscxx . . $ sigma_to_pairs(1a8333acb2d82ae1).(struct fsmcxx . . $ fsm# *net) {
608
609 int i, j, x, y, z, next_x = 0;
610 struct fsm_statecxx . . $ fsm_state# *fsm;
611
612 fsm = net->statescxx . . $ fsm#states.;
613
614 epsilon_symbolcxx . . $ epsilon_symbol. = -1;
615 maxsigmacxx . . $ maxsigma. = sigma_maxcxx . . $ sigma_max(e25613b9dc6b48e4).(net->sigmacxx . . $ fsm#sigma.);
616
617 maxsigmacxx . . $ maxsigma.++;
618
619 single_sigma_arraycxx . . $ single_sigma_array. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(2*maxsigmacxx . . $ maxsigma.*maxsigmacxx . . $ maxsigma.*sizeof(int));
620 double_sigma_arraycxx . . $ double_sigma_array. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(maxsigmacxx . . $ maxsigma.*maxsigmacxx . . $ maxsigma.*sizeof(int));
621
622 for (i=0; i < maxsigmacxx . . $ maxsigma.; i++) {
623 for (j=0; j< maxsigmacxx . . $ maxsigma.; j++) {
624 *(double_sigma_arraycxx . . $ double_sigma_array.+maxsigmacxx . . $ maxsigma.*i+j) = -1;
625 }
626 }
627
628 /* f(x) -> y,z sigma pair */
629 /* f(y,z) -> x simple entry */
630 /* if exists f(n) <-> EPSILON, EPSILON, save n */
631 /* symbol(x) x>=1 */
632
633 /* Forward mapping: */
634 /* *(double_sigma_array+maxsigma*in+out) */
635
636 /* Backmapping: */
637 /* *(single_sigma_array+(symbol*2) = in(symbol) */
638 /* *(single_sigma_array+(symbol*2+1) = out(symbol) */
639
640 /* Table for checking whether a state is final */
641
642 finalscxx . . $ finals. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_statescxx . . $ num_states., sizeof(_Boolcxx . . $ `fomalib.h:31:11`!));
643 x = 0; num_finalscxx . . $ num_finals. = 0;
644 net->aritycxx . . $ fsm#arity. = 1;
645 for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) {
646 if ((fsm+i)->final_statecxx . . $ fsm_state#final_state. == 1 && finalscxx . . $ finals.[(fsm+i)->state_nocxx . . $ fsm_state#state_no.] != 1) {
647 num_finalscxx . . $ num_finals.++;
648 finalscxx . . $ finals.[(fsm+i)->state_nocxx . . $ fsm_state#state_no.] = 1;
649 }
650 y = (fsm+i)->incxx . . $ fsm_state#in.;
651 z = (fsm+i)->outcxx . . $ fsm_state#out.;
652 if (y != z || y == UNKNOWNcxx . . $ `fomalib.h:50:9`! || z == UNKNOWNcxx . . $ `fomalib.h:50:9`!)
653 net->aritycxx . . $ fsm#arity. = 2;
654 if ((y == -1) || (z == -1))
655 continue;
656 if (*(double_sigma_arraycxx . . $ double_sigma_array.+maxsigmacxx . . $ maxsigma.*y+z) == -1) {
657 *(double_sigma_arraycxx . . $ double_sigma_array.+maxsigmacxx . . $ maxsigma.*y+z) = x;
658 *(single_sigma_arraycxx . . $ single_sigma_array.+next_x) = y;
659 next_x++;
660 *(single_sigma_arraycxx . . $ single_sigma_array.+next_x) = z;
661 next_x++;
662 if (y == EPSILONcxx . . $ `fomalib.h:49:9`! && z == EPSILONcxx . . $ `fomalib.h:49:9`!) {
663 epsilon_symbolcxx . . $ epsilon_symbol. = x;
664 }
665 x++;
666 }
667 }
668 num_symbolscxx . . $ num_symbols. = x;
669 }
670
671 static INLINEcxx . . $ `fomalib.h:34:9`! int symbol_pair_to_single_symbolcxx . . $ symbol_pair_to_single_symbol(9b79fb6aee4c0440).(int in, int out) {
672 return(*(double_sigma_arraycxx . . $ double_sigma_array.+maxsigmacxx . . $ maxsigma.*in+out));
673 }