Xref: utzoo comp.sys.m6809:851 comp.os.os9:77
Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!hplabs!nsc!voder!wlbr!pete
From: pete@wlbr.EATON.COM (Pete Lyall)
Newsgroups: comp.sys.m6809,comp.os.os9
Subject: New 2 Pass CC driver
Keywords: OS9 6809 COCO3 LEVEL2 C Compiler
Message-ID: <22697@wlbr.EATON.COM>
Date: 12 Aug 88 21:31:48 GMT
Organization: Eaton IMSD, Westlake Village, CA
Lines: 1040


New 'CC' driver for the C Compiler - Kreider, Lyall, Dickhaus


This is the enhanced CC driver for the Coco3 using Level II. I also
have a slightly newer version that handles abbreviated '-l'
declarations (-l=gfxlib instead of -l=/r/lib/gfxlib.l), but it only
supports the single pass compiler. If someone wants to add those hacks
to this, let me know, and I'll mail them the other source so that they
can retrofit this two-pass compiler version.


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	cc.c
#	cc.h
#	cc.uue
#	ccdevice.a
#	readme
# This archive created: Fri Aug 12 14:26:04 1988
export PATH; PATH=/bin:$PATH
if test -f 'cc.c'
then
	echo shar: will not over-write existing file "'cc.c'"
else
cat << \SHAR_EOF > 'cc.c'
/*
** driver for the C compiler
*/
/*
**  01-23-85  Added -b and -t options. Enabled /nl.
**  ??-??-??  Added -O option to stop compilation after optimization.
**            Prevent optimization of ".a" files.
**  02-15-85  Fix naming conventions if -O is used.
**  ??-??-??  ll option for lex lib
**  07-30-86  P option for special debug and z for debug
**  03-24-87  don't optimize ".o" files, but accept as ".a"
**  03-12-88  Added two pass (CoCo) compiler support.  Bill Dickhaus
*/

#include "cc.h"
#include 

cleanup()
{
     if (childid)
          kill(childid, 2);
     if (newopath)
     {
          close(1);
          dup(newopath);
     }
     if (thisfilp)
          unlink(thisfilp);
     if (lasfilp)
          unlink(lasfilp);
}


trap(code)
int   code;
{
     cleanup();
     exit(code);
}

/*page*/
main(argc, argv)
int   argc;
char  **argv;
{
     char  **emp;
     int suffix, j, m, deltmpflg;
     register char  *p;

     j = 0;
     while ((--argc > 0) && (++j < 100))
     {
          if (*(p = *++argv) == '-')
          {
               while (*++p)
               {
                    switch (*p)
                    {
                    case 'a' :             /* stop at asm (no .r) (D) */
                         aflag = TRUE;
                         break;

                    case 'b' :              /* use different "cstart" */
                         bflag = TRUE;
                         if (*(p + 1) != '=')
                              break;
                         strcpy(mainline, (p + 2));
                         goto saver;

                    case 'c' :                /* include comments (C) */
                         cflag = TRUE;
                         break;

                    case 'd' :        /* make identifier (define) (C) */
                         if (*(p + 1) == '\0')
                              goto saver;
                         *--p = '-';
                         *(p + 1) = 'D';
                         macarray[maccnt++] = p;
                         goto saver;

                    case 'e' :                  /* set edition number */
                         emp = &edition;
                         goto emcommon;

                    case 'f' :                /* set outfile path (L) */
                         if (*++p != '=')
                              goto saver;
                         strcpy(objname, (p + 1));
                         if (objname[0] == '\0')
                              goto saver;
                         ++fflag;
                         suffix = findsuff(objname);
                         if (suffix == 'c' || suffix == 'r')
                              error("Suffix '.%c' not allowed for output", suffix);
                         goto saver;
                         /*page*/
                    case 'l' :               /* specify a library (L) */
                         if (*(p + 1) == 'l')
                         {
                              llflg++;
                              goto saver;
                         }
                         else
                              if (*(p + 1) != '=')
                                   goto saver;
                         if (libcnt == 4)
                              error("Too many libraries");
                         *--p = '-';
                         libarray[libcnt++] = p;
                         goto saver;

                    case 'm' :                     /* set memory size */
                         emp = &xtramem;
                         *p &= 0x5f;
emcommon:
                         if ((*(p + 1)))
                         {
                              *--p = '-';
                              *emp = p;
                         }
                         goto saver;

                    case 'M' :         /* ask linker for link map (L) */
                         mflag = TRUE;
                         break;

                    case 'n' :              /* give module a name (L) */
                         *--p = '-';
                         modname = p;
                         goto saver;

                    case 'o' :                    /* no optimizer (O) */
                         oflag = FALSE;
                         break;

                    case 'O' :             /* stop after optimization */
                         o2flg = TRUE;
                         break;

                    case 'P' :
                         p2flg = TRUE;         /* fall to set pflag too */

                    case 'p' :                    /* add profiler (C) */
                         pflag = TRUE;
                         break;

                    case 'q' :                      /* use quiet mode */
                         qflag = TRUE;
                         freopen("c.errors", "w", stderr);
                         break;

                    case 'r' :                /* stop at .r (no link) */
                         rflag = TRUE;
                         if (*++p != '=')
                             goto saver;
                         strcpy(rlib, (p + 1));
                         if (rlib[0] == '\0')
                             goto saver;
                         strcat(rlib, "/");
                         goto saver;
                         /*page*/
                    case 's' :               /* no stack checking (C) */
                         sflag = TRUE;
                         break;

                    case 'S' :     /* ask linker for symbol table (L) */
                         s2flg = TRUE;
                         break;

                    case 't' :            /* use transendental library */
                         tflag = TRUE;
                         break;

                    case 'T' :              /* use alternate (or NO) tmpdir*/
                         if (*(p + 1) != '=')
                         {
                              tmpdir = FALSE;
                              break;
                         }
                         else
                              {
                              strcpy(tmpname, (p + 2));
                              strcat(tmpname,"/");
                         }
                         goto saver;

                    case 'w' :    /* waste the compile for error check */
                         nullflag = TRUE;
                         break;

                    case 'x' :    /* use the work dir for main library */
                         xflag = TRUE;
                         break;

                    case 'z' :
                         zflag = TRUE;
                         break;

                    default  :
                         error("unknown flag : -%c\n", *p);
                    }  /* end of switch */
               }  /* end of inner while */
saver:
               continue;
          }  /* end of if */
          else
          {
               switch (suffix = findsuff(*argv))
               {
               case 'r' :
                    rsufflg = 1;
               case 'a' :
               case 'c' :
               case 'o' :
                    suffarray[filcnt] = suffix;
                    namarray[filcnt] = *argv;
                    ++filcnt;
                    break;

               default  :
                    error("%s : no recognised suffix", *argv);
               }  /* end of switch */
          }  /* end of else */
     }  /* end of outer while */
     /*page*/
     /*   command line now parsed, start real work   */
     logo();                                            /* identify us */
     if (filcnt == 0)
     {
          fprintf(stderr, "no files!\n");
          exit (0);
     }

     if ((aflag + rflag) > 1)
          error("incompatible flags");

     if (fflag)
          if (filcnt >1)
               if (aflag || rflag)
                    error("%s : output name not applicable", objname);

     if (fflag == 0)
          strcpy(objname, ((filcnt == 1) ? namarray[0] : "output"));


     if((tmpdir) && (*tmpname == '\0'))
          for(loopcnt=0;loopcnt code)
          trap(childstat);
}


chkccdev()
{
     char *s, c;
     register char  *p;
     struct mod_exec *q;
     struct mod_config  *r;

     if ((q = modlink("ccdevice", 4, 0)) != -1)
     {
          strcpy(devnam1, (char *)q + q->m_data);
          munlink(q);
          return (devnam1);
     }
     else
          {
          if ((r = modlink("Init", 0x0c, 0)) != -1)
          {
               s = (char *)r + r->m_sysdrive;
               p = devnam1;
               while ((c = *s++) > 0)
                    *p++ = c;
               *p++ = (c & 0x7f);
               *p = 0;
               munlink(r);
               return (devnam1);
          }
     }
     return (0);
}


error(format, arg)
char  *format,   *arg;
{
     logo();                             /* print logo if not done yet */
     fprintf(stderr, format, arg);
     putc('\n', stderr);
     trap(0);
}


chgsuff(s, c)
char  *s, c;
{
     register char  *p = s;

     while(*p++)
          ;
     if (*(p - 3) != '.')
          return;
     if (c == '\0')
          *(p - 3) = 0;
     else
          *(p - 2) = c;
}



findsuff(p)
register char *p;
{
     int   j;
     char  c;

     j = 0;
     while (c = *p++)
          if (c == '/')
               j = 0;
          else
               j++;
     if (j <= 29 && j > 2 && *(p - 3) == '.')
          return (*(p - 2) | 0x40);
     else
          return (0);
}


splcat(s)
char  *s;
{
     register char *p = s;

     *frkprmp++ = 0x20;
     while (*frkprmp++ = *p++)
          ;
     --frkprmp;
}


trmcat()
{
     *frkprmp++ = '\n';
     *frkprmp = '\0';
     frkprmsiz = frkprmp - parmbuf;
}


dummy()
{
}


logo()
{
     if (hello == 0)
          fprintf(stderr, "\n cc version %d.%d.%d\n", VERSION, MAJREV, MINREV);
}

















SHAR_EOF
fi # end of overwriting check
if test -f 'cc.h'
then
	echo shar: will not over-write existing file "'cc.h'"
else
cat << \SHAR_EOF > 'cc.h'
#include 

#define  VERSION     2
#define  MAJREV      2
#define  MINREV      1

#define  TWOPASS     TRUE    /* change to FALSE for one pass compiler */
#define  ASSEMBLER   "rma"   /* change to "c.asm" if not dev pak */
#define  LINKER      "rlink" /* change to "c.link" if not dev pak */

direct int  aflag = FALSE,
            bflag = FALSE,
            cflag = FALSE,
            fflag = FALSE,
            llflg = FALSE,
            mflag = FALSE,
            oflag = TRUE,
            o2flg = FALSE,
            pflag = FALSE,
            p2flg = FALSE,
            qflag = FALSE,
            rflag = FALSE,
            sflag = FALSE,
            s2flg = FALSE,
            tflag = FALSE,
            xflag = FALSE,
            zflag = FALSE,
            tmpdir = TRUE,
            
            childid = 0,
            childstat = 0,
            filcnt = 0,
            hello = FALSE,
            libcnt = 0,
            maccnt = 0,
            newopath = 0,
            nullflag = FALSE,
            rsufflg = FALSE,
            loopcnt;

direct char *thisfilp = 0,
            *lasfilp = 0;

direct int  frkprmsiz = 0;
direct char *frkprmp = 0;

char        *tmproot[] = { "/R", "/R0", "/DD/TMP"} ;
char        tmptail[] = "ctmp.XXXXXX";
char        tmpname[64] = "";
char        rlib[60] = "";

char    mainline[20] = "cstart.r";

char        *libarray[4],
            *namarray[100],
            suffarray[100],
            *macarray[100],
            ofn[60],
            *xtramem,
            *modname,
            *edition,
            destfile[60],
            srcfile[60],
            objname[60],
            parmbuf[256],
            devnam1[20];
SHAR_EOF
fi # end of overwriting check
if test -f 'cc.uue'
then
	echo shar: will not over-write existing file "'cc.uue'"
else
cat << \SHAR_EOF > 'cc.uue'
begin 764 cc
MA\T@4@ -$8%: !D+IV/C J:@I\ P'R;X.30@-$!/7Z? 6B;[KN0SA#")!JS0"IH"!#2<$H>0F]C4$
M;Q^!#2RI HJCJ0*(.300
M,*LPBS00[*$PR^R$XV+MA!"LY";Q,F0Y-$#,_[@7_X/<)2<.S  "- ;<)30&
M%QN,,F3<,2<3S  !- 87&@\R8MPQ- 87&8DR8MPW)PG<-S0&%QER,F+<.2<=
MW#DT!A<992 2-$#,_[H7_S@7_ZKL9#0&%QP9,F(UP#1 S/^J%_\B,G9/7^UD
M%@-7KN@0, *OZ!#NA.;$P2T0)@+@%@+-YL0='P$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#0@( \T((WO[7XG!\;6-2 6 #H0KF00/QPD M#,'0)N\?(!"^ $OM*4]?-: T0!\CKF2OJ0:E,(T "! _"35 %@ 5'S)/- :M MN0:E,F([3^VI HS,__\Y)?5/7SD7 @7^33L8A _!CD /P M 0 $ M ']$'(0=1!Y8W1M<"Y86%A86%@ M M M &-S=&%R="YR )Q #Z !D IL M> 0 ( 0 !& ( M M M M 0$! 0$! 0$!$1$1$1$! M 0$! 0$! 0$! 0$! 0$! 0$P(" @(" @(" @(" @(" @2$A(2$A(2$A(2" @ M(" @("!"0D)"0D(" @(" @(" @(" @(" @(" @(" B @(" @($1$1$1$1 0$ G! 0$! 0$! 0$! 0$! 0$! 0$(" @( $ P!% $, 00 8V, WFPX end SHAR_EOF fi # end of overwriting check if test -f 'ccdevice.a' then echo shar: will not over-write existing file "'ccdevice.a'" else cat << \SHAR_EOF > 'ccdevice.a' * * cc1, cc2 and c.prep call defdrive() to determine the "system" device * for pathlists to the DEFS and LIB directories. The technique used is * to link to the "Init" module and determine the name of the booted device. * Unfortunately, this is not always the correct device. Systems that have * a hard disk usually boot from the floppy drive (/D0) and change execution * and data directories to the hard disk (/H0). This leaves defdrive() * referring to /D0 instead of /H0 unless the "Init" module has been changed. * * Edition 3 and later of cc1, cc2 and c.prep will attempt to link to * a data module called "ccdevice" and extract the default system drive * string from there. If no "ccdevice" module is in memory, they will * use defdrive() as before to obtain the string. The following assembly * code, when assembled and linked, can be loaded into memory (Level II * systems) or merged to the end of cc1, cc2 and c.prep each (Level I * systems) to override the call to defdrive(). * * To assemble and link: * * c.asm ccdevice.a -o=ccdevice.r * c.link ccdevice.r -f=ccdevice * * To merge with cc1 (others similar): * * merge /h0/cmds/cc1 ccdevice >xxx * attr xxx pe e * del -x cc1 * copy xxx /h0/cmds/cc1 * del xxx * psect ccdevice_a,$40,$81,1,0,ccdev ccdev fcc "/D0" Device name here fcb 0 Must have this zero byte endsect SHAR_EOF fi # end of overwriting check if test -f 'readme' then echo shar: will not over-write existing file "'readme'" else cat << \SHAR_EOF > 'readme' CC replaces the standard CC1 compiler driver program. CC was originally written by Carl Kreider with additions by Pete Lyall. I have added the ability to use the two pass CoCo version of the C compiler. I've also added support of the -r=pathname option generated by the MAKE utility from the CoCo OS9 LII Developers Pak. This version of CC uses a ramdisk, if it is installed, for all the temporary files, making it much faster. It also supports additional compiler options like auto-inclusion of the CLIBT.L library, stop after optimization (before assembly) and many others. Also included is a data module, "ccdevice", that causes the compiler to use the device name in the module (default is D0) as the default location of compiler files (LIB and DEFS directories). Included in this archive are the following files: cc.h Header file for cc.c, three defines in this file may need to be changed before compilation, see notes below. cc.c C source code for cc. cc Compiled, executable version, set up for the two pass compiler, the rma assembler, and rlink linker. ccdevice.a Source code for the ccdevice data module. Directions for assembly are included in the source code. This module must be loaded or merged with another module (I merged it with cc). readme This file. The following defines can be changed in cc.h: #define TWOPASS TRUE /* change to FALSE for one pass compiler */ #define ASSEMBLER "rma" /* change to c.asm if you don't have the dev pak */ #define LINKER "rlink" /* change to c.link if you don't have the dev pak */ WARNING! The programs c.pass2, c.opt and rma do not return any kind of error condition after disk errors. This can cause some rather strange results if you don't make your ram disk big enough to hold each temporary file. The compile may seem to be continuing normally, but almost always fails in the link step. Make sure you have plenty of free space for the temporary files on you ram disk. Bill Dickhaus [70325,523] SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 -- Pete Lyall (OS9 Users Group VP)| DELPHI: OS9UGVP | Eaton Corp.(818)-706-5693 Compuserve: 76703,4230 (OS9 Sysop) OS9 (home): (805)-985-0632 (24hr./1200 baud) Internet: pete@wlbr.eaton.com UUCP: {scgvax,jplgodo,voder}!wlbr!pete