main.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /***** spin: main.c *****/
  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. #include <stdlib.h>
  11. #include "spin.h"
  12. #include "version.h"
  13. #include <signal.h>
  14. /* #include <malloc.h> */
  15. #include <time.h>
  16. #ifdef PC
  17. #include <io.h>
  18. extern int unlink(const char *);
  19. #else
  20. #include <unistd.h>
  21. #endif
  22. #include "y.tab.h"
  23. extern int DstepStart, lineno, tl_terse;
  24. extern FILE *yyin, *yyout, *tl_out;
  25. extern Symbol *context;
  26. extern char *claimproc;
  27. extern void repro_src(void);
  28. extern void qhide(int);
  29. Symbol *Fname, *oFname;
  30. int Etimeouts; /* nr timeouts in program */
  31. int Ntimeouts; /* nr timeouts in never claim */
  32. int analyze, columns, dumptab, has_remote, has_remvar;
  33. int interactive, jumpsteps, m_loss, nr_errs, cutoff;
  34. int s_trail, ntrail, verbose, xspin, notabs, rvopt;
  35. int no_print, no_wrapup, Caccess, limited_vis, like_java;
  36. int separate; /* separate compilation */
  37. int export_ast; /* pangen5.c */
  38. int inlineonly; /* show inlined code */
  39. int seedy; /* be verbose about chosen seed */
  40. int dataflow = 1, merger = 1, deadvar = 1, ccache = 1;
  41. static int preprocessonly, SeedUsed;
  42. #if 0
  43. meaning of flags on verbose:
  44. 1 -g global variable values
  45. 2 -l local variable values
  46. 4 -p all process actions
  47. 8 -r receives
  48. 16 -s sends
  49. 32 -v verbose
  50. 64 -w very verbose
  51. #endif
  52. static char Operator[] = "operator: ";
  53. static char Keyword[] = "keyword: ";
  54. static char Function[] = "function-name: ";
  55. static char **add_ltl = (char **)0;
  56. static char **ltl_file = (char **)0;
  57. static char **nvr_file = (char **)0;
  58. static char *PreArg[64];
  59. static int PreCnt = 0;
  60. static char out1[64];
  61. static void explain(int);
  62. #ifndef CPP
  63. /* OS2: "spin -Picc -E/Pd+ -E/Q+" */
  64. /* Visual C++: "spin -PCL -E/E */
  65. #ifdef PC
  66. #define CPP "gcc -E -x c" /* most systems have gcc anyway */
  67. /* else use "cpp" */
  68. #else
  69. #ifdef SOLARIS
  70. #define CPP "/usr/ccs/lib/cpp"
  71. #else
  72. #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
  73. #define CPP "cpp"
  74. #else
  75. #define CPP "/bin/cpp" /* classic Unix systems */
  76. #endif
  77. #endif
  78. #endif
  79. #endif
  80. static char *PreProc = CPP;
  81. extern int depth; /* at least some steps were made */
  82. void
  83. alldone(int estatus)
  84. {
  85. if (preprocessonly == 0
  86. && strlen(out1) > 0)
  87. (void) unlink((const char *)out1);
  88. if (seedy && !analyze && !export_ast
  89. && !s_trail && !preprocessonly && depth > 0)
  90. printf("seed used: %d\n", SeedUsed);
  91. if (xspin && (analyze || s_trail))
  92. { if (estatus)
  93. printf("spin: %d error(s) - aborting\n",
  94. estatus);
  95. else
  96. printf("Exit-Status 0\n");
  97. }
  98. exit(estatus);
  99. }
  100. void
  101. preprocess(char *a, char *b, int a_tmp)
  102. { char precmd[512], cmd[1024]; int i;
  103. #ifdef PC
  104. extern int try_zpp(char *, char *);
  105. if (PreCnt == 0 && try_zpp(a, b)) goto out;
  106. #endif
  107. strcpy(precmd, PreProc);
  108. for (i = 1; i <= PreCnt; i++)
  109. { strcat(precmd, " ");
  110. strcat(precmd, PreArg[i]);
  111. }
  112. sprintf(cmd, "%s %s > %s", precmd, a, b);
  113. if (system((const char *)cmd))
  114. { (void) unlink((const char *) b);
  115. if (a_tmp) (void) unlink((const char *) a);
  116. fprintf(stdout, "spin: preprocessing failed\n"); /* 4.1.2 was stderr */
  117. alldone(1); /* no return, error exit */
  118. }
  119. #ifdef PC
  120. out:
  121. #endif
  122. if (a_tmp) (void) unlink((const char *) a);
  123. }
  124. FILE *
  125. cpyfile(char *src, char *tgt)
  126. { FILE *inp, *out;
  127. char buf[1024];
  128. inp = fopen(src, "r");
  129. out = fopen(tgt, "w");
  130. if (!inp || !out)
  131. { printf("spin: cannot cp %s to %s\n", src, tgt);
  132. alldone(1);
  133. }
  134. while (fgets(buf, 1024, inp))
  135. fprintf(out, "%s", buf);
  136. fclose(inp);
  137. return out;
  138. }
  139. void
  140. usage(void)
  141. {
  142. printf("use: spin [-option] ... [-option] file\n");
  143. printf("\tNote: file must always be the last argument\n");
  144. printf("\t-A apply slicing algorithm\n");
  145. printf("\t-a generate a verifier in pan.c\n");
  146. printf("\t-B no final state details in simulations\n");
  147. printf("\t-b don't execute printfs in simulation\n");
  148. printf("\t-C print channel access info (combine with -g etc.)\n");
  149. printf("\t-c columnated -s -r simulation output\n");
  150. printf("\t-d produce symbol-table information\n");
  151. printf("\t-Dyyy pass -Dyyy to the preprocessor\n");
  152. printf("\t-Eyyy pass yyy to the preprocessor\n");
  153. printf("\t-f \"..formula..\" translate LTL ");
  154. printf("into never claim\n");
  155. printf("\t-F file like -f, but with the LTL ");
  156. printf("formula stored in a 1-line file\n");
  157. printf("\t-g print all global variables\n");
  158. printf("\t-h at end of run, print value of seed for random nr generator used\n");
  159. printf("\t-i interactive (random simulation)\n");
  160. printf("\t-I show result of inlining and preprocessing\n");
  161. printf("\t-J reverse eval order of nested unlesses\n");
  162. printf("\t-jN skip the first N steps ");
  163. printf("in simulation trail\n");
  164. printf("\t-l print all local variables\n");
  165. printf("\t-M print msc-flow in Postscript\n");
  166. printf("\t-m lose msgs sent to full queues\n");
  167. printf("\t-N file use never claim stored in file\n");
  168. printf("\t-nN seed for random nr generator\n");
  169. printf("\t-o1 turn off dataflow-optimizations in verifier\n");
  170. printf("\t-o2 don't hide write-only variables in verifier\n");
  171. printf("\t-o3 turn off statement merging in verifier\n");
  172. printf("\t-Pxxx use xxx for preprocessing\n");
  173. printf("\t-p print all statements\n");
  174. printf("\t-qN suppress io for queue N in printouts\n");
  175. printf("\t-r print receive events\n");
  176. printf("\t-S1 and -S2 separate pan source for claim and model\n");
  177. printf("\t-s print send events\n");
  178. printf("\t-T do not indent printf output\n");
  179. printf("\t-t[N] follow [Nth] simulation trail\n");
  180. printf("\t-Uyyy pass -Uyyy to the preprocessor\n");
  181. printf("\t-uN stop a simulation run after N steps\n");
  182. printf("\t-v verbose, more warnings\n");
  183. printf("\t-w very verbose (when combined with -l or -g)\n");
  184. printf("\t-[XYZ] reserved for use by xspin interface\n");
  185. printf("\t-V print version number and exit\n");
  186. alldone(1);
  187. }
  188. void
  189. optimizations(char nr)
  190. {
  191. switch (nr) {
  192. case '1':
  193. dataflow = 1 - dataflow; /* dataflow */
  194. if (verbose&32)
  195. printf("spin: dataflow optimizations turned %s\n",
  196. dataflow?"on":"off");
  197. break;
  198. case '2':
  199. /* dead variable elimination */
  200. deadvar = 1 - deadvar;
  201. if (verbose&32)
  202. printf("spin: dead variable elimination turned %s\n",
  203. deadvar?"on":"off");
  204. break;
  205. case '3':
  206. /* statement merging */
  207. merger = 1 - merger;
  208. if (verbose&32)
  209. printf("spin: statement merging turned %s\n",
  210. merger?"on":"off");
  211. break;
  212. case '4':
  213. /* rv optimization */
  214. rvopt = 1 - rvopt;
  215. if (verbose&32)
  216. printf("spin: rendezvous optimization turned %s\n",
  217. rvopt?"on":"off");
  218. break;
  219. case '5':
  220. /* case caching */
  221. ccache = 1 - ccache;
  222. if (verbose&32)
  223. printf("spin: case caching turned %s\n",
  224. ccache?"on":"off");
  225. break;
  226. default:
  227. printf("spin: bad or missing parameter on -o\n");
  228. usage();
  229. break;
  230. }
  231. }
  232. #if 0
  233. static int
  234. Rename(const char *old, char *new)
  235. { FILE *fo, *fn;
  236. char buf[1024];
  237. if ((fo = fopen(old, "r")) == NULL)
  238. { printf("spin: cannot open %s\n", old);
  239. return 1;
  240. }
  241. if ((fn = fopen(new, "w")) == NULL)
  242. { printf("spin: cannot create %s\n", new);
  243. fclose(fo);
  244. return 2;
  245. }
  246. while (fgets(buf, 1024, fo))
  247. fputs(buf, fn);
  248. fclose(fo);
  249. fclose(fn);
  250. return 0; /* success */
  251. }
  252. #endif
  253. int
  254. main(int argc, char *argv[])
  255. { Symbol *s;
  256. int T = (int) time((time_t *)0);
  257. int usedopts = 0;
  258. extern void ana_src(int, int);
  259. yyin = stdin;
  260. yyout = stdout;
  261. tl_out = stdout;
  262. /* unused flags: e, w, x, y, z, A, G, I, L, O, Q, R, S, T, W */
  263. while (argc > 1 && argv[1][0] == '-')
  264. { switch (argv[1][1]) {
  265. /* generate code for separate compilation: S1 or S2 */
  266. case 'S': separate = atoi(&argv[1][2]);
  267. /* fall through */
  268. case 'a': analyze = 1; break;
  269. case 'A': export_ast = 1; break;
  270. case 'B': no_wrapup = 1; break;
  271. case 'b': no_print = 1; break;
  272. case 'C': Caccess = 1; break;
  273. case 'c': columns = 1; break;
  274. case 'D': PreArg[++PreCnt] = (char *) &argv[1][0];
  275. break; /* define */
  276. case 'd': dumptab = 1; break;
  277. case 'E': PreArg[++PreCnt] = (char *) &argv[1][2];
  278. break;
  279. case 'F': ltl_file = (char **) (argv+2);
  280. argc--; argv++; break;
  281. case 'f': add_ltl = (char **) argv;
  282. argc--; argv++; break;
  283. case 'g': verbose += 1; break;
  284. case 'h': seedy = 1; break;
  285. case 'i': interactive = 1; break;
  286. case 'I': inlineonly = 1; break;
  287. case 'J': like_java = 1; break;
  288. case 'j': jumpsteps = atoi(&argv[1][2]); break;
  289. case 'l': verbose += 2; break;
  290. case 'M': columns = 2; break;
  291. case 'm': m_loss = 1; break;
  292. case 'N': nvr_file = (char **) (argv+2);
  293. argc--; argv++; break;
  294. case 'n': T = atoi(&argv[1][2]); tl_terse = 1; break;
  295. case 'o': optimizations(argv[1][2]);
  296. usedopts = 1; break;
  297. case 'P': PreProc = (char *) &argv[1][2]; break;
  298. case 'p': verbose += 4; break;
  299. case 'q': if (isdigit(argv[1][2]))
  300. qhide(atoi(&argv[1][2]));
  301. break;
  302. case 'r': verbose += 8; break;
  303. case 's': verbose += 16; break;
  304. case 'T': notabs = 1; break;
  305. case 't': s_trail = 1;
  306. if (isdigit(argv[1][2]))
  307. ntrail = atoi(&argv[1][2]);
  308. break;
  309. case 'U': PreArg[++PreCnt] = (char *) &argv[1][0];
  310. break; /* undefine */
  311. case 'u': cutoff = atoi(&argv[1][2]); break; /* new 3.4.14 */
  312. case 'v': verbose += 32; break;
  313. case 'V': printf("%s\n", Version);
  314. alldone(0);
  315. break;
  316. case 'w': verbose += 64; break;
  317. case 'X': xspin = notabs = 1;
  318. #ifndef PC
  319. signal(SIGPIPE, alldone); /* not posix... */
  320. #endif
  321. break;
  322. case 'Y': limited_vis = 1; break; /* used by xspin */
  323. case 'Z': preprocessonly = 1; break; /* used by xspin */
  324. default : usage(); break;
  325. }
  326. argc--; argv++;
  327. }
  328. if (usedopts && !analyze)
  329. printf("spin: warning -o[123] option ignored in simulations\n");
  330. if (ltl_file)
  331. { char formula[4096];
  332. add_ltl = ltl_file-2; add_ltl[1][1] = 'f';
  333. if (!(tl_out = fopen(*ltl_file, "r")))
  334. { printf("spin: cannot open %s\n", *ltl_file);
  335. alldone(1);
  336. }
  337. fgets(formula, 4096, tl_out);
  338. fclose(tl_out);
  339. tl_out = stdout;
  340. *ltl_file = (char *) formula;
  341. }
  342. if (argc > 1)
  343. { char cmd[128], out2[64];
  344. /* must remain in current dir */
  345. strcpy(out1, "pan.pre");
  346. if (add_ltl || nvr_file)
  347. strcpy(out2, "pan.___");
  348. if (add_ltl)
  349. { tl_out = cpyfile(argv[1], out2);
  350. nr_errs = tl_main(2, add_ltl); /* in tl_main.c */
  351. fclose(tl_out);
  352. preprocess(out2, out1, 1);
  353. } else if (nvr_file)
  354. { FILE *fd; char buf[1024];
  355. if ((fd = fopen(*nvr_file, "r")) == NULL)
  356. { printf("spin: cannot open %s\n",
  357. *nvr_file);
  358. alldone(1);
  359. }
  360. tl_out = cpyfile(argv[1], out2);
  361. while (fgets(buf, 1024, fd))
  362. fprintf(tl_out, "%s", buf);
  363. fclose(tl_out);
  364. fclose(fd);
  365. preprocess(out2, out1, 1);
  366. } else
  367. preprocess(argv[1], out1, 0);
  368. if (preprocessonly)
  369. alldone(0);
  370. if (!(yyin = fopen(out1, "r")))
  371. { printf("spin: cannot open %s\n", out1);
  372. alldone(1);
  373. }
  374. if (strncmp(argv[1], "progress", 8) == 0
  375. || strncmp(argv[1], "accept", 6) == 0)
  376. sprintf(cmd, "_%s", argv[1]);
  377. else
  378. strcpy(cmd, argv[1]);
  379. oFname = Fname = lookup(cmd);
  380. if (oFname->name[0] == '\"')
  381. { int i = (int) strlen(oFname->name);
  382. oFname->name[i-1] = '\0';
  383. oFname = lookup(&oFname->name[1]);
  384. }
  385. } else
  386. { oFname = Fname = lookup("<stdin>");
  387. if (add_ltl)
  388. { if (argc > 0)
  389. exit(tl_main(2, add_ltl));
  390. printf("spin: missing argument to -f\n");
  391. alldone(1);
  392. }
  393. printf("%s\n", Version);
  394. printf("reading input from stdin:\n");
  395. fflush(stdout);
  396. }
  397. if (columns == 2)
  398. { extern void putprelude(void);
  399. if (xspin || verbose&(1|4|8|16|32))
  400. { printf("spin: -c precludes all flags except -t\n");
  401. alldone(1);
  402. }
  403. putprelude();
  404. }
  405. if (columns && !(verbose&8) && !(verbose&16))
  406. verbose += (8+16);
  407. if (columns == 2 && limited_vis)
  408. verbose += (1+4);
  409. Srand(T); /* defined in run.c */
  410. SeedUsed = T;
  411. s = lookup("_"); s->type = PREDEF; /* write-only global var */
  412. s = lookup("_p"); s->type = PREDEF;
  413. s = lookup("_pid"); s->type = PREDEF;
  414. s = lookup("_last"); s->type = PREDEF;
  415. s = lookup("_nr_pr"); s->type = PREDEF; /* new 3.3.10 */
  416. yyparse();
  417. fclose(yyin);
  418. loose_ends();
  419. if (inlineonly)
  420. { repro_src();
  421. return 0;
  422. }
  423. chanaccess();
  424. if (!Caccess)
  425. { if (!s_trail && (dataflow || merger))
  426. ana_src(dataflow, merger);
  427. sched();
  428. alldone(nr_errs);
  429. }
  430. return 0;
  431. }
  432. int
  433. yywrap(void) /* dummy routine */
  434. {
  435. return 1;
  436. }
  437. void
  438. non_fatal(char *s1, char *s2)
  439. { extern char yytext[];
  440. printf("spin: line %3d %s, Error: ",
  441. lineno, Fname?Fname->name:"nofilename");
  442. if (s2)
  443. printf(s1, s2);
  444. else
  445. printf(s1);
  446. if (yytext && strlen(yytext)>1)
  447. printf(" near '%s'", yytext);
  448. printf("\n");
  449. nr_errs++;
  450. }
  451. void
  452. fatal(char *s1, char *s2)
  453. {
  454. non_fatal(s1, s2);
  455. alldone(1);
  456. }
  457. char *
  458. emalloc(int n)
  459. { char *tmp;
  460. if (n == 0)
  461. return NULL; /* robert shelton 10/20/06 */
  462. if (!(tmp = (char *) malloc(n)))
  463. fatal("not enough memory", (char *)0);
  464. memset(tmp, 0, n);
  465. return tmp;
  466. }
  467. void
  468. trapwonly(Lextok *n, char *unused)
  469. { extern int realread;
  470. short i = (n->sym)?n->sym->type:0;
  471. if (i != MTYPE
  472. && i != BIT
  473. && i != BYTE
  474. && i != SHORT
  475. && i != INT
  476. && i != UNSIGNED)
  477. return;
  478. if (realread)
  479. n->sym->hidden |= 128; /* var is read at least once */
  480. }
  481. void
  482. setaccess(Symbol *sp, Symbol *what, int cnt, int t)
  483. { Access *a;
  484. for (a = sp->access; a; a = a->lnk)
  485. if (a->who == context
  486. && a->what == what
  487. && a->cnt == cnt
  488. && a->typ == t)
  489. return;
  490. a = (Access *) emalloc(sizeof(Access));
  491. a->who = context;
  492. a->what = what;
  493. a->cnt = cnt;
  494. a->typ = t;
  495. a->lnk = sp->access;
  496. sp->access = a;
  497. }
  498. Lextok *
  499. nn(Lextok *s, int t, Lextok *ll, Lextok *rl)
  500. { Lextok *n = (Lextok *) emalloc(sizeof(Lextok));
  501. static int warn_nn = 0;
  502. n->ntyp = (short) t;
  503. if (s && s->fn)
  504. { n->ln = s->ln;
  505. n->fn = s->fn;
  506. } else if (rl && rl->fn)
  507. { n->ln = rl->ln;
  508. n->fn = rl->fn;
  509. } else if (ll && ll->fn)
  510. { n->ln = ll->ln;
  511. n->fn = ll->fn;
  512. } else
  513. { n->ln = lineno;
  514. n->fn = Fname;
  515. }
  516. if (s) n->sym = s->sym;
  517. n->lft = ll;
  518. n->rgt = rl;
  519. n->indstep = DstepStart;
  520. if (t == TIMEOUT) Etimeouts++;
  521. if (!context) return n;
  522. if (t == 'r' || t == 's')
  523. setaccess(n->sym, ZS, 0, t);
  524. if (t == 'R')
  525. setaccess(n->sym, ZS, 0, 'P');
  526. if (context->name == claimproc)
  527. { int forbidden = separate;
  528. switch (t) {
  529. case ASGN:
  530. printf("spin: Warning, never claim has side-effect\n");
  531. break;
  532. case 'r': case 's':
  533. non_fatal("never claim contains i/o stmnts",(char *)0);
  534. break;
  535. case TIMEOUT:
  536. /* never claim polls timeout */
  537. if (Ntimeouts && Etimeouts)
  538. forbidden = 0;
  539. Ntimeouts++; Etimeouts--;
  540. break;
  541. case LEN: case EMPTY: case FULL:
  542. case 'R': case NFULL: case NEMPTY:
  543. /* status becomes non-exclusive */
  544. if (n->sym && !(n->sym->xu&XX))
  545. { n->sym->xu |= XX;
  546. if (separate == 2) {
  547. printf("spin: warning, make sure that the S1 model\n");
  548. printf(" also polls channel '%s' in its claim\n",
  549. n->sym->name);
  550. } }
  551. forbidden = 0;
  552. break;
  553. case 'c':
  554. AST_track(n, 0); /* register as a slice criterion */
  555. /* fall thru */
  556. default:
  557. forbidden = 0;
  558. break;
  559. }
  560. if (forbidden)
  561. { printf("spin: never, saw "); explain(t); printf("\n");
  562. fatal("incompatible with separate compilation",(char *)0);
  563. }
  564. } else if ((t == ENABLED || t == PC_VAL) && !(warn_nn&t))
  565. { printf("spin: Warning, using %s outside never claim\n",
  566. (t == ENABLED)?"enabled()":"pc_value()");
  567. warn_nn |= t;
  568. } else if (t == NONPROGRESS)
  569. { fatal("spin: Error, using np_ outside never claim\n", (char *)0);
  570. }
  571. return n;
  572. }
  573. Lextok *
  574. rem_lab(Symbol *a, Lextok *b, Symbol *c) /* proctype name, pid, label name */
  575. { Lextok *tmp1, *tmp2, *tmp3;
  576. has_remote++;
  577. c->type = LABEL; /* refered to in global context here */
  578. fix_dest(c, a); /* in case target of rem_lab is jump */
  579. tmp1 = nn(ZN, '?', b, ZN); tmp1->sym = a;
  580. tmp1 = nn(ZN, 'p', tmp1, ZN);
  581. tmp1->sym = lookup("_p");
  582. tmp2 = nn(ZN, NAME, ZN, ZN); tmp2->sym = a;
  583. tmp3 = nn(ZN, 'q', tmp2, ZN); tmp3->sym = c;
  584. return nn(ZN, EQ, tmp1, tmp3);
  585. #if 0
  586. .---------------EQ-------.
  587. / \
  588. 'p' -sym-> _p 'q' -sym-> c (label name)
  589. / /
  590. '?' -sym-> a (proctype) NAME -sym-> a (proctype name)
  591. /
  592. b (pid expr)
  593. #endif
  594. }
  595. Lextok *
  596. rem_var(Symbol *a, Lextok *b, Symbol *c, Lextok *ndx)
  597. { Lextok *tmp1;
  598. has_remote++;
  599. has_remvar++;
  600. dataflow = 0; /* turn off dead variable resets 4.2.5 */
  601. tmp1 = nn(ZN, '?', b, ZN); tmp1->sym = a;
  602. tmp1 = nn(ZN, 'p', tmp1, ndx);
  603. tmp1->sym = c;
  604. return tmp1;
  605. #if 0
  606. cannot refer to struct elements
  607. only to scalars and arrays
  608. 'p' -sym-> c (variable name)
  609. / \______ possible arrayindex on c
  610. /
  611. '?' -sym-> a (proctype)
  612. /
  613. b (pid expr)
  614. #endif
  615. }
  616. static void
  617. explain(int n)
  618. { FILE *fd = stdout;
  619. switch (n) {
  620. default: if (n > 0 && n < 256)
  621. fprintf(fd, "'%c' = '", n);
  622. fprintf(fd, "%d'", n);
  623. break;
  624. case '\b': fprintf(fd, "\\b"); break;
  625. case '\t': fprintf(fd, "\\t"); break;
  626. case '\f': fprintf(fd, "\\f"); break;
  627. case '\n': fprintf(fd, "\\n"); break;
  628. case '\r': fprintf(fd, "\\r"); break;
  629. case 'c': fprintf(fd, "condition"); break;
  630. case 's': fprintf(fd, "send"); break;
  631. case 'r': fprintf(fd, "recv"); break;
  632. case 'R': fprintf(fd, "recv poll %s", Operator); break;
  633. case '@': fprintf(fd, "@"); break;
  634. case '?': fprintf(fd, "(x->y:z)"); break;
  635. case ACTIVE: fprintf(fd, "%sactive", Keyword); break;
  636. case AND: fprintf(fd, "%s&&", Operator); break;
  637. case ASGN: fprintf(fd, "%s=", Operator); break;
  638. case ASSERT: fprintf(fd, "%sassert", Function); break;
  639. case ATOMIC: fprintf(fd, "%satomic", Keyword); break;
  640. case BREAK: fprintf(fd, "%sbreak", Keyword); break;
  641. case C_CODE: fprintf(fd, "%sc_code", Keyword); break;
  642. case C_DECL: fprintf(fd, "%sc_decl", Keyword); break;
  643. case C_EXPR: fprintf(fd, "%sc_expr", Keyword); break;
  644. case C_STATE: fprintf(fd, "%sc_state",Keyword); break;
  645. case C_TRACK: fprintf(fd, "%sc_track",Keyword); break;
  646. case CLAIM: fprintf(fd, "%snever", Keyword); break;
  647. case CONST: fprintf(fd, "a constant"); break;
  648. case DECR: fprintf(fd, "%s--", Operator); break;
  649. case D_STEP: fprintf(fd, "%sd_step", Keyword); break;
  650. case D_PROCTYPE: fprintf(fd, "%sd_proctype", Keyword); break;
  651. case DO: fprintf(fd, "%sdo", Keyword); break;
  652. case DOT: fprintf(fd, "."); break;
  653. case ELSE: fprintf(fd, "%selse", Keyword); break;
  654. case EMPTY: fprintf(fd, "%sempty", Function); break;
  655. case ENABLED: fprintf(fd, "%senabled",Function); break;
  656. case EQ: fprintf(fd, "%s==", Operator); break;
  657. case EVAL: fprintf(fd, "%seval", Function); break;
  658. case FI: fprintf(fd, "%sfi", Keyword); break;
  659. case FULL: fprintf(fd, "%sfull", Function); break;
  660. case GE: fprintf(fd, "%s>=", Operator); break;
  661. case GOTO: fprintf(fd, "%sgoto", Keyword); break;
  662. case GT: fprintf(fd, "%s>", Operator); break;
  663. case HIDDEN: fprintf(fd, "%shidden", Keyword); break;
  664. case IF: fprintf(fd, "%sif", Keyword); break;
  665. case INCR: fprintf(fd, "%s++", Operator); break;
  666. case INAME: fprintf(fd, "inline name"); break;
  667. case INLINE: fprintf(fd, "%sinline", Keyword); break;
  668. case INIT: fprintf(fd, "%sinit", Keyword); break;
  669. case ISLOCAL: fprintf(fd, "%slocal", Keyword); break;
  670. case LABEL: fprintf(fd, "a label-name"); break;
  671. case LE: fprintf(fd, "%s<=", Operator); break;
  672. case LEN: fprintf(fd, "%slen", Function); break;
  673. case LSHIFT: fprintf(fd, "%s<<", Operator); break;
  674. case LT: fprintf(fd, "%s<", Operator); break;
  675. case MTYPE: fprintf(fd, "%smtype", Keyword); break;
  676. case NAME: fprintf(fd, "an identifier"); break;
  677. case NE: fprintf(fd, "%s!=", Operator); break;
  678. case NEG: fprintf(fd, "%s! (not)",Operator); break;
  679. case NEMPTY: fprintf(fd, "%snempty", Function); break;
  680. case NFULL: fprintf(fd, "%snfull", Function); break;
  681. case NON_ATOMIC: fprintf(fd, "sub-sequence"); break;
  682. case NONPROGRESS: fprintf(fd, "%snp_", Function); break;
  683. case OD: fprintf(fd, "%sod", Keyword); break;
  684. case OF: fprintf(fd, "%sof", Keyword); break;
  685. case OR: fprintf(fd, "%s||", Operator); break;
  686. case O_SND: fprintf(fd, "%s!!", Operator); break;
  687. case PC_VAL: fprintf(fd, "%spc_value",Function); break;
  688. case PNAME: fprintf(fd, "process name"); break;
  689. case PRINT: fprintf(fd, "%sprintf", Function); break;
  690. case PRINTM: fprintf(fd, "%sprintm", Function); break;
  691. case PRIORITY: fprintf(fd, "%spriority", Keyword); break;
  692. case PROCTYPE: fprintf(fd, "%sproctype",Keyword); break;
  693. case PROVIDED: fprintf(fd, "%sprovided",Keyword); break;
  694. case RCV: fprintf(fd, "%s?", Operator); break;
  695. case R_RCV: fprintf(fd, "%s??", Operator); break;
  696. case RSHIFT: fprintf(fd, "%s>>", Operator); break;
  697. case RUN: fprintf(fd, "%srun", Operator); break;
  698. case SEP: fprintf(fd, "token: ::"); break;
  699. case SEMI: fprintf(fd, ";"); break;
  700. case SHOW: fprintf(fd, "%sshow", Keyword); break;
  701. case SND: fprintf(fd, "%s!", Operator); break;
  702. case STRING: fprintf(fd, "a string"); break;
  703. case TRACE: fprintf(fd, "%strace", Keyword); break;
  704. case TIMEOUT: fprintf(fd, "%stimeout",Keyword); break;
  705. case TYPE: fprintf(fd, "data typename"); break;
  706. case TYPEDEF: fprintf(fd, "%stypedef",Keyword); break;
  707. case XU: fprintf(fd, "%sx[rs]", Keyword); break;
  708. case UMIN: fprintf(fd, "%s- (unary minus)", Operator); break;
  709. case UNAME: fprintf(fd, "a typename"); break;
  710. case UNLESS: fprintf(fd, "%sunless", Keyword); break;
  711. }
  712. }