(uxnasm) Warn for refs size limit

This commit is contained in:
neauoire 2021-11-27 14:44:28 -08:00
parent 78853ac5c6
commit b4e50165b6
1 changed files with 27 additions and 23 deletions

View File

@ -72,6 +72,12 @@ error(const char *name, const char *msg)
return 0; return 0;
} }
static char *
sublabel(char *src, char *scope, char *name)
{
return scat(scat(scpy(scope, src, 64), "/"), name);
}
static Macro * static Macro *
findmacro(char *name) findmacro(char *name)
{ {
@ -161,6 +167,23 @@ makelabel(char *name)
return 1; return 1;
} }
static int
makereference(char *scope, char *label, Uint16 addr)
{
char subw[64];
Reference *r;
if(p.rlen == 2048)
return error("Too many references", label);
r = &p.refs[p.rlen++];
if(label[1] == '&')
scpy(sublabel(subw, scope, label + 2), r->name, 64);
else
scpy(label + 1, r->name, 64);
r->rune = label[0];
r->addr = addr;
return 1;
}
static void static void
writebyte(Uint8 b) writebyte(Uint8 b)
{ {
@ -192,25 +215,6 @@ writelitbyte(Uint8 b)
litlast = 1; litlast = 1;
} }
static char *
sublabel(char *src, char *scope, char *name)
{
return scat(scat(scpy(scope, src, 64), "/"), name);
}
static void
prefill(char *scope, char *label, Uint16 addr)
{
char subw[64];
Reference *r = &p.refs[p.rlen++];
if(label[1] == '&')
scpy(sublabel(subw, scope, label + 2), r->name, 64);
else
scpy(label + 1, r->name, 64);
r->rune = label[0];
r->addr = addr;
}
static int static int
doinclude(const char *filename) doinclude(const char *filename)
{ {
@ -274,19 +278,19 @@ tokenize(char *w, FILE *f)
writeshort(shex(w + 1), 1); writeshort(shex(w + 1), 1);
break; break;
case '.': /* literal byte zero-page */ case '.': /* literal byte zero-page */
prefill(p.scope, w, p.ptr - litlast); makereference(p.scope, w, p.ptr - litlast);
writelitbyte(0xff); writelitbyte(0xff);
break; break;
case ',': /* literal byte relative */ case ',': /* literal byte relative */
prefill(p.scope, w, p.ptr - litlast); makereference(p.scope, w, p.ptr - litlast);
writelitbyte(0xff); writelitbyte(0xff);
break; break;
case ';': /* literal short absolute */ case ';': /* literal short absolute */
prefill(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
writeshort(0xffff, 1); writeshort(0xffff, 1);
break; break;
case ':': /* raw short absolute */ case ':': /* raw short absolute */
prefill(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
writeshort(0xffff, 0); writeshort(0xffff, 0);
break; break;
case '\'': /* raw char */ case '\'': /* raw char */