(uxnasm) Optimizations
This commit is contained in:
parent
3777f30281
commit
858b38b967
41
src/uxnasm.c
41
src/uxnasm.c
|
@ -156,14 +156,11 @@ makemacro(char *name, FILE *f)
|
||||||
{
|
{
|
||||||
Macro *m;
|
Macro *m;
|
||||||
char word[0x40];
|
char word[0x40];
|
||||||
if(findmacro(name))
|
if(!slen(name)) return error_asm("Macro is empty", name);
|
||||||
return error_asm("Macro duplicate", name);
|
if(findmacro(name)) return error_asm("Macro is duplicate", name);
|
||||||
if(sihx(name) && slen(name) % 2 == 0)
|
if(sihx(name)) return error_asm("Macro is hex number", name);
|
||||||
return error_asm("Macro name is hex number", name);
|
if(isopcode(name)) return error_asm("Macro is opcode", name);
|
||||||
if(isopcode(name) || !slen(name))
|
if(p.macro_len == 0x100) return error_asm("Macros limit exceeded", name);
|
||||||
return error_asm("Macro name is invalid", name);
|
|
||||||
if(p.macro_len == 0x100)
|
|
||||||
return error_asm("Macros limit exceeded", name);
|
|
||||||
m = &p.macros[p.macro_len++];
|
m = &p.macros[p.macro_len++];
|
||||||
scpy(name, m->name, 0x40);
|
scpy(name, m->name, 0x40);
|
||||||
while(fscanf(f, "%63s", word) == 1) {
|
while(fscanf(f, "%63s", word) == 1) {
|
||||||
|
@ -182,16 +179,12 @@ static int
|
||||||
makelabel(char *name)
|
makelabel(char *name)
|
||||||
{
|
{
|
||||||
Label *l;
|
Label *l;
|
||||||
if(findlabel(name))
|
if(!slen(name)) return error_asm("Label is empty", name);
|
||||||
return error_asm("Label duplicate", name);
|
if(findlabel(name)) return error_asm("Label is duplicate", name);
|
||||||
if(sihx(name) && (slen(name) == 2 || slen(name) == 4))
|
if(sihx(name)) return error_asm("Label is hex number", name);
|
||||||
return error_asm("Label name is hex number", name);
|
if(isopcode(name)) return error_asm("Label is opcode", name);
|
||||||
if(isopcode(name) || !slen(name))
|
if(isrune(name[0])) return error_asm("Label name is runic", name);
|
||||||
return error_asm("Label name is invalid", name);
|
if(p.label_len == 0x400) return error_asm("Labels limit exceeded", name);
|
||||||
if(isrune(name[0]))
|
|
||||||
return error_asm("Label name is runic", name);
|
|
||||||
if(p.label_len == 0x400)
|
|
||||||
return error_asm("Labels limit exceeded", name);
|
|
||||||
l = &p.labels[p.label_len++];
|
l = &p.labels[p.label_len++];
|
||||||
l->addr = p.ptr;
|
l->addr = p.ptr;
|
||||||
l->refs = 0;
|
l->refs = 0;
|
||||||
|
@ -262,12 +255,6 @@ writebyte(Uint8 b)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
writeopcode(char *w)
|
|
||||||
{
|
|
||||||
return writebyte(findopcode(w));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
writeshort(Uint16 s, int lit)
|
writeshort(Uint16 s, int lit)
|
||||||
{
|
{
|
||||||
|
@ -396,7 +383,7 @@ parse(char *w, FILE *f)
|
||||||
default:
|
default:
|
||||||
/* opcode */
|
/* opcode */
|
||||||
if(isopcode(w))
|
if(isopcode(w))
|
||||||
return writeopcode(w);
|
return writebyte(findopcode(w));
|
||||||
/* raw byte */
|
/* raw byte */
|
||||||
else if(sihx(w) && slen(w) == 2)
|
else if(sihx(w) && slen(w) == 2)
|
||||||
return writebyte(shex(w));
|
return writebyte(shex(w));
|
||||||
|
@ -481,9 +468,7 @@ review(char *filename)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < p.label_len; i++)
|
for(i = 0; i < p.label_len; i++)
|
||||||
if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
|
if(p.labels[i].name[0] - 'A' > 25 && !p.labels[i].refs)
|
||||||
continue; /* Ignore capitalized labels(devices) */
|
|
||||||
else if(!p.labels[i].refs)
|
|
||||||
fprintf(stdout, "-- Unused label: %s\n", p.labels[i].name);
|
fprintf(stdout, "-- Unused label: %s\n", p.labels[i].name);
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
"Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n",
|
"Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n",
|
||||||
|
|
Loading…
Reference in New Issue