From 1d8d8de4e8b7c7aaa11265a068f4061f2546b9ea Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Sun, 19 Feb 2017 16:18:06 +1100 Subject: [PATCH] Replace getype()/getail() stuff with a modified version of the original getype() which constructs the type as a linked list, keeping track of the tail so that it can build onto the inner type as things are parsed, this fixes a bug where (*name)() was interpreted as FUNC,PTR rather than PTR,FUNC, and makes arrays easier --- c0.h | 3 +- c03.c | 300 +++++++++++++++------------------- test/{arr0.c => arr0.i} | 0 test/{arr0.dump => arr0.ir} | 0 test/{arr1.c => arr1.i} | 0 test/{arr1.dump => arr1.ir} | 0 test/{arr2.c => arr2.i} | 0 test/{arr2.dump => arr2.ir} | 0 test/{enu0.c => enu0.i} | 0 test/{enu0.dump => enu0.ir} | 0 test/{enu1.c => enu1.i} | 0 test/{enu1.dump => enu1.ir} | 0 test/{fld0.c => fld0.i} | 0 test/{fld0.dump => fld0.ir} | 0 test/{fld1.c => fld1.i} | 0 test/{fld1.dump => fld1.ir} | 0 test/{fld2.c => fld2.i} | 0 test/{fld2.dump => fld2.ir} | 0 test/fun0.i | 10 ++ test/fun0.ir | 42 +++++ test/fun0.s | 25 +++ test/{hello.dump => hello.ir} | 0 test/n.sh | 8 +- test/{str0.c => str0.i} | 0 test/{str0.dump => str0.ir} | 0 test/{str1.c => str1.i} | 0 test/{str1.dump => str1.ir} | 0 27 files changed, 215 insertions(+), 173 deletions(-) rename test/{arr0.c => arr0.i} (100%) rename test/{arr0.dump => arr0.ir} (100%) rename test/{arr1.c => arr1.i} (100%) rename test/{arr1.dump => arr1.ir} (100%) rename test/{arr2.c => arr2.i} (100%) rename test/{arr2.dump => arr2.ir} (100%) rename test/{enu0.c => enu0.i} (100%) rename test/{enu0.dump => enu0.ir} (100%) rename test/{enu1.c => enu1.i} (100%) rename test/{enu1.dump => enu1.ir} (100%) rename test/{fld0.c => fld0.i} (100%) rename test/{fld0.dump => fld0.ir} (100%) rename test/{fld1.c => fld1.i} (100%) rename test/{fld1.dump => fld1.ir} (100%) rename test/{fld2.c => fld2.i} (100%) rename test/{fld2.dump => fld2.ir} (100%) create mode 100644 test/fun0.i create mode 100644 test/fun0.ir create mode 100644 test/fun0.s rename test/{hello.dump => hello.ir} (100%) rename test/{str0.c => str0.i} (100%) rename test/{str0.dump => str0.ir} (100%) rename test/{str1.c => str1.i} (100%) rename test/{str1.dump => str1.ir} (100%) diff --git a/c0.h b/c0.h index 15f263f..2d290b6 100644 --- a/c0.h +++ b/c0.h @@ -253,11 +253,12 @@ int declist __P((int sclass)); /*int*/struct type *getkeywords __P((int *scptr/*, struct nmlist *tptr*/)); /*union str*/struct stype *strdec __P((int mosf, int kind)); int declare __P((int askw, struct /*nmlist*/type *tptr, int offset)); +void XXXdumptype __P((struct type *dtype)); int XXXoldtype __P((struct type *dtype, struct tdim *dimp, struct SS **strp)); int decl1 __P((int askw, struct /*nmlist*/type *atptr, int offset, struct nmlist *absname)); struct nmlist *pushdecl __P((register struct nmlist *sp)); /*int getype __P((register struct tdim *dimp, struct nmlist *absname));*/ -struct type *getype __P((struct type *tptr, int *nullok, int anonok)); +struct rtype *getype __P((struct rtype *tail, int anonok)); void typov __P((void)); int align __P((/*int*/struct type *type, int offset, int aflen)); void decsyn __P((int o)); diff --git a/c03.c b/c03.c index ca50a04..bdd67b7 100644 --- a/c03.c +++ b/c03.c @@ -351,11 +351,43 @@ int declare(askw, tptr, offset) int askw; struct /*nmlist*/type *tptr; int offse * Process a single declarator */ /* convert detailed type description to old type description */ +void XXXdumptype(dtype) struct type *dtype; { + static char *basic_types[] = { + "INT", + "CHAR", + "FLOAT", + "DOUBLE", + "STRUCT", + "RSTRUCT", + "LONG", + "UNSIGN", + "UNCHAR", + "UNLONG", + "VOID", + "REF", + "BITFLD" + }; + switch (dtype->t_id) { + case REF | PTR: + fprintf(stderr, "PTR,"); + goto reftype; + case REF | FUNC: + fprintf(stderr, "FUNC,"); + goto reftype; + case REF | ARRAY: + fprintf(stderr, "ARRAY(%d),", ((struct atype *)dtype)->at_nelt); + reftype: + XXXdumptype(((struct rtype *)dtype)->rt_reftype); + break; + default: + fprintf(stderr, "%s", basic_types[dtype->t_id]); + break; + } +} int XXXoldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct SS **strp; { int type; switch (dtype->t_id) { case REF | PTR: - /*fprintf(stderr, "ptr(");*/ type = XXXoldtype(((struct rtype *)dtype)->rt_reftype, dimp, strp); if (type & BIGTYPE) { typov(); @@ -364,7 +396,6 @@ int XXXoldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct type = (type & TYPE) | (type & ~TYPE) << TYLEN | PTR; break; case REF | FUNC: - /*fprintf(stderr, "func(");*/ type = XXXoldtype(((struct ftype *)dtype)->ft_reftype, dimp, strp); if (type & BIGTYPE) { typov(); @@ -373,7 +404,6 @@ int XXXoldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct type = (type & TYPE) | (type & ~TYPE) << TYLEN | FUNC; break; case REF | ARRAY: - /*fprintf(stderr, "array(%d, ", ((struct atype *)dtype)->at_nelt);*/ if (dimp->rank>=5) { error0("Rank too large"); dimp->rank = 4; @@ -387,38 +417,34 @@ int XXXoldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct type = (type & TYPE) | (type & ~TYPE) << TYLEN | ARRAY; break; case STRUCT: - /*fprintf(stderr, "struct(%d", dtype->t_id);*/ *strp = &((struct stype *)dtype)->st_S; - goto got_strp; + type = STRUCT; + break; case BITFLD: - /*fprintf(stderr, "bitfld(%d", dtype->t_id);*/ *strp = NULL; type = UNSIGN; break; default: - /*fprintf(stderr, "basic(%d", dtype->t_id);*/ *strp = NULL; - got_strp: type = dtype->t_id; break; } - /*fprintf(stderr, ")", type);*/ return type; } int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; int offset; struct nmlist *absname; { int t1, a, elsize; register int skw; - struct type *dtype, *dt, *dt1; + struct rtype rtype, *tail; /* int type;*/ register struct nmlist *dsym; - register struct /*nmlist*/type *tptr; - /* struct tdim dim;*/ + /* register struct nmlist *tptr; + struct tdim dim;*/ /*struct SS *strp; int *dp;*/ int isinit; skw = askw; - tptr = atptr; + /* tptr = atptr;*/ mosflg = skw==MOS? FMOS: 0; /* dim.rank = 0;*/ if (((peeksym=symbol())==SEMI || peeksym==RPARN) && absname==NULL) @@ -433,15 +459,23 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; error0("Negative field width"); t1 = 0; } - elsize = align(tptr/*->nl_type*/, offset, t1); + elsize = align(/*tptr->nl_type*/atptr, offset, t1); bitoffs += t1; return(elsize); } /* t1 = getype(&dim, absname); if (t1 == -1) return(0);*/ - a = 1; /* nullok */ - dtype = getype(tptr, &a, absname != NULL); + /* we will construct a type which looks like a pointer to the real type, */ + /* this is so that getype() can check the enclosing type, if REF | ARRAY */ + /* then dimension must be specified, e.g. a[][10] is OK, but a[][] is not */ + rtype.rt_id = REF | PTR; + tail = getype(&rtype, absname!=NULL); + if (tail) + tail->rt_reftype = atptr; /* otherwise, had error and set tail to int */ + /*fprintf(stderr, "name %s type ", defsym ? defsym->nl_name : absname ? absname->nl_name : "???"); + XXXdumptype(rtype.rt_reftype); + fprintf(stderr, "\n");*/ if (defsym) absname = NULL; /* if (tptr->nl_subsp) { @@ -462,7 +496,7 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; t1 >>= TYLEN; } type |= tptr->nl_type&TYPE;*/ - if (/*(type&XTYPE) == FUNC*/dtype->t_id == (REF | FUNC)) { + if (/*(type&XTYPE) == FUNC*/rtype.rt_reftype->t_id == (REF | FUNC)) { if (skw==AUTO) skw = EXTERN; if ((skw!=EXTERN && skw!=TYPEDEF) && absname==NULL) @@ -538,19 +572,16 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; if (tptr->nl_strp) dsym->nl_strp = tptr->nl_strp;*/ /* new way */ - if ((skw==ARG||skw==AREG) && dsym->nl_class==ARG1) - /* got type for previously declared K&R function argument */ - /* just clobber the type, no type compatibility check needed */ - dsym->nl_dtype = dtype; - else if (skw==EXTERN && dsym->nl_class==EXTERN) { + if (skw==EXTERN && dsym->nl_class==EXTERN) { /* got redeclaration of previously declared extern symbol */ /* compare types, picking up any new dimension information */ + struct type *dt, *dt1; for ( - dt = dtype, dt1 = dsym->nl_dtype; + dt = rtype.rt_reftype, dt1 = dsym->nl_dtype; (t1 = dt->t_id) == dt1->t_id; dt=((struct rtype *)dt)->rt_reftype, dt1=((struct rtype *)dt1)->rt_reftype ) - switch (t1 & TYPE) { + switch (t1) { case REF | PTR: case FUNC | PTR: break; @@ -573,16 +604,18 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; } redec(); done: - dtype = dsym->nl_dtype; + ; } - else if (dsym->nl_class) { + else if (dsym->nl_class==0 || (skw==ARG||skw==AREG) && dsym->nl_class==ARG1) + /* new declaration, or real declaration of K&R function argument */ + /* just clobber the type, no type compatibility check needed */ + dsym->nl_dtype = rtype.rt_reftype; + else { redec(); goto syntax; } - else - dsym->nl_dtype = dtype; /*dim.rank = 0; - dsym->nl_type = XXXoldtype(dtype, &dim, (struct SS **)&dsym->nl_strp); + dsym->nl_type = XXXoldtype(dsym->nl_dtype, &dim, (struct SS **)&dsym->nl_strp); if (dim.rank && dsym->nl_subsp == 0) dsym->nl_subsp = (int *)Dblock(dim.rank*sizeof(dim.rank)); for (a=0; anl_name);*/ - elsize = length(/*(struct node *)dsym*/dtype); + elsize = length(/*(struct node *)dsym*/dsym->nl_dtype); if ((peeksym = symbol())==COLON) { elsize = 0; peeksym = -1; t1 = conexp(); - a = align(/*type*/dtype, offset, t1); + a = align(/*type*/dsym->nl_dtype, offset, t1); /*fprintf(stderr, "a bitfield strp %p\n", dsym->nl_strp);*/ - if (/*dsym->nl_flag&FFIELD*/dtype->t_id == BITFLD) { -#define bdtype ((struct btype *)dtype) - if (/*dsym->nl_strp->F.bitoffs*/bdtype->bt_bitoffs!=bitoffs - || /*dsym->nl_strp->F.flen*/bdtype->bt_flen!=t1) + if (dsym->/*nl_flag&FFIELD*/nl_dtype->t_id == BITFLD) { + if (/*dsym->nl_strp->F.bitoffs*/((struct btype *)dsym->nl_dtype)->bt_bitoffs!=bitoffs + || /*dsym->nl_strp->F.flen*/((struct btype *)dsym->nl_dtype)->bt_flen!=t1) redec(); -#undef bdtype } else { /* dsym->nl_strp = (union str *)Dblock(sizeof(struct FS));*/ -#define bdtype (*(struct btype **)&dtype) - bdtype = (struct btype *)Dblock(sizeof(struct btype)); - bdtype->bt_id = BITFLD; - bdtype->bt_flen = t1; - bdtype->bt_bitoffs = bitoffs; - /*dsym->nl_strp = (union str *)&bdtype->bt_F;*/ - dsym->nl_dtype = (struct type *)bdtype; -#undef bdtype + struct btype *btp = (struct btype *)Dblock(sizeof(struct btype)); + btp->bt_id = BITFLD; + btp->bt_flen = t1; + btp->bt_bitoffs = bitoffs; + /*dsym->nl_strp = (union str *)&btp->bt_F;*/ + dsym->nl_dtype = (struct type *)btp; } /*fprintf(stderr, "b bitfield strp %p\n", dsym->nl_strp);*/ /* dsym->nl_flag |= FFIELD; @@ -633,7 +662,7 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; dsym->nl_strp->F.flen = t1;*/ bitoffs += t1; } else - a = align(/*type*/dtype, offset, 0); + a = align(/*type*/dsym->nl_dtype, offset, 0); elsize += a; offset += a; if (++nmems >= NMEMS) { @@ -659,14 +688,14 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; if (skw==AUTO) { /* if (STAUTO < 0) { */ /*fprintf(stderr, "%s autolen %d -> ", dsym->nl_name, autolen);*/ - autolen -= rlength(/*(struct node *)dsym*/dtype); + autolen -= rlength(/*(struct node *)dsym*/dsym->nl_dtype); dsym->nl_offset = autolen; if (autolen < maxauto) maxauto = autolen; /*fprintf(stderr, "%d maxauto %d\n", autolen, maxauto);*/ /* } else { */ /* dsym->nl_offset = autolen; */ - /* autolen += rlength(*//*(struct node *)dsym*//*dtype); */ + /* autolen += rlength(*//*(struct node *)dsym*//*dsym->nl_dtype); */ /* if (autolen > maxauto) */ /* maxauto = autolen; */ /* } */ @@ -681,14 +710,14 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr; outcode("B", EVEN); } else outcode("BBNBN", BSS, LABEL, isn0++, SSPACE, - rlength(/*(struct node *)dsym*/dtype)); + rlength(/*(struct node *)dsym*/dsym->nl_dtype)); outcode("B", PROG); isinit = 0; } else if (skw==REG && isinit) { cinit(dsym, 0, REG); isinit = 0; } else if (skw==ENUM) { - if (/*type*/dtype->t_id!=INT) + if (/*type*/dsym->nl_dtype->t_id!=INT) error0("Illegal enumeration %s", dsym->nl_name); dsym->nl_class = ENUMCON; dsym->nl_offset = offset; @@ -732,31 +761,43 @@ struct nmlist *pushdecl(sp) register struct nmlist *sp; { /* * Read a declarator and get the implied type */ -/*int getype(dimp, absname) register struct tdim *dimp; struct nmlist *absname; { - static struct nmlist argtype; - int type; +/*int getype(dimp, absname) register struct tdim *dimp; struct nmlist *absname;*/ struct rtype *getype(tail, anonok) struct rtype *tail; int anonok; { + /* static struct nmlist argtype;*/ + static struct type t_int = {INT}; + /* int type;*/ + struct rtype *newtail; register int o; register struct nmlist *ds; defsym = 0; - type = 0; + /* type = 0;*/ switch(o=symbol()) { case TIMES: - type = getype(dimp, absname); + /* type = getype(dimp, absname); if (type==-1) - return(type); - if (type&BIGTYPE) { + return(type);*/ + tail = getype(tail, anonok); + if (tail==NULL) + return(NULL); + /* if (type&BIGTYPE) { typov(); type = 0; } - return(type<rt_id = REF | PTR; + tail->rt_reftype = (struct type *)newtail; + return newtail; case LPARN: - if (absname==NULL || nextchar()!=')') { - type = getype(dimp, absname); + if (/*absname==NULL*/!anonok || nextchar()!=')') { + /* type = getype(dimp, absname); if (type==-1) - return(type); + return(type);*/ + tail = getype(tail, anonok); + if (tail==NULL) + return(NULL); if ((o=symbol()) != RPARN) goto syntax; goto getf; @@ -764,12 +805,12 @@ struct nmlist *pushdecl(sp) register struct nmlist *sp; { default: peeksym = o; - if (absname) + if (/*absname*/anonok) goto getf; break; case NAME: - defsym = ds = csym; + defsym = /*ds =*/ csym; getf: switch(o=symbol()) { @@ -777,24 +818,31 @@ struct nmlist *pushdecl(sp) register struct nmlist *sp; { if (blklev==0) { blklev++; ds = defsym; - declare(ARG1, &argtype, 0); + declare(ARG1, &/*argtype*/t_int, 0); defsym = ds; blklev--; } else if ((o=symbol()) != RPARN) goto syntax; - if (type&BIGTYPE) { + /* if (type&BIGTYPE) { typov(); type = 0; } - type = type<ft_id = REF | FUNC; + fnewtail->ft_arglist = NULL; + tail->rt_reftype = (struct type *)fnewtail; + tail = (struct rtype *)fnewtail; +#undef fnewtail goto getf; case LBRACK: - if (dimp->rank>=5) { + /* if (dimp->rank>=5) { error0("Rank too large"); dimp->rank = 4; - } + }*/ if ((o=symbol()) != RBRACK) { peeksym = o; ds = defsym; @@ -803,121 +851,35 @@ struct nmlist *pushdecl(sp) register struct nmlist *sp; { if ((o=symbol())!=RBRACK) goto syntax; } else { - if (dimp->rank!=0) + /* if (dimp->rank!=0)*/ + if (tail->rt_id == (REF | ARRAY)) error0("Null dimension"); cval = 0; } - dimp->dimens[dimp->rank++] = cval; + /* dimp->dimens[dimp->rank++] = cval; if (type&BIGTYPE) { typov(); type = 0; } - type = type<ft_id = REF | FUNC; - ft->ft_arglist = NULL; - goto gett; -#undef ft - - case LBRACK: - if ((o=symbol()) != RBRACK) { - peeksym = o; - ds = defsym; - cval = conexp(); - defsym = ds; - if ((o=symbol())!=RBRACK) - goto syntax; - } else { - /* note: this was (and remains) incorrect, as fooled by complicated types */ - if (!*nullok) - error0("Null dimension"); - cval = 0; - } - *nullok = 0; -#define at (*(struct atype **)&rt) - at = (struct atype *)Dblock(sizeof(struct atype)); - at->at_id = REF | ARRAY; - at->at_nelt = cval; -#undef at - gett: - rt->rt_reftype = getail(dtype, nullok); - return (struct type *)rt; - - default: - peeksym = o; - return(dtype); - } -syntax: - decsyn(o); - return(NULL); -} -struct type *getype(dtype, nullok, anonok) struct type *dtype; int *nullok; int anonok; { - struct rtype *rt; - register int o; - - defsym = 0; -getp: - switch(o=symbol()) { - - case TIMES: - rt = (struct rtype *)Dblock(sizeof(struct rtype)); - rt->rt_id = REF | PTR; - rt->rt_reftype = dtype; - dtype = (struct type *)rt; - goto getp; - - case LPARN: - if (!anonok || nextchar()!=')') { - dtype = getype(dtype, nullok, anonok); - if (dtype==NULL) - return(NULL); - if ((o=symbol()) != RPARN) - goto syntax; + type = type<at_id = REF | ARRAY; + anewtail->at_nelt = cval; + tail->rt_reftype = (struct type *)anewtail; + tail = (struct rtype *)anewtail; +#undef anewtail goto getf; } - - default: peeksym = o; - if (anonok) - goto getf; - break; - - case NAME: - defsym = csym; - getf: - return getail(dtype, nullok); + /* return(type);*/ + return(tail); } syntax: decsyn(o); - return(NULL); + /* return(-1);*/ + tail->rt_reftype = &t_int; + return(NULL); } /* diff --git a/test/arr0.c b/test/arr0.i similarity index 100% rename from test/arr0.c rename to test/arr0.i diff --git a/test/arr0.dump b/test/arr0.ir similarity index 100% rename from test/arr0.dump rename to test/arr0.ir diff --git a/test/arr1.c b/test/arr1.i similarity index 100% rename from test/arr1.c rename to test/arr1.i diff --git a/test/arr1.dump b/test/arr1.ir similarity index 100% rename from test/arr1.dump rename to test/arr1.ir diff --git a/test/arr2.c b/test/arr2.i similarity index 100% rename from test/arr2.c rename to test/arr2.i diff --git a/test/arr2.dump b/test/arr2.ir similarity index 100% rename from test/arr2.dump rename to test/arr2.ir diff --git a/test/enu0.c b/test/enu0.i similarity index 100% rename from test/enu0.c rename to test/enu0.i diff --git a/test/enu0.dump b/test/enu0.ir similarity index 100% rename from test/enu0.dump rename to test/enu0.ir diff --git a/test/enu1.c b/test/enu1.i similarity index 100% rename from test/enu1.c rename to test/enu1.i diff --git a/test/enu1.dump b/test/enu1.ir similarity index 100% rename from test/enu1.dump rename to test/enu1.ir diff --git a/test/fld0.c b/test/fld0.i similarity index 100% rename from test/fld0.c rename to test/fld0.i diff --git a/test/fld0.dump b/test/fld0.ir similarity index 100% rename from test/fld0.dump rename to test/fld0.ir diff --git a/test/fld1.c b/test/fld1.i similarity index 100% rename from test/fld1.c rename to test/fld1.i diff --git a/test/fld1.dump b/test/fld1.ir similarity index 100% rename from test/fld1.dump rename to test/fld1.ir diff --git a/test/fld2.c b/test/fld2.i similarity index 100% rename from test/fld2.c rename to test/fld2.i diff --git a/test/fld2.dump b/test/fld2.ir similarity index 100% rename from test/fld2.dump rename to test/fld2.ir diff --git a/test/fun0.i b/test/fun0.i new file mode 100644 index 0000000..3d53be5 --- /dev/null +++ b/test/fun0.i @@ -0,0 +1,10 @@ +int (*a)(); + +int silly(x) int x; { + return x; +} + +void main() { + a = silly; + a(1); +} diff --git a/test/fun0.ir b/test/fun0.ir new file mode 100644 index 0000000..e9b65d5 --- /dev/null +++ b/test/fun0.ir @@ -0,0 +1,42 @@ +CSPACE a 2 +SYMDEF silly +PROG +RLABEL silly +SAVE +ANAME x 4 +SETREG 5 +BRANCH 1 +LABEL 2 +NAME AUTO INT 4 +RFORCE INT +EXPR 4 +BRANCH 3 +LABEL 3 +RETRN +LABEL 1 +SETSTK 0 +BRANCH 2 +SYMDEF main +PROG +RLABEL main +SAVE +SETREG 5 +BRANCH 4 +LABEL 5 +NAME EXTERN PTR,FUNC,INT a +NAME EXTERN FUNC,INT silly +AMPER PTR,FUNC,INT +ASSIGN PTR,FUNC,INT +EXPR 8 +NAME EXTERN PTR,FUNC,INT a +STAR FUNC,INT +CON INT 1 +CALL INT +EXPR 9 +LABEL 6 +RETRN +LABEL 4 +SETSTK 0 +BRANCH 5 +EOFC +*EOFC diff --git a/test/fun0.s b/test/fun0.s new file mode 100644 index 0000000..2652bd2 --- /dev/null +++ b/test/fun0.s @@ -0,0 +1,25 @@ +.comm _a,2 +.globl _silly +.text +_silly: +~~silly: +jsr r5,csv +~x=4 +jbr L1 +L2:mov 4(r5),r0 +jbr L3 +L3:jmp cret +L1:jbr L2 +.globl _main +.text +_main: +~~main: +jsr r5,csv +jbr L4 +L5:mov $_silly,_a +mov $1,(sp) +jsr pc,*_a +L6:jmp cret +L4:jbr L5 +.globl +.data diff --git a/test/hello.dump b/test/hello.ir similarity index 100% rename from test/hello.dump rename to test/hello.ir diff --git a/test/n.sh b/test/n.sh index f6a9c57..0c63683 100755 --- a/test/n.sh +++ b/test/n.sh @@ -1,7 +1,9 @@ #!/bin/sh -for i in *.c +for i in *.i do echo $i - ../ccom <$i >x - diff --unified x `basename $i .c`.s + f=`basename $i .i` + ../ccom <$f.i >s + diff -q s $f.s done +rm -f s diff --git a/test/str0.c b/test/str0.i similarity index 100% rename from test/str0.c rename to test/str0.i diff --git a/test/str0.dump b/test/str0.ir similarity index 100% rename from test/str0.dump rename to test/str0.ir diff --git a/test/str1.c b/test/str1.i similarity index 100% rename from test/str1.c rename to test/str1.i diff --git a/test/str1.dump b/test/str1.ir similarity index 100% rename from test/str1.dump rename to test/str1.ir -- 2.34.1