Ejemplo n.º 1
0
Archivo: pmov.c Proyecto: 8l/qbe
int
main()
{
	Ins *i1;
	unsigned long long tm, rm, cnt;
	RMap mend;
	int reg[NIReg], val[NIReg+1];
	int t, i, r, nr;

	tmp = (Tmp[Tmp0+NIReg]){{{0}}};
	for (t=0; t<Tmp0+NIReg; t++)
		if (t >= Tmp0) {
			tmp[t].cls = Kw;
			tmp[t].hint.r = -1;
			tmp[t].hint.m = 0;
			tmp[t].slot = -1;
			sprintf(tmp[t].name, "tmp%d", t-Tmp0+1);
		}

	bsinit_(mbeg.b, Tmp0+NIReg);
	bsinit_(mend.b, Tmp0+NIReg);
	cnt = 0;
	for (tm = 0; tm < 1ull << (2*NIReg); tm++) {
		mbeg.n = 0;
		bszero(mbeg.b);
		ip = ins;

		/* find what temporaries are in copy and
		 * wether or not they are in register
		 */
		for (t=0; t<NIReg; t++)
			switch ((tm >> (2*t)) & 3) {
			case 0:
				/* not in copy, not in reg */
				break;
			case 1:
				/* not in copy, in reg */
				radd(&mbeg, Tmp0+t, t+1);
				break;
			case 2:
				/* in copy, not in reg */
				*ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}, Kw};
				break;
			case 3:
				/* in copy, in reg */
				*ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}, Kw};
				radd(&mbeg, Tmp0+t, t+1);
				break;
			}

		if (ip == ins)
			/* cancel if the parallel move
			 * is empty
			 */
			goto Nxt;

		/* find registers for temporaries
		 * in mbeg
		 */
		nr = ip - ins;
		rm = (1ull << (nr+1)) - 1;
		for (i=0; i<nr; i++)
			reg[i] = i+1;

		for (;;) {
			/* set registers on copies
			 */
			for (i=0, i1=ins; i1<ip; i1++, i++)
				i1->arg[0] = TMP(reg[i]);

			/* compile the parallel move
			 */
			rcopy(&mend, &mbeg);
			dopm(&dummyb, ip-1, &mend);
			cnt++;

			/* check that mend contain mappings for
			 * source registers and does not map any
			 * assigned temporary, then check that
			 * all temporaries in mend are mapped in
			 * mbeg and not used in the copy
			 */
			for (i1=ins; i1<ip; i1++) {
				r = i1->arg[0].val;
				assert(rfree(&mend, r) == r);
				t = i1->to.val;
				assert(!bshas(mend.b, t));
			}
			for (i=0; i<mend.n; i++) {
				t = mend.t[i];
				assert(bshas(mbeg.b, t));
				t -= Tmp0;
				assert(((tm >> (2*t)) & 3) == 1);
			}

			/* execute the code generated and check
			 * that all assigned temporaries got their
			 * value, and that all live variables's
			 * content got preserved
			 */
			 for (i=1; i<=NIReg; i++)
			 	val[i] = i;
			 iexec(val);
			 for (i1=ins; i1<ip; i1++) {
			 	t = i1->to.val;
			 	r = rfind(&mbeg, t);
			 	if (r != -1)
			 		assert(val[r] == i1->arg[0].val);
			 }
			 for (i=0; i<mend.n; i++) {
			 	t = mend.t[i];
			 	r = mend.r[i];
			 	assert(val[t-Tmp0+1] == r);
			 }

			/* find the next register assignment */
			i = nr - 1;
			for (;;) {
				r = reg[i];
				rm &= ~(1ull<<r);
				do
					r++;
				while (r <= NIReg && (rm & (1ull<<r)));
				if (r == NIReg+1) {
					if (i == 0)
						goto Nxt;
					i--;
				} else {
					rm |= (1ull<<r);
					reg[i++] = r;
					break;
				}
			}
			for (; i<nr; i++)
				for (r=1; r<=NIReg; r++)
					if (!(rm & (1ull<<r))) {
						rm |= (1ull<<r);
						reg[i] = r;
						break;
					}
		}
	Nxt:	freeall();
	}
	printf("%llu tests successful!\n", cnt);
	exit(0);
}
Ejemplo n.º 2
0
int main() {
  char lstr[8][64];
  char buffer[80];
  char verb[80];
  char wd[512];
  int len;
  int prog;
  int selected_sbuffer = 0;

  while (1) {
    iwrites("wsh-");
    fgetwd(wd);
    iwrites(wd);
    iwrites("> ");
    ireads(buffer, 80);
    len = sfindc(buffer, ' ');
    if (len < 0)
      len = slength(buffer);
    scopy(verb, buffer, len);
    if (!scompare(verb, "help")) {
      iwrites("\ncat: print file contents\ncd: change directories\necho: print a string\nhelp: display this message\nls: list files\npwd: print current working directory\nloads: load a string to be used with all commands which act upon strings\nprintf: write to a pre-existing file\nprints: print the currently loaded string\nrms: unload the currently loaded string\ncons: concatenate a string to the end of the currently loaded string\nloadfs: load the contents of a file into the String Buffer\nchsf: switch to the next String Buffer\nchsb: switch to the previous String Buffer\npsb: print the currently selected String Buffer\nreboot: reboot the operating system\n\n");
    }
    else if (!scompare(verb, "ls")) {
      ls();
    }
    else if (!scompare(verb, "cd")) {
      cd(buffer + len + 1);
    }
    else if (!scompare(verb, "cat")) {
      /* Mrew? */
      cat(buffer + len + 1);
    }
    else if  (!scompare(verb, "echo")){
      echo(buffer + len + 1);
    }
    else if  (!scompare(verb, "pwd")){
      pwd();
    }
    else if (!scompare(verb, "reboot")) {
      ireboot();
    }
    else if (!scompare(verb, "printf")) {
      printf(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "loads")) {
      loads(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "prints")) {
      iwrites(lstr[selected_sbuffer]);
      iwrites("\n");
    }
    else if (!scompare(verb, "rms")) {
      scopy(lstr[selected_sbuffer], "\0", 1);
    }
    else if (!scompare(verb, "loadfs")) {
      loadfs(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "cons")) {
      cons(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "chsf")) {
      selected_sbuffer = chsf(selected_sbuffer);
    }
    else if (!scompare(verb, "psb")) {
      psb(selected_sbuffer);
    }
    else if (!scompare(verb, "chsb")) {
      selected_sbuffer = chsb(selected_sbuffer);
    }
    /*
    else if (!scompare(verb, "mk")) {
      mk(buffer + len + 1);
    }
    */
    else if (sfindc(verb, '/') == -1) {
      prog = fget("/bin/");
      if (!prog) {
        iwrites("Error: unable to locate bin directory\n");
        continue;
      }
      prog = ffind(prog, verb);
      if (!prog) {
        iwrites("Error: unrecognized command \"");
        iwrites(verb);
        iwrites("\"\n");
        continue;
      }
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else if (prog = fget(verb)) {
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else {
      iwrites("Error: executable not found\n");
      continue;
    }
  }
}