(uxmasm) Merged item finding routines

This commit is contained in:
Devine Lu Linvega 2024-03-27 10:47:12 -07:00
parent a56a4e0be0
commit 93a409500a
1 changed files with 6 additions and 14 deletions

View File

@ -59,6 +59,8 @@ static char *push(char *s, char c) { char *ptr = storenext; while((*storenext++
#define isopcode(x) (findopcode(x) || scmp(x, "BRK", 4)) #define isopcode(x) (findopcode(x) || scmp(x, "BRK", 4))
#define writeshort(x) (writebyte(x >> 8) && writebyte(x & 0xff)) #define writeshort(x) (writebyte(x >> 8) && writebyte(x & 0xff))
#define makesublabel(x) push(scat(scat(scpy(scope, sublabel, 0x40), "/"), x), 0) #define makesublabel(x) push(scat(scat(scpy(scope, sublabel, 0x40), "/"), x), 0)
#define findlabel(x) finditem(x, p.labels, p.label_len)
#define findmacro(x) finditem(x, p.macros, p.macro_len)
#define error_top(name, msg) !!fprintf(stderr, "%s: %s\n", name, msg) #define error_top(name, msg) !!fprintf(stderr, "%s: %s\n", name, msg)
#define error_asm(name) !!fprintf(stderr, "%s: %s in @%s, %s:%d.\n", name, token, scope, source, p.line) #define error_asm(name) !!fprintf(stderr, "%s: %s in @%s, %s:%d.\n", name, token, scope, source, p.line)
@ -67,24 +69,14 @@ static char *push(char *s, char c) { char *ptr = storenext; while((*storenext++
static int parse(char *w, FILE *f); static int parse(char *w, FILE *f);
static Item * static Item *
findmacro(char *name) finditem(char *name, Item *list, int length)
{
int i;
for(i = 0; i < p.macro_len; i++)
if(scmp(p.macros[i].name, name, 0x40))
return &p.macros[i];
return NULL;
}
static Item *
findlabel(char *name)
{ {
int i; int i;
if(name[0] == '&') if(name[0] == '&')
name = makesublabel(name + 1); name = makesublabel(name + 1);
for(i = 0; i < p.label_len; i++) for(i = 0; i < length; i++)
if(scmp(p.labels[i].name, name, 0x40)) if(scmp(list[i].name, name, 0x40))
return &p.labels[i]; return &list[i];
return NULL; return NULL;
} }