pangen3.h 22 KB

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