OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [rev_86/] [Tools/] [as09/] [symtab.c] - Blame information for rev 200

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 83 davidgb
/*
2
 *      install --- add a symbol to the table
3
 */
4
install(str,val)
5
char    *str;
6
int     val;
7
{
8
        struct link *lp;
9
 struct nlist *np,*p,*backp;
10
 int     i;
11
 char *LastChar();      /* ver TER_2.0 */
12
 
13
 if( !alpha(*str) ){
14
  error("Illegal Symbol Name");
15
  return(NO);
16
  }
17
 if( (np = lookup(str)) != NULL ){
18
  if (*LastChar(str) == '@') {  /* redefinable symbol  ver TER_2.0 */
19
        np->def = val;          /* redefined */
20
        return(YES);
21
        }
22
  if( Pass==2 ){
23
   np->def2 = 2;        /* defined for this pass=Pass  ver TER_2.0 */
24
   if( np->def == val )
25
    return(YES);
26
   else{
27
    error("Phasing Error");
28
    return(NO);
29
    }
30
   }
31
  error("Symbol Redefined");
32
  return(NO);
33
  }
34
 /* enter new symbol */
35
#ifdef DEBUG
36
 printf("Installing %s as %d\n",str,val);
37
#endif
38
 np = (struct nlist *) alloc(sizeof(struct nlist));
39
 if( np == (struct nlist *)ERR ){
40
  error("Symbol table full");
41
  return(NO);
42
  }
43
 np->name = alloc(strlen(str)+1);
44
 if( np->name == (char *)ERR ){
45
  error("Symbol table full");
46
  return(NO);
47
  }
48
 strcpy(np->name,str);
49
 np->def = val;
50
 np->def2 = 1;  /* defined for this pass=Pass  ver TER_2.0 */
51
 np->Lnext = NULL;
52
        np->Rnext = NULL;
53
           lp = (struct link *) alloc(sizeof(struct link));
54
           np->L_list = lp;
55
           lp->L_num = Line_num;
56
           lp->next = NULL;
57
        p = root;
58
          backp = NULL;
59
           while (p != NULL)
60
            {
61
              backp = p;
62
              i = strcmp (str,p->name);
63
               if (i<0)
64
                   p=p->Lnext;
65
                  else p=p->Rnext;
66
            }
67
          if (backp == NULL)
68
              root = np;
69
             else if (strcmp(str,backp->name)<0)
70
                  backp->Lnext = np;
71
                 else backp->Rnext = np;
72
          return (YES);
73
}
74
 
75
/*
76
 *      lookup --- find string in symbol table
77
 */
78
struct nlist *
79
lookup(char *name)
80
{
81
 struct nlist *np;
82
 int     i;
83
 char   *c;     /* ver TER_2.0 */
84
 
85
 c = name;      /* copy symbol pointer */
86
 while(alphan(*c))      /* search for end of symbol */
87
  c++;  /* next char */
88
 *c = EOS;      /* disconnect anything after for good compare */
89
                /* end of mods for ver TER_2.0 */
90
 
91
        np = root;      /* and now go on and look for symbol */
92
         while (np != NULL)
93
          {
94
            i = strcmp(name,np->name);
95
             if (i == 0)
96
               {
97
                 Last_sym = np->def;
98
                 return (np);
99
               }
100
             else if (i < 0)
101
                 np = np->Lnext;
102
                else np = np->Rnext;
103
          }
104
      Last_sym = 0;
105
/*      if (Pass == 2)
106
        error ("symbol Undefined on pass 2"); */
107
                /* commented out ver TER_2.0 2 Jul 89 */
108
                /* function used in IFD */
109
        return (NULL);
110
}
111
 
112
 
113
#define NMNE (sizeof(table)/ sizeof(struct oper))
114
#define NPSE (sizeof(pseudo)/ sizeof(struct oper))
115
/*
116
 *      mne_look --- mnemonic lookup
117
 *
118
 *      Return pointer to an oper structure if found.
119
 *      Searches both the machine mnemonic table and the pseudo table.
120
 */
121
struct oper *
122
mne_look(str)
123
char    *str;
124
{
125
 struct oper *low,*high,*mid;
126
 int     cond;
127
 
128
 /* Search machine mnemonics first */
129
 low =  &table[0];
130
 high = &table[ NMNE-1 ];
131
 while (low <= high){
132
  mid = low + (high-low)/2;
133
  if( ( cond = strcmp(str,mid->mnemonic)) < 0)
134
   high = mid - 1;
135
  else if (cond > 0)
136
   low = mid + 1;
137
  else
138
   return(mid);
139
 }
140
 
141
 /* Check for pseudo ops */
142
 low =  &pseudo[0];
143
 high = &pseudo[ NPSE-1 ];
144
 while (low <= high){
145
  mid = low + (high-low)/2;
146
  if( ( cond = strcmp(str,mid->mnemonic)) < 0)
147
   high = mid - 1;
148
  else if (cond > 0)
149
   low = mid + 1;
150
  else
151
   return(mid);
152
 }
153
 
154
 return(NULL);
155
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.