pangen3.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /***** spin: pangen3.h *****/
  2. /* Copyright (c) 1991-2000 by Lucent Technologies - Bell Laboratories */
  3. /* All Rights Reserved. This software is for educational purposes only. */
  4. /* Permission is given to distribute this code provided that this intro- */
  5. /* ductory message is not removed and no monies are exchanged. */
  6. /* No guarantee is expressed or implied by the distribution of this code. */
  7. /* Software written by Gerard J. Holzmann as part of the book: */
  8. /* `Design and Validation of Computer Protocols,' ISBN 0-13-539925-4, */
  9. /* Prentice Hall, Englewood Cliffs, NJ, 07632. */
  10. /* Send bug-reports and/or questions to: gerard@research.bell-labs.com */
  11. static char *Head0[] = {
  12. "#ifdef VERI",
  13. "#define BASE 1",
  14. "#else",
  15. "#define BASE 0",
  16. "#endif",
  17. "typedef struct Trans {",
  18. " short atom; /* if &2 = atomic trans; if &8 local */",
  19. " short st; /* the nextstate */",
  20. "#ifdef HAS_UNLESS",
  21. " short escp[HAS_UNLESS]; /* lists the escape states */",
  22. " short e_trans; /* if set, this is an escp-trans */",
  23. "#endif",
  24. " short tpe[2]; /* class of operation (for reduction) */",
  25. " short qu[6]; /* for conditional selections: qid's */",
  26. " uchar ty[6]; /* ditto: type's */",
  27. "#ifdef NIBIS",
  28. " short om; /* completion status of preselects */",
  29. "#endif",
  30. " char *tp; /* src txt of statement */",
  31. " int t_id; /* transition id, unique within proc */",
  32. " int forw; /* index forward transition */",
  33. " int back; /* index return transition */",
  34. " struct Trans *nxt;",
  35. "} Trans;\n",
  36. "#define qptr(x) (((uchar *)&now)+q_offset[x])",
  37. "#define pptr(x) (((uchar *)&now)+proc_offset[x])",
  38. /* "#define Pptr(x) ((proc_offset[x])?pptr(x):noptr)", */
  39. "extern uchar *Pptr(int);",
  40. "#define q_sz(x) (((Q0 *)qptr(x))->Qlen)\n",
  41. "#ifndef VECTORSZ",
  42. "#define VECTORSZ 1024 /* sv size in bytes */",
  43. "#endif\n",
  44. 0,
  45. };
  46. static char *Header[] = {
  47. "#ifdef VERBOSE",
  48. "#define CHECK",
  49. "#define DEBUG",
  50. "#endif",
  51. "#ifdef SAFETY",
  52. "#ifndef NOFAIR",
  53. "#define NOFAIR",
  54. "#endif",
  55. "#endif",
  56. "#ifdef NOREDUCE",
  57. "#define XUSAFE",
  58. "#if !defined(SAFETY) && !defined(MA)",
  59. "#define FULLSTACK",
  60. "#endif",
  61. "#else",
  62. "#ifdef BITSTATE",
  63. "#ifdef SAFETY",
  64. "#define CNTRSTACK",
  65. "#else",
  66. "#define FULLSTACK",
  67. "#endif",
  68. "#else",
  69. "#define FULLSTACK",
  70. "#endif",
  71. "#endif",
  72. "#ifdef BITSTATE",
  73. "#define NOCOMP",
  74. "#if !defined(LC) && defined(SC)",
  75. "#define LC",
  76. "#endif",
  77. "#endif",
  78. "#ifndef MEMCNT",
  79. "#ifdef PC",
  80. "#define MEMCNT 25 /* 32 Mb */",
  81. "#else",
  82. "#define MEMCNT 28",
  83. "#endif",
  84. "#endif",
  85. "#if defined(COLLAPSE2) || defined(COLLAPSE3) || defined(COLLAPSE4)",
  86. "/* accept the above for backward compatibility */",
  87. "#define COLLAPSE",
  88. "#endif",
  89. "#ifdef HC",
  90. "#define HC2",
  91. "#endif",
  92. "#ifdef HC0", /* 32 bits */
  93. "#define HC 0",
  94. "#endif",
  95. "#ifdef HC1", /* 32+8 bits */
  96. "#define HC 1",
  97. "#endif",
  98. "#ifdef HC2", /* 32+16 bits */
  99. "#define HC 2",
  100. "#endif",
  101. "#ifdef HC3", /* 32+24 bits */
  102. "#define HC 3",
  103. "#endif",
  104. "#ifdef HC4", /* 32+32 bits - combine with -DMA=8 */
  105. "#define HC 4",
  106. "#endif",
  107. "#ifdef COLLAPSE",
  108. "unsigned long ncomps[256+2];",
  109. "#endif",
  110. "#define MAXQ 255",
  111. "#define MAXPROC 255",
  112. "#define WS sizeof(long) /* word size in bytes */",
  113. "typedef struct Stack { /* for queues and processes */",
  114. "#if VECTORSZ>32000",
  115. " int o_delta;",
  116. " int o_offset;",
  117. " int o_skip;",
  118. " int o_delqs;",
  119. "#else",
  120. " short o_delta;",
  121. " short o_offset;",
  122. " short o_skip;",
  123. " short o_delqs;",
  124. "#endif",
  125. " short o_boq;",
  126. "#ifndef XUSAFE",
  127. " char *o_name;",
  128. "#endif",
  129. " char *body;",
  130. " struct Stack *nxt;",
  131. " struct Stack *lst;",
  132. "} Stack;\n",
  133. "typedef struct Svtack { /* for complete state vector */",
  134. "#if VECTORSZ>32000",
  135. " int o_delta;",
  136. " int m_delta;",
  137. "#else",
  138. " short o_delta; /* current size of frame */",
  139. " short m_delta; /* maximum size of frame */",
  140. "#endif",
  141. "#if SYNC",
  142. " short o_boq;",
  143. "#endif",
  144. " char *body;",
  145. " struct Svtack *nxt;",
  146. " struct Svtack *lst;",
  147. "} Svtack;\n",
  148. "Trans ***trans; /* 1 ptr per state per proctype */\n",
  149. "#if defined(FULLSTACK)",
  150. "struct H_el *Lstate;",
  151. "#endif",
  152. "int depthfound = -1; /* loop detection */",
  153. "int proc_offset[MAXPROC], proc_skip[MAXPROC];",
  154. "int q_offset[MAXQ], q_skip[MAXQ];",
  155. "#if VECTORSZ<65536",
  156. " unsigned short vsize;",
  157. "#else",
  158. " unsigned long vsize; /* vector size in bytes */",
  159. "#endif",
  160. "#ifdef SVDUMP",
  161. "int vprefix=0, svfd; /* runtime option -pN */",
  162. "#endif",
  163. "char *tprefix = \"trail\"; /* runtime option -tsuffix */",
  164. "short boq = -1; /* blocked_on_queue status */",
  165. 0,
  166. };
  167. static char *Head1[] = {
  168. "typedef struct State {",
  169. " uchar _nr_pr;",
  170. " uchar _nr_qs;",
  171. " uchar _a_t; /* cycle detection */",
  172. #if 0
  173. in _a_t: bits 0,4, and 5 =(1|16|32) are set during a 2nd dfs
  174. bit 1 is used as the A-bit for fairness
  175. bit 7 (128) is the proviso bit, for reduced 2nd dfs (acceptance)
  176. #endif
  177. "#ifndef NOFAIR",
  178. " uchar _cnt[NFAIR]; /* counters, weak fairness */",
  179. "#endif",
  180. "#ifndef NOVSZ",
  181. #ifdef SOLARIS
  182. "#if 0",
  183. /* v3.4
  184. * noticed alignment problems with some Solaris
  185. * compilers, if widest field isn't wordsized
  186. */
  187. #else
  188. "#if VECTORSZ<65536",
  189. #endif
  190. " unsigned short _vsz;",
  191. "#else",
  192. " unsigned long _vsz;",
  193. "#endif",
  194. "#endif",
  195. "#ifdef HAS_LAST", /* cannot go before _cnt - see hstore() */
  196. " uchar _last; /* pid executed in last step */",
  197. "#endif",
  198. "#ifdef EVENT_TRACE",
  199. "#if nstates_event<256",
  200. " uchar _event;",
  201. "#else",
  202. " unsigned short _event;",
  203. "#endif",
  204. "#endif",
  205. 0,
  206. };
  207. static char *Addp0[] = {
  208. /* addproc(....parlist... */ ")",
  209. "{ int k, j, h = now._nr_pr;",
  210. " uchar *o_this = this;\n",
  211. "#ifndef INLINE",
  212. " if (TstOnly) return (h < MAXPROC);",
  213. "#endif",
  214. "#ifndef NOBOUNDCHECK",
  215. "/* redefine Index only within this procedure */",
  216. "#undef Index",
  217. "#define Index(x, y) Boundcheck(x, y, 0, 0, 0)",
  218. "#endif",
  219. " if (h >= MAXPROC)",
  220. " Uerror(\"too many processes\");",
  221. " switch (n) {",
  222. " case 0: j = sizeof(P0); break;",
  223. 0,
  224. };
  225. static char *Addp1[] = {
  226. " default: Uerror(\"bad proc - addproc\");",
  227. " }",
  228. " if (vsize%%WS)",
  229. " proc_skip[h] = WS-(vsize%%WS);",
  230. " else",
  231. " proc_skip[h] = 0;",
  232. "#ifndef NOCOMP",
  233. " for (k = vsize + proc_skip[h]; k > vsize; k--)",
  234. " Mask[k-1] = 1; /* align */",
  235. "#endif",
  236. " vsize += proc_skip[h];",
  237. " proc_offset[h] = vsize;",
  238. "#ifdef SVDUMP",
  239. " if (vprefix > 0)",
  240. " { int dummy = 0;",
  241. " write(svfd, (uchar *) &dummy, sizeof(int)); /* mark */",
  242. " write(svfd, (uchar *) &h, sizeof(int));",
  243. " write(svfd, (uchar *) &n, sizeof(int));",
  244. " write(svfd, (uchar *) &proc_offset[h], sizeof(int));",
  245. " write(svfd, (uchar *) &now, vprefix-4*sizeof(int)); /* padd */",
  246. " }",
  247. "#endif",
  248. " now._nr_pr += 1;",
  249. " if (fairness && ((int) now._nr_pr + 1 >= (8*NFAIR)/2))",
  250. " { printf(\"Error: too many processes -- current\");",
  251. " printf(\" max is %%d procs (-DNFAIR=%%d)\\n\",",
  252. " (8*NFAIR)/2 - 2, NFAIR);",
  253. " printf(\"\\trecompile with -DNFAIR=%%d\\n\",",
  254. " NFAIR+1);",
  255. " exit(1);",
  256. " }",
  257. " vsize += j;",
  258. "#ifndef NOVSZ",
  259. " now._vsz = vsize;",
  260. "#endif",
  261. "#ifndef NOCOMP",
  262. " for (k = 1; k <= Air[n]; k++)",
  263. " Mask[vsize - k] = 1; /* pad */",
  264. " Mask[vsize-j] = 1; /* _pid */",
  265. "#endif",
  266. " hmax = max(hmax, vsize);",
  267. " if (vsize >= VECTORSZ)",
  268. " { printf(\"pan: error, VECTORSZ too small, recompile pan.c\");",
  269. " printf(\" with -DVECTORSZ=N with N>%%d\\n\", vsize);",
  270. " Uerror(\"aborting\");",
  271. " }",
  272. " memset((char *)pptr(h), 0, j);",
  273. " this = pptr(h);",
  274. " if (BASE > 0 && h > 0)",
  275. " ((P0 *)this)->_pid = h-BASE;",
  276. " else",
  277. " ((P0 *)this)->_pid = h;",
  278. " switch (n) {",
  279. 0,
  280. };
  281. static char *Addq0[] = {
  282. "int",
  283. "addqueue(int n, int is_rv)",
  284. "{ int j=0, i = now._nr_qs, k;\n",
  285. " if (i >= MAXQ)",
  286. " Uerror(\"too many queues\");",
  287. " switch (n) {",
  288. 0,
  289. };
  290. static char *Addq1[] = {
  291. " default: Uerror(\"bad queue - addqueue\");",
  292. " }",
  293. " if (vsize%%WS)",
  294. " q_skip[i] = WS-(vsize%%WS);",
  295. " else",
  296. " q_skip[i] = 0;",
  297. "#ifndef NOCOMP",
  298. " k = vsize; if (is_rv) k += j;",
  299. " for (k += q_skip[i]; k > vsize; k--)",
  300. " Mask[k-1] = 1; /* align */",
  301. "#endif",
  302. " vsize += q_skip[i];",
  303. " q_offset[i] = vsize;",
  304. " now._nr_qs += 1;",
  305. " vsize += j;",
  306. "#ifndef NOVSZ",
  307. " now._vsz = vsize;",
  308. "#endif",
  309. " hmax = max(hmax, vsize);",
  310. " if (vsize >= VECTORSZ)",
  311. " Uerror(\"VECTORSZ is too small, edit pan.h\");",
  312. " memset((char *)qptr(i), 0, j);",
  313. " ((Q0 *)qptr(i))->_t = n;",
  314. " return i+1;",
  315. "}\n",
  316. 0,
  317. };
  318. static char *Addq11[] = {
  319. "{ int j, k; uchar *z;\n",
  320. " if (!into--)",
  321. " uerror(\"ref to uninitialized chan name (sending)\");",
  322. " if (into >= (int) now._nr_qs || into < 0)",
  323. " Uerror(\"qsend bad queue#\");",
  324. " z = qptr(into);",
  325. " j = ((Q0 *)qptr(into))->Qlen;",
  326. " switch (((Q0 *)qptr(into))->_t) {",
  327. 0,
  328. };
  329. static char *Addq2[] = {
  330. " case 0: printf(\"queue %%d was deleted\\n\", into+1);",
  331. " default: Uerror(\"bad queue - qsend\");",
  332. " }",
  333. "#ifdef EVENT_TRACE",
  334. " if (in_s_scope(into+1))",
  335. " require('s', into);",
  336. "#endif",
  337. "}\n",
  338. "#if SYNC",
  339. "int",
  340. "q_zero(int from)",
  341. "{ if (!from--)",
  342. " uerror(\"ref to uninitialized chan name (q_zero)\");",
  343. " switch(((Q0 *)qptr(from))->_t) {",
  344. 0,
  345. };
  346. static char *Addq3[] = {
  347. " case 0: printf(\"queue %%d was deleted\\n\", from+1);",
  348. " }",
  349. " Uerror(\"bad queue q-zero\");",
  350. "}",
  351. "int",
  352. "not_RV(int from)",
  353. "{ if (q_zero(from))",
  354. " { printf(\"==>> a test of the contents of a rv \");",
  355. " printf(\"channel always returns FALSE\\n\");",
  356. " uerror(\"error to poll rendezvous channel\");",
  357. " }",
  358. " return 1;",
  359. "}",
  360. "#endif",
  361. "#ifndef XUSAFE",
  362. "void",
  363. "setq_claim(int x, int m, char *s, int y, char *p)",
  364. "{ if (x == 0)",
  365. " uerror(\"x[rs] claim on uninitialized channel\");",
  366. " if (x < 0 || x > MAXQ)",
  367. " Uerror(\"cannot happen setq_claim\");",
  368. " q_claim[x] |= m;",
  369. " p_name[y] = p;",
  370. " q_name[x] = s;",
  371. " if (m&2) q_S_check(x, y);",
  372. " if (m&1) q_R_check(x, y);",
  373. "}",
  374. "short q_sender[MAXQ+1];",
  375. "int",
  376. "q_S_check(int x, int who)",
  377. "{ if (!q_sender[x])",
  378. " { q_sender[x] = who+1;",
  379. "#if SYNC",
  380. " if (q_zero(x))",
  381. " { printf(\"chan %%s (%%d), \",",
  382. " q_name[x], x-1);",
  383. " printf(\"sndr proc %%s (%%d)\\n\",",
  384. " p_name[who], who);",
  385. " uerror(\"xs chans cannot be used for rv\");",
  386. " }",
  387. "#endif",
  388. " } else",
  389. " if (q_sender[x] != who+1)",
  390. " { printf(\"pan: xs assertion violated: \");",
  391. " printf(\"access to chan <%%s> (%%d)\\npan: by \",",
  392. " q_name[x], x-1);",
  393. " printf(\"%%s (proc %%d) and by %%s (proc %%d)\\n\",",
  394. " p_name[q_sender[x]-1], q_sender[x]-1,",
  395. " p_name[who], who);",
  396. " uerror(\"error, partial order reduction invalid\");",
  397. " }",
  398. " return 1;",
  399. "}",
  400. "short q_recver[MAXQ+1];",
  401. "int",
  402. "q_R_check(int x, int who)",
  403. "{ if (!q_recver[x])",
  404. " { q_recver[x] = who+1;",
  405. "#if SYNC",
  406. " if (q_zero(x))",
  407. " { printf(\"chan %%s (%%d), \",",
  408. " q_name[x], x-1);",
  409. " printf(\"recv proc %%s (%%d)\\n\",",
  410. " p_name[who], who);",
  411. " uerror(\"xr chans cannot be used for rv\");",
  412. " }",
  413. "#endif",
  414. " } else",
  415. " if (q_recver[x] != who+1)",
  416. " { printf(\"pan: xr assertion violated: \");",
  417. " printf(\"access to chan %%s (%%d)\\n\",",
  418. " q_name[x], x-1);",
  419. " printf(\"pan: by %%s (proc %%d) \",",
  420. " p_name[q_recver[x]-1], q_recver[x]-1);",
  421. " printf(\"and by %%s (proc %%d)\\n\",",
  422. " p_name[who], who);",
  423. " uerror(\"error, partial order reduction invalid\");",
  424. " }",
  425. " return 1;",
  426. "}",
  427. "#endif",
  428. "int",
  429. "q_len(int x)",
  430. "{ if (!x--)",
  431. " uerror(\"ref to uninitialized chan name (len)\");",
  432. " return ((Q0 *)qptr(x))->Qlen;",
  433. "}\n",
  434. "int",
  435. "q_full(int from)",
  436. "{ if (!from--)",
  437. " uerror(\"ref to uninitialized chan name (qfull)\");",
  438. " switch(((Q0 *)qptr(from))->_t) {",
  439. 0,
  440. };
  441. static char *Addq4[] = {
  442. " case 0: printf(\"queue %%d was deleted\\n\", from+1);",
  443. " }",
  444. " Uerror(\"bad queue - q_full\");",
  445. " return 0;",
  446. "}\n",
  447. "#ifdef HAS_UNLESS",
  448. "int",
  449. "q_e_f(int from)",
  450. "{ /* empty or full */",
  451. " return !q_len(from) || q_full(from);",
  452. "}",
  453. "#endif",
  454. "int",
  455. "qrecv(int from, int slot, int fld, int done)",
  456. "{ uchar *z;",
  457. " int j, k, r=0;\n",
  458. " if (!from--)",
  459. " uerror(\"ref to uninitialized chan name (receiving)\");",
  460. " if (from >= (int) now._nr_qs || from < 0)",
  461. " Uerror(\"qrecv bad queue#\");",
  462. " z = qptr(from);",
  463. "#ifdef EVENT_TRACE",
  464. " if (done && (in_r_scope(from+1)))",
  465. " require('r', from);",
  466. "#endif",
  467. " switch (((Q0 *)qptr(from))->_t) {",
  468. 0,
  469. };
  470. static char *Addq5[] = {
  471. " case 0: printf(\"queue %%d was deleted\\n\", from+1);",
  472. " default: Uerror(\"bad queue - qrecv\");",
  473. " }",
  474. " return r;",
  475. "}\n",
  476. "#ifndef BITSTATE",
  477. "#ifdef COLLAPSE",
  478. "long",
  479. "col_q(int i, char *z)",
  480. "{ int j, k;",
  481. " char *x, *y;",
  482. " Q0 *ptr = (Q0 *) qptr(i);",
  483. " switch (ptr->_t) {",
  484. 0,
  485. };
  486. static char *Code0[] = {
  487. "void",
  488. "run(void)",
  489. "{ int i;",
  490. " memset((char *)&now, 0, sizeof(State));",
  491. " vsize = sizeof(State) - VECTORSZ;",
  492. "#ifndef NOVSZ",
  493. " now._vsz = vsize;",
  494. "#endif",
  495. "/* optional provisioning statements, e.g. to */",
  496. "/* set hidden variables, used as constants */",
  497. "#ifdef PROV",
  498. "#include PROV",
  499. "#endif",
  500. " settable();",
  501. 0,
  502. };
  503. static char *R0[] = {
  504. " Maxbody = max(Maxbody, sizeof(P%d));",
  505. " reached[%d] = reached%d;",
  506. " accpstate[%d] = (uchar *) emalloc(nstates%d);",
  507. " progstate[%d] = (uchar *) emalloc(nstates%d);",
  508. " stopstate[%d] = (uchar *) emalloc(nstates%d);",
  509. " visstate[%d] = (uchar *) emalloc(nstates%d);",
  510. " stopstate[%d][endstate%d] = 1;",
  511. 0,
  512. };
  513. static char *R0a[] = {
  514. " retrans(%d, nstates%d, start%d, src_ln%d, reached%d);",
  515. 0,
  516. };
  517. static char *R0b[] = {
  518. " if (state_tables)",
  519. " { printf(\"\\nTransition Type: \");",
  520. " printf(\"A=atomic; D=d_step; L=local; G=global\\n\");",
  521. " printf(\"Source-State Labels: \");",
  522. " printf(\"p=progress; e=end; a=accept;\\n\");",
  523. "#ifdef MERGED",
  524. " printf(\"Note: statement merging was used. Only the first\\n\");",
  525. " printf(\" stmnt executed in each merge sequence is shown\\n\");",
  526. " printf(\" (use spin -a -o3 to disable statement merging)\\n\");",
  527. "#endif",
  528. " exit(0);",
  529. " }",
  530. 0,
  531. };
  532. static char *Code1[] = {
  533. "#ifdef NP",
  534. "#define ACCEPT_LAB 1 /* at least 1 in np_ */",
  535. "#else",
  536. "#define ACCEPT_LAB %d /* user-defined accept labels */",
  537. "#endif",
  538. 0,
  539. };
  540. static char *Code3[] = {
  541. "#define PROG_LAB %d /* progress labels */",
  542. 0,
  543. };
  544. static char *R2[] = {
  545. "uchar *accpstate[%d];",
  546. "uchar *progstate[%d];",
  547. "uchar *reached[%d];",
  548. "uchar *stopstate[%d];",
  549. "uchar *visstate[%d];",
  550. 0,
  551. };
  552. static char *R3[] = {
  553. " Maxbody = max(Maxbody, sizeof(Q%d));",
  554. 0,
  555. };
  556. static char *R4[] = {
  557. " r_ck(reached%d, nstates%d, %d, src_ln%d, src_file%d);",
  558. 0,
  559. };
  560. static char *R5[] = {
  561. " case %d: j = sizeof(P%d); break;",
  562. 0,
  563. };
  564. static char *R6[] = {
  565. " }",
  566. " this = o_this;",
  567. " return h-BASE;",
  568. "#ifndef NOBOUNDCHECK",
  569. "#undef Index",
  570. "#define Index(x, y) Boundcheck(x, y, II, tt, t)",
  571. "#endif",
  572. "}\n",
  573. "#if defined(BITSTATE) && defined(COLLAPSE)",
  574. "/* just to allow compilation, to generate the error */",
  575. "long col_p(int i, char *z) { return 0; }",
  576. "long col_q(int i, char *z) { return 0; }",
  577. "#endif",
  578. "#ifndef BITSTATE",
  579. "#ifdef COLLAPSE",
  580. "long",
  581. "col_p(int i, char *z)",
  582. "{ int j, k; unsigned long ordinal(char *, long, short);",
  583. " char *x, *y;",
  584. " P0 *ptr = (P0 *) pptr(i);",
  585. " switch (ptr->_t) {",
  586. " case 0: j = sizeof(P0); break;",
  587. 0,
  588. };
  589. static char *R8a[] = {
  590. " default: Uerror(\"bad proctype - collapse\");",
  591. " }",
  592. " if (z) x = z; else x = scratch;",
  593. " y = (char *) ptr; k = proc_offset[i];",
  594. " for ( ; j > 0; j--, y++)",
  595. " if (!Mask[k++]) *x++ = *y;",
  596. " if (z) return (long) (x - z);",
  597. " for (j = 0; j < WS-1; j++)",
  598. " *x++ = 0;",
  599. " x -= j;",
  600. " return ordinal(scratch, x-scratch, 2+ptr->_t);",
  601. "}",
  602. "#endif",
  603. "#endif",
  604. 0,
  605. };
  606. static char *R8b[] = {
  607. " default: Uerror(\"bad qtype - collapse\");",
  608. " }",
  609. " if (z) x = z; else x = scratch;",
  610. " y = (char *) ptr; k = q_offset[i];",
  611. " /* no need to store the empty slots at the end */",
  612. " j -= (q_max[ptr->_t] - ptr->Qlen) * ((j - 2)/q_max[ptr->_t]);",
  613. " for ( ; j > 0; j--, y++)",
  614. " if (!Mask[k++]) *x++ = *y;",
  615. " if (z) return (long) (x - z);",
  616. " for (j = 0; j < WS-1; j++)",
  617. " *x++ = 0;",
  618. " x -= j;",
  619. " return ordinal(scratch, x-scratch, 1); /* chan */",
  620. "}",
  621. "#endif",
  622. "#endif",
  623. 0,
  624. };
  625. static char *R9[] = {
  626. "typedef struct Q%d {",
  627. " uchar Qlen; /* q_size */",
  628. " uchar _t; /* q_type */",
  629. " struct {",
  630. 0,
  631. };
  632. static char *R10[] = {
  633. "typedef struct Q0 {\t/* generic q */",
  634. " uchar Qlen, _t;",
  635. "} Q0;",
  636. 0,
  637. };
  638. static char *R12[] = {
  639. "\t\tcase %d: r = ((Q%d *)z)->contents[slot].fld%d; break;",
  640. 0,
  641. };
  642. char *R13[] = {
  643. "int ",
  644. "unsend(int into)",
  645. "{ int m=0, j, k; uchar *z;\n",
  646. " if (!into--)",
  647. " uerror(\"ref to uninitialized chan (unsend)\");",
  648. " z = qptr(into);",
  649. " j = ((Q0 *)z)->Qlen;",
  650. " ((Q0 *)z)->Qlen = --j;",
  651. " switch (((Q0 *)qptr(into))->_t) {",
  652. 0,
  653. };
  654. char *R14[] = {
  655. " default: Uerror(\"bad queue - unsend\");",
  656. " }",
  657. " return m;",
  658. "}\n",
  659. "void",
  660. "unrecv(int from, int slot, int fld, int fldvar, int strt)",
  661. "{ int j; uchar *z;\n",
  662. " if (!from--)",
  663. " uerror(\"ref to uninitialized chan (unrecv)\");",
  664. " z = qptr(from);",
  665. " j = ((Q0 *)z)->Qlen;",
  666. " if (strt) ((Q0 *)z)->Qlen = j+1;",
  667. " switch (((Q0 *)qptr(from))->_t) {",
  668. 0,
  669. };
  670. char *R15[] = {
  671. " default: Uerror(\"bad queue - qrecv\");",
  672. " }",
  673. "}",
  674. 0,
  675. };
  676. static char *Proto[] = {
  677. "",
  678. "/** function prototypes **/",
  679. "char *emalloc(unsigned long);",
  680. "char *Malloc(unsigned long);",
  681. "int Boundcheck(int, int, int, int, Trans *);",
  682. "/* int abort(void); */",
  683. "int addqueue(int, int);",
  684. "/* int atoi(char *); */",
  685. "int close(int);",
  686. #ifndef PC
  687. "int creat(char *, unsigned short);",
  688. "int write(int, void *, unsigned);",
  689. #endif
  690. "int delproc(int, int);",
  691. "int endstate(void);",
  692. "int hstore(char *, int, short);",
  693. "#ifdef MA",
  694. "int gstore(char *, int, uchar);",
  695. "#endif",
  696. "int q_cond(short, Trans *);",
  697. "int q_full(int);",
  698. "int q_len(int);",
  699. "int q_zero(int);",
  700. "int qrecv(int, int, int, int);",
  701. "int unsend(int);",
  702. "void *sbrk(int);",
  703. "void Uerror(char *);",
  704. "void assert(int, char *, int, int, Trans *);",
  705. "void checkcycles(void);",
  706. "void crack(int, int, Trans *, short *);",
  707. "void d_hash(uchar *, int);",
  708. "void delq(int);",
  709. "void do_reach(void);",
  710. "void exit(int);",
  711. "void hinit(void);",
  712. "void imed(Trans *, int, int);",
  713. "void new_state(void);",
  714. "void p_restor(int);",
  715. "void putpeg(int, int);",
  716. "void putrail(void);",
  717. "void q_restor(void);",
  718. "void retrans(int, int, int, short *, uchar *);",
  719. "void settable(void);",
  720. "void setq_claim(int, int, char *, int, char *);",
  721. "void sv_restor(void);",
  722. "void sv_save(char *);",
  723. "void tagtable(int, int, int, short *, uchar *);",
  724. "void uerror(char *);",
  725. "void unrecv(int, int, int, int, int);",
  726. "void usage(FILE *);",
  727. "void wrap_stats(void);",
  728. "void xrefsrc(int, S_F_MAP *, int, int);",
  729. "#if defined(FULLSTACK) && defined(BITSTATE)",
  730. "int onstack_now(void);",
  731. "void onstack_init(void);",
  732. "void onstack_put(void);",
  733. "void onstack_zap(void);",
  734. "#endif",
  735. "#ifndef XUSAFE",
  736. "int q_S_check(int, int);",
  737. "int q_R_check(int, int);",
  738. "uchar q_claim[MAXQ+1];",
  739. "char *q_name[MAXQ+1];",
  740. "char *p_name[MAXPROC+1];",
  741. "#endif",
  742. 0,
  743. };
  744. static char *SvMap[] = {
  745. "void",
  746. "to_compile(void)",
  747. "{ char ctd[1024], carg[64]; int n;",
  748. "#ifdef BITSTATE",
  749. " strcpy(ctd, \"-DBITSTATE \");",
  750. "#else",
  751. " strcpy(ctd, \"\");",
  752. "#endif",
  753. "#ifdef PC",
  754. " strcat(ctd, \"-DPC \");",
  755. "#endif",
  756. "#ifdef NOVSZ",
  757. " strcat(ctd, \"-DNOVSZ \");",
  758. "#endif",
  759. "#ifdef MEMCNT",
  760. "#ifdef PC",
  761. " n = 25;",
  762. "#else",
  763. " n = 28;",
  764. "#endif",
  765. " if (MEMCNT != n)",
  766. " { sprintf(carg, \"-DMEMCNT=%%d \", MEMCNT);",
  767. " strcat(ctd, carg);",
  768. " }",
  769. "#endif",
  770. "#ifdef MEMLIM",
  771. " sprintf(carg, \"-DMEMLIM=%%d \", MEMLIM);",
  772. " strcat(ctd, carg);",
  773. "#endif",
  774. "#ifdef NOCLAIM",
  775. " strcat(ctd, \"-DNOCLAIM \");",
  776. "#endif",
  777. "#ifdef SAFETY",
  778. " strcat(ctd, \"-DSAFETY \");",
  779. "#else",
  780. "#ifdef NOFAIR",
  781. " strcat(ctd, \"-DNOFAIR \");",
  782. "#else",
  783. "#ifdef NFAIR",
  784. " if (NFAIR != 2)",
  785. " { sprintf(carg, \"-DNFAIR=%%d \", NFAIR);",
  786. " strcat(ctd, carg);",
  787. " }",
  788. "#endif",
  789. "#endif",
  790. "#endif",
  791. "#ifdef NOREDUCE",
  792. " strcat(ctd, \"-DNOREDUCE \");",
  793. "#else",
  794. "#ifdef XUSAFE",
  795. " strcat(ctd, \"-DXUSAFE \");",
  796. "#endif",
  797. "#endif",
  798. "#ifdef NP",
  799. " strcat(ctd, \"-DNP \");",
  800. "#endif",
  801. "#ifdef PEG",
  802. " strcat(ctd, \"-DPEG \");",
  803. "#endif",
  804. "#ifdef VAR_RANGES",
  805. " strcat(ctd, \"-DVAR_RANGES \");",
  806. "#endif",
  807. "#ifdef HC0",
  808. " strcat(ctd, \"-DHC0 \");",
  809. "#endif",
  810. "#ifdef HC1",
  811. " strcat(ctd, \"-DHC1 \");",
  812. "#endif",
  813. "#ifdef HC2",
  814. " strcat(ctd, \"-DHC2 \");",
  815. "#endif",
  816. "#ifdef HC3",
  817. " strcat(ctd, \"-DHC3 \");",
  818. "#endif",
  819. "#ifdef HC4",
  820. " strcat(ctd, \"-DHC4 \");",
  821. "#endif",
  822. "#ifdef CHECK",
  823. " strcat(ctd, \"-DCHECK \");",
  824. "#endif",
  825. "#ifdef CTL",
  826. " strcat(ctd, \"-DCTL \");",
  827. "#endif",
  828. "#ifdef NIBIS",
  829. " strcat(ctd, \"-DNIBIS \");",
  830. "#endif",
  831. "#ifdef NOBOUNDCHECK",
  832. " strcat(ctd, \"-DNOBOUNDCHECK \");",
  833. "#endif",
  834. "#ifdef NOSTUTTER",
  835. " strcat(ctd, \"-DNOSTUTTER \");",
  836. "#endif",
  837. "#ifdef REACH",
  838. " strcat(ctd, \"-DREACH \");",
  839. "#endif",
  840. "#ifdef PRINTF",
  841. " strcat(ctd, \"-DPRINTF \");",
  842. "#endif",
  843. "#ifdef OTIM",
  844. " strcat(ctd, \"-DOTIM \");",
  845. "#endif",
  846. "#ifdef COLLAPSE",
  847. " strcat(ctd, \"-DCOLLAPSE \");",
  848. "#endif",
  849. "#ifdef SVDUMP",
  850. " strcat(ctd, \"-DSVDUMP \");",
  851. "#endif",
  852. "#ifdef VECTORSZ",
  853. " if (VECTORSZ != 1024)",
  854. " { sprintf(carg, \"-DVECTORSZ=%%d \", VECTORSZ);",
  855. " strcat(ctd, carg);",
  856. " }",
  857. "#endif",
  858. "#ifdef VERBOSE",
  859. " strcat(ctd, \"-DVERBOSE \");",
  860. "#endif",
  861. "#ifdef CHECK",
  862. " strcat(ctd, \"-DCHECK \");",
  863. "#endif",
  864. "#ifdef SDUMP",
  865. " strcat(ctd, \"-DSDUMP \");",
  866. "#endif",
  867. "#ifdef COVEST",
  868. " strcat(ctd, \"-DCOVEST \");",
  869. "#endif",
  870. " printf(\"Compiled as: cc -o pan %%span.c\", ctd);",
  871. "#if defined(COVEST) && defined(BITSTATE)",
  872. " printf(\" -lm\\n\");",
  873. "#else",
  874. " printf(\"\\n\");",
  875. "#endif",
  876. "}",
  877. 0,
  878. };