summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-10-04 11:41:48 -0400
committerOri Bernstein <ori@eigenstate.org>2014-10-04 11:41:48 -0400
commita8359030735219db18bc48b4e481c67ad6e48484 (patch)
tree7d6b4ada31d2b0d14257af6a9d864bd319d0f49d /6
parent6f62df231794edb17630f9f07ffaffe569072f13 (diff)
downloadmc-a8359030735219db18bc48b4e481c67ad6e48484.tar.gz
Start work of porting to Plan 9.
We're missing getopt, but everything else seems to work as far as compiling goes. Remaining work: - Converting assembly syntax - Invoking plan9 executables correctly
Diffstat (limited to '6')
-rw-r--r--6/insns.def68
-rw-r--r--6/isel.c8
-rw-r--r--6/locs.c2
-rw-r--r--6/main.c16
-rw-r--r--6/ra.c20
-rw-r--r--6/simp.c4
6 files changed, 64 insertions, 54 deletions
diff --git a/6/insns.def b/6/insns.def
index a04f0e3..6e9aeda 100644
--- a/6/insns.def
+++ b/6/insns.def
@@ -18,17 +18,17 @@
For technical reasons, the indexing on use and def statments is 1-based,
instead of 0-based. (0 is the sentinel value).
*/
-
-Insn(Inone, "BAD_INSN", Use(), Def())
+#define None .l={0},.r={0}
+Insn(Inone, "BAD_INSN", Use(None), Def(None))
/* Note, the mov instruction is specified in an overly general manner. */
Insn(Imov, "\tmov%t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Imovt, "PSEUDO: TRUNCATE\n", Use(.l={1}), Def(.l={2}))
Insn(Imovzx, "\tmovz%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Imovsx, "\tmovs%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
-Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
+Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
Insn(Ilea, "\tlea%2t %m,%r\n", Use(.l={1}), Def(.l={2}))
Insn(Iadd, "\tadd%t %x,%r\n", Use(.l={1,2}), Def(.l={2}))
@@ -47,23 +47,23 @@ Insn(Ishl, "\tsal%2t %u,%r\n", Use(.l={1,2}),
Insn(Isar, "\tsar%2t %u,%r\n", Use(.l={1,2}), Def(.l={2}))
Insn(Ishr, "\tshr%2t %u,%r\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(.l={}))
-Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(.l={}))
+Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(None))
+Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(None))
-Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def())
-Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def())
+Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def(None))
+Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def(None))
/* branch instructions */
-Insn(Isetz, "\tsetz %v\n", Use(), Def(.l={1}))
-Insn(Isetnz, "\tsetnz %v\n", Use(), Def(.l={1}))
-Insn(Isetl, "\tsetl %v\n", Use(), Def(.l={1}))
-Insn(Isetle, "\tsetle %v\n", Use(), Def(.l={1}))
-Insn(Isetg, "\tsetg %v\n", Use(), Def(.l={1}))
-Insn(Isetge, "\tsetge %v\n", Use(), Def(.l={1}))
-Insn(Isetb, "\tsetb %v\n", Use(), Def(.l={1}))
-Insn(Isetbe, "\tsetbe %v\n", Use(), Def(.l={1}))
-Insn(Iseta, "\tseta %v\n", Use(), Def(.l={1}))
-Insn(Isetae, "\tsetae %v\n", Use(), Def(.l={1}))
+Insn(Isetz, "\tsetz %v\n", Use(None), Def(.l={1}))
+Insn(Isetnz, "\tsetnz %v\n", Use(None), Def(.l={1}))
+Insn(Isetl, "\tsetl %v\n", Use(None), Def(.l={1}))
+Insn(Isetle, "\tsetle %v\n", Use(None), Def(.l={1}))
+Insn(Isetg, "\tsetg %v\n", Use(None), Def(.l={1}))
+Insn(Isetge, "\tsetge %v\n", Use(None), Def(.l={1}))
+Insn(Isetb, "\tsetb %v\n", Use(None), Def(.l={1}))
+Insn(Isetbe, "\tsetbe %v\n", Use(None), Def(.l={1}))
+Insn(Iseta, "\tseta %v\n", Use(None), Def(.l={1}))
+Insn(Isetae, "\tsetae %v\n", Use(None), Def(.l={1}))
/* fp specific instructions */
Insn(Imovs, "\tmovs%1t %x,%x\n", Use(.l={1}), Def(.l={2}))
@@ -75,24 +75,24 @@ Insn(Iadds, "\tadds%t %x,%f\n", Use(.l={1,2}),
Insn(Isubs, "\tsubs%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Imuls, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Idivs, "\tdivs%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def())
+Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def(None))
Insn(Ixorp, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
/* branch instructions */
Insn(Icall, "\tcall %v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah}))
Insn(Icallind, "\tcall *%v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah}))
-Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def())
-Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def())
-Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def())
-Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def())
-Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def())
-Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def())
-Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def())
-Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def())
-Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def())
-Insn(Ija, "\tja %v\n", Use(.l={1}), Def())
-Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def())
-Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def())
+Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def(None))
+Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def(None))
+Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def(None))
+Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def(None))
+Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def(None))
+Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def(None))
+Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def(None))
+Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def(None))
+Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def(None))
+Insn(Ija, "\tja %v\n", Use(.l={1}), Def(None))
+Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def(None))
+Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def(None))
/* not really an insn... */
-Insn(Ilbl, "%v:\n", Use(), Def())
+Insn(Ilbl, "%v:\n", Use(None), Def(None))
diff --git a/6/isel.c b/6/isel.c
index adc89df..bf0623c 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <inttypes.h>
#include <ctype.h>
@@ -1067,10 +1067,10 @@ static size_t writelit(FILE *fd, Htab *strtab, Node *v, Type *ty)
case Lflt:
if (tybase(v->lit.type)->type == Tyflt32) {
u.fv = v->lit.fltval;
- fprintf(fd, "\t.long 0x%"PRIx32"\n", u.lv);
+ fprintf(fd, "\t.long 0x%" PRIx32 "\n", u.lv);
} else if (tybase(v->lit.type)->type == Tyflt64) {
u.dv = v->lit.fltval;
- fprintf(fd, "\t.quad 0x%"PRIx64"\n", u.qv);
+ fprintf(fd, "\t.quad 0x%" PRIx64 "\n", u.qv);
}
break;
case Lstr:
@@ -1240,7 +1240,7 @@ void genasm(FILE *fd, Func *fn, Htab *globls, Htab *strtab)
is.curbb = is.bb[j];
for (i = 0; i < fn->cfg->bb[j]->nnl; i++) {
/* put in a comment that says where this line comes from */
- snprintf(buf, sizeof buf, "\n\t# bb = %zd, bbidx = %zd, %s:%d",
+ snprintf(buf, sizeof buf, "\n\t# bb = %ld, bbidx = %ld, %s:%d",
j, i, file->file.name, fn->cfg->bb[j]->nl[i]->line);
g(&is, Ilbl, locstrlbl(buf), NULL);
isel(&is, fn->cfg->bb[j]->nl[i]);
diff --git a/6/locs.c b/6/locs.c
index 1f45c39..f4b1ef2 100644
--- a/6/locs.c
+++ b/6/locs.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
diff --git a/6/main.c b/6/main.c
index 9aafd25..c453dd7 100644
--- a/6/main.c
+++ b/6/main.c
@@ -1,12 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
-#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -70,7 +69,8 @@ static void assem(char *asmsrc, char *path)
if (pid == -1) {
die("couldn't fork");
} else if (pid == 0) {
- execvp(cmd[0], cmd);
+ if (execvp(cmd[0], cmd) == -1)
+ die("Couldn't exec assembler\n");
} else {
waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
@@ -93,8 +93,8 @@ static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix)
else
base = path;
gettimeofday(&tv, NULL);
- srandom(tv.tv_usec);
- snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, random(), (long)tv.tv_usec, base, suffix);
+ srand(tv.tv_usec);
+ snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, (long)rand(), (long)tv.tv_usec, base, suffix);
return buf;
}
@@ -110,8 +110,10 @@ static void genuse(char *path)
else
swapsuffix(buf, 1024, path, ".myr", ".use");
f = fopen(buf, "w");
- if (!f)
- err(1, "Could not open path %s\n", buf);
+ if (!f) {
+ fprintf(stderr, "Could not open path %s\n", buf);
+ exit(1);
+ }
writeuse(f, file);
fclose(f);
}
diff --git a/6/ra.c b/6/ra.c
index 5268a12..214b751 100644
--- a/6/ra.c
+++ b/6/ra.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <assert.h>
#include <limits.h>
@@ -24,19 +24,23 @@ static void printedge(FILE *fd, char *msg, size_t a, size_t b);
/* tables of uses/defs by instruction */
Usemap usetab[] = {
+#define Def(...)
#define Use(...) {__VA_ARGS__}
#define Insn(i, fmt, use, def) use,
#include "insns.def"
#undef Insn
#undef Use
+#undef Def
};
Usemap deftab[] = {
+#define Use(...)
#define Def(...) {__VA_ARGS__}
#define Insn(i, fmt, use, def) def,
#include "insns.def"
#undef Insn
#undef Def
+#undef Use
};
/* A map of which registers interfere */
@@ -618,15 +622,17 @@ static void decdegree(Isel *s, regid m)
if (found)
wldel(s, &s->wlspill, &s->nwlspill, idx);
if (moverelated(s, m)) {
- if (!found)
- assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx));
- else
+ if (!found) {
+ assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx) != 0);
+ } else {
wlput(&s->wlfreeze, &s->nwlfreeze, locmap[m]);
+ }
} else {
- if (!found)
+ if (!found) {
assert(wlfind(s->wlsimp, s->nwlsimp, m, &idx));
- else
+ } else {
wlput(&s->wlsimp, &s->nwlsimp, locmap[m]);
+ }
}
}
}
@@ -916,7 +922,7 @@ static int paint(Isel *s)
spilled = 0;
while (s->nselstk) {
- bzero(taken, Nreg*sizeof(int));
+ memset(taken, 0, Nreg*sizeof(int));
n = lpop(&s->selstk, &s->nselstk);
for (j = 0; j < s->ngadj[n->reg.id];j++) {
diff --git a/6/simp.c b/6/simp.c
index 95df2b5..82ad832 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
@@ -1289,6 +1289,7 @@ static Node *simpucon(Simp *s, Node *n, Node *dst)
static Node *simpuget(Simp *s, Node *n, Node *dst)
{
die("No uget simplification yet");
+ return NULL;
}
/* simplifies
@@ -1338,6 +1339,7 @@ static Node *simplazy(Simp *s, Node *n)
static Node *comparecomplex(Simp *s, Node *n, Op op)
{
fatal(n->line, "Complex comparisons not yet supported\n");
+ return NULL;
}
static Node *compare(Simp *s, Node *n, int fields)