Пример #1
0
void
genaddproc(void)
{	ProcList *p;
	int i = 0;

	if (separate ==2) goto shortcut;

	fprintf(tc, "int\naddproc(int n");
	for (i = 0; i < Npars; i++)
		fprintf(tc, ", int par%d", i);

	ntimes(tc, 0, 1, Addp0);
	ntimes(tc, 1, nrRdy+1, R5); /* +1 for np_ */
	ntimes(tc, 0, 1, Addp1);

	if (has_provided)
	{	fprintf(tt, "\nint\nprovided(int II, unsigned char ot, ");
		fprintf(tt, "int tt, Trans *t)\n");
		fprintf(tt, "{\n\tswitch(ot) {\n");
	}
shortcut:
	tc_predef_np();
	for (p = rdy; p; p = p->nxt)
	{	Pid = p->tn;
		put_pinit(p);
	}
	if (separate == 2) return;

	Pid = 0;
	if (has_provided)
	{	fprintf(tt, "\tdefault: return 1; /* e.g., a claim */\n");
		fprintf(tt, "\t}\n\treturn 0;\n}\n");
	}

	ntimes(tc, i, i+1, R6);
	if (separate == 0)
		ntimes(tc, 1, nrRdy+1, R5); /* +1 for np_ */
	else
		ntimes(tc, 1, nrRdy, R5);
	ntimes(tc, 0, 1, R8a);
}
Пример #2
0
void
putprelude(void)
{	char snap[256]; FILE *fd;

	sprintf(snap, "%s.ps", oFname?oFname->name:"msc");
	if (!(pfd = fopen(snap, MFLAGS)))
		fatal("cannot create file '%s'", snap);

	fprintf(pfd, "%%!PS-Adobe-2.0\n");
	fprintf(pfd, "%%%%Creator: %s\n", SpinVersion);
	fprintf(pfd, "%%%%Title: MSC %s\n", oFname?oFname->name:"--");
	fprintf(pfd, "%%%%BoundingBox: 119 154 494 638\n");
	ntimes(pfd, 0, 1, PsPre);

	if (s_trail)
	{	if (ntrail)
		sprintf(snap, "%s%d.trail", oFname?oFname->name:"msc", ntrail);
		else
		sprintf(snap, "%s.trail", oFname?oFname->name:"msc");
		if (!(fd = fopen(snap, "r")))
		{	snap[strlen(snap)-2] = '\0';
			if (!(fd = fopen(snap, "r")))
				fatal("cannot open trail file", (char *) 0);
		}
		TotSteps = 1;
		while (fgets(snap, 256, fd)) TotSteps++;
		fclose(fd);
	}
	TotSteps += 10;
	R = (int   *) emalloc(TotSteps * sizeof(int));
	D = (int   *) emalloc(TotSteps * sizeof(int));
	M = (short *) emalloc(TotSteps * sizeof(short));
	T = (short *) emalloc(TotSteps * sizeof(short));
	L = (char **) emalloc(TotSteps * sizeof(char *));
	I = (char **) emalloc(TotSteps * sizeof(char *));
	ProcLine = (char *) emalloc(1024 * sizeof(char));
	startpage();
}
Пример #3
0
void
genheader(void)
{	ProcList *p; int i;

	if (separate == 2)
	{	putunames(th);
		goto here;
	}

	fprintf(th, "#define SYNC	%d\n", u_sync);
	fprintf(th, "#define ASYNC	%d\n\n", u_async);

	putunames(th);

	fprintf(tc, "short Air[] = { ");
	for (p = rdy, i=0; p; p = p->nxt, i++)
		fprintf(tc, "%s (short) Air%d", (p!=rdy)?",":"", i);
	fprintf(tc, ", (short) Air%d", i);	/* np_ */
	fprintf(tc, " };\n");

	fprintf(th, "char *procname[] = {\n");
		reverse_names(rdy);
	fprintf(th, "   \":np_:\",\n");
	fprintf(th, "};\n\n");

here:
	for (p = rdy; p; p = p->nxt)
		put_ptype(p->n->name, p->tn, mst, nrRdy+1);
		/* +1 for np_ */
	put_ptype("np_", nrRdy, mst, nrRdy+1);

	ntimes(th, 0, 1, Head0);

	if (separate != 2)
	{	extern void c_add_stack(FILE *);

		ntimes(th, 0, 1, Header);
		c_add_stack(th);
		ntimes(th, 0, 1, Header0);
	}
	ntimes(th, 0, 1, Head1);

	LstSet = ZS;
	(void) doglobal("", PUTV);

	hastrack = c_add_sv(th);

	fprintf(th, "	uchar sv[VECTORSZ];\n");
	fprintf(th, "} State");
#ifdef SOLARIS
	fprintf(th,"\n#ifdef GCC\n");
	fprintf(th, "\t__attribute__ ((aligned(8)))");
	fprintf(th, "\n#endif\n\t");
#endif
	fprintf(th, ";\n\n");

	fprintf(th, "#define HAS_TRACK	%d\n", hastrack);

	if (separate != 2)
		dohidden();
}
Пример #4
0
void
gensvmap(void)
{
	ntimes(tc, 0, 1, SvMap);
}
Пример #5
0
void
genother(void)
{	ProcList *p;

	switch (separate) {
	case 2:
		if (claimnr >= 0)
		ntimes(tc, claimnr, claimnr+1, R0); /* claim only */
		break;
	case 1:
		ntimes(tc,     0,    1, Code0);
		ntimes(tc, 0, claimnr, R0);	/* all except claim */
		ntimes(tc, claimnr+1, nrRdy, R0);
		break;
	case 0:
		ntimes(tc,     0,    1, Code0);
		ntimes(tc,     0, nrRdy+1, R0); /* +1 for np_ */
		break;
	}

	for (p = rdy; p; p = p->nxt)
		end_labs(p->n, p->tn);

	switch (separate) {
	case 2:
		if (claimnr >= 0)
		ntimes(tc, claimnr, claimnr+1, R0a); /* claim only */
		return;
	case 1:
		ntimes(tc, 0, claimnr, R0a);	/* all except claim */
		ntimes(tc, claimnr+1, nrRdy, R0a);
		fprintf(tc, "	if (state_tables)\n");
		fprintf(tc, "		ini_claim(%d, 0);\n", claimnr);
		break;
	case 0:
		ntimes(tc, 0, nrRdy, R0a);	/* all */
		break;
	}

	ntimes(tc, 0,     1, R0b);
	if (separate == 1 && acceptors == 0)
		acceptors = 1;	/* assume at least 1 acceptstate */
	ntimes(th, acceptors,   acceptors+1,   Code1);
	ntimes(th, progressors, progressors+1, Code3);
	ntimes(th, nrRdy+1, nrRdy+2, R2); /* +1 for np_ */

	fprintf(tc, "	iniglobals();\n");
	ntimes(tc, 0,     1, Code2a);
	ntimes(tc, 0,     1, Code2b);	/* bfs option */
	ntimes(tc, 0,     1, Code2c);
	ntimes(tc, 0,     nrRdy, R4);
	fprintf(tc, "}\n\n");

	fprintf(tc, "void\n");
	fprintf(tc, "iniglobals(void)\n{\n");
	if (doglobal("", INIV) > 0)
	{	fprintf(tc, "#ifdef VAR_RANGES\n");
		(void) doglobal("logval(\"", LOGV);
		fprintf(tc, "#endif\n");
	}
	ntimes(tc, 1, nqs+1, R3);
	fprintf(tc, "\tMaxbody = max(Maxbody, sizeof(State)-VECTORSZ);");
	fprintf(tc, "\n}\n\n");
}
Пример #6
0
void
genaddqueue(void)
{	char buf0[256];
	int j, qmax = 0;
	Queue *q;

	ntimes(tc, 0, 1, Addq0);
	if (has_io && !nqs)
		fprintf(th, "#define NQS	1 /* nqs=%d, but has_io */\n", nqs);
	else
		fprintf(th, "#define NQS	%d\n", nqs);
	fprintf(th, "short q_flds[%d];\n", nqs+1);
	fprintf(th, "short q_max[%d];\n", nqs+1);

	for (q = qtab; q; q = q->nxt)
		if (q->nslots > qmax)
			qmax = q->nslots;

	for (q = qtab; q; q = q->nxt)
	{	j = q->qid;
		fprintf(tc, "\tcase %d: j = sizeof(Q%d);", j, j);
		fprintf(tc, " q_flds[%d] = %d;", j, q->nflds);
		fprintf(tc, " q_max[%d] = %d;", j, max(1,q->nslots));
		fprintf(tc, " break;\n");

		fprintf(th, "typedef struct Q%d {\n", j);
		qlen_type(qmax);	/* 4.2.2 */
		fprintf(th, "	uchar _t;	/* q_type */\n");
		fprintf(th, "	struct {\n");

		for (j = 0; j < q->nflds; j++)
		{	switch (q->fld_width[j]) {
			case BIT:
				if (q->nflds != 1)
				{	fprintf(th, "\t\tunsigned");
					fprintf(th, " fld%d : 1;\n", j);
					break;
				} /* else fall through: smaller struct */
			case MTYPE:
			case CHAN:
			case BYTE:
				fprintf(th, "\t\tuchar fld%d;\n", j);
				break;
			case SHORT:
				fprintf(th, "\t\tshort fld%d;\n", j);
				break;
			case INT:
				fprintf(th, "\t\tint fld%d;\n", j);
				break;
			default:
				fatal("bad channel spec", "");
			}
		}
		fprintf(th, "	} contents[%d];\n", max(1, q->nslots));
		fprintf(th, "} Q%d;\n", q->qid);
	}

	fprintf(th, "typedef struct Q0 {\t/* generic q */\n");
	qlen_type(qmax);	/* 4.2.2 */
	fprintf(th, "	uchar _t;\n");
	fprintf(th, "} Q0;\n");

	ntimes(tc, 0, 1, Addq1);

	if (has_random)
	{	fprintf(th, "int Q_has(int");
		for (j = 0; j < Mpars; j++)
			fprintf(th, ", int, int");
		fprintf(th, ");\n");

		fprintf(tc, "int\nQ_has(int into");
		for (j = 0; j < Mpars; j++)
			fprintf(tc, ", int want%d, int fld%d", j, j);
		fprintf(tc, ")\n");
		fprintf(tc, "{	int i;\n\n");
		fprintf(tc, "	if (!into--)\n");
		fprintf(tc, "	uerror(\"ref to unknown chan ");
		fprintf(tc, "(recv-poll)\");\n\n");
		fprintf(tc, "	if (into >= now._nr_qs || into < 0)\n");
		fprintf(tc, "		Uerror(\"qrecv bad queue#\");\n\n");
		fprintf(tc, "	for (i = 0; i < ((Q0 *)qptr(into))->Qlen;");
		fprintf(tc, " i++)\n");
		fprintf(tc, "	{\n");
		for (j = 0; j < Mpars; j++)
		{	fprintf(tc, "		if (want%d && ", j);
			fprintf(tc, "qrecv(into+1, i, %d, 0) != fld%d)\n",
				j, j);
			fprintf(tc, "			continue;\n");
		}
		fprintf(tc, "		return i+1;\n");
		fprintf(tc, "	}\n");
		fprintf(tc, "	return 0;\n");
		fprintf(tc, "}\n");
	}

	fprintf(tc, "#if NQS>0\n");
	fprintf(tc, "void\nqsend(int into, int sorted");
	for (j = 0; j < Mpars; j++)
		fprintf(tc, ", int fld%d", j);
	fprintf(tc, ")\n");
	ntimes(tc, 0, 1, Addq11);

	for (q = qtab; q; q = q->nxt)
	{	sprintf(buf0, "((Q%d *)z)->", q->qid);
		fprintf(tc, "\tcase %d:%s\n", q->qid,
			(q->nslots)?"":" /* =rv= */");
		if (q->nslots == 0)	/* reset handshake point */
			fprintf(tc, "\t\t(trpt+2)->o_m = 0;\n");

		if (has_sorted)
		{	fprintf(tc, "\t\tif (!sorted) goto append%d;\n", q->qid);
			fprintf(tc, "\t\tfor (j = 0; j < %sQlen; j++)\n", buf0);
			fprintf(tc, "\t\t{\t/* find insertion point */\n");
			sprintf(buf0, "((Q%d *)z)->contents[j].fld", q->qid);
			for (j = 0; j < q->nflds; j++)
			{	fprintf(tc, "\t\t\tif (fld%d > %s%d) continue;\n",
						j, buf0, j);
				fprintf(tc, "\t\t\tif (fld%d < %s%d) ", j, buf0, j);
				fprintf(tc, "goto found%d;\n\n", q->qid);
			}
			fprintf(tc, "\t\t}\n");
			fprintf(tc, "\tfound%d:\n", q->qid);
			sprintf(buf0, "((Q%d *)z)->", q->qid);
			fprintf(tc, "\t\tfor (k = %sQlen - 1; k >= j; k--)\n", buf0);
			fprintf(tc, "\t\t{\t/* shift up */\n");
			for (j = 0; j < q->nflds; j++)
			{	fprintf(tc, "\t\t\t%scontents[k+1].fld%d = ",
					buf0, j);
				fprintf(tc, "%scontents[k].fld%d;\n",
					buf0, j);
			}
			fprintf(tc, "\t\t}\n");
			fprintf(tc, "\tappend%d:\t/* insert in slot j */\n", q->qid);
		}

		fprintf(tc, "#ifdef HAS_SORTED\n");
		fprintf(tc, "\t\t(trpt+1)->ipt = j;\n");	/* ipt was bup.oval */
		fprintf(tc, "#endif\n");
		fprintf(tc, "\t\t%sQlen = %sQlen + 1;\n", buf0, buf0);
		sprintf(buf0, "((Q%d *)z)->contents[j].fld", q->qid);
		for (j = 0; j < q->nflds; j++)
			fprintf(tc, "\t\t%s%d = fld%d;\n", buf0, j, j);
		fprintf(tc, "\t\tbreak;\n");
	}
	ntimes(tc, 0, 1, Addq2);

	for (q = qtab; q; q = q->nxt)
	fprintf(tc, "\tcase %d: return %d;\n", q->qid, (!q->nslots));

	ntimes(tc, 0, 1, Addq3);

	for (q = qtab; q; q = q->nxt)
	fprintf(tc, "\tcase %d: return (q_sz(from) == %d);\n",
			q->qid, max(1, q->nslots));

	ntimes(tc, 0, 1, Addq4);
	for (q = qtab; q; q = q->nxt)
	{	sprintf(buf0, "((Q%d *)z)->", q->qid);
		fprintf(tc, "	case %d:%s\n\t\t",
			q->qid, (q->nslots)?"":" /* =rv= */");
		if (q->nflds == 1)
		{	fprintf(tc, "if (fld == 0) r = %s", buf0);
			fprintf(tc, "contents[slot].fld0;\n");
		} else
		{	fprintf(tc, "switch (fld) {\n");
			ncases(tc, q->qid, 0, q->nflds, R12);
			fprintf(tc, "\t\tdefault: Uerror");
			fprintf(tc, "(\"too many fields in recv\");\n");
			fprintf(tc, "\t\t}\n");
		}
		fprintf(tc, "\t\tif (done)\n");
		if (q->nslots == 0)
		{	fprintf(tc, "\t\t{	j = %sQlen - 1;\n",  buf0);
			fprintf(tc, "\t\t	%sQlen = 0;\n", buf0);
			sprintf(buf0, "\t\t\t((Q%d *)z)->contents", q->qid);
		} else
	 	{	fprintf(tc, "\t\t{	j = %sQlen;\n",  buf0);
			fprintf(tc, "\t\t	%sQlen = --j;\n", buf0);
			fprintf(tc, "\t\t	for (k=slot; k<j; k++)\n");
			fprintf(tc, "\t\t	{\n");
			sprintf(buf0, "\t\t\t((Q%d *)z)->contents", q->qid);
			for (j = 0; j < q->nflds; j++)
			{	fprintf(tc, "\t%s[k].fld%d = \n", buf0, j);
				fprintf(tc, "\t\t%s[k+1].fld%d;\n", buf0, j);
			}
			fprintf(tc, "\t\t	}\n");
	 	}

		for (j = 0; j < q->nflds; j++)
			fprintf(tc, "%s[j].fld%d = 0;\n", buf0, j);
		fprintf(tc, "\t\t\tif (fld+1 != %d)\n\t\t\t", q->nflds);
		fprintf(tc, "\tuerror(\"missing pars in receive\");\n");
		/* incompletely received msgs cannot be unrecv'ed */
		fprintf(tc, "\t\t}\n");
		fprintf(tc, "\t\tbreak;\n");
	}
	ntimes(tc, 0, 1, Addq5);
	for (q = qtab; q; q = q->nxt)
	fprintf(tc, "	case %d: j = sizeof(Q%d); break;\n",
		q->qid, q->qid);
	ntimes(tc, 0, 1, R8b);

	ntimes(th, 0, 1, Proto);	/* tag on function prototypes */
	fprintf(th, "void qsend(int, int");
	for (j = 0; j < Mpars; j++)
		fprintf(th, ", int");
	fprintf(th, ");\n");

	fprintf(th, "#define Addproc(x)	addproc(x");
	for (j = 0; j < Npars; j++)
		fprintf(th, ", 0");
	fprintf(th, ")\n");
}
Пример #7
0
void
genunio(void)
{	char buf1[256];
	Queue *q; int i;

	ntimes(tc, 0, 1, R13);
	for (q = qtab; q; q = q->nxt)
	{	fprintf(tc, "\tcase %d:\n", q->qid);

		if (has_sorted)
		{	sprintf(buf1, "((Q%d *)z)->contents", q->qid);
			fprintf(tc, "#ifdef HAS_SORTED\n");
			fprintf(tc, "\t\tj = trpt->ipt;\n");	/* ipt was bup.oval */
			fprintf(tc, "#endif\n");
			fprintf(tc, "\t\tfor (k = j; k < ((Q%d *)z)->Qlen; k++)\n",
				q->qid);
			fprintf(tc, "\t\t{\n");
			for (i = 0; i < q->nflds; i++)
			fprintf(tc, "\t\t\t%s[k].fld%d = %s[k+1].fld%d;\n",
				buf1, i, buf1, i);
			fprintf(tc, "\t\t}\n");
			fprintf(tc, "\t\tj = ((Q0 *)z)->Qlen;\n");
		}

		sprintf(buf1, "((Q%d *)z)->contents[j].fld", q->qid);
		for (i = 0; i < q->nflds; i++)
			fprintf(tc, "\t\t%s%d = 0;\n", buf1, i);
		if (q->nslots==0)
		{	/* check if rendezvous succeeded, 1 level down */
			fprintf(tc, "\t\t_m = (trpt+1)->o_m;\n");
			fprintf(tc, "\t\tif (_m) (trpt-1)->o_pm |= 1;\n");
			fprintf(tc, "\t\tUnBlock;\n");
		} else
			fprintf(tc, "\t\t_m = trpt->o_m;\n");

		fprintf(tc, "\t\tbreak;\n");
	}
	ntimes(tc, 0, 1, R14);
	for (q = qtab; q; q = q->nxt)
	{	sprintf(buf1, "((Q%d *)z)->contents", q->qid);
		fprintf(tc, "	case %d:\n", q->qid);
		if (q->nslots == 0)
			fprintf(tc, "\t\tif (strt) boq = from+1;\n");
		else if (q->nslots > 1)	/* shift */
		{	fprintf(tc, "\t\tif (strt && slot<%d)\n",
							q->nslots-1);
			fprintf(tc, "\t\t{\tfor (j--; j>=slot; j--)\n");
			fprintf(tc, "\t\t\t{");
			for (i = 0; i < q->nflds; i++)
			{	fprintf(tc, "\t%s[j+1].fld%d =\n\t\t\t",
							buf1, i);
				fprintf(tc, "\t%s[j].fld%d;\n\t\t\t",
							buf1, i);
			}
			fprintf(tc, "}\n\t\t}\n");
		}
		strcat(buf1, "[slot].fld");
		fprintf(tc, "\t\tif (strt) {\n");
		for (i = 0; i < q->nflds; i++)
			fprintf(tc, "\t\t\t%s%d = 0;\n", buf1, i);
		fprintf(tc, "\t\t}\n");
		if (q->nflds == 1)	/* set */
			fprintf(tc, "\t\tif (fld == 0) %s0 = fldvar;\n",
							buf1);
		else
		{	fprintf(tc, "\t\tswitch (fld) {\n");
			for (i = 0; i < q->nflds; i++)
			{	fprintf(tc, "\t\tcase %d:\t%s", i, buf1);
				fprintf(tc, "%d = fldvar; break;\n", i);
			}
			fprintf(tc, "\t\t}\n");
		}
		fprintf(tc, "\t\tbreak;\n");
	}
	ntimes(tc, 0, 1, R15);
}