Annotation of researchv10dc/cmd/icon/src/link/glob.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Routines for processing .u2 files.
                      3:  */
                      4: 
                      5: #include "ilink.h"
                      6: #include "opcode.h"
                      7: #include "../h/version.h"
                      8: 
                      9: int trace = 0;                 /* initial setting of &trace */
                     10: int nrecords = 0;              /* number of records in program */
                     11: 
                     12: /*
                     13:  * globals reads the global information from infile (.u2) and merges it with
                     14:  *  the global table and record table.
                     15:  */
                     16: globals(i)
                     17: int i;
                     18:    {
                     19:    register char *id;
                     20:    register int n, op;
                     21:    int k;
                     22:    int implicit;
                     23:    char *name;
                     24:    struct gentry *gp, *glocate();
                     25:    extern char *getid(), *getstr();
                     26:    extern struct gentry *putglob();
                     27:    if (getop(&name) != Op_Version) {
                     28:       fprintf(stderr,"ucode file has no version identification\n");
                     29:       exit(ErrorExit);
                     30:       }
                     31:    id = getid();               /* get version number of ucode */
                     32:    newline();
                     33:    if (strcmp(id,UVersion)) {
                     34:       fprintf(stderr,"ucode file version mismatch\n");
                     35:       fprintf(stderr,"\tucode version: %s\n",id);
                     36:       fprintf(stderr,"\texpected version: %s\n",UVersion);
                     37:       exit(ErrorExit);
                     38:       }
                     39:    while ((op = getop(&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:                putglob(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:                err(id, "inconsistent redeclaration", 0);
                     61:                while (n--)
                     62:                   newline();
                     63:                }
                     64:             break;
                     65: 
                     66:          case Op_Impl:         /* undeclared identifiers should be noted */
                     67:             if (getop(&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:                   err(id, "inconsistent redeclaration", 0);
                     94:                else if (gp == NULL || (k & (F_Proc & ~F_Global)))
                     95:                   putglob(id, k, getdec(), 0);
                     96:                newline();
                     97:                }
                     98:             break;
                     99: 
                    100:          case Op_Link:         /* link the named file */
                    101:             name = getstr();   /* get the name and */
                    102:             addlfile(name);    /*  put it on the list of files to link */
                    103:             newline();
                    104:             break;
                    105: 
                    106:          default:
                    107:             fprintf(stderr, "%s: ill-formed global file %s\n", pname, inname);
                    108:             exit(ErrorExit);
                    109:          }
                    110:       }
                    111:    }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.