0b55f123 |
1 | /***** spin: pangen2.h *****/ |
2 | |
3 | /* Copyright (c) 1989-2007 by Lucent Technologies, Bell Laboratories. */ |
4 | /* All Rights Reserved. This software is for educational purposes only. */ |
5 | /* No guarantee whatsoever is expressed or implied by the distribution of */ |
6 | /* this code. Permission is given to distribute this code provided that */ |
7 | /* this introductory message is not removed and no monies are exchanged. */ |
8 | /* Software written by Gerard J. Holzmann. For tool documentation see: */ |
9 | /* http://spinroot.com/ */ |
10 | /* Send all bug-reports and/or questions to: bugs@spinroot.com */ |
11 | /* (c) 2007: small additions for V5.0 to support multi-core verifications */ |
12 | |
13 | static char *Nvr1[] = { /* allow separate compilation */ |
14 | "#ifdef VERI", |
15 | "void", |
16 | "check_claim(int st)", |
17 | "{", |
18 | " if (st == endclaim)", |
19 | " uerror(\"claim violated!\");", |
20 | " if (stopstate[VERI][st])", |
21 | " uerror(\"end state in claim reached\");", |
22 | "}", |
23 | "#endif", |
24 | 0, |
25 | }; |
26 | |
27 | static char *Pre0[] = { |
28 | "#ifdef SC", |
29 | "#define _FILE_OFFSET_BITS 64", /* to allow file sizes greater than 2Gb */ |
30 | "#endif", |
31 | "#include <stdio.h>", |
32 | "#include <signal.h>", |
33 | "#include <stdlib.h>", |
34 | "#include <stdarg.h>", |
35 | "#include <string.h>", |
36 | "#include <ctype.h>", |
37 | "#include <errno.h>", |
38 | "#if defined(WIN32) || defined(WIN64)", |
39 | "#include <time.h>", |
40 | "#else", |
41 | "#include <unistd.h>", |
42 | "#include <sys/times.h>", |
43 | "#endif", |
44 | "#include <sys/types.h>", /* defines off_t */ |
45 | "#include <sys/stat.h>", |
46 | "#include <fcntl.h>", |
47 | |
48 | "#define Offsetof(X, Y) ((unsigned long)(&(((X *)0)->Y)))", |
49 | "#ifndef max", |
50 | "#define max(a,b) (((a)<(b)) ? (b) : (a))", |
51 | "#endif", |
52 | "#ifndef PRINTF", |
53 | "int Printf(const char *fmt, ...); /* prototype only */", |
54 | "#endif", |
55 | 0, |
56 | }; |
57 | |
58 | static char *Preamble[] = { |
59 | |
60 | "#ifdef CNTRSTACK", |
61 | "#define onstack_now() (LL[trpt->j6] && LL[trpt->j7])", |
62 | "#define onstack_put() LL[trpt->j6]++; LL[trpt->j7]++", |
63 | "#define onstack_zap() LL[trpt->j6]--; LL[trpt->j7]--", |
64 | "#endif", |
65 | |
66 | "#if !defined(SAFETY) && !defined(NOCOMP)", |
67 | /* |
68 | * V_A identifies states in the current statespace |
69 | * A_V identifies states in the 'other' statespace |
70 | * S_A remembers how many leading bytes in the sv |
71 | * are used for these markers + fairness bits |
72 | */ |
73 | "#define V_A (((now._a_t&1)?2:1) << (now._a_t&2))", |
74 | "#define A_V (((now._a_t&1)?1:2) << (now._a_t&2))", |
75 | "int S_A = 0;", |
76 | "#else", |
77 | "#define V_A 0", |
78 | "#define A_V 0", |
79 | "#define S_A 0", |
80 | "#endif", |
81 | |
82 | "#ifdef MA", |
83 | "#undef onstack_now", |
84 | "#undef onstack_put", |
85 | "#undef onstack_zap", |
86 | "#define onstack_put() ;", |
87 | "#define onstack_zap() gstore((char *) &now, vsize, 4)", |
88 | "#else", |
89 | "#if defined(FULLSTACK) && !defined(BITSTATE)", |
90 | "#define onstack_put() trpt->ostate = Lstate", |
91 | "#define onstack_zap() { \\", |
92 | " if (trpt->ostate) \\", |
93 | " trpt->ostate->tagged = \\", |
94 | " (S_A)? (trpt->ostate->tagged&~V_A) : 0; \\", |
95 | " }", |
96 | "#endif", |
97 | "#endif", |
98 | |
99 | "#ifndef NO_V_PROVISO", |
100 | "#define V_PROVISO", |
101 | "#endif", |
102 | "#if !defined(NO_RESIZE) && !defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(SPACE) && NCORE==1", |
103 | " #define AUTO_RESIZE", |
104 | "#endif", |
105 | "", |
106 | "struct H_el {", |
107 | " struct H_el *nxt;", |
108 | "#ifdef FULLSTACK", |
109 | " unsigned int tagged;", |
110 | " #if defined(BITSTATE) && !defined(NOREDUCE) && !defined(SAFETY)", |
111 | " unsigned int proviso;", /* uses just 1 bit 0/1 */ |
112 | " #endif", |
113 | "#endif", |
114 | "#if defined(CHECK) || (defined(COLLAPSE) && !defined(FULLSTACK))", |
115 | " unsigned long st_id;", |
116 | "#endif", |
117 | "#if !defined(SAFETY) || defined(REACH)", |
118 | " unsigned int D;", |
119 | "#endif", |
120 | "#if NCORE>1", |
121 | " /* could cost 1 extra word: 4 bytes if 32-bit and 8 bytes if 64-bit */", |
122 | " #ifdef V_PROVISO", |
123 | " uchar cpu_id; /* id of cpu that created the state */", |
124 | " #endif", |
125 | "#endif", |
126 | "#ifdef COLLAPSE", |
127 | " #if VECTORSZ<65536", |
128 | " unsigned short ln;", /* length of vector */ |
129 | " #else", |
130 | " unsigned long ln;", /* length of vector */ |
131 | " #endif", |
132 | "#endif", |
133 | "#if defined(AUTO_RESIZE) && !defined(BITSTATE)", |
134 | " unsigned long m_K1;", |
135 | "#endif", |
136 | " unsigned long state;", |
137 | "} **H_tab, **S_Tab;\n", |
138 | |
139 | "typedef struct Trail {", |
140 | " int st; /* current state */", |
141 | " uchar pr; /* process id */", |
142 | " uchar tau; /* 8 bit-flags */", |
143 | " uchar o_pm; /* 8 more bit-flags */", |
144 | "#if 0", |
145 | " Meaning of bit-flags:", |
146 | " tau&1 -> timeout enabled", |
147 | " tau&2 -> request to enable timeout 1 level up (in claim)", |
148 | " tau&4 -> current transition is a claim move", |
149 | " tau&8 -> current transition is an atomic move", |
150 | " tau&16 -> last move was truncated on stack", |
151 | " tau&32 -> current transition is a preselected move", |
152 | " tau&64 -> at least one next state is not on the stack", |
153 | " tau&128 -> current transition is a stutter move", |
154 | |
155 | " o_pm&1 -> the current pid moved -- implements else", |
156 | " o_pm&2 -> this is an acceptance state", |
157 | " o_pm&4 -> this is a progress state", |
158 | " o_pm&8 -> fairness alg rule 1 undo mark", |
159 | " o_pm&16 -> fairness alg rule 3 undo mark", |
160 | " o_pm&32 -> fairness alg rule 2 undo mark", |
161 | " o_pm&64 -> the current proc applied rule2", |
162 | " o_pm&128 -> a fairness, dummy move - all procs blocked", |
163 | "#endif", |
164 | "#ifdef NSUCC", |
165 | " uchar n_succ; /* nr of successor states */", |
166 | "#endif", |
167 | "#if defined(FULLSTACK) && defined(MA) && !defined(BFS)", |
168 | " uchar proviso;", |
169 | "#endif", |
170 | "#ifndef BFS", |
171 | " uchar o_n, o_ot; /* to save locals */", |
172 | "#endif", |
173 | " uchar o_m;", |
174 | "#ifdef EVENT_TRACE", |
175 | "#if nstates_event<256", |
176 | " uchar o_event;", |
177 | "#else", |
178 | " unsigned short o_event;", |
179 | "#endif", |
180 | "#endif", |
181 | " int o_tt;", |
182 | "#ifndef BFS", |
183 | " short o_To;", |
184 | "#ifdef RANDOMIZE", |
185 | " short oo_i;", |
186 | "#endif", |
187 | "#endif", |
188 | "#if defined(HAS_UNLESS) && !defined(BFS)", |
189 | " int e_state; /* if escape trans - state of origin */", |
190 | "#endif", |
191 | "#if (defined(FULLSTACK) && !defined(MA)) || defined(BFS) || (NCORE>1)", |
192 | " struct H_el *ostate; /* pointer to stored state */", |
193 | "#endif", |
194 | /* CNTRSTACK when !NOREDUCE && BITSTATE && SAFETY, uses LL[] */ |
195 | "#if defined(CNTRSTACK) && !defined(BFS)", |
196 | " long j6, j7;", |
197 | "#endif", |
198 | " Trans *o_t;", /* transition fct, next state */ |
199 | "#ifdef SCHED", |
200 | " /* based on Qadeer&Rehof, Tacas 2005, LNCS 3440, pp. 93-107 */", |
201 | " #if NCORE>1", |
202 | " #error \"-DSCHED cannot be combined with -DNCORE (yet)\"", |
203 | " #endif", |
204 | " int sched_limit;", |
205 | "#endif", |
206 | "#ifdef HAS_SORTED", |
207 | " short ipt;", /* insertion slot in q */ |
208 | "#endif", |
209 | " union {", |
210 | " int oval;", /* single backup value of variable */ |
211 | " int *ovals;", /* ptr to multiple values */ |
212 | " } bup;", |
213 | "} Trail;", |
214 | "Trail *trail, *trpt;", |
215 | |
216 | "FILE *efd;", |
217 | "uchar *this;", |
218 | "long maxdepth=10000;", |
219 | "long omaxdepth=10000;", |
220 | "#ifdef SCHED", |
221 | "int sched_max = 10;", |
222 | "#endif", |
223 | "#ifdef PERMUTED", |
224 | " uchar permuted = 1;", |
225 | "#else", |
226 | " uchar permuted = 0;", |
227 | "#endif", |
228 | "double quota; /* time limit */", |
229 | "#if NCORE>1", |
230 | "long z_handoff = -1;", |
231 | "#endif", |
232 | "#ifdef SC", /* stack cycling */ |
233 | "char *stackfile;", |
234 | "#endif", |
235 | "uchar *SS, *LL;", |
236 | "uchar HASH_NR = 0;", |
237 | "", |
238 | "double memcnt = (double) 0;", |
239 | "double memlim = (double) (1<<30); /* 1 GB */", |
240 | "#if NCORE>1", |
241 | "double mem_reserved = (double) 0;", |
242 | "#endif", |
243 | "", |
244 | "/* for emalloc: */", |
245 | "static char *have;", |
246 | "static long left = 0L;", |
247 | "static double fragment = (double) 0;", |
248 | "static unsigned long grow;", |
249 | "", |
250 | "unsigned int HASH_CONST[] = {", |
251 | " /* asuming 4 bytes per int */", |
252 | " 0x88888EEF, 0x00400007,", |
253 | " 0x04c11db7, 0x100d4e63,", |
254 | " 0x0fc22f87, 0x3ff0c3ff,", |
255 | " 0x38e84cd7, 0x02b148e9,", |
256 | " 0x98b2e49d, 0xb616d379,", |
257 | " 0xa5247fd9, 0xbae92a15,", |
258 | " 0xb91c8bc5, 0x8e5880f3,", |
259 | " 0xacd7c069, 0xb4c44bb3,", |
260 | " 0x2ead1fb7, 0x8e428171,", |
261 | " 0xdbebd459, 0x828ae611,", |
262 | " 0x6cb25933, 0x86cdd651,", |
263 | " 0x9e8f5f21, 0xd5f8d8e7,", |
264 | " 0x9c4e956f, 0xb5cf2c71,", |
265 | " 0x2e805a6d, 0x33fc3a55,", |
266 | " 0xaf203ed1, 0xe31f5909,", |
267 | " 0x5276db35, 0x0c565ef7,", |
268 | " 0x273d1aa5, 0x8923b1dd,", |
269 | " 0", |
270 | "};", |
271 | "#if NCORE>1", |
272 | "extern int core_id;", |
273 | "#endif", |
274 | "long mreached=0;", |
275 | "int done=0, errors=0, Nrun=1;", |
276 | "int c_init_done=0;", |
277 | "char *c_stack_start = (char *) 0;", |
278 | "double nstates=0, nlinks=0, truncs=0, truncs2=0;", |
279 | "double nlost=0, nShadow=0, hcmp=0, ngrabs=0;", |
280 | "#if defined(ZAPH) && defined(BITSTATE)", |
281 | "double zstates = 0;", |
282 | "#endif", |
283 | "int c_init_run;", |
284 | "#ifdef BFS", |
285 | "double midrv=0, failedrv=0, revrv=0;", |
286 | "#endif", |
287 | "unsigned long nr_states=0; /* nodes in DFA */", |
288 | "long Fa=0, Fh=0, Zh=0, Zn=0;", |
289 | "long PUT=0, PROBE=0, ZAPS=0;", |
290 | "long Ccheck=0, Cholds=0;", |
291 | "int a_cycles=0, upto=1, strict=0, verbose = 0, signoff = 0;", |
292 | "#ifdef HAS_CODE", |
293 | "int gui = 0, coltrace = 0, readtrail = 0;", |
294 | "int whichtrail = 0, onlyproc = -1, silent = 0;", |
295 | "#endif", |
296 | "int state_tables=0, fairness=0, no_rck=0, Nr_Trails=0;", |
297 | "char simvals[128];", |
298 | "#ifndef INLINE", |
299 | "int TstOnly=0;", |
300 | "#endif", |
301 | "unsigned long mask, nmask;", |
302 | "#ifdef BITSTATE", |
303 | "int ssize=23; /* 1 Mb */", |
304 | "#else", |
305 | "int ssize=19; /* 512K slots */", |
306 | "#endif", |
307 | "int hmax=0, svmax=0, smax=0;", |
308 | "int Maxbody=0, XX;", |
309 | "uchar *noptr; /* used by macro Pptr(x) */", |
310 | "#ifdef VAR_RANGES", |
311 | "void logval(char *, int);", |
312 | "void dumpranges(void);", |
313 | "#endif", |
314 | |
315 | "#ifdef MA", |
316 | "#define INLINE_REV", |
317 | "extern void dfa_init(unsigned short);", |
318 | "extern int dfa_member(unsigned long);", |
319 | "extern int dfa_store(uchar *);", |
320 | "unsigned int maxgs = 0;", |
321 | "#endif", |
322 | "", |
323 | "#ifdef ALIGNED", |
324 | " State comp_now __attribute__ ((aligned (8)));", |
325 | " /* gcc 64-bit aligned for Itanium2 systems */", |
326 | " /* MAJOR runtime penalty if not used on those systems */", |
327 | "#else", |
328 | " State comp_now; /* compressed state vector */", |
329 | "#endif", |
330 | "", |
331 | "State comp_msk;", |
332 | "uchar *Mask = (uchar *) &comp_msk;", |
333 | "#ifdef COLLAPSE", |
334 | "State comp_tmp;", |
335 | "static char *scratch = (char *) &comp_tmp;", |
336 | "#endif", |
337 | |
338 | "Stack *stack; /* for queues, processes */", |
339 | "Svtack *svtack; /* for old state vectors */", |
340 | "#ifdef BITSTATE", |
341 | "static unsigned int hfns = 3; /* new default */", |
342 | "#endif", |
343 | "static unsigned long j1;", |
344 | "static unsigned long K1, K2;", |
345 | "static unsigned long j2, j3, j4;", |
346 | "#ifdef BITSTATE", |
347 | #ifndef POWOW |
348 | "static long udmem;", |
349 | #endif |
350 | "#endif", |
351 | "static long A_depth = 0;", |
352 | "long depth = 0;", |
353 | /* depth: not static to support -S2, but possible clash with embedded code */ |
354 | "#if NCORE>1", |
355 | "long nr_handoffs = 0;", |
356 | "#endif", |
357 | "static uchar warned = 0, iterative = 0, exclusive = 0, like_java = 0, every_error = 0;", |
358 | "static uchar noasserts = 0, noends = 0, bounded = 0;", |
359 | "#if SYNC>0 && ASYNC==0", |
360 | "void set_recvs(void);", |
361 | "int no_recvs(int);", |
362 | "#endif", |
363 | "#if SYNC", |
364 | "#define IfNotBlocked if (boq != -1) continue;", |
365 | "#define UnBlock boq = -1", |
366 | "#else", |
367 | "#define IfNotBlocked /* cannot block */", |
368 | "#define UnBlock /* don't bother */", |
369 | "#endif\n", |
370 | "#ifdef BITSTATE", |
371 | "int (*bstore)(char *, int);", |
372 | "int bstore_reg(char *, int);", |
373 | #ifndef POWOW |
374 | "int bstore_mod(char *, int);", |
375 | #endif |
376 | "#endif", |
377 | "void active_procs(void);", |
378 | "void cleanup(void);", |
379 | "void do_the_search(void);", |
380 | "void find_shorter(int);", |
381 | "void iniglobals(void);", |
382 | "void stopped(int);", |
383 | "void wrapup(void);", |
384 | "int *grab_ints(int);", |
385 | "void ungrab_ints(int *, int);", |
386 | 0, |
387 | }; |
388 | |
389 | static char *Tail[] = { |
390 | "Trans *", |
391 | "settr( int t_id, int a, int b, int c, int d,", |
392 | " char *t, int g, int tpe0, int tpe1)", |
393 | "{ Trans *tmp = (Trans *) emalloc(sizeof(Trans));\n", |
394 | " tmp->atom = a&(6|32); /* only (2|8|32) have meaning */", |
395 | " if (!g) tmp->atom |= 8; /* no global references */", |
396 | " tmp->st = b;", |
397 | " tmp->tpe[0] = tpe0;", |
398 | " tmp->tpe[1] = tpe1;", |
399 | " tmp->tp = t;", |
400 | " tmp->t_id = t_id;", |
401 | " tmp->forw = c;", |
402 | " tmp->back = d;", |
403 | " return tmp;", |
404 | "}\n", |
405 | "Trans *", |
406 | "cpytr(Trans *a)", |
407 | "{ Trans *tmp = (Trans *) emalloc(sizeof(Trans));\n", |
408 | " int i;", |
409 | " tmp->atom = a->atom;", |
410 | " tmp->st = a->st;", |
411 | "#ifdef HAS_UNLESS", |
412 | " tmp->e_trans = a->e_trans;", |
413 | " for (i = 0; i < HAS_UNLESS; i++)", |
414 | " tmp->escp[i] = a->escp[i];", |
415 | "#endif", |
416 | " tmp->tpe[0] = a->tpe[0];", |
417 | " tmp->tpe[1] = a->tpe[1];", |
418 | " for (i = 0; i < 6; i++)", |
419 | " { tmp->qu[i] = a->qu[i];", |
420 | " tmp->ty[i] = a->ty[i];", |
421 | " }", |
422 | " tmp->tp = (char *) emalloc(strlen(a->tp)+1);", |
423 | " strcpy(tmp->tp, a->tp);", |
424 | " tmp->t_id = a->t_id;", |
425 | " tmp->forw = a->forw;", |
426 | " tmp->back = a->back;", |
427 | " return tmp;", |
428 | "}\n", |
429 | "#ifndef NOREDUCE", |
430 | "int", |
431 | "srinc_set(int n)", |
432 | "{ if (n <= 2) return LOCAL;", |
433 | " if (n <= 2+ DELTA) return Q_FULL_F; /* 's' or nfull */", |
434 | " if (n <= 2+2*DELTA) return Q_EMPT_F; /* 'r' or nempty */", |
435 | " if (n <= 2+3*DELTA) return Q_EMPT_T; /* empty */", |
436 | " if (n <= 2+4*DELTA) return Q_FULL_T; /* full */", |
437 | " if (n == 5*DELTA) return GLOBAL;", |
438 | " if (n == 6*DELTA) return TIMEOUT_F;", |
439 | " if (n == 7*DELTA) return ALPHA_F;", |
440 | " Uerror(\"cannot happen srinc_class\");", |
441 | " return BAD;", |
442 | "}", |
443 | "int", |
444 | "srunc(int n, int m)", |
445 | "{ switch(m) {", |
446 | " case Q_FULL_F: return n-2;", |
447 | " case Q_EMPT_F: return n-2-DELTA;", |
448 | " case Q_EMPT_T: return n-2-2*DELTA;", |
449 | " case Q_FULL_T: return n-2-3*DELTA;", |
450 | " case ALPHA_F:", |
451 | " case TIMEOUT_F: return 257; /* non-zero, and > MAXQ */", |
452 | " }", |
453 | " Uerror(\"cannot happen srunc\");", |
454 | " return 0;", |
455 | "}", |
456 | "#endif", |
457 | "int cnt;", |
458 | "#ifdef HAS_UNLESS", |
459 | "int", |
460 | "isthere(Trans *a, int b)", /* is b already in a's list? */ |
461 | "{ Trans *t;", |
462 | " for (t = a; t; t = t->nxt)", |
463 | " if (t->t_id == b)", |
464 | " return 1;", |
465 | " return 0;", |
466 | "}", |
467 | "#endif", |
468 | "#ifndef NOREDUCE", |
469 | "int", |
470 | "mark_safety(Trans *t) /* for conditional safety */", |
471 | "{ int g = 0, i, j, k;", |
472 | "", |
473 | " if (!t) return 0;", |
474 | " if (t->qu[0])", |
475 | " return (t->qu[1])?2:1; /* marked */", |
476 | "", |
477 | " for (i = 0; i < 2; i++)", |
478 | " { j = srinc_set(t->tpe[i]);", |
479 | " if (j >= GLOBAL && j != ALPHA_F)", |
480 | " return -1;", |
481 | " if (j != LOCAL)", |
482 | " { k = srunc(t->tpe[i], j);", |
483 | " if (g == 0", |
484 | " || t->qu[0] != k", |
485 | " || t->ty[0] != j)", |
486 | " { t->qu[g] = k;", |
487 | " t->ty[g] = j;", |
488 | " g++;", |
489 | " } } }", |
490 | " return g;", |
491 | "}", |
492 | "#endif", |
493 | "void", |
494 | "retrans(int n, int m, int is, short srcln[], uchar reach[], uchar lstate[])", |
495 | " /* process n, with m states, is=initial state */", |
496 | "{ Trans *T0, *T1, *T2, *T3;", |
497 | " int i, k;", |
498 | "#ifndef NOREDUCE", |
499 | " int g, h, j, aa;", |
500 | "#endif", |
501 | "#ifdef HAS_UNLESS", |
502 | " int p;", |
503 | "#endif", |
504 | " if (state_tables >= 4)", |
505 | " { printf(\"STEP 1 proctype %%s\\n\", ", |
506 | " procname[n]);", |
507 | " for (i = 1; i < m; i++)", |
508 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
509 | " crack(n, i, T0, srcln);", |
510 | " return;", |
511 | " }", |
512 | " do {", |
513 | " for (i = 1, cnt = 0; i < m; i++)", |
514 | " { T2 = trans[n][i];", |
515 | " T1 = T2?T2->nxt:(Trans *)0;", |
516 | "/* prescan: */ for (T0 = T1; T0; T0 = T0->nxt)", |
517 | "/* choice in choice */ { if (T0->st && trans[n][T0->st]", |
518 | " && trans[n][T0->st]->nxt)", |
519 | " break;", |
520 | " }", |
521 | "#if 0", |
522 | " if (T0)", |
523 | " printf(\"\\tstate %%d / %%d: choice in choice\\n\",", |
524 | " i, T0->st);", |
525 | "#endif", |
526 | " if (T0)", |
527 | " for (T0 = T1; T0; T0 = T0->nxt)", |
528 | " { T3 = trans[n][T0->st];", |
529 | " if (!T3->nxt)", |
530 | " { T2->nxt = cpytr(T0);", |
531 | " T2 = T2->nxt;", |
532 | " imed(T2, T0->st, n, i);", |
533 | " continue;", |
534 | " }", |
535 | " do { T3 = T3->nxt;", |
536 | " T2->nxt = cpytr(T3);", |
537 | " T2 = T2->nxt;", |
538 | " imed(T2, T0->st, n, i);", |
539 | " } while (T3->nxt);", |
540 | " cnt++;", |
541 | " }", |
542 | " }", |
543 | " } while (cnt);", |
544 | |
545 | " if (state_tables >= 3)", |
546 | " { printf(\"STEP 2 proctype %%s\\n\", ", |
547 | " procname[n]);", |
548 | " for (i = 1; i < m; i++)", |
549 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
550 | " crack(n, i, T0, srcln);", |
551 | " return;", |
552 | " }", |
553 | " for (i = 1; i < m; i++)", |
554 | " { if (trans[n][i] && trans[n][i]->nxt) /* optimize */", |
555 | " { T1 = trans[n][i]->nxt;", |
556 | "#if 0", |
557 | " printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",", |
558 | " T1->st, T1->forw, i);", |
559 | "#endif", |
560 | " if (!trans[n][T1->st]) continue;", |
561 | " T0 = cpytr(trans[n][T1->st]);", |
562 | " trans[n][i] = T0;", |
563 | " reach[T1->st] = 1;", |
564 | " imed(T0, T1->st, n, i);", |
565 | " for (T1 = T1->nxt; T1; T1 = T1->nxt)", |
566 | " {", |
567 | "#if 0", |
568 | " printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",", |
569 | " T1->st, T1->forw, i);", |
570 | "#endif", |
571 | " if (!trans[n][T1->st]) continue;", |
572 | " T0->nxt = cpytr(trans[n][T1->st]);", |
573 | " T0 = T0->nxt;", |
574 | " reach[T1->st] = 1;", |
575 | " imed(T0, T1->st, n, i);", |
576 | " } } }", |
577 | " if (state_tables >= 2)", |
578 | " { printf(\"STEP 3 proctype %%s\\n\", ", |
579 | " procname[n]);", |
580 | " for (i = 1; i < m; i++)", |
581 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
582 | " crack(n, i, T0, srcln);", |
583 | " return;", |
584 | " }", |
585 | "#ifdef HAS_UNLESS", |
586 | " for (i = 1; i < m; i++)", |
587 | " { if (!trans[n][i]) continue;", |
588 | " /* check for each state i if an", |
589 | " * escape to some state p is defined", |
590 | " * if so, copy and mark p's transitions", |
591 | " * and prepend them to the transition-", |
592 | " * list of state i", |
593 | " */", |
594 | " if (!like_java) /* the default */", |
595 | " { for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
596 | " for (k = HAS_UNLESS-1; k >= 0; k--)", |
597 | " { if (p = T0->escp[k])", |
598 | " for (T1 = trans[n][p]; T1; T1 = T1->nxt)", |
599 | " { if (isthere(trans[n][i], T1->t_id))", |
600 | " continue;", |
601 | " T2 = cpytr(T1);", |
602 | " T2->e_trans = p;", |
603 | " T2->nxt = trans[n][i];", |
604 | " trans[n][i] = T2;", |
605 | " } }", |
606 | " } else /* outermost unless checked first */", |
607 | " { Trans *T4;", |
608 | " T4 = T3 = (Trans *) 0;", |
609 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
610 | " for (k = HAS_UNLESS-1; k >= 0; k--)", |
611 | " { if (p = T0->escp[k])", |
612 | " for (T1 = trans[n][p]; T1; T1 = T1->nxt)", |
613 | " { if (isthere(trans[n][i], T1->t_id))", |
614 | " continue;", |
615 | " T2 = cpytr(T1);", |
616 | " T2->nxt = (Trans *) 0;", |
617 | " T2->e_trans = p;", |
618 | " if (T3) T3->nxt = T2;", |
619 | " else T4 = T2;", |
620 | " T3 = T2;", |
621 | " } }", |
622 | " if (T4)", |
623 | " { T3->nxt = trans[n][i];", |
624 | " trans[n][i] = T4;", |
625 | " }", |
626 | " }", |
627 | " }", |
628 | "#endif", |
629 | |
630 | "#ifndef NOREDUCE", |
631 | " for (i = 1; i < m; i++)", |
632 | " { if (a_cycles)", |
633 | " { /* moves through these states are visible */", |
634 | " #if PROG_LAB>0 && defined(HAS_NP)", |
635 | " if (progstate[n][i])", |
636 | " goto degrade;", |
637 | " for (T1 = trans[n][i]; T1; T1 = T1->nxt)", |
638 | " if (progstate[n][T1->st])", |
639 | " goto degrade;", |
640 | " #endif", |
641 | " if (accpstate[n][i] || visstate[n][i])", |
642 | " goto degrade;", |
643 | " for (T1 = trans[n][i]; T1; T1 = T1->nxt)", |
644 | " if (accpstate[n][T1->st])", |
645 | " goto degrade;", |
646 | " }", |
647 | " T1 = trans[n][i];", |
648 | " if (!T1) continue;", |
649 | " g = mark_safety(T1); /* V3.3.1 */", |
650 | " if (g < 0) goto degrade; /* global */", |
651 | " /* check if mixing of guards preserves reduction */", |
652 | " if (T1->nxt)", |
653 | " { k = 0;", |
654 | " for (T0 = T1; T0; T0 = T0->nxt)", |
655 | " { if (!(T0->atom&8))", |
656 | " goto degrade;", |
657 | " for (aa = 0; aa < 2; aa++)", |
658 | " { j = srinc_set(T0->tpe[aa]);", |
659 | " if (j >= GLOBAL && j != ALPHA_F)", |
660 | " goto degrade;", |
661 | " if (T0->tpe[aa]", |
662 | " && T0->tpe[aa]", |
663 | " != T1->tpe[0])", |
664 | " k = 1;", |
665 | " } }", |
666 | " /* g = 0; V3.3.1 */", |
667 | " if (k) /* non-uniform selection */", |
668 | " for (T0 = T1; T0; T0 = T0->nxt)", |
669 | " for (aa = 0; aa < 2; aa++)", |
670 | " { j = srinc_set(T0->tpe[aa]);", |
671 | " if (j != LOCAL)", |
672 | " { k = srunc(T0->tpe[aa], j);", |
673 | " for (h = 0; h < 6; h++)", |
674 | " if (T1->qu[h] == k", |
675 | " && T1->ty[h] == j)", |
676 | " break;", |
677 | " if (h >= 6)", |
678 | " { T1->qu[g%%6] = k;", |
679 | " T1->ty[g%%6] = j;", |
680 | " g++;", |
681 | " } } }", |
682 | " if (g > 6)", |
683 | " { T1->qu[0] = 0; /* turn it off */", |
684 | " printf(\"pan: warning, line %%d, \",", |
685 | " srcln[i]);", |
686 | " printf(\"too many stmnt types (%%d)\",", |
687 | " g);", |
688 | " printf(\" in selection\\n\");", |
689 | " goto degrade;", |
690 | " }", |
691 | " }", |
692 | " /* mark all options global if >=1 is global */", |
693 | " for (T1 = trans[n][i]; T1; T1 = T1->nxt)", |
694 | " if (!(T1->atom&8)) break;", |
695 | " if (T1)", |
696 | "degrade: for (T1 = trans[n][i]; T1; T1 = T1->nxt)", |
697 | " T1->atom &= ~8; /* mark as unsafe */", |
698 | |
699 | " /* can only mix 'r's or 's's if on same chan */", |
700 | " /* and not mixed with other local operations */", |
701 | " T1 = trans[n][i];", |
702 | |
703 | " if (!T1 || T1->qu[0]) continue;", |
704 | |
705 | " j = T1->tpe[0];", |
706 | " if (T1->nxt && T1->atom&8)", |
707 | " { if (j == 5*DELTA)", |
708 | " { printf(\"warning: line %%d \", srcln[i]);", |
709 | " printf(\"mixed condition \");", |
710 | " printf(\"(defeats reduction)\\n\");", |
711 | " goto degrade;", |
712 | " }", |
713 | " for (T0 = T1; T0; T0 = T0->nxt)", |
714 | " for (aa = 0; aa < 2; aa++)", |
715 | " if (T0->tpe[aa] && T0->tpe[aa] != j)", |
716 | " { printf(\"warning: line %%d \", srcln[i]);", |
717 | " printf(\"[%%d-%%d] mixed %%stion \",", |
718 | " T0->tpe[aa], j, ", |
719 | " (j==5*DELTA)?\"condi\":\"selec\");", |
720 | " printf(\"(defeats reduction)\\n\");", |
721 | " printf(\" '%%s' <-> '%%s'\\n\",", |
722 | " T1->tp, T0->tp);", |
723 | " goto degrade;", |
724 | " } }", |
725 | " }", |
726 | "#endif", |
727 | " for (i = 1; i < m; i++)", /* R */ |
728 | " { T2 = trans[n][i];", |
729 | " if (!T2", |
730 | " || T2->nxt", |
731 | " || strncmp(T2->tp, \".(goto)\", 7)", |
732 | " || !stopstate[n][i])", |
733 | " continue;", |
734 | " stopstate[n][T2->st] = 1;", |
735 | " }", |
736 | " if (state_tables)", |
737 | " { printf(\"proctype \");", |
738 | " if (!strcmp(procname[n], \":init:\"))", |
739 | " printf(\"init\\n\");", |
740 | " else", |
741 | " printf(\"%%s\\n\", procname[n]);", |
742 | " for (i = 1; i < m; i++)", |
743 | " reach[i] = 1;", |
744 | " tagtable(n, m, is, srcln, reach);", |
745 | " } else", |
746 | " for (i = 1; i < m; i++)", |
747 | " { int nrelse;", |
748 | " if (strcmp(procname[n], \":never:\") != 0)", |
749 | " { for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
750 | " { if (T0->st == i", |
751 | " && strcmp(T0->tp, \"(1)\") == 0)", |
752 | " { printf(\"error: proctype '%%s' \",", |
753 | " procname[n]);", |
754 | " printf(\"line %%d, state %%d: has un\",", |
755 | " srcln[i], i);", |
756 | " printf(\"conditional self-loop\\n\");", |
757 | " pan_exit(1);", |
758 | " } } }", |
759 | " nrelse = 0;", |
760 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
761 | " { if (strcmp(T0->tp, \"else\") == 0)", |
762 | " nrelse++;", |
763 | " }", |
764 | " if (nrelse > 1)", |
765 | " { printf(\"error: proctype '%%s' state\",", |
766 | " procname[n]);", |
767 | " printf(\" %%d, inherits %%d\", i, nrelse);", |
768 | " printf(\" 'else' stmnts\\n\");", |
769 | " pan_exit(1);", |
770 | " } }", |
771 | " if (!state_tables && strcmp(procname[n], \":never:\") == 0)", |
772 | " { int h = 0;", |
773 | " for (i = 1; i < m; i++)", |
774 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
775 | " if (T0->forw > h) h = T0->forw;", |
776 | " h++;", |
777 | " frm_st0 = (short *) emalloc(h * sizeof(short));", |
778 | " for (i = 1; i < m; i++)", |
779 | " for (T0 = trans[n][i]; T0; T0 = T0->nxt)", |
780 | " frm_st0[T0->forw] = i;", |
781 | " }", |
782 | "#ifndef LOOPSTATE", |
783 | " if (state_tables)", |
784 | "#endif", |
785 | " do_dfs(n, m, is, srcln, reach, lstate);", |
786 | "#ifdef T_REVERSE", |
787 | " /* process n, with m states, is=initial state -- reverse list */", |
788 | " if (!state_tables && strcmp(procname[n], \":never:\") != 0)", |
789 | " { for (i = 1; i < m; i++)", /* for each state */ |
790 | " { Trans *T4 = (Trans *) 0;", |
791 | " T1 = (Trans *) 0;", /* points to reversed list */ |
792 | " T2 = (Trans *) 0;", /* points to first entry */ |
793 | " T3 = (Trans *) 0;", /* remembers any else */ |
794 | " for (T0 = trans[n][i]; T0; T0 = T4)", |
795 | " { T4 = T0->nxt;", |
796 | " if (strcmp(T0->tp, \"else\") == 0)", |
797 | " { T3 = T0;", |
798 | " T0->nxt = (Trans *) 0;", |
799 | " } else", |
800 | " { T0->nxt = T1;", |
801 | " if (!T1) { T2 = T0; }", |
802 | " T1 = T0;", |
803 | " } }", |
804 | " if (T2 && T3) { T2->nxt = T3; }", /* at the end */ |
805 | " trans[n][i] = T1; /* reversed -- else at end */", |
806 | " } }", |
807 | "#endif", |
808 | "}", |
809 | "void", |
810 | "imed(Trans *T, int v, int n, int j) /* set intermediate state */", |
811 | "{ progstate[n][T->st] |= progstate[n][v];", |
812 | " accpstate[n][T->st] |= accpstate[n][v];", |
813 | " stopstate[n][T->st] |= stopstate[n][v];", |
814 | " mapstate[n][j] = T->st;", |
815 | "}", |
816 | "void", |
817 | "tagtable(int n, int m, int is, short srcln[], uchar reach[])", |
818 | "{ Trans *z;\n", |
819 | " if (is >= m || !trans[n][is]", |
820 | " || is <= 0 || reach[is] == 0)", |
821 | " return;", |
822 | " reach[is] = 0;", |
823 | " if (state_tables)", |
824 | " for (z = trans[n][is]; z; z = z->nxt)", |
825 | " crack(n, is, z, srcln);", |
826 | " for (z = trans[n][is]; z; z = z->nxt)", |
827 | " {", |
828 | "#ifdef HAS_UNLESS", |
829 | " int i, j;", |
830 | "#endif", |
831 | " tagtable(n, m, z->st, srcln, reach);", |
832 | "#ifdef HAS_UNLESS", |
833 | " for (i = 0; i < HAS_UNLESS; i++)", |
834 | " { j = trans[n][is]->escp[i];", |
835 | " if (!j) break;", |
836 | " tagtable(n, m, j, srcln, reach);", |
837 | " }", |
838 | "#endif", |
839 | " }", |
840 | "}", |
841 | "void", |
842 | "dfs_table(int n, int m, int is, short srcln[], uchar reach[], uchar lstate[])", |
843 | "{ Trans *z;\n", |
844 | " if (is >= m || is <= 0 || !trans[n][is])", |
845 | " return;", |
846 | " if ((reach[is] & (4|8|16)) != 0)", |
847 | " { if ((reach[is] & (8|16)) == 16) /* on stack, not yet recorded */", |
848 | " { lstate[is] = 1;", |
849 | " reach[is] |= 8; /* recorded */", |
850 | " if (state_tables)", |
851 | " { printf(\"state %%d line %%d is a loopstate\\n\", is, srcln[is]);", |
852 | " } }", |
853 | " return;", |
854 | " }", |
855 | " reach[is] |= (4|16); /* visited | onstack */", |
856 | " for (z = trans[n][is]; z; z = z->nxt)", |
857 | " {", |
858 | "#ifdef HAS_UNLESS", |
859 | " int i, j;", |
860 | "#endif", |
861 | " dfs_table(n, m, z->st, srcln, reach, lstate);", |
862 | "#ifdef HAS_UNLESS", |
863 | " for (i = 0; i < HAS_UNLESS; i++)", |
864 | " { j = trans[n][is]->escp[i];", |
865 | " if (!j) break;", |
866 | " dfs_table(n, m, j, srcln, reach, lstate);", |
867 | " }", |
868 | "#endif", |
869 | " }", |
870 | " reach[is] &= ~16; /* no longer on stack */", |
871 | "}", |
872 | "void", |
873 | "do_dfs(int n, int m, int is, short srcln[], uchar reach[], uchar lstate[])", |
874 | "{ int i;", |
875 | " dfs_table(n, m, is, srcln, reach, lstate);", |
876 | " for (i = 0; i < m; i++)", |
877 | " reach[i] &= ~(4|8|16);", |
878 | "}", |
879 | "void", |
880 | "crack(int n, int j, Trans *z, short srcln[])", |
881 | "{ int i;\n", |
882 | " if (!z) return;", |
883 | " printf(\"\tstate %%3d -(tr %%3d)-> state %%3d \",", |
884 | " j, z->forw, z->st);", |
885 | " printf(\"[id %%3d tp %%3d\", z->t_id, z->tpe[0]);", |
886 | " if (z->tpe[1]) printf(\",%%d\", z->tpe[1]);", |
887 | "#ifdef HAS_UNLESS", |
888 | " if (z->e_trans)", |
889 | " printf(\" org %%3d\", z->e_trans);", |
890 | " else if (state_tables >= 2)", |
891 | " for (i = 0; i < HAS_UNLESS; i++)", |
892 | " { if (!z->escp[i]) break;", |
893 | " printf(\" esc %%d\", z->escp[i]);", |
894 | " }", |
895 | "#endif", |
896 | " printf(\"]\");", |
897 | " printf(\" [%%s%%s%%s%%s%%s] line %%d => \",", |
898 | " z->atom&6?\"A\":z->atom&32?\"D\":\"-\",", |
899 | " accpstate[n][j]?\"a\" :\"-\",", |
900 | " stopstate[n][j]?\"e\" : \"-\",", |
901 | " progstate[n][j]?\"p\" : \"-\",", |
902 | " z->atom & 8 ?\"L\":\"G\",", |
903 | " srcln[j]);", |
904 | " for (i = 0; z->tp[i]; i++)", |
905 | " if (z->tp[i] == \'\\n\')", |
906 | " printf(\"\\\\n\");", |
907 | " else", |
908 | " putchar(z->tp[i]);", |
909 | " if (z->qu[0])", |
910 | " { printf(\"\\t[\");", |
911 | " for (i = 0; i < 6; i++)", |
912 | " if (z->qu[i])", |
913 | " printf(\"(%%d,%%d)\",", |
914 | " z->qu[i], z->ty[i]);", |
915 | " printf(\"]\");", |
916 | " }", |
917 | " printf(\"\\n\");", |
918 | " fflush(stdout);", |
919 | "}", |
920 | "", |
921 | "#ifdef VAR_RANGES", |
922 | "#define BYTESIZE 32 /* 2^8 : 2^3 = 256:8 = 32 */", |
923 | "", |
924 | "typedef struct Vr_Ptr {", |
925 | " char *nm;", |
926 | " uchar vals[BYTESIZE];", |
927 | " struct Vr_Ptr *nxt;", |
928 | "} Vr_Ptr;", |
929 | "Vr_Ptr *ranges = (Vr_Ptr *) 0;", |
930 | "", |
931 | "void", |
932 | "logval(char *s, int v)", |
933 | "{ Vr_Ptr *tmp;", |
934 | "", |
935 | " if (v<0 || v > 255) return;", |
936 | " for (tmp = ranges; tmp; tmp = tmp->nxt)", |
937 | " if (!strcmp(tmp->nm, s))", |
938 | " goto found;", |
939 | " tmp = (Vr_Ptr *) emalloc(sizeof(Vr_Ptr));", |
940 | " tmp->nxt = ranges;", |
941 | " ranges = tmp;", |
942 | " tmp->nm = s;", |
943 | "found:", |
944 | " tmp->vals[(v)/8] |= 1<<((v)%%8);", |
945 | "}", |
946 | "", |
947 | "void", |
948 | "dumpval(uchar X[], int range)", |
949 | "{ int w, x, i, j = -1;", |
950 | "", |
951 | " for (w = i = 0; w < range; w++)", |
952 | " for (x = 0; x < 8; x++, i++)", |
953 | " {", |
954 | "from: if ((X[w] & (1<<x)))", |
955 | " { printf(\"%%d\", i);", |
956 | " j = i;", |
957 | " goto upto;", |
958 | " } }", |
959 | " return;", |
960 | " for (w = 0; w < range; w++)", |
961 | " for (x = 0; x < 8; x++, i++)", |
962 | " {", |
963 | "upto: if (!(X[w] & (1<<x)))", |
964 | " { if (i-1 == j)", |
965 | " printf(\", \");", |
966 | " else", |
967 | " printf(\"-%%d, \", i-1);", |
968 | " goto from;", |
969 | " } }", |
970 | " if (j >= 0 && j != 255)", |
971 | " printf(\"-255\");", |
972 | "}", |
973 | "", |
974 | "void", |
975 | "dumpranges(void)", |
976 | "{ Vr_Ptr *tmp;", |
977 | " printf(\"\\nValues assigned within \");", |
978 | " printf(\"interval [0..255]:\\n\");", |
979 | " for (tmp = ranges; tmp; tmp = tmp->nxt)", |
980 | " { printf(\"\\t%%s\\t: \", tmp->nm);", |
981 | " dumpval(tmp->vals, BYTESIZE);", |
982 | " printf(\"\\n\");", |
983 | " }", |
984 | "}", |
985 | "#endif", |
986 | 0, |
987 | }; |