Allow more tokens in the assembler.
I need this so I can add more %token lines to mach/powerpc/as/mach2.c The assembler's tempfile encoded each token in a byte. This only worked with tokens 0 to 127 and 256 and 383. If a token 384 or higher existed, the assembler stopped working. I need tokens 384 and higher. I change the token encoding to a 2-byte little-endian integer. I also change a byte in the string encoding.
This commit is contained in:
parent
ba2a03705e
commit
f705339f86
|
@ -22,7 +22,7 @@ static int infbsym(char *);
|
||||||
int
|
int
|
||||||
yylex(void)
|
yylex(void)
|
||||||
{
|
{
|
||||||
register c;
|
int c, c0, c1;
|
||||||
|
|
||||||
if (pass == PASS_1) {
|
if (pass == PASS_1) {
|
||||||
/* scan the input file */
|
/* scan the input file */
|
||||||
|
@ -59,20 +59,25 @@ yylex(void)
|
||||||
/* produce the intermediate token file */
|
/* produce the intermediate token file */
|
||||||
if (c <= 0)
|
if (c <= 0)
|
||||||
return(0);
|
return(0);
|
||||||
if (c <= 127)
|
if (c < 256) {
|
||||||
putc(c, tempfile);
|
putc(c, tempfile);
|
||||||
else
|
putc(0, tempfile);
|
||||||
|
} else {
|
||||||
putval(c);
|
putval(c);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* read from intermediate token file */
|
/* read from intermediate token file */
|
||||||
c = getc(tempfile);
|
c0 = getc(tempfile);
|
||||||
if (c == EOF)
|
if (c0 == EOF)
|
||||||
return(0);
|
return(0);
|
||||||
if (c > 127) {
|
c1 = getc(tempfile);
|
||||||
c += 128;
|
if (c1 == EOF)
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
c = c0 + (c1 << 8);
|
||||||
|
if (c >= 256)
|
||||||
c = getval(c);
|
c = getval(c);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
curr_token = c;
|
curr_token = c;
|
||||||
return(c);
|
return(c);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +89,7 @@ putval(int c)
|
||||||
register n = 0;
|
register n = 0;
|
||||||
register char *p = 0;
|
register char *p = 0;
|
||||||
|
|
||||||
assert(c >= 256 && c < 256+128);
|
assert(c == (c & 0xffff));
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case CODE1:
|
case CODE1:
|
||||||
n = 1; goto putnum;
|
n = 1; goto putnum;
|
||||||
|
@ -99,9 +104,11 @@ putval(int c)
|
||||||
break;
|
break;
|
||||||
v >>= 8;
|
v >>= 8;
|
||||||
}
|
}
|
||||||
|
assert(n <= 4);
|
||||||
c = NUMBER0 + n;
|
c = NUMBER0 + n;
|
||||||
putnum:
|
putnum:
|
||||||
putc(c-128, tempfile);
|
putc(c, tempfile);
|
||||||
|
putc(c >> 8, tempfile);
|
||||||
v = yylval.y_valu;
|
v = yylval.y_valu;
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
putc((int) (v >> (n*8)), tempfile);
|
putc((int) (v >> (n*8)), tempfile);
|
||||||
|
@ -117,14 +124,15 @@ putval(int c)
|
||||||
#endif
|
#endif
|
||||||
case STRING:
|
case STRING:
|
||||||
v = stringlen;
|
v = stringlen;
|
||||||
putc(c-128, tempfile);
|
putc(c, tempfile);
|
||||||
|
putc(c >> 8, tempfile);
|
||||||
for (n = 0; n < sizeof(v); n++) {
|
for (n = 0; n < sizeof(v); n++) {
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
break;
|
break;
|
||||||
v >>= 8;
|
v >>= 8;
|
||||||
}
|
}
|
||||||
c = NUMBER0 + n;
|
assert(n <= 4);
|
||||||
putc(c-128, tempfile);
|
putc(n, tempfile);
|
||||||
v = stringlen;
|
v = stringlen;
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
putc((int) (v >> (n*8)), tempfile);
|
putc((int) (v >> (n*8)), tempfile);
|
||||||
|
@ -146,7 +154,8 @@ putval(int c)
|
||||||
n = sizeof(word_t);
|
n = sizeof(word_t);
|
||||||
p = (char *) &yylval.y_word; break;
|
p = (char *) &yylval.y_word; break;
|
||||||
}
|
}
|
||||||
putc(c-128, tempfile);
|
putc(c, tempfile);
|
||||||
|
putc(c >> 8, tempfile);
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
putc(*p++, tempfile);
|
putc(*p++, tempfile);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +202,7 @@ getval(int c)
|
||||||
p = (char *) &yylval.y_strp; break;
|
p = (char *) &yylval.y_strp; break;
|
||||||
#endif
|
#endif
|
||||||
case STRING:
|
case STRING:
|
||||||
getval(getc(tempfile)+128);
|
getval(getc(tempfile)+NUMBER0);
|
||||||
stringlen = n = yylval.y_valu;
|
stringlen = n = yylval.y_valu;
|
||||||
p = stringbuf;
|
p = stringbuf;
|
||||||
p[n] = '\0'; break;
|
p[n] = '\0'; break;
|
||||||
|
|
Loading…
Reference in a new issue