From 179f5d399e083d1c6811de832afc8b92f4ca8a2f Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Wed, 8 Feb 2017 00:34:05 +1100 Subject: [PATCH] Created new driver ccom.c which creates its own tempfiles and runs both passes --- .gitignore | 3 +- Makefile | 28 +++++++++++------- c0.h | 10 ++++++- c00.c | 15 +++++++--- c04.c | 4 +++ c05.c | 4 +++ c1.h | 1 - c10.c | 2 ++ c11.c | 9 ++++++ c12.c | 4 --- ccom.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ccom.h | 5 ++++ fp.c | 3 +- n.sh | 8 ++++- 14 files changed, 156 insertions(+), 25 deletions(-) create mode 100644 ccom.c diff --git a/.gitignore b/.gitignore index 4fc5c53..0af40eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.bak *.o -c0 -c1 +ccom cvopt diff --git a/Makefile b/Makefile index a96c743..c750e85 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,29 @@ HOSTCC=cc INSTALL=install -CFLAGS = -O -LDC0FLAGS= -i -LDC1FLAGS= -n +CFLAGS=-Wall -Wno-char-subscripts -Wno-deprecated-declarations -Wno-format -Wno-maybe-uninitialized -Wno-parentheses -Wno-unused-result +#CFLAGS = -O +#LDC0FLAGS= -i +#LDC1FLAGS= -n DESTDIR = LIB=/lib -all: c0 c1 cvopt -c0: c00.o c01.o c02.o c03.o c04.o c05.o - ${CC} ${LDC0FLAGS} ${CFLAGS} -o c0 c00.o c01.o c02.o c03.o c04.o c05.o +all: ccom cvopt +#c0 c1 cvopt -c00.o c01.o c02.o c03.o c04.o c05.o: c0.h +ccom: ccom.o c00.o c01.o c02.o c03.o c04.o c05.o c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o + ${CC} ${CFLAGS} -o ccom ccom.o c00.o c01.o c02.o c03.o c04.o c05.o c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o -c1: c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o - ${CC} ${LDC1FLAGS} ${CFLAGS} -o c1 c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o +ccom.o: c0.h c1.h ccom.h -c10.o c11.o c12.o c13.o: c1.h +#c0: c00.o c01.o c02.o c03.o c04.o c05.o +# ${CC} ${LDC0FLAGS} ${CFLAGS} -o c0 c00.o c01.o c02.o c03.o c04.o c05.o + +c00.o c01.o c02.o c03.o c04.o c05.o: c0.h ccom.h + +#c1: c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o +# ${CC} ${LDC1FLAGS} ${CFLAGS} -o c1 c10.o c11.o c12.o c13.o fp.o fp_atof.o table.o + +c10.o c11.o c12.o c13.o: c1.h ccom.h table.o: optable cvopt ./cvopt < optable > junk.c diff --git a/c0.h b/c0.h index ead5d1a..5e3114e 100644 --- a/c0.h +++ b/c0.h @@ -5,7 +5,6 @@ #ifndef _C0_H #define _C0_H 1 -#include #include "ccom.h" /* @@ -199,11 +198,15 @@ extern int nchstr; extern int nerror; extern struct nmlist *paraml; extern struct nmlist *parame; +#if 0 extern int strflg; +#endif extern int mosflg; extern int initflg; +#if 0 extern char sbuf[BUFSIZ]; extern FILE *sbufp; +#endif extern int regvar; extern int bitoffs; extern struct tnode0 funcblk0; @@ -277,6 +280,11 @@ extern int mossym; #define FINIT 040 #define FLABL 0100 +extern struct kwtab { + char *kwname; + int kwval; +} kwtab[]; + #ifndef __P #ifdef __STDC__ #define __P(args) args diff --git a/c00.c b/c00.c index e257c71..6968a25 100644 --- a/c00.c +++ b/c00.c @@ -18,10 +18,7 @@ int peeksym = -1; int line = 1; struct tnode0 funcblk0 = { NAME }; -struct kwtab { - char *kwname; - int kwval; -} kwtab[] = { +struct kwtab kwtab[] = { {"int", INT}, {"char", CHAR}, {"float", FLOAT}, @@ -59,6 +56,7 @@ union tree0 *cmst[CMSIZ]; union tree0 **cp0 = cmst; int Wflag; /* print warning messages */ +#if 0 int main(argc, argv) int argc; char *argv[]; { register unsigned i; register struct kwtab *ip; @@ -123,6 +121,7 @@ int main(argc, argv) int argc; char *argv[]; { blkend(); exit(nerror!=0); } +#endif /* * Look up the identifier in symbuf in the symbol table. @@ -446,7 +445,11 @@ void putstr(lab, max) int lab; register int max; { nchstr = 0; if (lab) { +#if 1 + temp_fi = 1; +#else strflg++; +#endif outcode("BNB", LABEL, lab, BDATA); max = 10000; } else @@ -464,7 +467,11 @@ void putstr(lab, max) int lab; register int max; { outcode("10"); } outcode("0"); +#if 1 + temp_fi = 0; +#else strflg = 0; +#endif } void cntstr() { diff --git a/c04.c b/c04.c index af810f4..4d065c6 100644 --- a/c04.c +++ b/c04.c @@ -353,9 +353,13 @@ void outcode(s, va_alist) char *s; va_dcl register char *np; int n; +#if 1 + bufp = temp_fp[temp_fi]; +#else bufp = stdout; if (strflg) bufp = sbufp; +#endif _va_start(ap, s); for (;;) switch(*s++) { case 'B': diff --git a/c05.c b/c05.c index 4e5c264..752ce7b 100644 --- a/c05.c +++ b/c05.c @@ -233,11 +233,15 @@ int nchstr; int nerror; struct nmlist *paraml; struct nmlist *parame; +#if 0 int strflg; +#endif int mosflg; int initflg; +#if 0 char sbuf[BUFSIZ]; FILE *sbufp; +#endif int regvar; int bitoffs; char cvntab[]; diff --git a/c1.h b/c1.h index db4fdbb..1c14e7c 100644 --- a/c1.h +++ b/c1.h @@ -5,7 +5,6 @@ #ifndef _C1_H #define _C1_H 1 -#include #include #include "ccom.h" diff --git a/c10.c b/c10.c index 3224494..f45ec5b 100644 --- a/c10.c +++ b/c10.c @@ -37,6 +37,7 @@ struct table *cregtab; int nreg = 3; int isn1 = 10000; +#if 0 int main(argc, argv) int argc; char *argv[]; { char buf1[BUFSIZ], buf2[BUFSIZ]; @@ -80,6 +81,7 @@ int main(argc, argv) int argc; char *argv[]; { werror1("possibly too much data"); exit(nerror!=0); } +#endif /* * Given a tree1, a code table, and a diff --git a/c11.c b/c11.c index 62c16a3..b618f81 100644 --- a/c11.c +++ b/c11.c @@ -1092,15 +1092,24 @@ void getree() { int geti() { register int i; +#if 1 + i = fgetc(temp_fp[temp_fi]) & 0xff; + i |= (fgetc(temp_fp[temp_fi]) & 0xff) << 8; +#else i = getchar() & 0xff; i |= (getchar() & 0xff) << 8; +#endif return(i); } static void outname(s) register char *s; { register int c; +#if 1 + while ((c = fgetc(temp_fp[temp_fi])) != 0 && c != EOF) +#else while (c = getchar()) +#endif *s++ = c; *s++ = '\0'; } diff --git a/c12.c b/c12.c index 81820b7..27e733c 100644 --- a/c12.c +++ b/c12.c @@ -311,10 +311,6 @@ union tree1 *optim(tree1) register union tree1 *tree1; { union tree1 *unoptim(tree1) register union tree1 *tree1; { register union tree1 *subtre, *p; -#ifndef pdp11 - _LONG temp_long; - uint16_t temp[2]; -#endif if (tree1==NULL) return(NULL); diff --git a/ccom.c b/ccom.c new file mode 100644 index 0000000..7f62edf --- /dev/null +++ b/ccom.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include "c0.h" +#include "c1.h" + +/* new merged main program for C compiler pass [01], makes own tempfiles */ +int temp_fi; +FILE *temp_fp[2]; +char buf0[BUFSIZ]; +char buf1[BUFSIZ]; +char buf2[BUFSIZ]; + +int main(argc, argv) int argc; char **argv; { + register unsigned i; + register struct kwtab *ip; + char temp_name[16]; + int fd; + + if (argc >= 2 && strcmp(argv[1], "-") != 0 && freopen(argv[1], "r", stdin) == 0) { + error0("Can't find %s", argv[1]); + exit(1); + } + for (i = 0; i < 2; ++i) { + strcpy(temp_name, "/tmp/ccomXXXXXX"); + fd = mkstemp(temp_name); + if (fd == -1 || (temp_fp[i] = fdopen(fd, "w+")) == 0 || unlink(temp_name)) { + error0("Can't create temp: %s", temp_name); + exit(1); + } + } + setbuf(stdin, buf0); + setbuf(temp_fp[0], buf1); + setbuf(temp_fp[1], buf2); + + /* + * The hash table locations of the keywords + * are marked; if an identifier hashes to one of + * these locations, it is looked up in in the keyword + * table first. + */ + for (ip=kwtab; ip->kwname; ip++) { + i = hash(ip->kwname); + kwhash[i/LNBPW] |= 1 << (i%LNBPW); + } + coremax = locbase = /*sbrk(0);*/ funcbase = curbase = sbrk(0); + temp_fi = 0; + while(!eof) + extdef(); + outcode("B", EOFC); + temp_fi = 1; + outcode("B", EOFC); + blkend(); + if (nerror) + exit(1); + fclose(stdin); + + if (argc >= 3 && strcmp(argv[2], "-") != 0 && freopen(argv[2], "w", stdin) == 0) { + error0("Can't create %s", argv[2]); + exit(1); + } + setbuf(stdout, buf0); + + /*funcbase = curbase = coremax = sbrk(0);*/ + temp_fi = 0; + rewind(temp_fp[0]); + getree(); + /* + * If any floating-point instructions + * were used, generate a reference that + * pulls in the floating-point part of printf. + */ + if (nfloat) + printf(".globl fltused\n"); + /* + * tack on the string file. + */ + printf(".globl\n.data\n"); + temp_fi = 1; + rewind(temp_fp[1]); + getree(); + if (totspace >= (_UNSIGNED_INT)56000) + werror1("possibly too much data"); + exit(nerror!=0); +} diff --git a/ccom.h b/ccom.h index 2addbaf..42baf3b 100644 --- a/ccom.h +++ b/ccom.h @@ -1,6 +1,8 @@ #ifndef _CCOM_H_ #define _CCOM_H_ +#include + #ifdef pdp11 typedef int _INT; typedef long _LONG; @@ -324,4 +326,7 @@ struct swtab { #define PCVOK 040000 /* pass 0 only */ #define CNVRT 01000 /* pass 1 only */ +extern int temp_fi; +extern FILE *temp_fp[2]; + #endif diff --git a/fp.c b/fp.c index 241b733..b8efa0d 100644 --- a/fp.c +++ b/fp.c @@ -361,10 +361,9 @@ static int32_t moveifp11(val) _DOUBLE *val; { } static int32_t moviffp11(val, fac) int32_t val; _DOUBLE *fac; { - int32_t i, qdouble, leni; + int32_t i; int32_t exp, sign; - qdouble = FPS & FPS_D; fac->l = val; fac->h = 0; if (fac->l) { diff --git a/n.sh b/n.sh index b18b15b..5575176 100755 --- a/n.sh +++ b/n.sh @@ -1,2 +1,8 @@ #!/bin/sh -make CFLAGS=-g LDC0FLAGS= LDC1FLAGS= "$@" +ROOT="`pwd |sed -e 's/\/lib\/ccom$//'`" +HOSTCC="cc -g -I$ROOT/cross/usr/include -L$ROOT/cross/usr/lib/ -Wall -Wno-char-subscripts -Wno-deprecated-declarations -Wno-format -Wno-maybe-uninitialized -Wno-parentheses -Wno-unused-result" +INSTALL="$ROOT/scripts/install.sh --strip-program=/bin/true" +MANROFF="nroff -man" +mkdir --parents "$ROOT/cross/lib" +make CC="$HOSTCC" MANROFF="$MANROFF" LDC0FLAGS= LDC1FLAGS= PURFLAG= && \ +make INSTALL="$INSTALL" DESTDIR="$ROOT/cross" install -- 2.34.1