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

Subversion Repositories System09

[/] [System09/] [trunk/] [Tools/] [as09/] [symtab.c] - Blame information for rev 78

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

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

powered by: WebSVN 2.1.0

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