Removed optimizations from uxnasm

This commit is contained in:
Devine Lu Linvega 2022-08-06 12:17:34 -07:00
parent 7a12088bbe
commit d60c5a01b0
1 changed files with 2 additions and 19 deletions

View File

@ -44,8 +44,6 @@ typedef struct {
} Program; } Program;
Program p; Program p;
static int litlast = 0;
static int jsrlast = 0;
/* clang-format off */ /* clang-format off */
@ -207,8 +205,6 @@ writebyte(Uint8 b)
return error("Memory overwrite", ""); return error("Memory overwrite", "");
p.data[p.ptr++] = b; p.data[p.ptr++] = b;
p.length = p.ptr; p.length = p.ptr;
litlast = 0;
jsrlast = 0;
return 1; return 1;
} }
@ -217,8 +213,6 @@ writeopcode(char *w)
{ {
Uint8 res; Uint8 res;
res = writebyte(findopcode(w)); res = writebyte(findopcode(w));
if(scmp(w, "JSR2", 4))
jsrlast = 1;
return res; return res;
} }
@ -233,15 +227,8 @@ writeshort(Uint16 s, int lit)
static int static int
writelitbyte(Uint8 b) writelitbyte(Uint8 b)
{ {
if(litlast) { /* literals optimization */
Uint8 hb = p.data[p.ptr - 1];
p.ptr -= 2;
p.length = p.ptr;
return writeshort((hb << 8) + b, 1);
}
if(!writebyte(findopcode("LIT"))) return 0; if(!writebyte(findopcode("LIT"))) return 0;
if(!writebyte(b)) return 0; if(!writebyte(b)) return 0;
litlast = 1;
return 1; return 1;
} }
@ -292,24 +279,20 @@ parse(char *w, FILE *f)
if(!sihx(w + 1)) if(!sihx(w + 1))
return error("Invalid padding", w); return error("Invalid padding", w);
p.ptr = shex(w + 1); p.ptr = shex(w + 1);
litlast = jsrlast = 0;
break; break;
case '$': /* pad-relative */ case '$': /* pad-relative */
if(!sihx(w + 1)) if(!sihx(w + 1))
return error("Invalid padding", w); return error("Invalid padding", w);
p.ptr += shex(w + 1); p.ptr += shex(w + 1);
litlast = jsrlast = 0;
break; break;
case '@': /* label */ case '@': /* label */
if(!makelabel(w + 1)) if(!makelabel(w + 1))
return error("Invalid label", w); return error("Invalid label", w);
scpy(w + 1, p.scope, 0x40); scpy(w + 1, p.scope, 0x40);
litlast = jsrlast = 0;
break; break;
case '&': /* sublabel */ case '&': /* sublabel */
if(!makelabel(sublabel(subw, p.scope, w + 1))) if(!makelabel(sublabel(subw, p.scope, w + 1)))
return error("Invalid sublabel", w); return error("Invalid sublabel", w);
litlast = jsrlast = 0;
break; break;
case '#': /* literals hex */ case '#': /* literals hex */
if(!sihx(w + 1) || (slen(w) != 3 && slen(w) != 5)) if(!sihx(w + 1) || (slen(w) != 3 && slen(w) != 5))
@ -321,11 +304,11 @@ parse(char *w, FILE *f)
} }
break; break;
case '.': /* literal byte zero-page */ case '.': /* literal byte zero-page */
makereference(p.scope, w, p.ptr - litlast); makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0; if(!writelitbyte(0xff)) return 0;
break; break;
case ',': /* literal byte relative */ case ',': /* literal byte relative */
makereference(p.scope, w, p.ptr - litlast); makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0; if(!writelitbyte(0xff)) return 0;
break; break;
case ';': /* literal short absolute */ case ';': /* literal short absolute */