pangen2.h 23 KB

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