|
|
1.1 ! root 1: # To unbundle, sh this file ! 2: echo makefile 1>&2 ! 3: sed 's/.//' >makefile <<'//GO.SYSIN DD makefile' ! 4: -CC = cc ! 5: -YFLAGS = -dDv ! 6: -CFLAGS = -g ! 7: -OBJS = pret.o pret1.o pret2.o pret3.o pret4.o pret6.o pret7.o pret8.o pret9.o pret0.o pretlex.o ! 8: - ! 9: -# FILES: ! 10: -# pret.y - yacc parser ! 11: -# pret.h - constants and macros ! 12: -# pret.d - internal representation of the tables ! 13: -# pret0.c - reduction of the state machines ! 14: -# pret1.c - qsets ! 15: -# pret2.c - operations on rows and columns ! 16: -# pret3.c - procedures ! 17: -# pret4.c - processes ! 18: -# pret6.c - queues and messages ! 19: -# pret7.c - memory allocation ! 20: -# pret8.c - variables ! 21: -# pret9.c - parameters ! 22: -# pret.expr.c - expressions ! 23: -# pretlex.c lexical analyzer ! 24: - ! 25: -pret: $(OBJS) pret.h pret.d ! 26: - $(CC) $(CFLAGS) $(OBJS) -lln -o pret ! 27: - ! 28: -pret.o: pret.y pret.expr.c ! 29: - ! 30: -pretlex.o: pretlex.l x.tab.h ! 31: - lex pretlex.l ! 32: - $(CC) $(CFLAGS) -c lex.yy.c ! 33: - rm lex.yy.c ! 34: - mv lex.yy.o pretlex.o ! 35: - ! 36: -x.tab.h: y.tab.h ! 37: - -cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h ! 38: - ! 39: -clean: ! 40: - rm -f *.o [xy].tab.[ch] y.output pret.out pret.err pret.tmp core a.out ! 41: - ! 42: -install: ! 43: - cp pret /usr/bin ! 44: //GO.SYSIN DD makefile ! 45: echo pret.d 1>&2 ! 46: sed 's/.//' >pret.d <<'//GO.SYSIN DD pret.d' ! 47: - /* ! 48: - ** 3-dimensional table: ! 49: - ** one row per state ! 50: - ** one column per event ! 51: - ** one `pilar' per possible response ! 52: - */ ! 53: - ! 54: - struct ENTRY { ! 55: - int nrpils; /* size of pilar stack */ ! 56: - struct PILAR *pilar; ! 57: - struct ENTRY *nextrow; ! 58: - struct ENTRY *nextcol; ! 59: - }; ! 60: - struct PILAR { ! 61: - int transf; /* row transition function */ ! 62: - int code; /* output message or bltin index */ ! 63: - struct PILAR *nxtp; /* last pilar points to NULL */ ! 64: - }; ! 65: - ! 66: - struct COL { ! 67: - int coltype; /* msg, spont, tau, default, task, condition */ ! 68: - int ccode; ! 69: - }; ! 70: - ! 71: - struct ROW { ! 72: - char name[256]; /* can be composite name */ ! 73: - char reached; /* is row reachable ? */ ! 74: - char refcount; /* label reference index */ ! 75: - char labeled; /* start of do-loop or label */ ! 76: - int mapping; /* indicates transit rows */ ! 77: - int maptwo; /* renumbers reduced table */ ! 78: - }; ! 79: //GO.SYSIN DD pret.d ! 80: echo pret.expr.c 1>&2 ! 81: sed 's/.//' >pret.expr.c <<'//GO.SYSIN DD pret.expr.c' ! 82: -#define DEBUG 0 ! 83: - ! 84: -#define setv 1 ! 85: -#define addeq 2 ! 86: -#define subeq 3 ! 87: -#define muleq 4 ! 88: -#define diveq 5 ! 89: -#define modeq 6 ! 90: -#define plus 7 ! 91: -#define minus 8 ! 92: -#define times 9 ! 93: -#define div 10 ! 94: -#define mod 11 ! 95: -#define power 12 ! 96: -#define uminus 13 ! 97: -#define gt 14 ! 98: -#define lt 15 ! 99: -#define ge 16 ! 100: -#define le 17 ! 101: -#define eq 18 ! 102: -#define ne 19 ! 103: -#define land 20 ! 104: -#define lor 21 ! 105: -#define lnot 22 ! 106: -#define princ 23 ! 107: -#define prdec 24 ! 108: -#define poinc 25 ! 109: -#define podec 26 ! 110: - ! 111: -#define OP 0 ! 112: -#define NM 1 ! 113: - ! 114: -#define unary(c) (c == uminus || c == lnot || c >= princ) ! 115: -#define binary(c) !unary(c) ! 116: - ! 117: -struct REVPOL { ! 118: - char toktyp; ! 119: - short tokval; ! 120: -} *parsed; ! 121: - ! 122: -int prs = 0; ! 123: -extern int verbose; ! 124: -char * Emalloc(); ! 125: - ! 126: -pushnm(tok) ! 127: -{ if (prs >= EXPRMAX) ! 128: - whoops("expression too long"); ! 129: - parsed[prs].toktyp = NM; ! 130: - parsed[prs++].tokval = tok; ! 131: -} ! 132: - ! 133: -pushop(tok) ! 134: -{ if (prs >= EXPRMAX) ! 135: - whoops("expression too long"); ! 136: - parsed[prs].toktyp = OP; ! 137: - parsed[prs++].tokval = tok; ! 138: -} ! 139: - ! 140: -struct Node * ! 141: -newnode(ntyp, nval, left, right) ! 142: - struct Node *left, *right; ! 143: -{ ! 144: - struct Node *try; ! 145: - ! 146: - try = (struct Node *) Emalloc(sizeof(struct Node)); ! 147: - try->ntyp = ntyp; ! 148: - try->nval = nval; ! 149: - try->left = left; ! 150: - try->right = right; ! 151: - return try; ! 152: -} ! 153: - ! 154: -makeexpr(n) ! 155: -{ pushexpr(n); ! 156: - return -(2 + addrevpol()); ! 157: -} ! 158: - ! 159: -pushexpr(n) ! 160: - struct Node *n; ! 161: -{ ! 162: - if (n == NULL) return; ! 163: - switch (n->ntyp) { ! 164: - case NM: pushnm(n->nval); break; ! 165: - case OP: pushexpr(n->left); pushexpr(n->right); pushop(n->nval); break; ! 166: - default: whoops("unknown node type"); ! 167: - } ! 168: -} ! 169: - ! 170: -struct { ! 171: - short n; ! 172: - struct REVPOL *p; ! 173: -} revpols[MANY]; ! 174: - ! 175: -int npols = 0; ! 176: - ! 177: -numexps(fd) ! 178: - FILE *fd; ! 179: -{ int i, j; ! 180: - struct REVPOL *p; ! 181: - ! 182: - fprintf(fd, "EXPR %d\n", npols); ! 183: - for (i = 0; i < npols; i++) ! 184: - { fprintf(fd, "%d: ", revpols[i].n); ! 185: - p = revpols[i].p; ! 186: - for (j = (revpols[i].n)-1; j >= 0; j--) ! 187: - fprintf(fd, "%d/%d ", p[j].toktyp, p[j].tokval); ! 188: - putc('\n', fd); ! 189: -} } ! 190: - ! 191: -findsame(a) ! 192: -{ struct REVPOL *p, *q; ! 193: - int k = revpols[a].n; ! 194: - int i, j; ! 195: - ! 196: - q = revpols[a].p; ! 197: - for (i = 0; i < npols; i++) ! 198: - { if (revpols[i].n != revpols[a].n) ! 199: - continue; ! 200: - p = revpols[i].p; ! 201: - for (j = 0; j < k; j++) ! 202: - if (p[j].toktyp != q[j].toktyp ! 203: - || p[j].tokval != q[j].tokval) ! 204: - break; ! 205: - if (j == k) ! 206: - break; ! 207: - } ! 208: - return i; ! 209: -} ! 210: - ! 211: -addrevpol() ! 212: -{ int i; ! 213: - int retval; ! 214: - ! 215: - if (npols >= MANY) ! 216: - whoops("too many expressions"); ! 217: - ! 218: - revpols[npols].n = prs; ! 219: - revpols[npols].p = parsed; ! 220: - ! 221: - if ((retval = findsame(npols)) == npols) ! 222: - npols++; ! 223: - ! 224: -#if 0 ! 225: - printf("exp(%d): ", prs); ! 226: - for (i = prs-1; i >= 0; i--) ! 227: - { if (parsed[i].toktyp == NM) ! 228: - { printf("%d ", parsed[i].tokval); ! 229: - continue; ! 230: - } ! 231: - switch(parsed[i].tokval) { ! 232: - case setv: printf("= "); break; ! 233: - case addeq: printf("+= "); break; ! 234: - case subeq: printf("-= "); break; ! 235: - case muleq: printf("*= "); break; ! 236: - case diveq: printf("/= "); break; ! 237: - case modeq: printf("%= "); break; ! 238: - case plus: printf("+ "); break; ! 239: - case minus: printf("- "); break; ! 240: - case times: printf("* "); break; ! 241: - case div: printf("/ "); break; ! 242: - case mod: printf("% "); break; ! 243: - case power: printf("^ "); break; ! 244: - case uminus: printf(".- "); break; ! 245: - case gt: printf("> "); break; ! 246: - case lt: printf("< "); break; ! 247: - case ge: printf(">= "); break; ! 248: - case le: printf("<= "); break; ! 249: - case eq: printf("== "); break; ! 250: - case ne: printf("!= "); break; ! 251: - case land: printf("&& "); break; ! 252: - case lor: printf("|| "); break; ! 253: - case lnot: printf("! "); break; ! 254: - case princ: printf("++. "); break; ! 255: - case prdec: printf("--. "); break; ! 256: - case poinc: printf(".++ "); break; ! 257: - case podec: printf(".-- "); break; ! 258: - default: fprintf(stderr, "%d", parsed[i].tokval); ! 259: - whoops("unknown operator"); ! 260: - } ! 261: - } ! 262: - putchar('\n'); ! 263: -#endif ! 264: - parsed = (struct REVPOL *) Emalloc(EXPRMAX * sizeof(struct REVPOL)); ! 265: - prs = 0; ! 266: - ! 267: - return retval; ! 268: -} ! 269: //GO.SYSIN DD pret.expr.c ! 270: echo pret.h 1>&2 ! 271: sed 's/.//' >pret.h <<'//GO.SYSIN DD pret.h' ! 272: -#define NORM 0 /* normal message */ ! 273: -#define INITM 1 /* initial message */ ! 274: - ! 275: -#define SND 2 ! 276: -#define RCV 4 ! 277: -#define SAR 6 ! 278: -#define RFR 1 ! 279: -#define DCL 2 ! 280: -#define RAD 3 ! 281: -#define ADR 4 ! 282: -#define DAR 6 ! 283: - ! 284: -#define MAXNAME 32 /* max available composite namelength */ ! 285: -#define MAXPROC 16 /* max number of processes */ ! 286: -#define MANY 512 /* max nr of distinct rows or names */ ! 287: -#define MAXDEPTH 32 /* max nesting depth of if's and do's */ ! 288: -#define EXPRMAX 64 ! 289: -#define NOSTATE -1 /* default state */ ! 290: - ! 291: -#define SOME 1 /* not none */ ! 292: -#define NONE -1 /* default signal */ ! 293: -#define NEW -1 ! 294: -#define OLD 0 ! 295: -#define LAB 1 ! 296: - ! 297: -#define ISM 0 /* message variable */ ! 298: -#define ISQ 1 /* queue-set variable */ ! 299: -#define ISV 2 /* protocol variable */ ! 300: -#define ISQN 3 /* queuename variable */ ! 301: - ! 302: - /* types of transitions: */ ! 303: -#define INP 10 /* recv specific message */ ! 304: -#define DFL 11 /* default input from q */ ! 305: -#define TMO 12 /* transition on timeout */ ! 306: -#define OUTP 13 /* append message to a q */ ! 307: -#define SPN 14 /* builtin call or transit state */ ! 308: -#define CND 15 /* conditional */ ! 309: -#define FCT 16 /* function call */ ! 310: - ! 311: - /* `builtins:' */ ! 312: -#define INCR 16 /* increment */ ! 313: -#define DECR 17 /* decrement */ ! 314: -#define SUBT 18 /* subtract */ ! 315: -#define ADDT 19 /* add */ ! 316: -#define SETV 32 /* set: = */ ! 317: -#define ISEQ 256 /* compare: == */ ! 318: -#define NTEQ 257 /* != */ ! 319: -#define GREQ 258 /* >= */ ! 320: -#define SMEQ 259 /* <= */ ! 321: -#define GRNQ 260 /* > */ ! 322: -#define SMNQ 261 /* < */ ! 323: - ! 324: -#define SPNT(u) (u == TMO || u == OUTP) ! 325: - ! 326: -struct QTABLE { ! 327: - char name[MAXNAME]; ! 328: - short status; ! 329: - short limit; ! 330: - short owner; ! 331: - int multiple; ! 332: - unsigned char magic; ! 333: -}; ! 334: - ! 335: -#define BASEVAL MAXPROC /* base value for coding messages */ ! 336: -#define NQUEUES 2*MAXPROC /* maximum number of queues */ ! 337: - ! 338: -struct PROCTABLE { ! 339: - char name[MAXNAME]; ! 340: - int nrstates; ! 341: - int unreach; ! 342: - int replic; ! 343: -}; ! 344: //GO.SYSIN DD pret.h ! 345: echo pret.y 1>&2 ! 346: sed 's/.//' >pret.y <<'//GO.SYSIN DD pret.y' ! 347: -%{ ! 348: -#include <stdio.h> ! 349: -#include "pret.h" ! 350: -#include "pret.d" ! 351: - ! 352: -#define YYDEBUG 1 ! 353: - ! 354: -struct Node { ! 355: - int ntyp; /* OP ~ nval&left&right, NM ~ val */ ! 356: - int nval; ! 357: - struct Node *left, *right; ! 358: -}; ! 359: - ! 360: -extern struct Node *newnode(); ! 361: - ! 362: -struct PARS { ! 363: - int home; ! 364: - int dest; ! 365: - int bpnt; ! 366: -} ties[MAXDEPTH]; ! 367: - ! 368: -FILE *tb; /* temp file to store tables */ ! 369: - ! 370: -char procname[MAXNAME], refname[MAXNAME], qsetname[MAXNAME]; ! 371: -char str[256], filename[256]; ! 372: -char strings[MANY][MAXNAME]; ! 373: -extern char yytext[]; ! 374: -extern struct QTABLE qtable[NQUEUES]; ! 375: -extern int varwidths; ! 376: -int nnames = 0; ! 377: -int linenumber = 1; ! 378: -int linecode = 0; /* include source code references */ ! 379: -int nest = 0; /* nesting level of comments (lex) */ ! 380: -int anyerror = 0; ! 381: - ! 382: -int pid = NONE; /* process number */ ! 383: -int qid = NONE; /* queue number */ ! 384: -int rid = NONE; /* template number when defined */ ! 385: -int sid = NONE; /* qset number */ ! 386: -int nid = NONE; /* template number when refered */ ! 387: -int cid = NONE; /* index in call table */ ! 388: -int qind, qisz; /* queue's initial string size */ ! 389: -int parnum; /* counts actual parameters */ ! 390: -int assertion = -1; /* id of assertion table, if any */ ! 391: -int inertion = -1; /* id of error table, if any */ ! 392: -int vartype, inside; ! 393: -int n, m, from, xx, zz; ! 394: -int soo = 0; /* start of optionlist */ ! 395: -int curstate = 0; ! 396: -int curdepth = 0; ! 397: -int lastloop = -1; ! 398: - ! 399: -int verbose = 0; ! 400: -int nopurge = 0; ! 401: - ! 402: -checknames() ! 403: -{ ! 404: - checkrefs(); ! 405: - checkglobvars(); ! 406: - checkqs(); ! 407: -} ! 408: - ! 409: -putglobals(fd) ! 410: - FILE *fd; ! 411: -{ ! 412: - numrefs(fd); ! 413: - numprocs(fd); ! 414: - numsorts(fd); ! 415: - numinits(fd); ! 416: - numglobvars(fd); ! 417: -} ! 418: - ! 419: -puttables(fd1) ! 420: - FILE *fd1; ! 421: -{ FILE *fd2; ! 422: - char buffer[MANY]; ! 423: - int howmuch; ! 424: - ! 425: - if ((fd2 = fopen("pret.tmp", "r")) == NULL) ! 426: - whoops("cannot find pret.tmp"); ! 427: - ! 428: - while ((howmuch = fread(buffer, sizeof(*buffer), MANY, fd2)) > 0) ! 429: - fwrite(buffer, sizeof(*buffer), howmuch, fd1); ! 430: - ! 431: - fclose(fd2); ! 432: - unlink("pret.tmp"); ! 433: -} ! 434: - ! 435: -makebin() ! 436: -{ FILE *fd; ! 437: - ! 438: - if ((fd = fopen((anyerror)?"pret.err":"pret.out", "w")) == NULL) ! 439: - whoops("cannot create output file"); ! 440: - ! 441: - putglobals(fd); ! 442: - puttables(fd); ! 443: - numexps(fd); ! 444: - fclose(fd); ! 445: - if (anyerror) ! 446: - fprintf(stderr, "output written to `pret.err'\n"); ! 447: -} ! 448: - ! 449: -transfer(cl, tg) ! 450: -{ int i = curstate; ! 451: - curstate = enterowname(NEW, "", DAR); ! 452: - setrans(i, cl, curstate, tg); ! 453: -} ! 454: - ! 455: -#include "pret.expr.c" ! 456: - ! 457: -%} ! 458: -%union{ ! 459: - int resu; ! 460: - struct Node *node; ! 461: -} ! 462: - ! 463: -%type <resu> PREIO INDEX QINDEX IMPORT ASGN ASGN ! 464: -%type <node> expr VARNAME ! 465: -%token <resu> NAME VALUE ARNAME QSNAME ! 466: - ! 467: -%start PROT_SPEC ! 468: -%token ASSERT ERROR ! 469: -%token PROCESS PBEGIN END IF FI DO OD ! 470: -%token timeout skip BREAK DEFAULT GOTO ! 471: -%token FLAG ARROW SEMICOLON COLON ! 472: -%token QUEUES QSET PVAR MESG ! 473: -%right '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ! 474: -%left OR ! 475: -%left AND ! 476: -%left GT GE LT LE EQ NE ! 477: -%left '+' '-' ! 478: -%left '*' '/' '%' ! 479: -%left UNARYMINUS NOT INC DEC ! 480: -%right '^' ! 481: - ! 482: -%% ! 483: - ! 484: -PROT_SPEC : ONEMODULE ! 485: - | PROT_SPEC ONEMODULE ! 486: - ; ! 487: - ! 488: -ONEMODULE : PROC_SPEC ! 489: - | TASK_SPEC ! 490: - | ONEDECL ! 491: - | REQUIREMENT ! 492: - ; ! 493: - ! 494: -PROC_SPEC : PROCESS NAME QINDEX ! 495: - { strcpy(procname, strings[$2]); ! 496: - pid = newprocname(strings[$2], $3); ! 497: - } ! 498: - PBEGIN ANYDECLS ! 499: - { extern int extras; ! 500: - int ival; ! 501: - curstate = enterowname(NEW, "", DAR); ! 502: - newcalltable(); ! 503: - ival = 3*MANY+pid+extras; ! 504: - addvarname("_PROCID", (DCL|RFR), ival, NONE, 0); ! 505: - } ! 506: - SEQUENCE END ! 507: - { wrapup(NONE, pid, tb, nopurge, verbose); ! 508: - pid = NONE; ! 509: - strcpy(procname, "_"); ! 510: - } ! 511: - ; ! 512: - ! 513: -ANYDECLS : /* empty */ ! 514: - | DECLS ! 515: - ; ! 516: -DECLS : ONEDECL ! 517: - | DECLS ONEDECL ! 518: - ; ! 519: - ! 520: -ONEDECL : QDECLS ! 521: - | VARDECLS ! 522: - ; ! 523: -/* ! 524: - * QUEUES ! 525: - * ====== ! 526: - */ ! 527: - ! 528: -QDECLS : QUEUES QDECL SEPARATOR ! 529: - ; ! 530: -QDECL : ONEQ ! 531: - | QNAMELIST ! 532: - ; ! 533: - ! 534: -ONEQ : NAME QINDEX '=' ! 535: - { if ($2 == NONE || (qisz=$2) <= 0) ! 536: - yyerror("illegal queue size, %s", strings[$1]); ! 537: - qid = newqname(strings[$1], DCL, qisz, NONE); ! 538: - } ! 539: - PBEGIN MNAMELIST END ! 540: - ; ! 541: - ! 542: -/* ! 543: - * VARIABLES and QUEUESETS ! 544: - * ======================= ! 545: - */ ! 546: - ! 547: -VARDECLS : PVAR VNAMELIST SEPARATOR ! 548: - | QSET QSETDECL SEPARATOR ! 549: - ; ! 550: - ! 551: -QINDEX : /* empty */ { $$ = NONE; } ! 552: - | '[' VALUE ']' { $$ = $2; } ! 553: - ; ! 554: - ! 555: -QSETDECL : NAME PBEGIN NAME QINDEX COLON ! 556: - { xx = newqname(strings[$3], RFR, NONE, $4); ! 557: - sid = newqset(strings[$1], strings[$3], DCL, $4); ! 558: - } ! 559: - SNAMELIST END ! 560: - { closeqset(sid); ! 561: - } ! 562: - ; ! 563: -/* ! 564: - * PROCEDURES ! 565: - * ========== ! 566: - */ ! 567: - ! 568: -TASK_SPEC : NAME ! 569: - { rid = newreftask(strings[$1], DCL); ! 570: - curstate = enterowname(NEW, "", DAR); ! 571: - strcpy(refname, strings[$1]); ! 572: - newcalltable(); ! 573: - vartype = ISV; ! 574: - inside = 1; ! 575: - } ! 576: - '(' ANYPARAMS ')' ! 577: - { inside = 0; ! 578: - } ! 579: - ANYPARTYPES ! 580: - { reorder(); /* renumber formal parameters */ ! 581: - } ! 582: - PBEGIN ! 583: - ANYDECLS ! 584: - SEQUENCE ! 585: - END ! 586: - { wrapup(rid, NONE, tb, nopurge, verbose); ! 587: - strcpy(refname, "_"); ! 588: - rid = NONE; ! 589: - } ! 590: - ; ! 591: - ! 592: -ANYPARAMS : /* empty */ ! 593: - | PNAMELIST ! 594: - | error ! 595: - { yyerror("bad namelist", ""); ! 596: - } ! 597: - ! 598: - ; ! 599: - ! 600: -ANYPARTYPES : /* empty */ ! 601: - | PARTYPES ! 602: - | error ! 603: - { yyerror("bad parameterlist", ""); ! 604: - } ! 605: - ; ! 606: - ! 607: -PARTYPES : ONEPARTYPE SEMICOLON ! 608: - | PARTYPES ONEPARTYPE SEMICOLON ! 609: - ; ! 610: -ONEPARTYPE : PVAR ! 611: - { vartype = ISV; ! 612: - } ! 613: - PNAMELIST ! 614: - | QSET NAME PBEGIN NAME COLON ! 615: - { strcpy(qsetname, strings[$2]); ! 616: - sid = newqset(strings[$2], strings[$4], DCL, NONE); ! 617: - qid = addFpar(rid, strings[$2], sid, ISQ, inside); ! 618: - vartype = ISM; ! 619: - } ! 620: - PNAMELIST END ! 621: - { qid = NONE; ! 622: - closeqset(sid); ! 623: - } ! 624: - ; ! 625: -/* ! 626: - * REQUIREMENTS ! 627: - * ============ ! 628: - */ ! 629: -REQUIREMENT : ASSERT ! 630: - PBEGIN ! 631: - { rid = newreftask(" assert", DCL); ! 632: - assertion = rid; ! 633: - curstate = enterowname(NEW, "", DAR); ! 634: - strcpy(refname, " assert"); ! 635: - newcalltable(); ! 636: - } ! 637: - _SEQUENCE ! 638: - END ! 639: - { wrapup(rid, NONE, tb, nopurge, verbose); ! 640: - strcpy(refname, "_"); ! 641: - rid = NONE; ! 642: - lastloop = -1; ! 643: - } ! 644: - | ERROR ! 645: - PBEGIN ! 646: - { rid = newreftask(" error", DCL); ! 647: - inertion = rid; ! 648: - curstate = enterowname(NEW, "", DAR); ! 649: - strcpy(refname, " error"); ! 650: - newcalltable(); ! 651: - } ! 652: - _SEQUENCE ! 653: - END ! 654: - { wrapup(rid, NONE, tb, nopurge, verbose); ! 655: - strcpy(refname, "_"); ! 656: - rid = NONE; ! 657: - lastloop = -1; ! 658: - } ! 659: - ; ! 660: -_SEQUENCE : _STMNT ! 661: - | _SEQUENCE SEPARATOR _STMNT ! 662: - ; ! 663: - ! 664: -_STMNT : skip { lastloop = -1; } ! 665: - | _SELECT { lastloop = -1; } ! 666: - | _CYCLE ! 667: - | SEND { lastloop = -1; } ! 668: - | GUARD { lastloop = -1; } ! 669: - | STRUCTGOTO { lastloop = -1; } ! 670: - | error ! 671: - { yyerror("illegal assertion statement, %s", yytext); ! 672: - } ! 673: - ; ! 674: -_SELECT : IF ! 675: - { if (++curdepth == MAXDEPTH) ! 676: - whoops("nesting too deep"); ! 677: - ! 678: - ties[curdepth].home = curstate; ! 679: - ties[curdepth].dest = enterowname(NEW, "", DAR); ! 680: - ties[curdepth].bpnt = ! 681: - (curdepth > 1) ? ties[curdepth-1].bpnt : -1; ! 682: - } ! 683: - _OPTIONLIST FI ! 684: - { setrowname(ties[curdepth].dest); ! 685: - curstate = ties[curdepth--].dest; ! 686: - } ! 687: - ; ! 688: - ! 689: -_CYCLE : DO ! 690: - { if (curdepth++ == MAXDEPTH) ! 691: - whoops("nesting too deep"); ! 692: - ! 693: - labelrow(curstate); ! 694: - ties[curdepth].home = curstate; ! 695: - ties[curdepth].dest = curstate; ! 696: - ties[curdepth].bpnt = enterowname(NEW, "", DAR); ! 697: - } ! 698: - _OPTIONLIST OD ! 699: - { lastloop = ties[curdepth].home; ! 700: - setrowname(ties[curdepth].bpnt); ! 701: - curstate = ties[curdepth--].bpnt; ! 702: - } ! 703: - ; ! 704: -_OPTIONLIST : _ONEOPTION ! 705: - | _ONEOPTION _OPTIONLIST ! 706: - ; ! 707: - ! 708: -_ONEOPTION : FLAG _SEQUENCE ! 709: - { getrowname(str, ties[curdepth].dest); ! 710: - from = curstate; ! 711: - curstate = enterowname(OLD, str, DAR); ! 712: - setrans(from, 0, curstate, NONE); ! 713: - curstate = ties[curdepth].home; ! 714: - } ! 715: - ; ! 716: -/* ! 717: - * NAMELISTS ! 718: - * ========= ! 719: - */ ! 720: - ! 721: -ANAMELIST : ANAME ! 722: - | ANAMELIST ',' ANAME ! 723: - ; ! 724: -MNAMELIST : MNAME ! 725: - | MNAMELIST ',' MNAME ! 726: - ; ! 727: -PNAMELIST : PNAME ! 728: - | PNAMELIST ',' PNAME ! 729: - ; ! 730: -QNAMELIST : QNAME ! 731: - | QNAMELIST ',' QNAME ! 732: - ; ! 733: -SNAMELIST : SNAME ! 734: - | SNAMELIST ',' SNAME ! 735: - ; ! 736: -VNAMELIST : VNAME ! 737: - | VNAMELIST ',' VNAME ! 738: - ; ! 739: -/* ! 740: - * NAMES ! 741: - * ===== ! 742: - */ ! 743: - ! 744: -ANAME : QSNAME { addApars(strings[$1], nid, parnum++, NONE); } ! 745: - | expr { addAspecial(makeexpr($1), nid, parnum++); } ! 746: - ; ! 747: -MNAME : NAME ! 748: - { qtable[qid].status |= ADR; ! 749: - addmsg(strings[$1], qid, SND, INITM, NONE); ! 750: - if (--qisz < 0) ! 751: - yyerror("queue overfilled, %s", strings[$1]); ! 752: - } ! 753: - ; ! 754: -PNAME : NAME ! 755: - { if (vartype == ISM) ! 756: - addsetname(strings[$1], sid, 1); ! 757: - else ! 758: - addFpar(rid, strings[$1], qid, vartype, inside); ! 759: - } ! 760: - ; ! 761: -QNAME : NAME '[' VALUE ']' ! 762: - { if ((qisz = $3) <= 0) ! 763: - yyerror("illegal queue size, %s", strings[$1]); ! 764: - newqname(strings[$1], DCL, $3, NONE); ! 765: - } ! 766: - | NAME '[' VALUE ']' '[' VALUE ']' ! 767: - { if ((qisz = $6) <= 0) ! 768: - yyerror("illegal queue size, %s", strings[$1]); ! 769: - newqname(strings[$1], DCL, qisz, $3); ! 770: - } ! 771: - ; ! 772: -SNAME : NAME { addsetname(strings[$1], sid, 0); } ! 773: - ; ! 774: -VNAME : NAME QINDEX ! 775: - { addvarname(strings[$1], DCL, NONE, $2, 0); ! 776: - } ! 777: - | NAME QINDEX '=' expr ! 778: - { addvarname(strings[$1], DCL, makeexpr($4), $2, 0); ! 779: - } ! 780: - | NAME QINDEX COLON VALUE ! 781: - { addvarname(strings[$1], DCL, NONE, $2, $4); ! 782: - } ! 783: - ; ! 784: -/* ! 785: - * CODE ! 786: - * ==== ! 787: - */ ! 788: - ! 789: -SEQUENCE : STMNT ! 790: - { soo = 0; ! 791: - } ! 792: - | SEQUENCE SEPARATOR STMNT ! 793: - { soo = 0; ! 794: - } ! 795: - ; ! 796: - ! 797: -STMNT : skip ! 798: - { if (soo) /* only if used as a guard */ ! 799: - transfer(0, NONE); ! 800: - } ! 801: - | SELECT ! 802: - | CYCLE ! 803: - | SEND ! 804: - | GUARD ! 805: - | JUMP ! 806: - | LABEL STMNT ! 807: - | TEMPLATE ! 808: - | BUILTIN ! 809: - | CONDITIONAL ! 810: - | END ! 811: - { yyerror("expecting a statement", ""); ! 812: - whoops("exit"); ! 813: - } ! 814: - ; ! 815: - ! 816: -SELECT : IF ! 817: - { if (++curdepth == MAXDEPTH) ! 818: - whoops("nesting too deep"); ! 819: - ! 820: - ties[curdepth].home = curstate; ! 821: - ties[curdepth].dest = enterowname(NEW, "", DAR); ! 822: - ties[curdepth].bpnt = ! 823: - (curdepth>1) ? ties[curdepth-1].bpnt : -1; ! 824: - } ! 825: - OPTIONLIST FI ! 826: - { setrowname(ties[curdepth].dest); ! 827: - curstate = ties[curdepth--].dest; ! 828: - } ! 829: - ; ! 830: - ! 831: -CYCLE : DO ! 832: - { if (curdepth++ == MAXDEPTH) ! 833: - whoops("nesting too deep"); ! 834: - ! 835: - labelrow(curstate); ! 836: - ties[curdepth].home = curstate; ! 837: - ties[curdepth].dest = curstate; ! 838: - ties[curdepth].bpnt = enterowname(NEW, "", DAR); ! 839: - } ! 840: - OPTIONLIST OD ! 841: - { setrowname(ties[curdepth].bpnt); ! 842: - curstate = ties[curdepth--].bpnt; ! 843: - } ! 844: - ; ! 845: - ! 846: -OPTIONLIST : ONEOPTION ! 847: - | ONEOPTION OPTIONLIST ! 848: - ; ! 849: - ! 850: -ONEOPTION : FLAG ! 851: - { soo = 1; /* start of an option string */ ! 852: - } ! 853: - SEQUENCE ! 854: - { getrowname(str, ties[curdepth].dest); ! 855: - from = curstate; ! 856: - curstate = enterowname(OLD, str, DAR); ! 857: - setrans(from, 0, curstate, NONE); ! 858: - curstate = ties[curdepth].home; ! 859: - } ! 860: - ; ! 861: - ! 862: -INDEX : /* empty */ { $$ = NONE; } ! 863: - | '[' expr ']' { $$ = makeexpr($2); } ! 864: - ; ! 865: - ! 866: -PREIO : NAME INDEX ! 867: - { strcpy(str, strings[$1]); /* swivel away name */ ! 868: - $$ = $2; ! 869: - } ! 870: - ; ! 871: - ! 872: -SEND : PREIO NOT NAME EXPORT ! 873: - { xx = newqname(str, ADR, NONE, $1); ! 874: - zz = addmsg(strings[$3], xx, SND, NORM, $1); ! 875: - n = entercolname(zz, OUTP); ! 876: - transfer(n, m); ! 877: - } ! 878: - ; ! 879: - ! 880: -EXPORT : /* empty */ { m = NONE; } ! 881: - | '(' expr ')' { m = makeexpr($2); } ! 882: - ; ! 883: - ! 884: -GUARD : PREIO '?' timeout ! 885: - { int x; ! 886: - xx = newqname(str, RFR, NONE, $1); ! 887: - x = addmsg(" tau", xx, SAR, NORM, $1); ! 888: - /* ! 889: - ** the leading space is to avoid ! 890: - ** clashes with a user name `tau', ! 891: - ** e.g. in a formal parameter list ! 892: - */ ! 893: - n = entercolname(x, TMO); ! 894: - transfer(n, NONE); ! 895: - } ! 896: - | PREIO '?' NAME IMPORT ! 897: - { xx = newqname(str, RFR, NONE, $1); ! 898: - zz = addmsg(strings[$3], xx, RCV, NORM, $1); ! 899: - n = entercolname(zz, INP); ! 900: - transfer(n, $4); ! 901: - } ! 902: - | PREIO '?' DEFAULT IMPORT ! 903: - { xx = newqname(str, RFR, NONE, $1); ! 904: - zz = addmsg(" any", xx, SAR, NORM, $1); ! 905: - n = entercolname(zz, DFL); ! 906: - transfer(n, $4); ! 907: - } ! 908: - ; ! 909: - ! 910: -IMPORT : /* empty */ ! 911: - { $$ = NONE; ! 912: - } ! 913: - | '(' ARNAME INDEX ')' ! 914: - { $$ = addvarname(strings[$2], RFR, NONE, $3, 0); ! 915: - } ! 916: - | '(' NAME ')' ! 917: - { $$ = addvarname(strings[$2], RFR, NONE, NONE, 0); ! 918: - } ! 919: - | '(' VALUE ')' ! 920: - { yyerror("importing into constant", ""); ! 921: - } ! 922: - ; ! 923: - ! 924: -SEPARATOR : ARROW ! 925: - | SEMICOLON ! 926: - | error ! 927: - { yyerror("expecting a stmnt separator", ""); ! 928: - } ! 929: - ; ! 930: - ! 931: -JUMP : GOTO NAME ! 932: - { from = curstate; ! 933: - curstate = enterowname(LAB, strings[$2], ADR); ! 934: - setrans(from, 0, curstate, NONE); ! 935: - curstate = enterowname(NEW, "", DAR); ! 936: - } ! 937: - | STRUCTGOTO ! 938: - ; ! 939: - ! 940: -STRUCTGOTO : BREAK ! 941: - { int i; ! 942: - from = curstate; ! 943: - i = ties[curdepth].bpnt; ! 944: - ! 945: - if (curdepth == 0 || i == -1) ! 946: - whoops("illegal break statement"); ! 947: - ! 948: - getrowname(str, i); ! 949: - curstate = enterowname(OLD, str, DAR); ! 950: - setrans(from, 0, curstate, NONE); ! 951: - curstate = enterowname(NEW, "", DAR); ! 952: - } ! 953: - ; ! 954: - ! 955: -TEMPLATE : NAME ! 956: - { nid = newreftask(strings[$1], RFR); ! 957: - parnum = 0; qid = sid = NONE; ! 958: - cid = newcall(nid); ! 959: - } ! 960: - '(' ANYACTUALS ')' ! 961: - { int x; ! 962: - parrefs(parnum, nid); ! 963: - x = entercolname(cid, FCT); ! 964: - transfer(x, NONE); ! 965: - } ! 966: - ; ! 967: - ! 968: -ANYACTUALS : /* empty */ ! 969: - | ANAMELIST ! 970: - ; ! 971: - ! 972: -CONDITIONAL : '(' expr ')' ! 973: - { transfer(entercolname(makeexpr($2), CND), NONE); ! 974: - } ! 975: - ; ! 976: - ! 977: -VARNAME : ARNAME INDEX ! 978: - { m = addvarname(strings[$1], RFR, NONE, $2, 0); ! 979: - $$ = newnode(NM, m, NULL, NULL); ! 980: - } ! 981: - | NAME ! 982: - { m = addvarname(strings[$1], RFR, NONE, NONE, 0); ! 983: - $$ = newnode(NM, m, NULL, NULL); ! 984: - } ! 985: - ; ! 986: - ! 987: -BUILTIN : VARNAME ASGN expr ! 988: - { m = makeexpr(newnode(OP, $2, $1, $3)); ! 989: - transfer(0, m); ! 990: - } ! 991: - | VARNAME INC ! 992: - { m = makeexpr(newnode(OP, poinc, $1, NULL)); ! 993: - transfer(0, m); ! 994: - } ! 995: - | VARNAME DEC ! 996: - { m = makeexpr(newnode(OP, podec, $1, NULL)); ! 997: - transfer(0, m); ! 998: - } ! 999: - ; ! 1000: - ! 1001: -ASGN : '=' { $$ = setv; } ! 1002: - | ADDEQ { $$ = addeq; } ! 1003: - | SUBEQ { $$ = subeq; } ! 1004: - | MULEQ { $$ = muleq; } ! 1005: - | DIVEQ { $$ = diveq; } ! 1006: - | MODEQ { $$ = modeq; } ! 1007: - ; ! 1008: - ! 1009: -expr : expr '+' expr { $$ = newnode(OP, plus, $1, $3); } ! 1010: - | expr '-' expr { $$ = newnode(OP, minus, $1, $3); } ! 1011: - | expr '*' expr { $$ = newnode(OP, times, $1, $3); } ! 1012: - | expr '/' expr { $$ = newnode(OP, div, $1, $3); } ! 1013: - | expr '%' expr { $$ = newnode(OP, mod, $1, $3); } ! 1014: - | expr '^' expr { $$ = newnode(OP, power, $1, $3); } ! 1015: - | expr GT expr { $$ = newnode(OP, gt, $1, $3); } ! 1016: - | expr GE expr { $$ = newnode(OP, ge, $1, $3); } ! 1017: - | expr LT expr { $$ = newnode(OP, lt, $1, $3); } ! 1018: - | expr LE expr { $$ = newnode(OP, le, $1, $3); } ! 1019: - | expr EQ expr { $$ = newnode(OP, eq, $1, $3); } ! 1020: - | expr NE expr { $$ = newnode(OP, ne, $1, $3); } ! 1021: - | expr AND expr { $$ = newnode(OP, land, $1, $3); } ! 1022: - | expr OR expr { $$ = newnode(OP, lor, $1, $3); } ! 1023: - | '-' expr %prec UNARYMINUS ! 1024: - { $$ = newnode(OP, uminus, $2, NULL); } ! 1025: - | NOT expr ! 1026: - { $$ = newnode(OP, lnot, $2, NULL); } ! 1027: - | VALUE ! 1028: - { $$ = newnode(NM, $1+3*MANY, NULL, NULL); } ! 1029: - | ARNAME INDEX ! 1030: - { m = addvarname(strings[$1], RFR, NONE, $2, 0); ! 1031: - $$ = newnode(NM, m, NULL, NULL); ! 1032: - } ! 1033: - | NAME ! 1034: - { m = addvarname(strings[$1], RFR, NONE, NONE, 0); ! 1035: - $$ = newnode(NM, m, NULL, NULL); ! 1036: - } ! 1037: - | '(' expr ')' { $$ = $2; } ! 1038: - ; ! 1039: - ! 1040: -LABEL : NAME COLON ! 1041: - { from = curstate; ! 1042: - curstate = enterowname(LAB, strings[$1], DCL); ! 1043: - labelrow(curstate); ! 1044: - setrans(from, 0, curstate, NONE); ! 1045: - } ! 1046: - ; ! 1047: -%% ! 1048: - ! 1049: -extern FILE *yyin; ! 1050: - ! 1051: -main(argc, argv) ! 1052: - char **argv; ! 1053: -{ ! 1054: - int base = 1, i = 1; ! 1055: - char c, buff[256]; ! 1056: - char outfile[32]; ! 1057: - ! 1058: - if (argc > base && argv[1][0] == '-') ! 1059: - { while ((c = argv[1][i++]) != '\0') ! 1060: - switch (c) { ! 1061: - case 's': varwidths = 1; break; ! 1062: - case 'v': verbose = 1; break; ! 1063: - case 'n': nopurge = 1; break; ! 1064: - case 'l': linecode = 1; break; ! 1065: - default : fprintf(stderr, "usage: pret [-vsnl] file\n"); ! 1066: - fprintf(stderr, "\tv - verbose\n"); ! 1067: - fprintf(stderr, "\ts - supertrace format\n"); ! 1068: - fprintf(stderr, "\tn - no minimization\n"); ! 1069: - fprintf(stderr, "\tl - enables linecode\n"); ! 1070: - exit(1); ! 1071: - } ! 1072: - base++; ! 1073: - } ! 1074: - if (argc <= base) ! 1075: - { fprintf(stderr, "usage: pret [-vnl] file\n"); ! 1076: - exit(1); ! 1077: - ! 1078: - } ! 1079: - if ((tb = fopen("pret.tmp", "w")) == NULL) ! 1080: - whoops("cannot create pret.tmp\n"); ! 1081: - ! 1082: - strcpy(procname, "_"); ! 1083: - strcpy(refname, "_"); ! 1084: - unlink("pret.out"); ! 1085: - unlink("pret.err"); ! 1086: - ! 1087: - if (argc > base) ! 1088: - { strcpy(filename, argv[base]); ! 1089: - ! 1090: - mktemp(strcpy(outfile, "/tmp/trans.XXXXXX")); ! 1091: - sprintf(buff, "/lib/cpp %s > %s", filename, outfile); ! 1092: - ! 1093: - if (system(buff)) ! 1094: - { unlink(outfile); ! 1095: - exit(1); ! 1096: - } else ! 1097: - if ((yyin = fopen(outfile, "r")) == NULL) ! 1098: - { printf("cannot open %s\n", outfile); ! 1099: - whoops("aborting"); ! 1100: - } ! 1101: - unlink(outfile); ! 1102: - } ! 1103: - parsed = (struct REVPOL *) ! 1104: - Emalloc(EXPRMAX * sizeof(struct REVPOL)); ! 1105: - prs = 0; ! 1106: - ! 1107: - yyparse(); ! 1108: - prepsorts(); ! 1109: - checknames(); ! 1110: - fclose(tb); ! 1111: - chatter(); ! 1112: - makebin(); ! 1113: - exit(0); ! 1114: -} ! 1115: - ! 1116: -newstring(str) ! 1117: - char *str; ! 1118: -{ register int i; ! 1119: - ! 1120: - for (i = 0; i < nnames; i++) ! 1121: - if (strcmp(str, strings[i]) == 0) ! 1122: - return i; ! 1123: - if (++nnames >= MANY) ! 1124: - yyerror("symbol table overflow, %s", str); ! 1125: - strncpy(strings[i], str, MAXNAME-1); ! 1126: - return i; ! 1127: -} ! 1128: //GO.SYSIN DD pret.y ! 1129: echo pret0.c 1>&2 ! 1130: sed 's/.//' >pret0.c <<'//GO.SYSIN DD pret0.c' ! 1131: -#include <stdio.h> ! 1132: -#include "pret.h" ! 1133: -#include "pret.d" ! 1134: - ! 1135: -#define DEBUG6 0 ! 1136: -#define DEBUG7 0 ! 1137: - ! 1138: -extern struct COL column[MANY]; ! 1139: -extern struct ROW row[MANY]; ! 1140: -extern int nrrows, nrcols, redrows; ! 1141: - ! 1142: -struct ENTRY * find(); ! 1143: -char * Emalloc(); ! 1144: - ! 1145: -char **triangle; ! 1146: -short **successor; ! 1147: -short *tmpsucc; ! 1148: -int *unmap; /* reverses maptwo values to original row numbers */ ! 1149: - ! 1150: -MAP(x) ! 1151: -{ int y = row[x].maptwo; /* gives a value between 0 and redrows */ ! 1152: - ! 1153: - unmap[y] = x; ! 1154: - return y; ! 1155: -} ! 1156: - ! 1157: -minimize() ! 1158: -{ int i, j; ! 1159: - int n = redrows; ! 1160: - ! 1161: - unmap = (int *) ! 1162: - Emalloc( n * sizeof (int) ); ! 1163: - triangle = (char **) ! 1164: - Emalloc( n * sizeof (char *) ); ! 1165: - /* ! 1166: - ** allocate a triangle of states ! 1167: - ** triangle[i][j] == 1 ! 1168: - ** will indicate that the states i and j are ! 1169: - ** in the same equivalence class ! 1170: - ** initially, claim all pairs to be equivalent ! 1171: - */ ! 1172: - ! 1173: - for (i = 1; i < n; i++) ! 1174: - { triangle[i] = (char *) ! 1175: - Emalloc(i * sizeof (char)); ! 1176: - for (j = 0; j < i; j++) ! 1177: - triangle[i][j] = 1; ! 1178: - } ! 1179: - tmpsucc = (short *) ! 1180: - Emalloc( n * sizeof (short)); ! 1181: - successor = (short **) ! 1182: - Emalloc( n * sizeof (short *) ); ! 1183: - ! 1184: - for (i = 0; i < n; i++) ! 1185: - { successor[i] = (short *) ! 1186: - Emalloc(n * sizeof (short)); ! 1187: - for (j = 0; j < n; j++) ! 1188: - successor[i][j] = 0; ! 1189: - } ! 1190: - partition(); ! 1191: - ! 1192: -#if DEBUG6 ! 1193: - putriangle(); ! 1194: -#endif ! 1195: - squash(); ! 1196: - ! 1197: - for (i = 1; i < n; i++) ! 1198: - free(triangle[i]); ! 1199: - free(triangle); ! 1200: - free(unmap); ! 1201: -} ! 1202: - ! 1203: -/* ! 1204: -newgeneration() ! 1205: -{ register int i,j; ! 1206: - ! 1207: - for (j = 0; j < n; i++) ! 1208: - tmpsucc[j] = 0; ! 1209: - for (i = 0; i < n; i++) ! 1210: - { for (j = 0; j < n; j++) ! 1211: - addkids(successor[i][j]); ! 1212: - for (j = 0; j < n; j++) ! 1213: - { successor[i][j] = tmpsucc[j]; ! 1214: - tmpsucc[i] = 0; ! 1215: - } ! 1216: - } ! 1217: -} ! 1218: - ! 1219: -addkids(whosekids) ! 1220: -{ register int h,k,x,y; ! 1221: - struct ENTRY *one = find(i, 0); ! 1222: - struct ENTRY *two = find(j, 0); ! 1223: - struct PILAR *a; ! 1224: - ! 1225: - ! 1226: - for (k = 0; k < nrcols; k++) ! 1227: - { for (h = 0; h < one->nrpils; h++) ! 1228: - { a = one->pilar; ! 1229: - ! 1230: - tmpsucc[target(a->transf)] = 1; ! 1231: - ! 1232: - a = a->nxtp; ! 1233: - } ! 1234: - one = one->nextcol; ! 1235: - two = two->nextcol; ! 1236: - } ! 1237: -} ! 1238: -*/ ! 1239: - ! 1240: -partition() ! 1241: -{ register int i, j, K; ! 1242: - int anychange = 1; ! 1243: - ! 1244: - /* ! 1245: - ** recursively scan through the ! 1246: - ** triangle to find non-equivalent pairs ! 1247: - ** until pi(1) -> pi(k) == pi(k-1) ! 1248: - */ ! 1249: - ! 1250: - for (K = 1; anychange == 1; K++) ! 1251: - { anychange = 0; ! 1252: -#if DEBUG7 ! 1253: - printf("%d Equivalence:\n", K); ! 1254: -#endif DEBUG7 ! 1255: - for (i = nrrows-1; i > 0; i--) ! 1256: - { if (row[i].mapping != NOSTATE) ! 1257: - continue; ! 1258: - ! 1259: - for (j = 0; j < i; j++) ! 1260: - { if (row[j].mapping != NOSTATE ! 1261: - || triangle[MAP(i)][MAP(j)] == 0) ! 1262: - continue; ! 1263: - ! 1264: - if ( !equiv(K, i, j) ) ! 1265: - { triangle[MAP(i)][MAP(j)] = 0; ! 1266: - anychange = 1; ! 1267: - } ! 1268: -#if DEBUG7 ! 1269: - else ! 1270: - { printf("\tstates: %2d,", MAP(i)); ! 1271: - printf("%2d\n", MAP(j)); ! 1272: - } ! 1273: -#endif DEBUG7 ! 1274: -} } } } ! 1275: - ! 1276: -#if DEBUG6 ! 1277: -putriangle() ! 1278: -{ int i, j; ! 1279: - int n = redrows; ! 1280: - int cn = 0; ! 1281: - char * class = (char *) Emalloc (n * sizeof (char) ); ! 1282: - ! 1283: - for (i = 0; i < n; i++) ! 1284: - class[i] = 0; ! 1285: - ! 1286: - for (i = 1; i < n; i++) ! 1287: - for (j = 0; j < i; j++) ! 1288: - if ( triangle[i][j] ) ! 1289: - { if (class[i] == 0 && class[j] == 0) ! 1290: - class[i] = class[j] = ++cn; ! 1291: - else if (class[i] != 0) ! 1292: - class[j] = class[i]; ! 1293: - else if (class[j] != 0) ! 1294: - class[i] = class[j]; ! 1295: - else ! 1296: - whoops("cannot happen, classes"); ! 1297: - } ! 1298: - ! 1299: - for (i = 1; i <= cn; i++) ! 1300: - { printf("class %2d: ", i); ! 1301: - for (j = 0; j < n; j++) ! 1302: - if (class[j] == i) ! 1303: - printf("%d,", j); ! 1304: - printf("\n\n"); ! 1305: - } ! 1306: - ! 1307: - free(class); ! 1308: -} ! 1309: -#endif ! 1310: - ! 1311: -squash() ! 1312: -{ int i, j; ! 1313: - int n = redrows; ! 1314: - for (i = 1; i < n; i++) ! 1315: - for (j = 0; j < i; j++) ! 1316: - if ( triangle[i][j] ) ! 1317: - { row[unmap[i]].mapping = unmap[j]; ! 1318: - row[unmap[j]].labeled |= row[unmap[i]].labeled; ! 1319: - } ! 1320: -} ! 1321: - ! 1322: -outequiv(A, B) ! 1323: - struct ENTRY *A, *B; ! 1324: -{ struct PILAR *at = A->pilar; ! 1325: - struct PILAR *it = B->pilar; ! 1326: - ! 1327: - /* ! 1328: - ** don't look at the at->transf's, ! 1329: - ** equal columns implicitly give ! 1330: - ** equal inputs or outputs, so ! 1331: - ** just compare the cargo codes ! 1332: - */ ! 1333: - ! 1334: - while (it != NULL && at != NULL) ! 1335: - { if (at->code != it->code) ! 1336: - break; ! 1337: - ! 1338: - at = at->nxtp; ! 1339: - it = it->nxtp; ! 1340: - } ! 1341: - ! 1342: - return (it == NULL && at == NULL); ! 1343: -} ! 1344: - ! 1345: -equiv(K, i, j) ! 1346: -{ int h, k, x, y, z; ! 1347: - struct ENTRY *one = find(i, 0); ! 1348: - struct ENTRY *two = find(j, 0); ! 1349: - struct PILAR *a, *b; ! 1350: - ! 1351: - if (one->nrpils != two->nrpils) ! 1352: - return 0; ! 1353: - ! 1354: - if (K == 1) ! 1355: - { for (k = 0; k < nrcols; k++) ! 1356: - { if ( !outequiv(one, two) ) ! 1357: - return 0; ! 1358: - ! 1359: - one = one->nextcol; ! 1360: - two = two->nextcol; ! 1361: - } ! 1362: - } else ! 1363: - for (k = 0; k < nrcols; k++) ! 1364: - { a = one->pilar; ! 1365: - b = two->pilar; ! 1366: - for (h = 0; h < one->nrpils; h++) ! 1367: - { ! 1368: - x = target(a->transf); ! 1369: - y = target(b->transf); ! 1370: - x = MAP(x); y = MAP(y); ! 1371: - if (y > x) { z=x; x=y; y=z; } ! 1372: - if (x != y && triangle[x][y] == 0) ! 1373: - return 0; ! 1374: - ! 1375: - a = a->nxtp; ! 1376: - b = b->nxtp; ! 1377: - } ! 1378: - one = one->nextcol; ! 1379: - two = two->nextcol; ! 1380: - } ! 1381: - ! 1382: - return 1; ! 1383: -} ! 1384: //GO.SYSIN DD pret0.c ! 1385: echo pret1.c 1>&2 ! 1386: sed 's/.//' >pret1.c <<'//GO.SYSIN DD pret1.c' ! 1387: -#include <stdio.h> ! 1388: -#include "pret.h" ! 1389: - ! 1390: -#define LOOK 0 ! 1391: -#define ADD 1 ! 1392: - ! 1393: -struct QSET_EL { ! 1394: - char name[MAXNAME]; /* message name */ ! 1395: - char status; /* usage of this message */ ! 1396: - int id; /* number assigned to msg */ ! 1397: - struct QSET_EL *nxtel; ! 1398: -}; ! 1399: - ! 1400: -struct QSETS { ! 1401: - int nrelmnts; ! 1402: - int status; /* usage of the qset itself */ ! 1403: - int qstatus; /* usage of the setowner (a queue) */ ! 1404: - char setname[MAXNAME]; /* symbolic name */ ! 1405: - char setowner[MAXNAME]; /* queue */ ! 1406: - int qind; /* NONE if simple q, #expr if array */ ! 1407: - struct QSET_EL *elmnts; ! 1408: - struct QSETS *nxtset; ! 1409: - int closed; ! 1410: -}; ! 1411: - ! 1412: -struct QSETS *frstset; ! 1413: -int nrsets = 0; ! 1414: - ! 1415: -extern struct QTABLE qtable[NQUEUES]; ! 1416: -extern char procname[MAXNAME]; ! 1417: -extern char refname[MAXNAME]; ! 1418: -extern pid, rid; ! 1419: -char *Emalloc(); ! 1420: - ! 1421: -isqset(str) ! 1422: - char *str; ! 1423: -{ struct QSETS *q = frstset; ! 1424: - char buf1[MAXNAME], buf2[MAXNAME]; ! 1425: - int i; ! 1426: - ! 1427: - buf1[0] = '\0'; ! 1428: - if (pid != NONE) ! 1429: - strncpy(buf1, procname, 8); ! 1430: - else if (rid != NONE) ! 1431: - strncpy(buf1, refname, 8); ! 1432: - strcat(buf1, ":"); ! 1433: - ! 1434: - strcpy(buf2, "global:"); ! 1435: - strcat(buf1, str); ! 1436: - strcat(buf2, str); ! 1437: - ! 1438: - for (i = 0; i < nrsets; i++, q = q->nxtset) ! 1439: - { if (strcmp(buf1, q->setname) == 0 ! 1440: - || strcmp(buf2, q->setname) == 0) ! 1441: - return 1; ! 1442: - } ! 1443: - return 0; ! 1444: -} ! 1445: - ! 1446: -struct QSETS * ! 1447: -findset(which) ! 1448: -{ struct QSETS *hook = frstset; ! 1449: - int i; ! 1450: - ! 1451: - if (which >= nrsets || which < 0) ! 1452: - whoops("cannot happen - findset"); ! 1453: - ! 1454: - for (i = 0; i < which; i++) ! 1455: - hook = hook->nxtset; ! 1456: - ! 1457: - return hook; ! 1458: -} ! 1459: - ! 1460: -inqset(which, what, usage, qind) ! 1461: - char *what; ! 1462: -{ ! 1463: - struct QSETS *hook = findset(which); ! 1464: - struct QSET_EL *hookl = hook->elmnts; ! 1465: - int i; ! 1466: - ! 1467: - for (i = 0; i < hook->nrelmnts; i++) ! 1468: - { if (strcmp(what, hookl->name) == 0) ! 1469: - { hookl->status |= usage; ! 1470: - if (hookl->id == -1) ! 1471: - whoops("unnumbered parameter"); ! 1472: - if (qind != hook->qind) ! 1473: - yyerror("queue indexing error, qset, %s", what); ! 1474: - return hookl->id; ! 1475: - } ! 1476: - hookl = hookl->nxtel; ! 1477: - } ! 1478: - ! 1479: - return -1; ! 1480: -} ! 1481: - ! 1482: -renumqset(which, N) ! 1483: -{ struct QSETS * hook = findset(which); ! 1484: - struct QSET_EL * hookl = hook->elmnts; ! 1485: - int i, j; ! 1486: - ! 1487: - qsetowner(which, 0); ! 1488: - for (i = 0, j = N; i < hook->nrelmnts; i++) ! 1489: - { hookl->id = j++; ! 1490: - hookl = hookl->nxtel; ! 1491: - } ! 1492: - return j; ! 1493: -} ! 1494: - ! 1495: -matchset(a, b) ! 1496: -{ struct QSETS * one = findset(a); ! 1497: - struct QSETS * two = findset(b); ! 1498: - struct QSET_EL * onel; ! 1499: - struct QSET_EL * twol; ! 1500: - int i; ! 1501: - ! 1502: - if (one->nrelmnts != two->nrelmnts) ! 1503: - { yyerror("qset does not match formal parameter, %s", one->setname); ! 1504: - return; ! 1505: - } ! 1506: - onel = one->elmnts; ! 1507: - twol = two->elmnts; ! 1508: - ! 1509: - for (i = 0; i < one->nrelmnts; i++) ! 1510: - { onel->status |= twol->status; ! 1511: - onel = onel->nxtel; ! 1512: - twol = twol->nxtel; ! 1513: - } ! 1514: - return two->qstatus; ! 1515: -} ! 1516: - ! 1517: -matchowner(a, str, how, qind) ! 1518: - char *str; ! 1519: -{ struct QSETS * hook = findset(a); ! 1520: - ! 1521: - if (strcmp(hook->setowner, str) == 0) ! 1522: - { hook->qstatus |= how; ! 1523: - if (qind != hook->qind) ! 1524: - yyerror("queue indexing error (qset ref), %s", str); ! 1525: - return 1; ! 1526: - } ! 1527: - return 0; ! 1528: -} ! 1529: - ! 1530: -struct QSET_EL * ! 1531: -mkelmnt(str, how) ! 1532: - char *str; ! 1533: -{ struct QSET_EL *try = (struct QSET_EL *) ! 1534: - Emalloc( sizeof( struct QSET_EL ) ); ! 1535: - ! 1536: - strcpy(try->name, str); ! 1537: - try->nxtel = NULL; ! 1538: - try->status = how; ! 1539: - try->id = -1; ! 1540: - ! 1541: - return try; ! 1542: -} ! 1543: - ! 1544: -struct QSETS * ! 1545: -mkset(str1, str2, how, qind) ! 1546: - char *str1, *str2; ! 1547: -{ struct QSET_EL *hook; ! 1548: - struct QSETS *try = (struct QSETS *) ! 1549: - Emalloc( sizeof( struct QSETS ) ); ! 1550: - ! 1551: - if (how == RFR) ! 1552: - yyerror("undeclared qset, %s", str1); ! 1553: - ! 1554: - try->status = how; ! 1555: - try->qstatus = 0; ! 1556: - try->nxtset = NULL; ! 1557: - strcpy(try->setname, str1); ! 1558: - strcpy(try->setowner, str2); ! 1559: - try->closed = 0; ! 1560: - try->qind = qind; ! 1561: - ! 1562: - try->nrelmnts = 0; ! 1563: - try->elmnts = mkelmnt(" tau", SAR); ! 1564: - try->nrelmnts++; ! 1565: - ! 1566: - hook = try->elmnts; ! 1567: - hook->nxtel = mkelmnt(" any", SND); ! 1568: - try->nrelmnts++; ! 1569: - ! 1570: - nrsets++; ! 1571: - return try; ! 1572: -} ! 1573: - ! 1574: -qsetowner(which, how) ! 1575: -{ struct QSETS *hook = findset(which); ! 1576: - return newqname(hook->setowner, how, NONE, hook->qind); ! 1577: -} ! 1578: - ! 1579: -inset(str, str2, mask, how, qind) ! 1580: - char *str, *str2; ! 1581: -{ struct QSETS *hook = frstset; ! 1582: - struct QSETS *last = frstset; ! 1583: - int i; ! 1584: - for (i = 0; i < nrsets && hook != NULL; i++) ! 1585: - { if (strcmp(hook->setname, str) == 0) ! 1586: - { if (mask == DCL) ! 1587: - yyerror("qset redeclared, %s", str); ! 1588: - hook->status |= mask; ! 1589: - break; ! 1590: - } ! 1591: - last = hook; ! 1592: - hook = hook->nxtset; ! 1593: - } ! 1594: - if (how == ADD && i == nrsets) ! 1595: - last->nxtset = mkset(str, str2, mask, qind); ! 1596: - ! 1597: - return i; ! 1598: -} ! 1599: - ! 1600: -newqset(str1, str2, mask, qind) ! 1601: - char *str1, *str2; ! 1602: -{ ! 1603: - int i = nrsets; ! 1604: - char str[MAXNAME]; ! 1605: - ! 1606: - if (pid != NONE) ! 1607: - strncpy(str, procname, 8); ! 1608: - else if (rid != NONE) ! 1609: - strncpy(str, refname, 8); ! 1610: - else ! 1611: - strcpy(str, "global"); ! 1612: - strcat(str, ":"); ! 1613: - strcat(str, str1); ! 1614: - ! 1615: - if (mask == RFR && (pid != NONE || rid != NONE)) ! 1616: - { if (inset(str, str2, mask, LOOK, qind) == nrsets) ! 1617: - { strcpy(str, "global"); ! 1618: - strcat(str, ":"); ! 1619: - strcat(str, str1); ! 1620: - } } ! 1621: - ! 1622: - if (nrsets == 0) ! 1623: - frstset = mkset(str, str2, mask, qind); ! 1624: - else ! 1625: - i = inset(str, str2, mask, ADD, qind); ! 1626: - ! 1627: - return i; ! 1628: -} ! 1629: - ! 1630: -closeqset(which) ! 1631: -{ struct QSETS *where = findset(which); ! 1632: - where->closed = 1; ! 1633: -} ! 1634: - ! 1635: -isclosed(which) ! 1636: -{ struct QSETS *where = findset(which); ! 1637: - return where->closed; ! 1638: -} ! 1639: - ! 1640: -addsetname(str, which, susp) ! 1641: - char *str; ! 1642: -{ struct QSETS *where = findset(which); ! 1643: - struct QSET_EL *hook = where->elmnts; ! 1644: - int i, j; ! 1645: - ! 1646: - j = newqname(where->setowner, 0, NONE, where->qind); ! 1647: - i = where->nrelmnts; ! 1648: - ! 1649: - if (i == 0) ! 1650: - where->elmnts = mkelmnt(str, 0); ! 1651: - else ! 1652: - { for (i = 1; i < where->nrelmnts; i++) ! 1653: - hook = hook->nxtel; ! 1654: - ! 1655: - hook->nxtel = mkelmnt(str, 0); ! 1656: - } ! 1657: - ! 1658: - /* if setowner is a formal parameter name ! 1659: - * the returned value `j' refers to the qset ! 1660: - * in which it was defined + an offset `MANY' ! 1661: - * if so, we must check that the message added ! 1662: - * here was also defined in the original set ! 1663: - */ ! 1664: - ! 1665: - if (susp && j >= MANY && isclosed(j - MANY)) /* current set is open */ ! 1666: - addmsg(str, j, 0, NORM, where->qind); /* check validity msg */ ! 1667: - ! 1668: - where->nrelmnts++; ! 1669: - ! 1670: - return i; ! 1671: -} ! 1672: - ! 1673: -callist(which, hit) ! 1674: -{ int i, j; ! 1675: - struct QSETS * hook = findset(which); ! 1676: - struct QSET_EL * kooh = hook->elmnts; ! 1677: - ! 1678: - for (i = 0; i < hook->nrelmnts; i++) ! 1679: - { j = addmsg(kooh->name, hit, kooh->status, NORM, hook->qind); ! 1680: - callentry(ISM, j); ! 1681: - kooh = kooh->nxtel; ! 1682: - } ! 1683: -} ! 1684: //GO.SYSIN DD pret1.c ! 1685: echo pret2.c 1>&2 ! 1686: sed 's/.//' >pret2.c <<'//GO.SYSIN DD pret2.c' ! 1687: -#include <stdio.h> ! 1688: -#include "pret.h" ! 1689: -#include "pret.d" ! 1690: - ! 1691: - struct COL column[MANY]; ! 1692: - struct ROW row[MANY]; ! 1693: - ! 1694: - struct ENTRY *rowtail; ! 1695: - struct ENTRY *coltail; ! 1696: - struct ENTRY *base; /* base of transition table */ ! 1697: - ! 1698: - struct ENTRY *newentry(); ! 1699: - struct PILAR *newunit(); ! 1700: - ! 1701: - int nrrows = 0; /* raw nr of rows (incremented by addrow() */ ! 1702: - int nrcols = 0; /* number of columns per table */ ! 1703: - int redrows = 0; /* reduced nr of rows (set by remap() */ ! 1704: - int extras = 0; /* counts replicated processes */ ! 1705: - ! 1706: -extern char procname[MAXNAME], refname[MAXNAME]; ! 1707: -extern int anyerror, pid, rid, curstate, lastloop; ! 1708: - ! 1709: -struct ENTRY * ! 1710: -find(R, C) ! 1711: -{ register int i; ! 1712: - register int r = R; ! 1713: - register int c = C; ! 1714: - register struct ENTRY *here = base; ! 1715: - ! 1716: - if (r >= nrrows || c >= nrcols || r < 0 || c < 0) ! 1717: - whoops ("bad table index"); ! 1718: - for (i = 0; i < r; i++) ! 1719: - here = here->nextrow; ! 1720: - for (i = 0; i < c; i++) ! 1721: - here = here->nextcol; ! 1722: - return here; ! 1723: -} ! 1724: - ! 1725: -getrowname(where, which) ! 1726: - char *where; ! 1727: -{ strcpy(where, row[which].name); ! 1728: -} ! 1729: - ! 1730: -setrowname(which) ! 1731: -{ char stro[256]; ! 1732: - extern linenumber; ! 1733: - extern char filename[]; ! 1734: - ! 1735: - sprintf(stro, "%d/%d:%s", linenumber, nrrows, filename); ! 1736: - strcpy(row[which].name, stro); ! 1737: -} ! 1738: - ! 1739: -deadlabels() ! 1740: -{ register int i; ! 1741: - for (i = 0; i < nrrows; i++) ! 1742: - switch(row[i].refcount) ! 1743: - { case ADR: printf("%s: undeclared label\n", row[i].name); ! 1744: - anyerror++; ! 1745: - break; ! 1746: - case DCL: printf("%s: unused label\n", row[i].name); ! 1747: - break; ! 1748: - case ADR+DCL: ! 1749: - break; ! 1750: - default: whoops("cannot happen - label"); ! 1751: - } ! 1752: -} ! 1753: - ! 1754: -remap() ! 1755: -{ register int i, j; ! 1756: - ! 1757: - for (i = j = 0; i < nrrows; i++) ! 1758: - if (row[i].mapping == NOSTATE) ! 1759: - row[i].maptwo = j++; ! 1760: - redrows = j; ! 1761: -} ! 1762: - ! 1763: -purgerows(how) ! 1764: -{ int i; extern int linecode, assertion, inertion; ! 1765: - ! 1766: - for (i = 0; i < nrrows; i++) ! 1767: - { row[i].mapping = NOSTATE; ! 1768: - row[i].maptwo = i; ! 1769: - } ! 1770: - redrows = nrrows; ! 1771: -/* -> bug if (!linecode) */ ! 1772: - if (!linecode || rid==assertion || rid==inertion) ! 1773: - transitrows(); /* remove dummy transitions */ ! 1774: - remap(); ! 1775: - ! 1776: - if (!linecode && !how) ! 1777: - { minimize(); ! 1778: - remap(); ! 1779: - } ! 1780: -} ! 1781: - ! 1782: -target(y) ! 1783: -{ int i = 0; ! 1784: - int x = y; ! 1785: - while (row[x].mapping != NOSTATE) ! 1786: - { x = row[x].mapping; ! 1787: - if (i++ > nrrows) ! 1788: - { printf("%s: ", (pid == NONE) ? procname : refname); ! 1789: - whoops("contains unconditional, infinite loop"); ! 1790: - } ! 1791: - } ! 1792: - return x; ! 1793: -} ! 1794: - ! 1795: -enterowname(how, stri, bang) ! 1796: - char *stri, bang; ! 1797: -{ register int i; ! 1798: - char stro[256]; ! 1799: - extern int linenumber; ! 1800: - extern char filename[]; ! 1801: - ! 1802: - switch(how) { ! 1803: - case LAB: sprintf(stro, "%s: %s", stri, filename); ! 1804: - for (i = 0; i < nrrows; i++) ! 1805: - if (strcmp(stro, row[i].name) == 0) ! 1806: - break; ! 1807: - ! 1808: - if (i < nrrows) ! 1809: - { if (bang == DCL && (row[i].refcount & DCL)) ! 1810: - { fprintf(stderr, "%d/%d %s %s\n", ! 1811: - i, nrrows, stro, row[i].name); ! 1812: - yyerror("label redeclared, %s", stro); ! 1813: - }else ! 1814: - row[i].refcount |= bang; ! 1815: - break; ! 1816: - } else ! 1817: - { addrow(); ! 1818: - row[i].refcount = bang; ! 1819: - row[i].labeled = 0; ! 1820: - strcpy(row[i].name, stro); ! 1821: - } ! 1822: - break; ! 1823: - case NEW: i = nrrows; ! 1824: - sprintf(stro, "%d/%d:%s", linenumber, i, filename); ! 1825: - addrow(); ! 1826: - row[i].refcount = bang; ! 1827: - row[i].labeled = 0; ! 1828: - strcpy(row[i].name, stro); ! 1829: - break; ! 1830: - case OLD: for (i = 0; i < nrrows; i++) ! 1831: - if (strcmp(stri, row[i].name) == 0) ! 1832: - break; ! 1833: - if (i == nrrows) ! 1834: - whoops("cannot happen - rows"); ! 1835: - break; ! 1836: - } ! 1837: - return i; ! 1838: -} ! 1839: - ! 1840: -labelrow(n) ! 1841: -{ ! 1842: - if (n < 0 || n >= nrrows) ! 1843: - whoops("cannot happen - labelrow"); ! 1844: - row[n].labeled = 1; ! 1845: - ! 1846: -} ! 1847: - ! 1848: -deadrows(p, r) ! 1849: -{ register int i, j, k; ! 1850: - struct ENTRY *it; ! 1851: - struct PILAR *at; ! 1852: - char fld[128]; ! 1853: - extern int nrprocs; ! 1854: - ! 1855: - for (i = 0; i < nrrows; i++) ! 1856: - row[i].reached = 0; ! 1857: - ! 1858: - for (i = 0; i < nrrows; i++) ! 1859: - { if (row[i].mapping != NOSTATE) ! 1860: - continue; ! 1861: - it = find(i, 0); ! 1862: - for (j = 0; j < nrcols; j++, it = it->nextcol) ! 1863: - { at = it->pilar; ! 1864: - do ! 1865: - { if (at->transf != NOSTATE) ! 1866: - { k = target(at->transf); ! 1867: - if (k != i) ! 1868: - row[k].reached = 1; ! 1869: - } ! 1870: - at = at->nxtp; ! 1871: - } while (at != NULL); ! 1872: - } } ! 1873: - ! 1874: - fld[0] = '\0'; ! 1875: - for (i = k = 0; i < nrrows; i++) ! 1876: - { if (row[i].mapping != NOSTATE) ! 1877: - continue; ! 1878: - if (row[i].reached == 0 && row[i].maptwo != 0) ! 1879: - { j = strlen(fld); k++; ! 1880: - sprintf(&fld[j], "%d, ", row[i].maptwo); ! 1881: - } } ! 1882: - ! 1883: - if (p == NONE) ! 1884: - refsize(r, redrows, k); ! 1885: - else ! 1886: - procsize(p, redrows, k); ! 1887: -} ! 1888: - ! 1889: -deadends(tb) ! 1890: - FILE *tb; ! 1891: -{ register int i, j, x; ! 1892: - struct ENTRY *it; ! 1893: - struct PILAR *at; ! 1894: - char field[256]; ! 1895: - int nrdeads = 0; ! 1896: - ! 1897: - if (nrrows == 0) ! 1898: - return; ! 1899: - ! 1900: - field[0] = '\0'; ! 1901: - for (i = 0; i < nrrows; i++) ! 1902: - { if (row[i].mapping != NOSTATE) ! 1903: - continue; ! 1904: - it = find(i, 0); ! 1905: - for (j = 0; j < nrcols; j++, it = it->nextcol) ! 1906: - { for (at = it->pilar; at != NULL; at = at->nxtp) ! 1907: - if (at->transf != NOSTATE) ! 1908: - break; ! 1909: - if (at != NULL) ! 1910: - break; ! 1911: - } ! 1912: - if (j == nrcols) ! 1913: - { x = strlen(field); ! 1914: - sprintf(&field[x], "%d,", row[i].maptwo); ! 1915: - nrdeads++; ! 1916: - } } ! 1917: - if ((i = lastloop) >= 0) ! 1918: - { if (i >= nrrows || row[i].mapping != NOSTATE) ! 1919: - whoops("cannot happen - deadends"); ! 1920: - x = strlen(field); ! 1921: - sprintf(&field[x], "%d,", row[i].maptwo); ! 1922: - nrdeads++; ! 1923: - } ! 1924: - fprintf(tb, "ENDSTATES %d: %s\n", nrdeads, field); ! 1925: -} ! 1926: - ! 1927: -transitrows() ! 1928: -{ register int i, j; ! 1929: - struct ENTRY *here, *there; ! 1930: - /* maintain row 0 as initial state */ ! 1931: - here = base->nextrow; ! 1932: - for (i = 1; i < nrrows; i++, here = here->nextrow) ! 1933: - { if (here->nrpils != 1 || here->pilar->code != NONE) ! 1934: - continue; ! 1935: - ! 1936: - there = here->nextcol; ! 1937: - for (j = 1; j < nrcols; j++, there = there->nextcol) ! 1938: - if (there->nrpils != 0) ! 1939: - break; ! 1940: - if (j == nrcols) ! 1941: - { row[i].mapping = here->pilar->transf; ! 1942: - row[here->pilar->transf].labeled |= row[i].labeled; ! 1943: - } } ! 1944: -} ! 1945: - ! 1946: -entercolname(val, what) ! 1947: -{ register int i; ! 1948: - ! 1949: - for (i = 0; i < nrcols; i++) ! 1950: - if (column[i].ccode == val && column[i].coltype == what) ! 1951: - break; ! 1952: - if (i == nrcols) ! 1953: - { addcol(); ! 1954: - column[i].ccode = val; ! 1955: - column[i].coltype = what; ! 1956: - } ! 1957: - return i; ! 1958: -} ! 1959: - ! 1960: -addrow() ! 1961: -{ register i = nrcols; ! 1962: - struct ENTRY *lastcol, *thiscol; ! 1963: - char uni[32]; ! 1964: - ! 1965: - if (nrcols == 0) ! 1966: - { rowtail = coltail = base = newentry(); ! 1967: - sprintf(uni, "%4d", curstate); ! 1968: - column[0].ccode = -1; ! 1969: - column[0].coltype = SPN; ! 1970: - strcpy(row[0].name, uni); ! 1971: - nrrows = nrcols = 1; ! 1972: - } else ! 1973: - { if (nrrows == MANY) ! 1974: - whoops("too many rows"); ! 1975: - lastcol = rowtail; ! 1976: - rowtail = thiscol = lastcol->nextrow = newentry(); ! 1977: - for (--i; i > 0; i--) ! 1978: - { thiscol = thiscol->nextcol = newentry(); ! 1979: - lastcol = lastcol->nextcol; ! 1980: - lastcol->nextrow = thiscol; ! 1981: - } ! 1982: - nrrows++; ! 1983: - } ! 1984: -} ! 1985: - ! 1986: -addcol() ! 1987: -{ register int i = nrrows; ! 1988: - struct ENTRY *lstrow, *thisrow; ! 1989: - ! 1990: - if (nrcols == 0) ! 1991: - whoops("cannot happen - columns"); ! 1992: - else ! 1993: - { lstrow = coltail; ! 1994: - coltail = thisrow = lstrow->nextcol = newentry(); ! 1995: - if (nrcols++ == MANY) ! 1996: - whoops("too many columns"); ! 1997: - for (--i; i > 0; i--) ! 1998: - { thisrow = thisrow->nextrow = newentry(); ! 1999: - lstrow = lstrow->nextrow; ! 2000: - lstrow->nextcol = thisrow; ! 2001: - } } ! 2002: -} ! 2003: - ! 2004: -setrans(r, c, tr, to) ! 2005: -{ struct ENTRY *ft; ! 2006: - struct PILAR *pt; ! 2007: - int i; ! 2008: - ft = find(r, c); ! 2009: - pt = ft->pilar; ! 2010: - for (i = ft->nrpils++; i > 0; i--) ! 2011: - pt = pt->nxtp; ! 2012: - ! 2013: - pt->code = to; ! 2014: - pt->transf = tr; ! 2015: - ! 2016: - pt->nxtp = newunit(); ! 2017: -} ! 2018: - ! 2019: -badstates(tb) ! 2020: - FILE *tb; ! 2021: -{ struct ENTRY *this, *that; ! 2022: - struct PILAR *at; ! 2023: - int i, k, x, nrbads = 0, nrlabs = 0; ! 2024: - char field[512], labfield[512]; ! 2025: - ! 2026: - if (nrrows == 0) ! 2027: - return; ! 2028: - ! 2029: - labfield[0] = field[0] = '\0'; ! 2030: - for (i = 0, this = base; this != NULL; this = this->nextrow, i++) ! 2031: - { if (row[i].mapping != NOSTATE) ! 2032: - continue; ! 2033: - ! 2034: - if (row[i].labeled) ! 2035: - { sprintf(&labfield[strlen(labfield)], "%d,", row[i].maptwo); ! 2036: - nrlabs++; ! 2037: - } ! 2038: - that = find(i, 0); ! 2039: - for (k = 0; k < nrcols; k++, that = that->nextcol) ! 2040: - { if (!SPNT(column[k].coltype)) ! 2041: - continue; ! 2042: - ! 2043: - for (at = that->pilar, x = 0; at != NULL; at = at->nxtp) ! 2044: - { if (at->transf == NOSTATE) ! 2045: - continue; ! 2046: - x++; break; ! 2047: - } ! 2048: - if (x > 0) ! 2049: - { sprintf(&field[strlen(field)],"%d,",row[i].maptwo); ! 2050: - nrbads++; ! 2051: - break; ! 2052: - } } ! 2053: - } ! 2054: - fprintf(tb, "BADSTATES %d: %s\n", nrbads, field); ! 2055: - fprintf(tb, "LABSTATES %d: %s\n", nrlabs, labfield); ! 2056: -} ! 2057: - ! 2058: -dumpforw(tb) ! 2059: - FILE *tb; ! 2060: -{ struct ENTRY *this, *that; ! 2061: - struct PILAR *at; ! 2062: - char field[256]; ! 2063: - int i, j, k, x, y; extern int linecode; ! 2064: - ! 2065: - if (pid == NONE) ! 2066: - fprintf(tb, "%s %d:", "REF", rid); ! 2067: - else ! 2068: - fprintf(tb, "%s %d:", "PROC", pid+extras); ! 2069: - ! 2070: - fprintf(tb, "%d/%d:", redrows, nrcols); ! 2071: - for (i = 0; i < nrcols; i++) ! 2072: - fprintf(tb, "%d(%d),", column[i].ccode, column[i].coltype); ! 2073: - putc('\n', tb); ! 2074: - ! 2075: - for (i = 0, this = base; this != NULL; this = this->nextrow, i++) ! 2076: - { if (row[i].mapping != NOSTATE) ! 2077: - continue; ! 2078: - ! 2079: - that = find(i, 0); ! 2080: - for (k = 0; k < nrcols; k++, that = that->nextcol) ! 2081: - { y = 0; field[0] = '\0'; ! 2082: - for (at = that->pilar; at != NULL; at = at->nxtp) ! 2083: - { if (at->transf == NOSTATE) ! 2084: - continue; ! 2085: - ! 2086: - j = row[ target(at->transf) ].maptwo; ! 2087: - ! 2088: - if ((x = strlen(field)) > 200) ! 2089: - whoops("string overflow"); ! 2090: - ! 2091: - sprintf(&field[x], "[%d,%d]", j, at->code); ! 2092: - y++; ! 2093: - } ! 2094: - ! 2095: - if (y > 0) ! 2096: - { fprintf(tb, "%d/%d ", row[i].maptwo, k); ! 2097: - fprintf(tb, "(%d) %s\n", y, field); ! 2098: - } } } ! 2099: - fprintf(tb, "0/0 (0)\n"); ! 2100: - ! 2101: - if (linecode) ! 2102: - { fprintf(tb, "rownames:\n"); ! 2103: - for (i = 0; i < redrows; i++) ! 2104: - fprintf(tb, "%s\n", row[i].name); ! 2105: - } ! 2106: -} ! 2107: - ! 2108: -wrapup(r, p, tb, np, vb) ! 2109: - FILE *tb; ! 2110: -{ ! 2111: - int i; ! 2112: - extern struct PROCTABLE proctable[MAXPROC]; ! 2113: - ! 2114: - purgerows(np); ! 2115: - dumpforw(tb); ! 2116: - deadends(tb); ! 2117: - badstates(tb); ! 2118: - putcalls(tb); ! 2119: - numlocvars(tb); ! 2120: - ! 2121: - if (r == NONE) ! 2122: - for (i = 1; i < proctable[p].replic; i++) ! 2123: - { extras++; ! 2124: - twiddle("_PROCID"); ! 2125: - dumpforw(tb); ! 2126: - deadends(tb); ! 2127: - badstates(tb); ! 2128: - putcalls(tb); ! 2129: - numlocvars(tb); ! 2130: - } ! 2131: - ! 2132: - if (vb) ! 2133: - { deadrows(p, r); ! 2134: - deadlabels(); ! 2135: - } ! 2136: - ! 2137: - release(); ! 2138: - scrapcalltable(); ! 2139: -} ! 2140: //GO.SYSIN DD pret2.c ! 2141: echo pret3.c 1>&2 ! 2142: sed 's/.//' >pret3.c <<'//GO.SYSIN DD pret3.c' ! 2143: -#include <stdio.h> ! 2144: -#include "pret.h" ! 2145: - ! 2146: - struct FORMALS { ! 2147: - char name[MAXNAME]; ! 2148: - int typefs; /* qset or pvar (default) */ ! 2149: - int tag; /* id */ ! 2150: - char used; /* reference count */ ! 2151: - char reset; /* default type overwritten */ ! 2152: - struct FORMALS *nxtpar; ! 2153: - }; ! 2154: - ! 2155: - struct { ! 2156: - char name[MAXNAME]; ! 2157: - int status; ! 2158: - int nrparams; ! 2159: - int nrstates; ! 2160: - int unreach; ! 2161: - struct FORMALS *params; /* formal parameters */ ! 2162: - } reftable[MAXPROC]; ! 2163: - ! 2164: - int nrrefs = 0; ! 2165: - ! 2166: - extern int anyerror, pid, rid, assertion, inertion; ! 2167: - extern char qsetname[MAXNAME]; ! 2168: - ! 2169: -refsize(n, m, k) ! 2170: -{ reftable[n].nrstates = m; ! 2171: - reftable[n].unreach = k; ! 2172: -} ! 2173: - ! 2174: -reorder() ! 2175: -{ int i, j, N, M; ! 2176: - struct FORMALS * hook; ! 2177: - ! 2178: - if (rid == NONE) ! 2179: - return; ! 2180: - /* ! 2181: - * make sure that formal msg parameters ! 2182: - * are numbered in the order in which they ! 2183: - * will be pushed onto the call stack in trace.c ! 2184: - */ ! 2185: - ! 2186: - j = reftable[rid].nrparams; ! 2187: - hook = reftable[rid].params; ! 2188: - ! 2189: - for (i = N = M = 0; i < j; i++) ! 2190: - { if (hook->typefs == ISQ || hook->typefs == ISQN) ! 2191: - N = renumqset(hook->tag, N); ! 2192: - else ! 2193: - hook->tag = M++; ! 2194: - ! 2195: - hook = hook->nxtpar; ! 2196: - } ! 2197: -} ! 2198: - ! 2199: -newreftask(str, mask) ! 2200: - char *str; ! 2201: -{ register int i; ! 2202: - ! 2203: - for (i = 0; i < nrrefs; i++) ! 2204: - if (strcmp(str, reftable[i].name) == 0) ! 2205: - break; ! 2206: - if (i == nrrefs) ! 2207: - { if (nrrefs >= MAXPROC) ! 2208: - whoops("too many procedures"); ! 2209: - if (mask == RFR) ! 2210: - yyerror("undeclared procedure, %s", str); ! 2211: - ! 2212: - reftable[i].status = 0; ! 2213: - reftable[i].nrparams = 0; ! 2214: - reftable[i].nrstates = 0; ! 2215: - reftable[i].unreach = 0; ! 2216: - strcpy(reftable[nrrefs++].name, str); ! 2217: - } else ! 2218: - { if (mask == DCL && (reftable[i].status & DCL)) ! 2219: - yyerror("procedure redeclared, %s", str); ! 2220: - if (mask == RFR && rid == i) ! 2221: - yyerror("recursive procedure, %s", str); ! 2222: - } ! 2223: - reftable[i].status |= mask; ! 2224: - ! 2225: - return i; ! 2226: -} ! 2227: - ! 2228: -struct FORMALS * ! 2229: -newparunit(str, nn, tp, ins) ! 2230: - char *str; ! 2231: -{ struct FORMALS * try = (struct FORMALS *) ! 2232: - Emalloc ( sizeof(struct FORMALS) ); ! 2233: - ! 2234: - try->used = 0; ! 2235: - try->reset = 0; ! 2236: - ! 2237: - strcpy(try->name, str); ! 2238: - ! 2239: - try->typefs = tp; ! 2240: - try->nxtpar = NULL; ! 2241: - ! 2242: - try->tag = nn; ! 2243: - if (!ins) ! 2244: - yyerror("unspecified parameter, %s", str); ! 2245: - ! 2246: - return try; ! 2247: -} ! 2248: - ! 2249: -addFpar(to, stri, n, vt, ins) ! 2250: - char *stri; ! 2251: -{ struct FORMALS *hook; ! 2252: - int N = reftable[to].nrparams; ! 2253: - int i = N; ! 2254: - ! 2255: - if (N == 0) ! 2256: - { reftable[to].params = newparunit(stri, n, vt, ins); ! 2257: - reftable[to].nrparams++; ! 2258: - } else ! 2259: - { hook = reftable[to].params; ! 2260: - for (i = 0; i < N; i++, hook = hook->nxtpar) ! 2261: - { if (strcmp(hook->name, stri) == 0) ! 2262: - { if (ins || hook->reset == 1) ! 2263: - yyerror("name clash, %s", stri); ! 2264: - ! 2265: - hook->tag = n; ! 2266: - hook->typefs = vt; ! 2267: - hook->reset = 1; ! 2268: - break; ! 2269: - } ! 2270: - if (hook->nxtpar == NULL) ! 2271: - { hook->nxtpar = newparunit(stri, n, vt, ins); ! 2272: - reftable[to].nrparams++; ! 2273: - i++; ! 2274: - break; ! 2275: - } } } ! 2276: - ! 2277: - return i; ! 2278: -} ! 2279: - ! 2280: -Fparname(str, which, vt, hit, how, qind) ! 2281: - char *str; ! 2282: -{ int i, j, k; ! 2283: - struct FORMALS * hook = reftable[which].params; ! 2284: - ! 2285: - for (i = 0, j = reftable[which].nrparams; i < j; i++) ! 2286: - { if (strcmp(str, hook->name) == 0 && hook->typefs == vt) ! 2287: - break; ! 2288: - if (hook->typefs == ISQ || hook->typefs == ISQN) ! 2289: - { switch (vt) { ! 2290: - case ISM: ! 2291: - if (hook->tag == hit ! 2292: - && (k = inqset(hook->tag, str, how, qind)) != -1) ! 2293: - return k; ! 2294: - break; ! 2295: - case ISQ: ! 2296: - if (matchowner(hook->tag, str, how, qind)) ! 2297: - return hook->tag; /* id of qset */ ! 2298: - break; ! 2299: - } } ! 2300: - hook = hook->nxtpar; ! 2301: - } ! 2302: - if (i == j || (vt == ISM && hook->tag != hit)) ! 2303: - return -1; ! 2304: - ! 2305: - hook->used |= how; ! 2306: - ! 2307: - if (vt == ISV) ! 2308: - return hook->tag; ! 2309: - ! 2310: - return i; ! 2311: -} ! 2312: - ! 2313: -checkrefs() ! 2314: -{ int i; ! 2315: - if (nrrefs == 0) ! 2316: - return; ! 2317: - for (i = 0; i < nrrefs; i++) ! 2318: - if (reftable[i].status == DCL) ! 2319: - { if (strcmp(reftable[i].name, " assert") != 0 ! 2320: - && strcmp(reftable[i].name, " error") != 0) ! 2321: - printf("%s: unused procedure\n", reftable[i].name); ! 2322: - } else if (reftable[i].status == RFR) ! 2323: - printf("%s: undeclared procedure\n", reftable[i].name); ! 2324: -} ! 2325: - ! 2326: -numrefs(fd) ! 2327: - FILE *fd; ! 2328: -{ extern int linecode; ! 2329: - fprintf(fd, "%d linecode\n", linecode); ! 2330: - fprintf(fd, "%d procedures ", nrrefs); ! 2331: - fprintf(fd, "(assert %d/%d)\n", assertion, inertion); ! 2332: -} ! 2333: - ! 2334: -parrefs(n, m) ! 2335: -{ int i; ! 2336: - if ((i = reftable[m].nrparams - n) == 0) ! 2337: - return; ! 2338: - if (i > 0) ! 2339: - yyerror("missing parameters, %s", reftable[m].name); ! 2340: - else ! 2341: - yyerror("too many parameters, %s", reftable[m].name); ! 2342: -} ! 2343: - ! 2344: -isdigit(c) { return (c >= '0' && c <= '9'); } ! 2345: - ! 2346: -addAspecial(val, which, pn) ! 2347: -{ struct FORMALS * hook = reftable[which].params; ! 2348: - int i; ! 2349: - ! 2350: - if (pn >= reftable[which].nrparams || pn < 0) ! 2351: - return; ! 2352: - ! 2353: - for (i = 0; i < pn; i++) ! 2354: - if ((hook = hook->nxtpar) == NULL) ! 2355: - whoops("cannot happen - addAspecial"); ! 2356: - ! 2357: - switch (hook->typefs) ! 2358: - { case ISQN: ! 2359: - case ISQ: yyerror("mismatched parameter, %s", "queue or qset"); ! 2360: - break; ! 2361: - case ISV: callentry(ISV, val); ! 2362: - break; ! 2363: - default : whoops("cannot happen - addAspecial"); ! 2364: - } ! 2365: -} ! 2366: - ! 2367: -addApars(what, which, pn, index) ! 2368: - char *what; ! 2369: -{ struct FORMALS * hook = reftable[which].params; ! 2370: - int val, hit, x; ! 2371: - ! 2372: - if (pn >= reftable[which].nrparams || pn < 0) ! 2373: - return; ! 2374: - ! 2375: - for (x = 0; x < pn; x++) ! 2376: - if ((hook = hook->nxtpar) == NULL) ! 2377: - whoops("cannot happen - formals"); ! 2378: - ! 2379: - switch (hook->typefs) ! 2380: - { case ISQN: ! 2381: - val = newqset(what, what, 0, index); ! 2382: - x = matchset(val, hook->tag); ! 2383: - hit = qsetowner(val, x); /* find queue-id */ ! 2384: - callentry(ISQ, hit); /* enter queue-id */ ! 2385: - callist(val, hit); /* enter messages */ ! 2386: - break; ! 2387: - case ISQ: val = newqset(what, "", RFR, index); ! 2388: - x = matchset(val, hook->tag); ! 2389: - hit = qsetowner(val, x); /* find queue-id */ ! 2390: - callentry(ISQ, hit); /* enter queue-id */ ! 2391: - callist(val, hit); /* enter messages */ ! 2392: - break; ! 2393: - case ISV: val = addvarname(what, RFR, NONE, index, 0); ! 2394: - callentry(ISV, val); ! 2395: - break; ! 2396: - default : whoops("cannot happen - addApars"); ! 2397: - } ! 2398: -} ! 2399: - ! 2400: -listrefs() ! 2401: -{ int i, k; ! 2402: - ! 2403: - for (i = 0; i < nrrefs; i++) ! 2404: - { printf("\t%2d\t%s, ", i+1, reftable[i].name); ! 2405: - for (k = strlen(reftable[i].name)+1; k < 10; k++) ! 2406: - putchar(' '); ! 2407: - k = reftable[i].nrstates; ! 2408: - printf("%d state%s", k, (k!=1)?"s":""); ! 2409: - if ((k = reftable[i].unreach) > 0) ! 2410: - printf(" (%d unreachable state%s)", k, (k>1)?"s":""); ! 2411: - putchar('\n'); ! 2412: - } ! 2413: -} ! 2414: //GO.SYSIN DD pret3.c ! 2415: echo pret4.c 1>&2 ! 2416: sed 's/.//' >pret4.c <<'//GO.SYSIN DD pret4.c' ! 2417: -#include <stdio.h> ! 2418: -#include "pret.h" ! 2419: - ! 2420: -struct PROCTABLE proctable[MAXPROC]; /* index to process names */ ! 2421: - ! 2422: -int nrprocs = 0; ! 2423: - ! 2424: -procsize(n, m, k) ! 2425: -{ proctable[n].nrstates = m; ! 2426: - proctable[n].unreach = k; ! 2427: -} ! 2428: - ! 2429: -newprocname(str, repl) ! 2430: - char *str; ! 2431: -{ register int i; ! 2432: - ! 2433: - for (i = 0; i < nrprocs; i++) ! 2434: - if (strcmp(str, proctable[i].name) == 0) ! 2435: - break; ! 2436: - ! 2437: - if (i == nrprocs) ! 2438: - { if (nrprocs >= MAXPROC) ! 2439: - whoops("too many processes"); ! 2440: - proctable[i].nrstates = 0; ! 2441: - proctable[i].unreach = 0; ! 2442: - proctable[i].replic = repl; ! 2443: - strcpy(proctable[nrprocs++].name, str); ! 2444: - } else ! 2445: - yyerror("process redeclared, %s", str); ! 2446: - ! 2447: - return i; ! 2448: -} ! 2449: - ! 2450: -numprocs(fd) ! 2451: - FILE *fd; ! 2452: -{ ! 2453: - extern int extras; ! 2454: - fprintf(fd, "%d processes\n", nrprocs+extras); ! 2455: -} ! 2456: - ! 2457: -chatter() ! 2458: -{ int i; ! 2459: - extern int verbose, nrqs, nrmesgs, nrrefs, assertion, inertion, extras; ! 2460: - ! 2461: - if (verbose) ! 2462: - { i = ((assertion != -1) + (inertion != -1)); ! 2463: - printf("\nOverview:\n========\n"); ! 2464: - printf("%d queue%s:\n", nrqs, (nrqs==1)?"":"s"); ! 2465: - listqs(); ! 2466: - printf("%d process%s:\n", ! 2467: - nrprocs+extras, (nrprocs+extras==1)?"":"es"); ! 2468: - listprs(); ! 2469: - printf("%d procedure%s:\n", nrrefs, (nrrefs==1)?"":"s"); ! 2470: - listrefs(); ! 2471: - printf("%d assertion%s\n", i, (i==1)?"":"s"); ! 2472: - } ! 2473: -} ! 2474: - ! 2475: -listprs() ! 2476: -{ int i, k; ! 2477: - ! 2478: - for (i = 0; i < nrprocs; i++) ! 2479: - { printf("\t%2d", i+1); ! 2480: - if (proctable[i].replic != NONE) ! 2481: - printf("x%d", proctable[i].replic); ! 2482: - printf("\t%s, ", proctable[i].name); ! 2483: - for (k = strlen(proctable[i].name)+1; k < 10; k++) ! 2484: - putchar(' '); ! 2485: - k = proctable[i].nrstates; ! 2486: - printf("%d state%s", k, (k!=1)?"s":""); ! 2487: - if ((k = proctable[i].unreach) > 0) ! 2488: - printf(" (%d unreachable state%s)", k, (k>1)?"s":""); ! 2489: - putchar('\n'); ! 2490: - } ! 2491: -} ! 2492: //GO.SYSIN DD pret4.c ! 2493: echo pret6.c 1>&2 ! 2494: sed 's/.//' >pret6.c <<'//GO.SYSIN DD pret6.c' ! 2495: -#include <stdio.h> ! 2496: -#include "pret.h" ! 2497: - ! 2498: -struct { ! 2499: - char name[MAXNAME]; ! 2500: - char mbox; ! 2501: - char status; ! 2502: - int qind; /* index!=NONE if q addressed is array */ ! 2503: - int equa; /* basename match */ ! 2504: - int code; ! 2505: -} mesgtable[MANY]; ! 2506: - ! 2507: -struct QTABLE qtable[NQUEUES]; ! 2508: - ! 2509: -int msize[NQUEUES]; /* mailbox sizes per queue */ ! 2510: - ! 2511: -int msgval = BASEVAL; ! 2512: -int nrmesgs = 0; ! 2513: -int nrqs = 0; ! 2514: - ! 2515: -int initable[MANY]; ! 2516: -int nrinits = 0; /* number initial messages */ ! 2517: - ! 2518: -extern anyerror, pid, rid; ! 2519: - ! 2520: -newqname(str, mask, lim, qind) ! 2521: - char *str; ! 2522: -{ ! 2523: - register int i; ! 2524: - ! 2525: - if (rid != NONE) ! 2526: - { if ((i = Fparname(str, rid, ISQ, NONE, mask, qind)) != -1) ! 2527: - return (MANY + i); /* id of qset + offset */ ! 2528: - } ! 2529: - for (i = 0; i < nrqs; i++) ! 2530: - if (strcmp(str, qtable[i].name) == 0) ! 2531: - break; ! 2532: - if (i == nrqs) ! 2533: - { if (nrqs >= NQUEUES) ! 2534: - whoops("too many queues"); ! 2535: - ! 2536: - qtable[i].owner = (mask == DCL || mask == RFR) ? pid : NONE; ! 2537: - qtable[i].limit = (lim == NONE) ? 2 : lim; ! 2538: - qtable[i].status = mask; ! 2539: - qtable[i].magic = 0; ! 2540: - qtable[i].multiple = qind; ! 2541: - strcpy(qtable[nrqs++].name, str); ! 2542: - } else ! 2543: - { if (mask == DCL) ! 2544: - { if (qtable[i].status & DCL) ! 2545: - yyerror("queue redeclared, %s", str); ! 2546: - ! 2547: - if (qtable[i].owner == NONE) ! 2548: - qtable[i].owner = pid; ! 2549: - else if (qtable[i].owner != pid && pid != NONE) ! 2550: - warning("queue read by 2 processes", str); ! 2551: - qtable[i].limit = lim; ! 2552: - qtable[i].multiple = qind; ! 2553: - } else if (mask & RFR) ! 2554: - { if (qtable[i].owner == NONE) ! 2555: - qtable[i].owner = pid; ! 2556: - ! 2557: - else if (qtable[i].owner != pid) ! 2558: - warning("queue read by 2 processes", str); ! 2559: - } ! 2560: - if ((mask & RFR) || (mask & ADR)) ! 2561: - { if (qind != qtable[i].multiple ! 2562: - && (qind == NONE || qtable[i].multiple == NONE)) ! 2563: - yyerror("queue indexing error, mesg name, %s", str); ! 2564: - } ! 2565: - qtable[i].status |= mask; ! 2566: - } ! 2567: - return i; ! 2568: -} ! 2569: - ! 2570: -addmsg(what, hit, mask, tpp, qind) ! 2571: - char *what; char mask; ! 2572: -{ register int i, j; ! 2573: - char str[MAXNAME]; ! 2574: - ! 2575: - if (rid != NONE) ! 2576: - { if ((i = Fparname(what, rid, ISM, hit - MANY, mask, qind)) != -1) ! 2577: - return (MANY + i); ! 2578: - if (hit >= MANY) ! 2579: - { yyerror("undeclared message, %s", what); ! 2580: - return -1; ! 2581: - } } ! 2582: - ! 2583: - strcpy(str, qtable[hit].name); ! 2584: - strcat(str, ":"); strcat(str, what); ! 2585: - ! 2586: - for (j = 0; j < nrmesgs; j++) ! 2587: - { if (strcmp(str, mesgtable[j].name) == 0) ! 2588: - break; ! 2589: - } ! 2590: - for (i = j; i < nrmesgs; i++) ! 2591: - if (strcmp(str, mesgtable[i].name) == 0 ! 2592: - && mesgtable[i].qind == qind) ! 2593: - break; ! 2594: - if (i == nrmesgs) ! 2595: - { if (nrmesgs >= MANY) ! 2596: - whoops("too many messages"); ! 2597: - if (qtable[hit].multiple != qind ! 2598: - && (qind == NONE || qtable[hit].multiple == NONE)) ! 2599: - yyerror("Queue indexing error, qname, %s", str); ! 2600: - ! 2601: - mesgtable[i].mbox = hit; ! 2602: - mesgtable[i].qind = qind; ! 2603: - mesgtable[i].status = mask; ! 2604: - strcpy(mesgtable[nrmesgs++].name, str); ! 2605: - mesgtable[i].code = msgval++; ! 2606: - mesgtable[i].equa = mesgtable[j].code; ! 2607: - } else ! 2608: - mesgtable[i].status |= mask; ! 2609: - ! 2610: - if (tpp == INITM) ! 2611: - initable[nrinits++] = mesgtable[i].code; ! 2612: - ! 2613: - if (strcmp(what, " any") == 0 && mask == SAR) ! 2614: - qtable[hit].magic = 1; ! 2615: - ! 2616: - return mesgtable[i].code; ! 2617: -} ! 2618: - ! 2619: -isoqs() ! 2620: -{ int i; ! 2621: - for (i = 0; i < nrqs; i++) ! 2622: - { if (!(qtable[i].status & DCL)) ! 2623: - printf("warning: queue `%s' undeclared\n", qtable[i].name); ! 2624: - if (qtable[i].owner == NONE) ! 2625: - printf("warning: queue `%s' unknown owner\n", qtable[i].name); ! 2626: - switch (qtable[i].status) { ! 2627: - case 0: /* used to check name existence in qsets */ ! 2628: - case DCL: printf("%s: isolated queue\n", qtable[i].name); ! 2629: - break; ! 2630: - case DCL+RFR: printf("%s: queue not addressed\n", qtable[i].name); ! 2631: - break; ! 2632: - case DCL+ADR: printf("%s: queue is never read\n", qtable[i].name); ! 2633: - default: break; ! 2634: - } ! 2635: - } ! 2636: -} ! 2637: - ! 2638: -silentcheck() ! 2639: -{ int i, j, k, p; ! 2640: - for (i = 0; i < nrqs; i++) ! 2641: - { if (msize[i] == 0) ! 2642: - continue; ! 2643: - k = strlen(qtable[i].name) + 1; ! 2644: - for (j = 0; j < nrmesgs; j++) ! 2645: - if (mesgtable[j].mbox == i && (p = mesgtable[j].status) != SAR) ! 2646: - { switch (p) { ! 2647: - case RCV: if (qtable[i].multiple) break; ! 2648: - printf("queue %s: ", qtable[i].name); ! 2649: - printf("mesg '%s' ", &mesgtable[j].name[k]); ! 2650: - printf("is received but not sent\n"); ! 2651: - anyerror++; ! 2652: - break; ! 2653: - case SND: if (qtable[i].magic != 0 ! 2654: - || qtable[i].multiple ! 2655: - || strcmp(&mesgtable[j].name[k], " any") == 0) ! 2656: - break; ! 2657: - printf("queue %s: ", qtable[i].name); ! 2658: - printf("mesg '%s' ", &mesgtable[j].name[k]); ! 2659: - printf("is sent but not received\n"); ! 2660: - anyerror++; ! 2661: - break; ! 2662: - case 0: printf("queue %s: ", qtable[i].name); ! 2663: - printf("mesg '%s' ", &mesgtable[j].name[k]); ! 2664: - printf("is never used\n"); ! 2665: - break; ! 2666: - } ! 2667: - } } ! 2668: -} ! 2669: - ! 2670: -checkqs() ! 2671: -{ isoqs(); ! 2672: - silentcheck(); ! 2673: -} ! 2674: - ! 2675: -numsorts(fd) ! 2676: - FILE *fd; ! 2677: -{ int i, j; ! 2678: - ! 2679: - for (i = j = 0; i < nrqs; i++) ! 2680: - { if (qtable[i].multiple == NONE) ! 2681: - j++; ! 2682: - else ! 2683: - j += qtable[i].multiple; ! 2684: - } ! 2685: - fprintf(fd, "%d queues:\n", j); ! 2686: - numesgs(fd); ! 2687: - for (i = 0; i < nrqs; i++) ! 2688: - { fprintf(fd, "%s\t%d/", ! 2689: - qtable[i].name, qtable[i].owner); ! 2690: - fprintf(fd, "%d/%d/%d: ", ! 2691: - qtable[i].limit, msize[i], qtable[i].multiple); ! 2692: - for (j = 0; j < nrmesgs; j++) ! 2693: - if (mesgtable[j].mbox == i) ! 2694: - fprintf(fd, "%d[%d,%d],", mesgtable[j].code, ! 2695: - mesgtable[j].qind, ! 2696: - mesgtable[j].equa); ! 2697: - putc('\n', fd); ! 2698: -} } ! 2699: - ! 2700: -numinits(fd) ! 2701: - FILE *fd; ! 2702: -{ int i; ! 2703: - fprintf(fd, "%d inits:\n", nrinits); ! 2704: - for (i = 0; i < nrinits; i++) ! 2705: - fprintf(fd, "%d,", initable[i]); ! 2706: - if (nrinits > 0) ! 2707: - putc('\n', fd); ! 2708: -} ! 2709: - ! 2710: -numesgs(fd) ! 2711: - FILE *fd; ! 2712: -{ int i, j; ! 2713: - char c; ! 2714: - ! 2715: - fprintf(fd, "%d messages, base %d:\n", nrmesgs, BASEVAL); ! 2716: - for (i = 0; i < nrmesgs; i++) ! 2717: - { for (j = 0; (c = mesgtable[i].name[j]) != '\0'; j++) ! 2718: - if (c == ':') ! 2719: - { j++; ! 2720: - break; ! 2721: - } ! 2722: - if (c == '\0') ! 2723: - j = 0; ! 2724: - ! 2725: - fprintf(fd, "%s ", &mesgtable[i].name[j]); ! 2726: - } ! 2727: - if (nrmesgs > 0) ! 2728: - putc('\n', fd); ! 2729: -} ! 2730: - ! 2731: -prepsorts() ! 2732: -{ int i, j; ! 2733: - for (i = 0; i < nrqs; i++) ! 2734: - { msize[i] = 0; ! 2735: - for (j = 0; j < nrmesgs; j++) ! 2736: - if (mesgtable[j].mbox == i) ! 2737: - msize[i]++; ! 2738: - } ! 2739: -} ! 2740: - ! 2741: -listqs() ! 2742: -{ int i, j, k, l, a; ! 2743: - ! 2744: - for (i = 0; i < nrqs; i++) ! 2745: - { ! 2746: - if (qtable[i].status & DCL == 0) /* formal q-parameter */ ! 2747: - continue; ! 2748: - ! 2749: - printf("\t%2d\t%s", i+1, qtable[i].name); ! 2750: - k = strlen(qtable[i].name) + 1; ! 2751: - if (qtable[i].multiple != NONE) ! 2752: - { printf("[%d], ", qtable[i].multiple); ! 2753: - a = (qtable[i].multiple>9)?4:3; ! 2754: - } else ! 2755: - { printf(", "); ! 2756: - a = 0; ! 2757: - } ! 2758: - for (j = 10; j > k+a; j--) putchar(' '); ! 2759: - printf("sort: "); ! 2760: - ! 2761: - for (j = l = 0; j < nrmesgs; j++) ! 2762: - if (mesgtable[j].mbox == i && ! 2763: - strcmp(&mesgtable[j].name[k], " tau") != 0 && ! 2764: - strcmp(&mesgtable[j].name[k], " any") != 0) ! 2765: - { if (l++ > 0) ! 2766: - printf(", "); ! 2767: - printf("%s", &mesgtable[j].name[k]); ! 2768: - if ((a = mesgtable[j].qind) != NONE) ! 2769: - { if (a < -1) ! 2770: - printf("/*%d", -(a+2)); ! 2771: - else ! 2772: - printf("/%d", a); ! 2773: - } } ! 2774: - printf("\n"); ! 2775: - } ! 2776: -} ! 2777: //GO.SYSIN DD pret6.c ! 2778: echo pret7.c 1>&2 ! 2779: sed 's/.//' >pret7.c <<'//GO.SYSIN DD pret7.c' ! 2780: -#include <stdio.h> ! 2781: -#include "pret.h" ! 2782: -#include "pret.d" ! 2783: - ! 2784: -extern FILE *tb; ! 2785: -extern int anyerror, linenumber; ! 2786: -extern int nrrows, nrcols, curstate, curdepth; ! 2787: -extern int nrvars, realnrvars; ! 2788: -extern struct ENTRY *base; ! 2789: -extern char filename[256]; ! 2790: - ! 2791: -char * ! 2792: -Emalloc(N) ! 2793: - unsigned N; ! 2794: -{ char *try, *malloc(); ! 2795: - if ((try = malloc(N)) == NULL) ! 2796: - whoops("out of memory"); ! 2797: - return try; ! 2798: -} ! 2799: - ! 2800: -whoops(s) ! 2801: - char *s; ! 2802: -{ yyerror(s, "aborting"); ! 2803: - fclose(tb); ! 2804: - unlink("pret.tmp"); ! 2805: - exit(1); ! 2806: -} ! 2807: - ! 2808: -yyerror(s1, s2) ! 2809: - char *s1, *s2; ! 2810: -{ ! 2811: - char buf[512]; ! 2812: - sprintf(buf, s1, s2); ! 2813: - ! 2814: - printf("\"%s\", line %2d: %s\n", filename, linenumber, buf); ! 2815: - fflush(stdout); ! 2816: - anyerror++; ! 2817: -} ! 2818: - ! 2819: -warning(s1, s2) ! 2820: - char *s1, *s2; ! 2821: -{ ! 2822: - printf("\"%s\", line %2d, warning: %s", filename, linenumber, s1); ! 2823: - if (strlen(s2) > 0 && strcmp(s1, "syntax error") != 0) ! 2824: - printf(" (%s)\n", s2); ! 2825: - else ! 2826: - printf("\n"); ! 2827: -} ! 2828: - ! 2829: -release() ! 2830: -{ register struct ENTRY *this, *temp1, *temp2; ! 2831: - register struct PILAR *that, *temp3; ! 2832: - ! 2833: - this = base; ! 2834: - while (this != NULL) ! 2835: - { temp1 = this->nextrow; ! 2836: - do ! 2837: - { temp2 = this->nextcol; ! 2838: - that = this->pilar; ! 2839: - do ! 2840: - { temp3 = that->nxtp; ! 2841: - free(that); ! 2842: - that = temp3; ! 2843: - } while (that != NULL); ! 2844: - free(this); ! 2845: - this = temp2; ! 2846: - } while (this != NULL); ! 2847: - this = temp1; ! 2848: - } ! 2849: - nrrows = nrcols = curstate = curdepth = 0; ! 2850: - nrvars = realnrvars = 0; ! 2851: -} ! 2852: - ! 2853: -struct PILAR * ! 2854: -newunit() ! 2855: -{ struct PILAR *try; ! 2856: - ! 2857: - try = (struct PILAR *) Emalloc(sizeof(struct PILAR)); ! 2858: - ! 2859: - try->transf = NOSTATE; ! 2860: - try->code = NONE; ! 2861: - try->nxtp = NULL; ! 2862: - ! 2863: - return try; ! 2864: -} ! 2865: - ! 2866: -struct ENTRY * ! 2867: -newentry() ! 2868: -{ struct ENTRY *try; ! 2869: - ! 2870: - try = (struct ENTRY *) Emalloc(sizeof(struct ENTRY)); ! 2871: - ! 2872: - try->pilar = newunit(); ! 2873: - try->nrpils = 0; ! 2874: - try->nextrow = try->nextcol = NULL; ! 2875: - return try; ! 2876: -} ! 2877: //GO.SYSIN DD pret7.c ! 2878: echo pret8.c 1>&2 ! 2879: sed 's/.//' >pret8.c <<'//GO.SYSIN DD pret8.c' ! 2880: -#include <stdio.h> ! 2881: -#include "pret.h" ! 2882: - ! 2883: -struct { ! 2884: - char name[MAXNAME]; ! 2885: - int status; ! 2886: - int initval; ! 2887: - int index; /* set if used as array */ ! 2888: - int width; /* in bits: for supertrace */ ! 2889: -} vartbl[MANY]; ! 2890: - ! 2891: -struct { ! 2892: - int m; /* index of basename in vartbl */ ! 2893: - int n; /* reference to the index */ ! 2894: -} ivartbl[MANY]; ! 2895: -int realnrvars=0; ! 2896: - ! 2897: -struct { ! 2898: - int m; /* index of basename in globvartbl */ ! 2899: - int n; /* reference to the index */ ! 2900: -} igvartbl[MANY]; ! 2901: -int realgvars=0; ! 2902: - ! 2903: -struct { ! 2904: - char name[MAXNAME]; ! 2905: - int status; ! 2906: - int initval; ! 2907: - int index; ! 2908: - int width; ! 2909: -} globvartbl[MANY]; ! 2910: - ! 2911: -int nrvars = 0; ! 2912: -int nrglobvars = 0; ! 2913: -int varwidths = 0; ! 2914: - ! 2915: -extern char procname[MAXNAME]; ! 2916: -extern char refname[MAXNAME]; ! 2917: -extern int anyerror, pid, rid; ! 2918: - ! 2919: -reallocal(m, n) ! 2920: -{ int i; ! 2921: - for (i = 0; i < realnrvars; i++) ! 2922: - if (ivartbl[i].m == m && ivartbl[i].n == n) ! 2923: - return i; ! 2924: - if ((i = realnrvars++) >= MANY) ! 2925: - whoops("reallocal overflow"); ! 2926: - ivartbl[i].n = n; ! 2927: - ivartbl[i].m = m; ! 2928: - return i; ! 2929: -} ! 2930: - ! 2931: -realglobal(m, n) ! 2932: -{ int i; ! 2933: - for (i = 0; i < realgvars; i++) ! 2934: - if (igvartbl[i].m == m && igvartbl[i].n == n) ! 2935: - return i; ! 2936: - if ((i = realgvars++) >= MANY) ! 2937: - whoops("realglobal overflow"); ! 2938: - igvartbl[i].n = n; ! 2939: - igvartbl[i].m = m; ! 2940: - return i; ! 2941: -} ! 2942: - ! 2943: -twiddle(suff) ! 2944: - char *suff; ! 2945: -{ int i; extern int extras; ! 2946: - ! 2947: - for (i = 0; i < nrvars; i++) ! 2948: - if (strcmp(vartbl[i].name, suff) == 0) ! 2949: - { vartbl[i].initval++; ! 2950: - return; ! 2951: - } ! 2952: - whoops("cannot happen, twiddle"); ! 2953: -} ! 2954: - ! 2955: -isarrayvar(suff) ! 2956: - char *suff; ! 2957: -{ int i; ! 2958: - ! 2959: - for (i = 0; i < nrvars; i++) ! 2960: - if (strcmp(vartbl[i].name, suff) == 0 ! 2961: - && vartbl[i].index != NONE) ! 2962: - return 1; ! 2963: - for (i = 0; i < nrglobvars; i++) ! 2964: - if (strcmp(globvartbl[i].name, suff) == 0 ! 2965: - && globvartbl[i].index != NONE) ! 2966: - return 1; ! 2967: - return 0; ! 2968: -} ! 2969: - ! 2970: -looklocal(suff, how, index) ! 2971: - char *suff; ! 2972: -{ int i; ! 2973: - ! 2974: - for (i = 0; i < nrvars; i++) ! 2975: - if (strcmp(vartbl[i].name, suff) == 0) ! 2976: - { vartbl[i].status |= how; ! 2977: - break; ! 2978: - } ! 2979: - ! 2980: - if (i != nrvars && how == DCL) ! 2981: - yyerror("local variable redeclared, %s", suff); ! 2982: - ! 2983: - if (i != nrvars && how == RFR && index != vartbl[i].index ! 2984: - && (index == NONE || vartbl[i].index == NONE)) ! 2985: - yyerror("local variable array indexing error, %s", suff); ! 2986: - return i; ! 2987: -} ! 2988: - ! 2989: -lookglobal(suff, how, index) ! 2990: - char *suff; ! 2991: -{ int i; ! 2992: - ! 2993: - for (i = 0; i < nrglobvars; i++) ! 2994: - if (strcmp(globvartbl[i].name, suff) == 0) ! 2995: - { globvartbl[i].status |= how; ! 2996: - break; ! 2997: - } ! 2998: - ! 2999: - if (pid == NONE && rid == NONE && i != nrglobvars && how == DCL) ! 3000: - yyerror("global variable redeclared, %s", suff); ! 3001: - ! 3002: - if (i != nrglobvars && how == RFR && index != globvartbl[i].index ! 3003: - && (index == NONE || globvartbl[i].index == NONE)) ! 3004: - yyerror("global variable array indexing error, %s", suff); ! 3005: - return i; ! 3006: -} ! 3007: - ! 3008: -putlocal(what, ival, how, index, width) ! 3009: - char *what; ! 3010: -{ int i; ! 3011: - ! 3012: - if ((i = nrvars++) >= MANY) ! 3013: - whoops("too many variables"); ! 3014: - ! 3015: - strcpy(vartbl[i].name, what); ! 3016: - vartbl[i].initval = ival; ! 3017: - vartbl[i].status = how; ! 3018: - vartbl[i].index = index; ! 3019: - vartbl[i].width = width; ! 3020: - if (index != NONE && ival != NONE) ! 3021: - { fprintf(stderr,"error: no automatic initialization"); ! 3022: - fprintf(stderr, " of array `%s'\n",what); ! 3023: - anyerror++; ! 3024: - } ! 3025: - if (width != 0) varwidths=1; ! 3026: - return (MANY + i); ! 3027: -} ! 3028: - ! 3029: -putglobal(what, ival, how, index, width) ! 3030: - char *what; ! 3031: -{ int i; ! 3032: - ! 3033: - if ((i = nrglobvars++) >= MANY) ! 3034: - whoops("too many variables"); ! 3035: - strcpy(globvartbl[i].name, what); ! 3036: - globvartbl[i].initval = ival; ! 3037: - globvartbl[i].status = how; ! 3038: - globvartbl[i].index = index; ! 3039: - globvartbl[i].width = width; ! 3040: - if (index != NONE && ival != NONE) ! 3041: - { fprintf(stderr,"error: no automatic initialization"); ! 3042: - fprintf(stderr, " of array `%s'\n",what); ! 3043: - anyerror++; ! 3044: - } ! 3045: - if (width != 0) varwidths=1; ! 3046: - ! 3047: - return i; ! 3048: -} ! 3049: -/* ! 3050: - * arrays are merely patched in for now ! 3051: - */ ! 3052: -addvarname(what, how, ival, index, width) ! 3053: - char *what; ! 3054: -{ ! 3055: - int i, islocal = (rid != NONE || pid != NONE); ! 3056: - ! 3057: - if (rid != NONE && (i = Fparname(what, rid, ISV, NONE, how, index)) != -1) ! 3058: - return (2*MANY + i); ! 3059: - /* formal parameter may not be an array reference */ ! 3060: - ! 3061: - if (islocal && (i = looklocal(what, how, index)) < nrvars) ! 3062: - return (MANY + reallocal(i, index)); ! 3063: - if ((i = lookglobal(what, how, index)) < nrglobvars) ! 3064: - return realglobal(i, index); ! 3065: - ! 3066: - if (how == RFR) ! 3067: - yyerror("undeclared variable, %s", what); ! 3068: - if (islocal) ! 3069: - return putlocal(what, ival, how, index, width); ! 3070: - ! 3071: - return putglobal(what, ival, how, index, width); ! 3072: -} ! 3073: - ! 3074: -checklocvars() ! 3075: -{ int i; ! 3076: - ! 3077: - for (i = 0; i < nrvars; i++) ! 3078: - if (vartbl[i].status == DCL) ! 3079: - { printf("%s: ", (pid != NONE)?procname:refname); ! 3080: - printf("pvar %s is never used\n", vartbl[i].name); ! 3081: - } ! 3082: -} ! 3083: - ! 3084: -checkglobvars() ! 3085: -{ int i; ! 3086: - ! 3087: - for (i = 0; i < nrglobvars; i++) ! 3088: - if (globvartbl[i].status == DCL) ! 3089: - { printf("global: "); ! 3090: - printf("pvar %s is never used\n", globvartbl[i].name); ! 3091: - } ! 3092: -} ! 3093: - ! 3094: -numglobvars(fd) ! 3095: - FILE *fd; ! 3096: -{ int i; ! 3097: - ! 3098: - fprintf(fd, "%d g-variables: ", nrglobvars); ! 3099: - for (i = 0; i < nrglobvars; i++) ! 3100: - fprintf(fd, "%d/%d,", globvartbl[i].initval, globvartbl[i].index); ! 3101: - putc('\n', fd); ! 3102: - if (varwidths) ! 3103: - { fprintf(fd, "%d g-widths: ", nrglobvars); ! 3104: - for (i = 0; i < nrglobvars; i++) ! 3105: - fprintf(fd, "%d,", globvartbl[i].width); ! 3106: - putc('\n', fd); ! 3107: - } ! 3108: - fprintf(fd, "%d g-uses: ", realgvars); ! 3109: - for (i = 0; i < realgvars; i++) ! 3110: - fprintf(fd, "%d/%d,", igvartbl[i].m, igvartbl[i].n); ! 3111: - putc('\n', fd); ! 3112: -} ! 3113: - ! 3114: -numlocvars(fd) ! 3115: - FILE *fd; ! 3116: -{ int i; ! 3117: - ! 3118: - fprintf(fd, "%d l-variables: ", nrvars); ! 3119: - for (i = 0; i < nrvars; i++) ! 3120: - fprintf(fd, "%d/%d,", vartbl[i].initval, vartbl[i].index); ! 3121: - putc('\n', fd); ! 3122: - if (varwidths) ! 3123: - { fprintf(fd, "%d l-widths: ", nrvars); ! 3124: - for (i = 0; i < nrvars; i++) ! 3125: - fprintf(fd, "%d,", vartbl[i].width); ! 3126: - putc('\n', fd); ! 3127: - } ! 3128: - ! 3129: - fprintf(fd, "%d l-uses: ", realnrvars); ! 3130: - for (i = 0; i < realnrvars; i++) ! 3131: - fprintf(fd, "%d/%d,", ivartbl[i].m, ivartbl[i].n); ! 3132: - putc('\n', fd); ! 3133: -} ! 3134: //GO.SYSIN DD pret8.c ! 3135: echo pret9.c 1>&2 ! 3136: sed 's/.//' >pret9.c <<'//GO.SYSIN DD pret9.c' ! 3137: -#include <stdio.h> ! 3138: -#include "pret.h" ! 3139: - ! 3140: -#define MAXACTUALS (MANY) ! 3141: - ! 3142: - struct ACTUALS { ! 3143: - int typefs[MAXACTUALS]; /* queue mesg or pvar */ ! 3144: - int index [MAXACTUALS]; /* qid, if mesg */ ! 3145: - struct ACTUALS *nxtcall; ! 3146: - int nractuals; ! 3147: - int whattask; /* id of task called */ ! 3148: - }; ! 3149: - ! 3150: - struct ACTUALS *calls; /* procedure call data */ ! 3151: - int nrcalls; /* nr of procedure calls */ ! 3152: - ! 3153: - extern pid, rid, linenumber; ! 3154: - ! 3155: -newcalltable() ! 3156: -{ nrcalls = 0; ! 3157: - calls = NULL; ! 3158: -} ! 3159: - ! 3160: -scrapcalltable() ! 3161: -{ struct ACTUALS *tmp; ! 3162: - struct ACTUALS *hook = calls; ! 3163: - int i; ! 3164: - ! 3165: - for (i = 0; i < nrcalls; i++) ! 3166: - { tmp = hook; ! 3167: - hook = hook->nxtcall; ! 3168: - free(tmp); ! 3169: - } ! 3170: -} ! 3171: - ! 3172: -newcall(ofwhat) ! 3173: -{ int i, j; ! 3174: - struct ACTUALS *new, *old; ! 3175: - ! 3176: - new = ( struct ACTUALS *) ! 3177: - Emalloc( sizeof(struct ACTUALS) ); ! 3178: - new->nractuals = 0; ! 3179: - new->whattask = ofwhat; ! 3180: - ! 3181: - if ((j = nrcalls++) == 0) ! 3182: - calls = new; ! 3183: - else ! 3184: - { old = calls; ! 3185: - for (i = 1; i < j; i++) ! 3186: - old = old->nxtcall; ! 3187: - old->nxtcall = new; ! 3188: - } ! 3189: - return nrcalls-1; ! 3190: -} ! 3191: - ! 3192: -putcalls(tb) ! 3193: - FILE *tb; ! 3194: -{ struct ACTUALS *hook; ! 3195: - int j, k, a, b; ! 3196: - int maxm = 0; ! 3197: - int maxv = 0; ! 3198: - ! 3199: - fprintf(tb, "FCT_CALLS %d\n", nrcalls); ! 3200: - for (j = 0, hook = calls; j < nrcalls; j++) ! 3201: - { ! 3202: - for (k = a = b = 0; k < hook->nractuals; k++) ! 3203: - { if (hook->typefs[k] == ISM) ! 3204: - a++; ! 3205: - else if (hook->typefs[k] == ISV) ! 3206: - b++; ! 3207: - } ! 3208: - if (a > maxm) maxm = a; ! 3209: - if (b > maxv) maxv = b; ! 3210: - ! 3211: - fprintf(tb, "%d-%d/%d:", hook->whattask, a, b); ! 3212: - for (k = 0; k < hook->nractuals; k++) ! 3213: - { if (hook->typefs[k] != ISQ) ! 3214: - fprintf(tb, " %d/%d", hook->typefs[k], hook->index[k]); ! 3215: - } ! 3216: - putc('\n', tb); ! 3217: - hook = hook->nxtcall; ! 3218: - } ! 3219: - fprintf(tb, "PARS %d/%d\n", maxm, maxv); ! 3220: -} ! 3221: - ! 3222: -callentry(x, val) ! 3223: -{ int i; ! 3224: - struct ACTUALS *hook = calls; ! 3225: - ! 3226: - for (i = 1; i < nrcalls; i++) ! 3227: - hook = hook->nxtcall; ! 3228: - ! 3229: - if ((i = hook->nractuals++) >= MAXACTUALS) ! 3230: - whoops("too many parameters"); ! 3231: - hook->typefs[i] = x; ! 3232: - hook->index[i] = val; ! 3233: -} ! 3234: //GO.SYSIN DD pret9.c ! 3235: echo pretlex.l 1>&2 ! 3236: sed 's/.//' >pretlex.l <<'//GO.SYSIN DD pretlex.l' ! 3237: -%{ ! 3238: -#include "stdio.h" ! 3239: -#include "pret.h" ! 3240: -#include "y.tab.h" ! 3241: - ! 3242: -extern linenumber, nest; ! 3243: -extern char filename[256]; ! 3244: - ! 3245: -putback(c) ! 3246: -{ unput(c); ! 3247: -} ! 3248: - ! 3249: -%} ! 3250: -%% ! 3251: -\n { linenumber++; } ! 3252: -\/\* { char c1, c2; /* comment string */ ! 3253: - ! 3254: - for(nest++, c2 = ' ';;){ ! 3255: - c1 = c2; ! 3256: - c2 = input(); ! 3257: - if (c1 == '/' && c2 == '*') ! 3258: - nest++; ! 3259: - else if (c1 == '*' && c2 == '/') ! 3260: - nest--; ! 3261: - if (nest <= 0) ! 3262: - break; ! 3263: - if (c2 == '\n') ! 3264: - linenumber++; ! 3265: - else if (c2 == 0) ! 3266: - whoops("unexpected eof (in comment)"); ! 3267: - } ! 3268: - } ! 3269: -[ \t] { ; } ! 3270: -^#[ ]+[0-9]+[ ]+\"[^\"]+\"\n { ! 3271: - sscanf(&yytext[1], "%d \"%s\"\n", &linenumber, filename); ! 3272: - filename[strlen(filename)-1] = 0; /* strip the last " */ ! 3273: - } ! 3274: -queue { return(QUEUES); } ! 3275: -qset { return(QSET); } ! 3276: -pvar { return(PVAR); } ! 3277: -proc { return(PROCESS); } ! 3278: -if { return(IF); } ! 3279: -fi { return(FI); } ! 3280: -do { return(DO); } ! 3281: -od { return(OD); } ! 3282: -skip { return(skip); } ! 3283: -goto { return(GOTO); } ! 3284: -break { return(BREAK); } ! 3285: -any { return(DEFAULT); } ! 3286: -default { return(DEFAULT); } ! 3287: -assert { return(ASSERT); } ! 3288: -error { return(ERROR); } ! 3289: -timeout { return(timeout); } ! 3290: -\{ { return(PBEGIN); } ! 3291: -\} { return(END); } ! 3292: -[0-9]+ { yylval.resu = atoi(yytext); return(VALUE); } ! 3293: -[a-zA-Z][_a-zA-Z0-9]* { ! 3294: - yylval.resu = newstring(yytext); ! 3295: - if (isarrayvar(yytext)) return(ARNAME); ! 3296: - if (isqset(yytext)) return(QSNAME); ! 3297: - return(NAME); ! 3298: - } ! 3299: -_PROCID { yylval.resu = newstring("_PROCID"); return(NAME); } ! 3300: -"::" { return(FLAG); } ! 3301: -"->" { return(ARROW); } ! 3302: -";" { return(SEMICOLON); } ! 3303: -":" { return(COLON); } ! 3304: -\+\+ { return(INC); } ! 3305: -\-\- { return(DEC); } ! 3306: -\+\= { return(ADDEQ); } ! 3307: -\-\= { return(SUBEQ); } ! 3308: -\*\= { return(MULEQ); } ! 3309: -\/\= { return(DIVEQ); } ! 3310: -\%\= { return(MODEQ); } ! 3311: -\|\| { return(OR); } ! 3312: -\&\& { return(AND); } ! 3313: -\>\= { return(GE); } ! 3314: -\<\= { return(LE); } ! 3315: -\!\= { return(NE); } ! 3316: -\> { return(GT); } ! 3317: -\< { return(LT); } ! 3318: -\! { return(NOT); } ! 3319: -== { return(EQ); } ! 3320: -. { return(yytext[0]); } ! 3321: //GO.SYSIN DD pretlex.l ! 3322: echo x.tab.h 1>&2 ! 3323: sed 's/.//' >x.tab.h <<'//GO.SYSIN DD x.tab.h' ! 3324: - ! 3325: -typedef union { ! 3326: - int resu; ! 3327: - struct Node *node; ! 3328: -} YYSTYPE; ! 3329: -extern YYSTYPE yylval; ! 3330: -# define NAME 257 ! 3331: -# define VALUE 258 ! 3332: -# define ARNAME 259 ! 3333: -# define QSNAME 260 ! 3334: -# define ASSERT 261 ! 3335: -# define ERROR 262 ! 3336: -# define PROCESS 263 ! 3337: -# define PBEGIN 264 ! 3338: -# define END 265 ! 3339: -# define IF 266 ! 3340: -# define FI 267 ! 3341: -# define DO 268 ! 3342: -# define OD 269 ! 3343: -# define timeout 270 ! 3344: -# define skip 271 ! 3345: -# define BREAK 272 ! 3346: -# define DEFAULT 273 ! 3347: -# define GOTO 274 ! 3348: -# define FLAG 275 ! 3349: -# define ARROW 276 ! 3350: -# define SEMICOLON 277 ! 3351: -# define COLON 278 ! 3352: -# define QUEUES 279 ! 3353: -# define QSET 280 ! 3354: -# define PVAR 281 ! 3355: -# define MESG 282 ! 3356: -# define ADDEQ 283 ! 3357: -# define SUBEQ 284 ! 3358: -# define MULEQ 285 ! 3359: -# define DIVEQ 286 ! 3360: -# define MODEQ 287 ! 3361: -# define OR 288 ! 3362: -# define AND 289 ! 3363: -# define GT 290 ! 3364: -# define GE 291 ! 3365: -# define LT 292 ! 3366: -# define LE 293 ! 3367: -# define EQ 294 ! 3368: -# define NE 295 ! 3369: -# define UNARYMINUS 296 ! 3370: -# define NOT 297 ! 3371: -# define INC 298 ! 3372: -# define DEC 299 ! 3373: //GO.SYSIN DD x.tab.h
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.