home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / icont / lglob.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  4KB  |  122 lines

  1. /*
  2.  * lgloc.c -- routines for processing .u2 files.
  3.  */
  4.  
  5. #include "link.h"
  6. #include "tproto.h"
  7. #include "opcode.h"
  8. #include "../h/version.h"
  9.  
  10. int nrecords = 0;        /* number of records in program */
  11.  
  12. /*
  13.  * readglob reads the global information from infile (.u2) and merges it with
  14.  *  the global table and record table.
  15.  */
  16. novalue readglob()
  17.    {
  18.    register char *id;
  19.    register int n, op;
  20.    int k;
  21.    int implicit;
  22.    char *name;
  23.    struct gentry *gp;
  24.    extern char *progname;
  25.  
  26.    if (getopc(&name) != Op_Version)
  27.       quitf("ucode file %s has no version identification",inname);
  28.    id = getid();        /* get version number of ucode */
  29.    newline();
  30.    if (strcmp(id,UVersion)) {
  31.       fprintf(stderr,"version mismatch in ucode file %s\n",inname);
  32.       fprintf(stderr,"\tucode version: %s\n",id);
  33.       fprintf(stderr,"\texpected version: %s\n",UVersion);
  34.  
  35.  
  36.       exit(ErrorExit);
  37.  
  38.       }
  39.    while ((op = getopc(&name)) != EOF) {
  40.       switch (op) {
  41.          case Op_Record:    /* a record declaration */
  42.             id = getid();    /* record name */
  43.             n = getdec();    /* number of fields */
  44.             newline();
  45.             gp = glocate(id);
  46.             /*
  47.              * It's ok if the name isn't already in use or if the
  48.              *  name is just used in a "global" declaration.  Otherwise,
  49.              *  it is an inconsistent redeclaration.
  50.              */
  51.             if (gp == NULL || (gp->g_flag & ~F_Global) == 0) {
  52.                putglobal(id, F_Record, n, ++nrecords);
  53.                while (n--) {    /* loop reading field numbers and names */
  54.                   k = getdec();
  55.                   putfield(getid(), nrecords, k);
  56.                   newline();
  57.                   }
  58.                }
  59.             else {
  60.                lfatal(id, "inconsistent redeclaration");
  61.                while (n--)
  62.                   newline();
  63.                }
  64.             break;
  65.  
  66.          case Op_Impl:        /* undeclared identifiers should be noted */
  67.             if (getopc(&name) == Op_Local)
  68.                implicit = 0;
  69.             else
  70.                implicit = F_ImpError;
  71.             break;
  72.  
  73.          case Op_Trace:        /* turn on tracing */
  74.             trace = -1;
  75.             break;
  76.  
  77.          case Op_Global:    /* global variable declarations */
  78.             n = getdec();    /* number of global declarations */
  79.             newline();
  80.             while (n--) {    /* process each declaration */
  81.                getdec();    /* throw away sequence number */
  82.                k = getoct();    /* get flags */
  83.                if (k & (F_Proc & ~F_Global))
  84.                   k |= implicit;
  85.                id = getid();    /* get variable name */
  86.                gp = glocate(id);
  87.                /*
  88.                 * Check for conflicting declarations and install the
  89.                 *  variable.
  90.                 */
  91.                if (gp != NULL &&
  92.                    (k & (F_Proc & ~F_Global)) && gp->g_flag != F_Global)
  93.                   lfatal(id, "inconsistent redeclaration");
  94.                else if (gp == NULL || (k & (F_Proc & ~F_Global)))
  95.                   putglobal(id, k, getdec(), 0);
  96.                newline();
  97.                }
  98.             break;
  99.  
  100.          case Op_Link:        /* link the named file */
  101.             name = getrest();    /* get the name and */
  102.  
  103. #if ARM
  104.         {
  105.             char *flipname (char *);
  106.  
  107.         /* put it on the list of files to link */
  108.             alsolink(flipname(name));
  109.             }
  110. #else                    /* ARM */
  111.             alsolink(name);    /*  put it on the list of files to link */
  112. #endif                    /* ARM */
  113.  
  114.             newline();
  115.             break;
  116.  
  117.          default:
  118.         quitf("ill-formed global file %s",inname);
  119.          }
  120.       }
  121.    }
  122.