pangen3.h 22 KB

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