From af1a5079fd1e8a2e1dfd7180b2e452671176dcc1 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Mon, 30 Nov 2015 11:44:37 -0500 Subject: change the wide bit to a class number --- lisc/Makefile | 3 ++- lisc/lisc.h | 16 +++++++++++++--- lisc/main.c | 4 +++- lisc/parse.c | 54 ++++++++++++++++++++++++++++++------------------------ lisc/util.c | 9 ++++++--- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/lisc/Makefile b/lisc/Makefile index 389e376..fc05701 100644 --- a/lisc/Makefile +++ b/lisc/Makefile @@ -1,5 +1,6 @@ BIN = lisc -OBJ = main.o util.o parse.o ssa.o live.o isel.o spill.o rega.o emit.o +# OBJ = main.o util.o parse.o mem.o ssa.o copy.o live.o isel.o spill.o rega.o emit.o +OBJ = main.o util.o parse.o ssa.o CFLAGS = -Wall -Wextra -std=c99 -g -pedantic diff --git a/lisc/lisc.h b/lisc/lisc.h index 6e0abe5..bebcc7b 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -157,6 +157,13 @@ enum Cmp { CMPS(X) NCmp }; enum Ty { TYS(X) NTy }; #undef X +enum Class { + Kw, + Kl, + Ks, + Kd +}; + enum Op { OXXX, @@ -169,6 +176,8 @@ enum Op { OAnd, OCmp, OCmp1 = OCmp + NCmp-1, + OStored, + OStores, OStorel, OStorew, OStoreh, @@ -223,10 +232,10 @@ struct OpDesc { }; struct Ins { - ushort op:15; - ushort wide:1; + ushort op:14; Ref to; Ref arg[2]; + ushort cls:2; }; struct Phi { @@ -234,7 +243,7 @@ struct Phi { Ref arg[NPred]; Blk *blk[NPred]; uint narg; - uint wide; + int cls; Phi *link; }; @@ -301,6 +310,7 @@ struct Con { CNum, CAddr, } type; + char flt; char label[NString]; int64_t val; }; diff --git a/lisc/main.c b/lisc/main.c index 10de4d6..0689ae8 100644 --- a/lisc/main.c +++ b/lisc/main.c @@ -30,6 +30,7 @@ dumpts(Bits *b, Tmp *tmp, FILE *f) static void data(Dat *d) { +#if 0 if (dbg) return; if (d->type == DEnd) { @@ -37,6 +38,7 @@ data(Dat *d) freeall(); } emitdat(d, stdout); +#endif } static void @@ -59,7 +61,6 @@ func(Fn *fn) filluse(fn); copy(fn); filluse(fn); -#endif isel(fn); filllive(fn); fillcost(fn); @@ -77,6 +78,7 @@ func(Fn *fn) emitfn(fn, stdout); printf("/* end function %s */\n\n", fn->name); } else +#endif fprintf(stderr, "\n"); freeall(); } diff --git a/lisc/parse.c b/lisc/parse.c index 9384b4b..8a67c87 100644 --- a/lisc/parse.c +++ b/lisc/parse.c @@ -9,6 +9,8 @@ OpDesc opdesc[NOp] = { [ORem] = { "rem", 2 }, [OMul] = { "mul", 2 }, [OAnd] = { "and", 2 }, + [OStored] = { "stored", 0 }, + [OStores] = { "stores", 0 }, [OStorel] = { "storel", 0 }, [OStorew] = { "storew", 0 }, [OStoreh] = { "storeh", 0 }, @@ -353,20 +355,24 @@ parsecls(int *tyn) for (i=0; i= NIns) err("too many instructions (1)"); - w = parsecls(&ty); + k = parsecls(&ty); r = parseref(); if (req(r, R)) err("invalid reference argument"); if (!arg && rtype(r) != RTmp) err("invalid function parameter"); - if (w == 2) + if (k == 4) if (arg) - *curi = (Ins){OArgc, 0, R, {TYPE(ty), r}}; + *curi = (Ins){OArgc, R, {TYPE(ty), r}, 0}; else - *curi = (Ins){OParc, 0, r, {TYPE(ty)}}; + *curi = (Ins){OParc, r, {TYPE(ty)}, 0}; else if (arg) - *curi = (Ins){OArg, w, R, {r}}; + *curi = (Ins){OArg, R, {r}, k}; else - *curi = (Ins){OPar, w, r, {R}}; + *curi = (Ins){OPar, r, {R}, k}; curi++; t = next(); if (t == TRParen) @@ -438,17 +444,17 @@ parseline(PState ps) Phi *phi; Ref r; Blk *b; - int t, op, i, w, ty; + int t, op, i, k, ty; t = nextnl(); if (ps == PLbl && t != TLbl && t != TRBrace) err("label or } expected"); switch (t) { default: - if (OStorel <= t && t <= OStoreb) { + if (OStored <= t && t <= OStoreb) { /* operations without result */ r = R; - w = 0; + k = 0; op = t; goto DoOp; } @@ -508,7 +514,7 @@ parseline(PState ps) } r = tmpref(tokval.str); expect(TEq); - w = parsecls(&ty); + k = parsecls(&ty); op = next(); DoOp: if (op == TPhi) { @@ -521,15 +527,15 @@ DoOp: parserefl(1); expect(TNL); op = OCall; - if (w == 2) { - w = 0; + if (k == 4) { + k = 0; arg[1] = TYPE(ty); } else arg[1] = R; goto Ins; } - if (w == 2) - err("size class must be w or l"); + if (k == 4) + err("size class must be w, l, s, or d"); if (op >= NPubOp) err("invalid instruction"); i = 0; @@ -558,7 +564,7 @@ DoOp: if (curi - insb >= NIns) err("too many instructions (2)"); curi->op = op; - curi->wide = w; + curi->cls = k; curi->to = r; curi->arg[0] = arg[0]; curi->arg[1] = arg[1]; @@ -567,7 +573,7 @@ DoOp: } else { phi = alloc(sizeof *phi); phi->to = r; - phi->wide = w; + phi->cls = k; memcpy(phi->arg, arg, i * sizeof arg[0]); memcpy(phi->blk, blk, i * sizeof blk[0]); phi->narg = i; @@ -883,6 +889,7 @@ printfn(Fn *fn, FILE *f) [OXPush] = 1, [OXDiv] = 1, }; + static char ktoc[] = "wlsd"; Blk *b; Phi *p; Ins *i; @@ -894,7 +901,7 @@ printfn(Fn *fn, FILE *f) for (p=b->phi; p; p=p->link) { fprintf(f, "\t"); printref(p->to, fn, f); - fprintf(f, " =%s phi ", p->wide ? "l" : "w"); + fprintf(f, " =%c phi ", ktoc[p->cls]); assert(p->narg); for (n=0;; n++) { fprintf(f, "@%s ", p->blk[n]->name); @@ -910,13 +917,12 @@ printfn(Fn *fn, FILE *f) fprintf(f, "\t"); if (!req(i->to, R)) { printref(i->to, fn, f); - fprintf(f, " ="); - fprintf(f, i->wide ? "l " : "w "); + fprintf(f, " =%c", ktoc[i->cls]); } assert(opdesc[i->op].name); fprintf(f, "%s", opdesc[i->op].name); if (req(i->to, R) && prcls[i->op]) - fprintf(f, i->wide ? "l" : "w"); + fputc(ktoc[i->cls], f); if (!req(i->arg[0], R)) { fprintf(f, " "); printref(i->arg[0], fn, f); diff --git a/lisc/util.c b/lisc/util.c index a45430f..0af81f9 100644 --- a/lisc/util.c +++ b/lisc/util.c @@ -92,17 +92,20 @@ bnew() } void -emit(int op, int w, Ref to, Ref arg0, Ref arg1) +emit(int op, int k, Ref to, Ref arg0, Ref arg1) { if (curi == insb) diag("emit: too many instructions"); - *--curi = (Ins){op, w, to, {arg0, arg1}}; + *--curi = (Ins){ + .op = op, .cls = k, + .to = to, .arg = {arg0, arg1} + }; } void emiti(Ins i) { - emit(i.op, i.wide, i.to, i.arg[0], i.arg[1]); + emit(i.op, i.cls, i.to, i.arg[0], i.arg[1]); } int -- cgit 1.4.1