#include "ccg"/*>>>>> start cc1 <<<<<<*//* Compiler begins execution here * inp is input fd, * output is output fd * (called multiple times from main) */compile()$(glbptr=startglb;/* clear globl symbols */locptr=startloc;/* clear local symbols */wqptr=wq;/* clear while queue */macptr=/* clear the macro pool */litptr=/* clear literal pool */  oursp=/* stack ptr (relative) */errcnt=/* no errors */eof=/* not eof yet */inp2=/* or include file */ncmp=/* no open compound states */lastst=/* no last statement yet */quote[1]=0;/*  ...all set to zero.... */kill();/* empty input line *//* fake a quote literal */quote[0]='"';cmode=1;/* enable preprocessing */ctext=0;glbflag=1;nxtlab=0;litlab=getlabel();/* process ALL input */parse();/* then dump literal pool */dumplits();/* and all static memory */dumpglbs();/* and link information  */dumpnams();/* summarize errors */ersum();$)/* *Process all input text * * At this level, only static * declarations, * defines, includes, and function * definitions are legal.... */parse()$(/* do until no more input */while (eof==0)$(abtchk();if(amatch("extern",6))$(if(amatch("char",4))declglb(cchar,extrn);else$(amatch("int",3);declglb(cint,extrn);$)ns();$)else if(amatch("char",4))$(declglb(cchar,global);ns();$)else if (amatch("int",3))$(declglb(cint,global);ns();$)else if(match("#include"))doinclude();else if(match("#define"))addmac();else newfunc();/* force eof if pending */blanks();$)$)/* * Dump the literal pool */dumplits()$(int k;/* if nothing there, exit...*/if (litptr==0) return;/* print literal label */outcdf(litlab);/* data for next n bytes */outdat(litptr);/* init an index... */k=0;while (k<litptr)/* to loop with */outbyte((litq[k++]&255));$)/* *Dump all static variables */dumpglbs()$(int j;cptr=startglb;while(cptr<glbptr)$(if(cptr[ident]!=function & cptr[storage]!= extrn)/* do if anything but function or external */$(outldf(cptr);j=((cptr[offset]&255)+((cptr[offset+1]&255)<<8));/* calc # bytes */if((cptr[type]==cint)|(cptr[ident]==pointer))j=j+j;outsp(j);/* need that many */$)cptr=cptr+symsiz;$)$)/* * Report errors for user */ersum()$(/* see if anything left hanging... */if(ncmp) error("missing closing bracket");if(errcnt==0)$(pl("No errors.");putchar(eol);$)$)/* *Open an include file */doinclude()$(char c,angflag;if(inp2)$(error("Can't nest include files");kill();return;$)mptr=0;if(match("<"))angflag=1;else if(match(quote))angflag=0;else$(error("missing quote or <");kill();return;$)while(c=line[lptr++])$(if(c==eol)$(error("missing quote or >");break;$)else if((c=='>' & angflag)| (c=='"' & angflag==0))break;else mline[mptr++]=c;$)mline[mptr]=0;normalize(mline,"H"); /* header */putchar(eol);ps("including ");ps(mline);putchar(eol);if((inp2=copen(mline,'r'))<0)$(inp2=0;error("Open failure on include file");$)kill();/* clear rest of line *//* so next read will come from *//* new file (if open) */$)/* *Close the output file */clout()$(/* if open, close it */if(output)cclose(output);output=0;/* mark as closed */$)/* check if user pressed break */abtchk()$(char i;if(peek(17))return;poke(17,255);i=7;while(i>0)cclose(i--);usr(dpeek(10)); /* jmp (DOS) */$)/* end of cc1 */