1 /***** spin: pangen2.h *****/
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 */
13 static char *Nvr1
[] = { /* allow separate compilation */
16 "check_claim(int st)",
18 " if (st == endclaim)",
19 " uerror(\"claim violated!\");",
20 " if (stopstate[VERI][st])",
21 " uerror(\"end state in claim reached\");",
27 static char *Pre0
[] = {
29 "#define _FILE_OFFSET_BITS 64", /* to allow file sizes greater than 2Gb */
32 "#include <signal.h>",
33 "#include <stdlib.h>",
34 "#include <stdarg.h>",
35 "#include <string.h>",
38 "#if defined(WIN32) || defined(WIN64)",
41 "#include <unistd.h>",
42 "#include <sys/times.h>",
44 "#include <sys/types.h>", /* defines off_t */
45 "#include <sys/stat.h>",
48 "#define Offsetof(X, Y) ((unsigned long)(&(((X *)0)->Y)))",
50 "#define max(a,b) (((a)<(b)) ? (b) : (a))",
53 "int Printf(const char *fmt, ...); /* prototype only */",
58 static char *Preamble
[] = {
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]--",
66 "#if !defined(SAFETY) && !defined(NOCOMP)",
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
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))",
86 "#define onstack_put() ;",
87 "#define onstack_zap() gstore((char *) &now, vsize, 4)",
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; \\",
99 "#ifndef NO_V_PROVISO",
102 "#if !defined(NO_RESIZE) && !defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(SPACE) && NCORE==1",
103 " #define AUTO_RESIZE",
107 " struct H_el *nxt;",
109 " unsigned int tagged;",
110 " #if defined(BITSTATE) && !defined(NOREDUCE) && !defined(SAFETY)",
111 " unsigned int proviso;", /* uses just 1 bit 0/1 */
114 "#if defined(CHECK) || (defined(COLLAPSE) && !defined(FULLSTACK))",
115 " unsigned long st_id;",
117 "#if !defined(SAFETY) || defined(REACH)",
121 " /* could cost 1 extra word: 4 bytes if 32-bit and 8 bytes if 64-bit */",
123 " uchar cpu_id; /* id of cpu that created the state */",
127 " #if VECTORSZ<65536",
128 " unsigned short ln;", /* length of vector */
130 " unsigned long ln;", /* length of vector */
133 "#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
134 " unsigned long m_K1;",
136 " unsigned long state;",
137 "} **H_tab, **S_Tab;\n",
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 */",
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",
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",
165 " uchar n_succ; /* nr of successor states */",
167 "#if defined(FULLSTACK) && defined(MA) && !defined(BFS)",
171 " uchar o_n, o_ot; /* to save locals */",
174 "#ifdef EVENT_TRACE",
175 "#if nstates_event<256",
178 " unsigned short o_event;",
188 "#if defined(HAS_UNLESS) && !defined(BFS)",
189 " int e_state; /* if escape trans - state of origin */",
191 "#if (defined(FULLSTACK) && !defined(MA)) || defined(BFS) || (NCORE>1)",
192 " struct H_el *ostate; /* pointer to stored state */",
194 /* CNTRSTACK when !NOREDUCE && BITSTATE && SAFETY, uses LL[] */
195 "#if defined(CNTRSTACK) && !defined(BFS)",
198 " Trans *o_t;", /* transition fct, next state */
200 " /* based on Qadeer&Rehof, Tacas 2005, LNCS 3440, pp. 93-107 */",
202 " #error \"-DSCHED cannot be combined with -DNCORE (yet)\"",
207 " short ipt;", /* insertion slot in q */
210 " int oval;", /* single backup value of variable */
211 " int *ovals;", /* ptr to multiple values */
214 "Trail *trail, *trpt;",
218 "long maxdepth=10000;",
219 "long omaxdepth=10000;",
221 "int sched_max = 10;",
224 " uchar permuted = 1;",
226 " uchar permuted = 0;",
228 "double quota; /* time limit */",
230 "long z_handoff = -1;",
232 "#ifdef SC", /* stack cycling */
236 "uchar HASH_NR = 0;",
238 "double memcnt = (double) 0;",
239 "double memlim = (double) (1<<30); /* 1 GB */",
241 "double mem_reserved = (double) 0;",
244 "/* for emalloc: */",
245 "static char *have;",
246 "static long left = 0L;",
247 "static double fragment = (double) 0;",
248 "static unsigned long grow;",
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,",
272 "extern int core_id;",
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;",
285 "double midrv=0, failedrv=0, revrv=0;",
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;",
293 "int gui = 0, coltrace = 0, readtrail = 0;",
294 "int whichtrail = 0, onlyproc = -1, silent = 0;",
296 "int state_tables=0, fairness=0, no_rck=0, Nr_Trails=0;",
297 "char simvals[128];",
301 "unsigned long mask, nmask;",
303 "int ssize=23; /* 1 Mb */",
305 "int ssize=19; /* 512K slots */",
307 "int hmax=0, svmax=0, smax=0;",
308 "int Maxbody=0, XX;",
309 "uchar *noptr; /* used by macro Pptr(x) */",
311 "void logval(char *, int);",
312 "void dumpranges(void);",
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;",
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 */",
328 " State comp_now; /* compressed state vector */",
332 "uchar *Mask = (uchar *) &comp_msk;",
335 "static char *scratch = (char *) &comp_tmp;",
338 "Stack *stack; /* for queues, processes */",
339 "Svtack *svtack; /* for old state vectors */",
341 "static unsigned int hfns = 3; /* new default */",
343 "static unsigned long j1;",
344 "static unsigned long K1, K2;",
345 "static unsigned long j2, j3, j4;",
348 "static long udmem;",
351 "static long A_depth = 0;",
353 /* depth: not static to support -S2, but possible clash with embedded code */
355 "long nr_handoffs = 0;",
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);",
364 "#define IfNotBlocked if (boq != -1) continue;",
365 "#define UnBlock boq = -1",
367 "#define IfNotBlocked /* cannot block */",
368 "#define UnBlock /* don't bother */",
371 "int (*bstore)(char *, int);",
372 "int bstore_reg(char *, int);",
374 "int bstore_mod(char *, int);",
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);",
389 static char *Tail
[] = {
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 */",
397 " tmp->tpe[0] = tpe0;",
398 " tmp->tpe[1] = tpe1;",
400 " tmp->t_id = t_id;",
407 "{ Trans *tmp = (Trans *) emalloc(sizeof(Trans));\n",
409 " tmp->atom = a->atom;",
412 " tmp->e_trans = a->e_trans;",
413 " for (i = 0; i < HAS_UNLESS; i++)",
414 " tmp->escp[i] = a->escp[i];",
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];",
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;",
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\");",
444 "srunc(int n, int 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;",
451 " case TIMEOUT_F: return 257; /* non-zero, and > MAXQ */",
453 " Uerror(\"cannot happen srunc\");",
460 "isthere(Trans *a, int b)", /* is b already in a's list? */
462 " for (t = a; t; t = t->nxt)",
463 " if (t->t_id == b)",
470 "mark_safety(Trans *t) /* for conditional safety */",
471 "{ int g = 0, i, j, k;",
473 " if (!t) return 0;",
475 " return (t->qu[1])?2:1; /* marked */",
477 " for (i = 0; i < 2; i++)",
478 " { j = srinc_set(t->tpe[i]);",
479 " if (j >= GLOBAL && j != ALPHA_F)",
482 " { k = srunc(t->tpe[i], j);",
485 " || t->ty[0] != j)",
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;",
504 " if (state_tables >= 4)",
505 " { printf(\"STEP 1 proctype %%s\\n\", ",
507 " for (i = 1; i < m; i++)",
508 " for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
509 " crack(n, i, T0, srcln);",
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)",
523 " printf(\"\\tstate %%d / %%d: choice in choice\\n\",",
527 " for (T0 = T1; T0; T0 = T0->nxt)",
528 " { T3 = trans[n][T0->st];",
530 " { T2->nxt = cpytr(T0);",
532 " imed(T2, T0->st, n, i);",
535 " do { T3 = T3->nxt;",
536 " T2->nxt = cpytr(T3);",
538 " imed(T2, T0->st, n, i);",
539 " } while (T3->nxt);",
545 " if (state_tables >= 3)",
546 " { printf(\"STEP 2 proctype %%s\\n\", ",
548 " for (i = 1; i < m; i++)",
549 " for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
550 " crack(n, i, T0, srcln);",
553 " for (i = 1; i < m; i++)",
554 " { if (trans[n][i] && trans[n][i]->nxt) /* optimize */",
555 " { T1 = trans[n][i]->nxt;",
557 " printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",",
558 " T1->st, T1->forw, i);",
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)",
568 " printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",",
569 " T1->st, T1->forw, i);",
571 " if (!trans[n][T1->st]) continue;",
572 " T0->nxt = cpytr(trans[n][T1->st]);",
574 " reach[T1->st] = 1;",
575 " imed(T0, T1->st, n, i);",
577 " if (state_tables >= 2)",
578 " { printf(\"STEP 3 proctype %%s\\n\", ",
580 " for (i = 1; i < m; i++)",
581 " for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
582 " crack(n, i, T0, srcln);",
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",
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))",
603 " T2->nxt = trans[n][i];",
604 " trans[n][i] = T2;",
606 " } else /* outermost unless checked first */",
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))",
616 " T2->nxt = (Trans *) 0;",
618 " if (T3) T3->nxt = T2;",
623 " { T3->nxt = trans[n][i];",
624 " trans[n][i] = T4;",
631 " for (i = 1; i < m; i++)",
633 " { /* moves through these states are visible */",
634 " #if PROG_LAB>0 && defined(HAS_NP)",
635 " if (progstate[n][i])",
637 " for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
638 " if (progstate[n][T1->st])",
641 " if (accpstate[n][i] || visstate[n][i])",
643 " for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
644 " if (accpstate[n][T1->st])",
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 */",
654 " for (T0 = T1; T0; T0 = T0->nxt)",
655 " { if (!(T0->atom&8))",
657 " for (aa = 0; aa < 2; aa++)",
658 " { j = srinc_set(T0->tpe[aa]);",
659 " if (j >= GLOBAL && j != ALPHA_F)",
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]);",
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)",
678 " { T1->qu[g%%6] = k;",
679 " T1->ty[g%%6] = j;",
683 " { T1->qu[0] = 0; /* turn it off */",
684 " printf(\"pan: warning, line %%d, \",",
686 " printf(\"too many stmnt types (%%d)\",",
688 " printf(\" in selection\\n\");",
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;",
696 "degrade: for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
697 " T1->atom &= ~8; /* mark as unsafe */",
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];",
703 " if (!T1 || T1->qu[0]) continue;",
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\");",
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 \",",
719 " (j==5*DELTA)?\"condi\":\"selec\");",
720 " printf(\"(defeats reduction)\\n\");",
721 " printf(\" '%%s' <-> '%%s'\\n\",",
727 " for (i = 1; i < m; i++)", /* R */
728 " { T2 = trans[n][i];",
731 " || strncmp(T2->tp, \".(goto)\", 7)",
732 " || !stopstate[n][i])",
734 " stopstate[n][T2->st] = 1;",
736 " if (state_tables)",
737 " { printf(\"proctype \");",
738 " if (!strcmp(procname[n], \":init:\"))",
739 " printf(\"init\\n\");",
741 " printf(\"%%s\\n\", procname[n]);",
742 " for (i = 1; i < m; i++)",
744 " tagtable(n, m, is, srcln, reach);",
746 " for (i = 1; i < m; i++)",
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' \",",
754 " printf(\"line %%d, state %%d: has un\",",
756 " printf(\"conditional self-loop\\n\");",
760 " for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
761 " { if (strcmp(T0->tp, \"else\") == 0)",
765 " { printf(\"error: proctype '%%s' state\",",
767 " printf(\" %%d, inherits %%d\", i, nrelse);",
768 " printf(\" 'else' stmnts\\n\");",
771 " if (!state_tables && strcmp(procname[n], \":never:\") == 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;",
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;",
783 " if (state_tables)",
785 " do_dfs(n, m, is, srcln, reach, lstate);",
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)",
796 " if (strcmp(T0->tp, \"else\") == 0)",
798 " T0->nxt = (Trans *) 0;",
801 " if (!T1) { T2 = T0; }",
804 " if (T2 && T3) { T2->nxt = T3; }", /* at the end */
805 " trans[n][i] = T1; /* reversed -- else at end */",
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;",
817 "tagtable(int n, int m, int is, short srcln[], uchar reach[])",
819 " if (is >= m || !trans[n][is]",
820 " || is <= 0 || 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)",
831 " tagtable(n, m, z->st, srcln, reach);",
833 " for (i = 0; i < HAS_UNLESS; i++)",
834 " { j = trans[n][is]->escp[i];",
836 " tagtable(n, m, j, srcln, reach);",
842 "dfs_table(int n, int m, int is, short srcln[], uchar reach[], uchar lstate[])",
844 " if (is >= m || is <= 0 || !trans[n][is])",
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]);",
855 " reach[is] |= (4|16); /* visited | onstack */",
856 " for (z = trans[n][is]; z; z = z->nxt)",
861 " dfs_table(n, m, z->st, srcln, reach, lstate);",
863 " for (i = 0; i < HAS_UNLESS; i++)",
864 " { j = trans[n][is]->escp[i];",
866 " dfs_table(n, m, j, srcln, reach, lstate);",
870 " reach[is] &= ~16; /* no longer on stack */",
873 "do_dfs(int n, int m, int is, short srcln[], uchar reach[], uchar lstate[])",
875 " dfs_table(n, m, is, srcln, reach, lstate);",
876 " for (i = 0; i < m; i++)",
877 " reach[i] &= ~(4|8|16);",
880 "crack(int n, int j, Trans *z, short srcln[])",
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]);",
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]);",
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\",",
904 " for (i = 0; z->tp[i]; i++)",
905 " if (z->tp[i] == \'\\n\')",
906 " printf(\"\\\\n\");",
908 " putchar(z->tp[i]);",
910 " { printf(\"\\t[\");",
911 " for (i = 0; i < 6; i++)",
913 " printf(\"(%%d,%%d)\",",
914 " z->qu[i], z->ty[i]);",
922 "#define BYTESIZE 32 /* 2^8 : 2^3 = 256:8 = 32 */",
924 "typedef struct Vr_Ptr {",
926 " uchar vals[BYTESIZE];",
927 " struct Vr_Ptr *nxt;",
929 "Vr_Ptr *ranges = (Vr_Ptr *) 0;",
932 "logval(char *s, int v)",
935 " if (v<0 || v > 255) return;",
936 " for (tmp = ranges; tmp; tmp = tmp->nxt)",
937 " if (!strcmp(tmp->nm, s))",
939 " tmp = (Vr_Ptr *) emalloc(sizeof(Vr_Ptr));",
940 " tmp->nxt = ranges;",
944 " tmp->vals[(v)/8] |= 1<<((v)%%8);",
948 "dumpval(uchar X[], int range)",
949 "{ int w, x, i, j = -1;",
951 " for (w = i = 0; w < range; w++)",
952 " for (x = 0; x < 8; x++, i++)",
954 "from: if ((X[w] & (1<<x)))",
955 " { printf(\"%%d\", i);",
960 " for (w = 0; w < range; w++)",
961 " for (x = 0; x < 8; x++, i++)",
963 "upto: if (!(X[w] & (1<<x)))",
967 " printf(\"-%%d, \", i-1);",
970 " if (j >= 0 && j != 255)",
971 " printf(\"-255\");",
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);",
This page took 0.093117 seconds and 4 git commands to generate.