/*
|
/*
|
* install --- add a symbol to the table
|
* install --- add a symbol to the table
|
*/
|
*/
|
install(str,val)
|
install(str,val)
|
char *str;
|
char *str;
|
int val;
|
int val;
|
{
|
{
|
struct link *lp;
|
struct link *lp;
|
struct nlist *np,*p,*backp;
|
struct nlist *np,*p,*backp;
|
int i;
|
int i;
|
char *LastChar(); /* ver TER_2.0 */
|
char *LastChar(); /* ver TER_2.0 */
|
|
|
if( !alpha(*str) ){
|
if( !alpha(*str) ){
|
error("Illegal Symbol Name");
|
error("Illegal Symbol Name");
|
return(NO);
|
return(NO);
|
}
|
}
|
if( (np = lookup(str)) != NULL ){
|
if( (np = lookup(str)) != NULL ){
|
if (*LastChar(str) == '@') { /* redefinable symbol ver TER_2.0 */
|
if (*LastChar(str) == '@') { /* redefinable symbol ver TER_2.0 */
|
np->def = val; /* redefined */
|
np->def = val; /* redefined */
|
return(YES);
|
return(YES);
|
}
|
}
|
if( Pass==2 ){
|
if( Pass==2 ){
|
np->def2 = 2; /* defined for this pass=Pass ver TER_2.0 */
|
np->def2 = 2; /* defined for this pass=Pass ver TER_2.0 */
|
if( np->def == val )
|
if( np->def == val )
|
return(YES);
|
return(YES);
|
else{
|
else{
|
error("Phasing Error");
|
error("Phasing Error");
|
return(NO);
|
return(NO);
|
}
|
}
|
}
|
}
|
error("Symbol Redefined");
|
error("Symbol Redefined");
|
return(NO);
|
return(NO);
|
}
|
}
|
/* enter new symbol */
|
/* enter new symbol */
|
#ifdef DEBUG
|
#ifdef DEBUG
|
printf("Installing %s as %d\n",str,val);
|
printf("Installing %s as %d\n",str,val);
|
#endif
|
#endif
|
np = (struct nlist *) alloc(sizeof(struct nlist));
|
np = (struct nlist *) alloc(sizeof(struct nlist));
|
if( np == (struct nlist *)ERR ){
|
if( np == (struct nlist *)ERR ){
|
error("Symbol table full");
|
error("Symbol table full");
|
return(NO);
|
return(NO);
|
}
|
}
|
np->name = alloc(strlen(str)+1);
|
np->name = alloc(strlen(str)+1);
|
if( np->name == (char *)ERR ){
|
if( np->name == (char *)ERR ){
|
error("Symbol table full");
|
error("Symbol table full");
|
return(NO);
|
return(NO);
|
}
|
}
|
strcpy(np->name,str);
|
strcpy(np->name,str);
|
np->def = val;
|
np->def = val;
|
np->def2 = 1; /* defined for this pass=Pass ver TER_2.0 */
|
np->def2 = 1; /* defined for this pass=Pass ver TER_2.0 */
|
np->Lnext = NULL;
|
np->Lnext = NULL;
|
np->Rnext = NULL;
|
np->Rnext = NULL;
|
lp = (struct link *) alloc(sizeof(struct link));
|
lp = (struct link *) alloc(sizeof(struct link));
|
np->L_list = lp;
|
np->L_list = lp;
|
lp->L_num = Line_num;
|
lp->L_num = Line_num;
|
lp->next = NULL;
|
lp->next = NULL;
|
p = root;
|
p = root;
|
backp = NULL;
|
backp = NULL;
|
while (p != NULL)
|
while (p != NULL)
|
{
|
{
|
backp = p;
|
backp = p;
|
i = strcmp (str,p->name);
|
i = strcmp (str,p->name);
|
if (i<0)
|
if (i<0)
|
p=p->Lnext;
|
p=p->Lnext;
|
else p=p->Rnext;
|
else p=p->Rnext;
|
}
|
}
|
if (backp == NULL)
|
if (backp == NULL)
|
root = np;
|
root = np;
|
else if (strcmp(str,backp->name)<0)
|
else if (strcmp(str,backp->name)<0)
|
backp->Lnext = np;
|
backp->Lnext = np;
|
else backp->Rnext = np;
|
else backp->Rnext = np;
|
return (YES);
|
return (YES);
|
}
|
}
|
|
|
/*
|
/*
|
* lookup --- find string in symbol table
|
* lookup --- find string in symbol table
|
*/
|
*/
|
struct nlist *
|
struct nlist *
|
lookup(char *name)
|
lookup(char *name)
|
{
|
{
|
struct nlist *np;
|
struct nlist *np;
|
int i;
|
int i;
|
char *c; /* ver TER_2.0 */
|
char *c; /* ver TER_2.0 */
|
|
|
c = name; /* copy symbol pointer */
|
c = name; /* copy symbol pointer */
|
while(alphan(*c)) /* search for end of symbol */
|
while(alphan(*c)) /* search for end of symbol */
|
c++; /* next char */
|
c++; /* next char */
|
*c = EOS; /* disconnect anything after for good compare */
|
*c = EOS; /* disconnect anything after for good compare */
|
/* end of mods for ver TER_2.0 */
|
/* end of mods for ver TER_2.0 */
|
|
|
np = root; /* and now go on and look for symbol */
|
np = root; /* and now go on and look for symbol */
|
while (np != NULL)
|
while (np != NULL)
|
{
|
{
|
i = strcmp(name,np->name);
|
i = strcmp(name,np->name);
|
if (i == 0)
|
if (i == 0)
|
{
|
{
|
Last_sym = np->def;
|
Last_sym = np->def;
|
return (np);
|
return (np);
|
}
|
}
|
else if (i < 0)
|
else if (i < 0)
|
np = np->Lnext;
|
np = np->Lnext;
|
else np = np->Rnext;
|
else np = np->Rnext;
|
}
|
}
|
Last_sym = 0;
|
Last_sym = 0;
|
/* if (Pass == 2)
|
/* if (Pass == 2)
|
error ("symbol Undefined on pass 2"); */
|
error ("symbol Undefined on pass 2"); */
|
/* commented out ver TER_2.0 2 Jul 89 */
|
/* commented out ver TER_2.0 2 Jul 89 */
|
/* function used in IFD */
|
/* function used in IFD */
|
return (NULL);
|
return (NULL);
|
}
|
}
|
|
|
|
|
#define NMNE (sizeof(table)/ sizeof(struct oper))
|
#define NMNE (sizeof(table)/ sizeof(struct oper))
|
#define NPSE (sizeof(pseudo)/ sizeof(struct oper))
|
#define NPSE (sizeof(pseudo)/ sizeof(struct oper))
|
/*
|
/*
|
* mne_look --- mnemonic lookup
|
* mne_look --- mnemonic lookup
|
*
|
*
|
* Return pointer to an oper structure if found.
|
* Return pointer to an oper structure if found.
|
* Searches both the machine mnemonic table and the pseudo table.
|
* Searches both the machine mnemonic table and the pseudo table.
|
*/
|
*/
|
struct oper *
|
struct oper *
|
mne_look(str)
|
mne_look(str)
|
char *str;
|
char *str;
|
{
|
{
|
struct oper *low,*high,*mid;
|
struct oper *low,*high,*mid;
|
int cond;
|
int cond;
|
|
|
/* Search machine mnemonics first */
|
/* Search machine mnemonics first */
|
low = &table[0];
|
low = &table[0];
|
high = &table[ NMNE-1 ];
|
high = &table[ NMNE-1 ];
|
while (low <= high){
|
while (low <= high){
|
mid = low + (high-low)/2;
|
mid = low + (high-low)/2;
|
if( ( cond = strcmp(str,mid->mnemonic)) < 0)
|
if( ( cond = strcmp(str,mid->mnemonic)) < 0)
|
high = mid - 1;
|
high = mid - 1;
|
else if (cond > 0)
|
else if (cond > 0)
|
low = mid + 1;
|
low = mid + 1;
|
else
|
else
|
return(mid);
|
return(mid);
|
}
|
}
|
|
|
/* Check for pseudo ops */
|
/* Check for pseudo ops */
|
low = &pseudo[0];
|
low = &pseudo[0];
|
high = &pseudo[ NPSE-1 ];
|
high = &pseudo[ NPSE-1 ];
|
while (low <= high){
|
while (low <= high){
|
mid = low + (high-low)/2;
|
mid = low + (high-low)/2;
|
if( ( cond = strcmp(str,mid->mnemonic)) < 0)
|
if( ( cond = strcmp(str,mid->mnemonic)) < 0)
|
high = mid - 1;
|
high = mid - 1;
|
else if (cond > 0)
|
else if (cond > 0)
|
low = mid + 1;
|
low = mid + 1;
|
else
|
else
|
return(mid);
|
return(mid);
|
}
|
}
|
|
|
return(NULL);
|
return(NULL);
|
}
|
}
|
|
|