|
@@ -92,43 +92,43 @@ typedef enum {
|
|
|
} PState;
|
|
} PState;
|
|
|
|
|
|
|
|
enum {
|
|
enum {
|
|
|
- TXXX = NPubOp,
|
|
|
|
|
- TCall,
|
|
|
|
|
- TPhi,
|
|
|
|
|
- TJmp,
|
|
|
|
|
- TJnz,
|
|
|
|
|
- TRet,
|
|
|
|
|
- TExport,
|
|
|
|
|
- TFunc,
|
|
|
|
|
- TType,
|
|
|
|
|
- TData,
|
|
|
|
|
- TAlign,
|
|
|
|
|
- TL,
|
|
|
|
|
- TW,
|
|
|
|
|
- TH,
|
|
|
|
|
- TB,
|
|
|
|
|
- TD,
|
|
|
|
|
- TS,
|
|
|
|
|
- TZ,
|
|
|
|
|
|
|
+ Txxx = NPubOp,
|
|
|
|
|
+ Tcall,
|
|
|
|
|
+ Tphi,
|
|
|
|
|
+ Tjmp,
|
|
|
|
|
+ Tjnz,
|
|
|
|
|
+ Tret,
|
|
|
|
|
+ Texport,
|
|
|
|
|
+ Tfunc,
|
|
|
|
|
+ Ttype,
|
|
|
|
|
+ Tdata,
|
|
|
|
|
+ Talign,
|
|
|
|
|
+ Tl,
|
|
|
|
|
+ Tw,
|
|
|
|
|
+ Th,
|
|
|
|
|
+ Tb,
|
|
|
|
|
+ Td,
|
|
|
|
|
+ Ts,
|
|
|
|
|
+ Tz,
|
|
|
|
|
|
|
|
- TInt,
|
|
|
|
|
- TFlts,
|
|
|
|
|
- TFltd,
|
|
|
|
|
- TTmp,
|
|
|
|
|
- TLbl,
|
|
|
|
|
- TGlo,
|
|
|
|
|
|
|
+ Tint,
|
|
|
|
|
+ Tflts,
|
|
|
|
|
+ Tfltd,
|
|
|
|
|
+ Ttmp,
|
|
|
|
|
+ Tlbl,
|
|
|
|
|
+ Tglo,
|
|
|
TTyp,
|
|
TTyp,
|
|
|
TStr,
|
|
TStr,
|
|
|
|
|
|
|
|
- TPlus,
|
|
|
|
|
- TEq,
|
|
|
|
|
- TComma,
|
|
|
|
|
- TLParen,
|
|
|
|
|
- TRParen,
|
|
|
|
|
- TLBrace,
|
|
|
|
|
- TRBrace,
|
|
|
|
|
- TNL,
|
|
|
|
|
- TEOF,
|
|
|
|
|
|
|
+ Tplus,
|
|
|
|
|
+ Teq,
|
|
|
|
|
+ Tcomma,
|
|
|
|
|
+ Tlparen,
|
|
|
|
|
+ Trparen,
|
|
|
|
|
+ Tlbrace,
|
|
|
|
|
+ Trbrace,
|
|
|
|
|
+ Tnl,
|
|
|
|
|
+ Teof,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -174,30 +174,30 @@ lex()
|
|
|
char *str;
|
|
char *str;
|
|
|
int tok;
|
|
int tok;
|
|
|
} tmap[] = {
|
|
} tmap[] = {
|
|
|
- { "call", TCall },
|
|
|
|
|
- { "phi", TPhi },
|
|
|
|
|
- { "jmp", TJmp },
|
|
|
|
|
- { "jnz", TJnz },
|
|
|
|
|
- { "ret", TRet },
|
|
|
|
|
- { "export", TExport },
|
|
|
|
|
- { "function", TFunc },
|
|
|
|
|
- { "type", TType },
|
|
|
|
|
- { "data", TData },
|
|
|
|
|
- { "align", TAlign },
|
|
|
|
|
- { "l", TL },
|
|
|
|
|
- { "w", TW },
|
|
|
|
|
- { "h", TH },
|
|
|
|
|
- { "b", TB },
|
|
|
|
|
- { "d", TD },
|
|
|
|
|
- { "s", TS },
|
|
|
|
|
- { "z", TZ },
|
|
|
|
|
|
|
+ { "call", Tcall },
|
|
|
|
|
+ { "phi", Tphi },
|
|
|
|
|
+ { "jmp", Tjmp },
|
|
|
|
|
+ { "jnz", Tjnz },
|
|
|
|
|
+ { "ret", Tret },
|
|
|
|
|
+ { "export", Texport },
|
|
|
|
|
+ { "function", Tfunc },
|
|
|
|
|
+ { "type", Ttype },
|
|
|
|
|
+ { "data", Tdata },
|
|
|
|
|
+ { "align", Talign },
|
|
|
|
|
+ { "l", Tl },
|
|
|
|
|
+ { "w", Tw },
|
|
|
|
|
+ { "h", Th },
|
|
|
|
|
+ { "b", Tb },
|
|
|
|
|
+ { "d", Td },
|
|
|
|
|
+ { "s", Ts },
|
|
|
|
|
+ { "z", Tz },
|
|
|
{ "loadw", Oload }, /* for convenience */
|
|
{ "loadw", Oload }, /* for convenience */
|
|
|
{ "loadl", Oload },
|
|
{ "loadl", Oload },
|
|
|
{ "loads", Oload },
|
|
{ "loads", Oload },
|
|
|
{ "loadd", Oload },
|
|
{ "loadd", Oload },
|
|
|
{ "alloc1", Oalloc },
|
|
{ "alloc1", Oalloc },
|
|
|
{ "alloc2", Oalloc },
|
|
{ "alloc2", Oalloc },
|
|
|
- { 0, TXXX }
|
|
|
|
|
|
|
+ { 0, Txxx }
|
|
|
};
|
|
};
|
|
|
static char tok[NString];
|
|
static char tok[NString];
|
|
|
int c, i;
|
|
int c, i;
|
|
@@ -206,41 +206,41 @@ lex()
|
|
|
do
|
|
do
|
|
|
c = fgetc(inf);
|
|
c = fgetc(inf);
|
|
|
while (isblank(c));
|
|
while (isblank(c));
|
|
|
- t = TXXX;
|
|
|
|
|
|
|
+ t = Txxx;
|
|
|
tokval.chr = c;
|
|
tokval.chr = c;
|
|
|
switch (c) {
|
|
switch (c) {
|
|
|
case EOF:
|
|
case EOF:
|
|
|
- return TEOF;
|
|
|
|
|
|
|
+ return Teof;
|
|
|
case ',':
|
|
case ',':
|
|
|
- return TComma;
|
|
|
|
|
|
|
+ return Tcomma;
|
|
|
case '(':
|
|
case '(':
|
|
|
- return TLParen;
|
|
|
|
|
|
|
+ return Tlparen;
|
|
|
case ')':
|
|
case ')':
|
|
|
- return TRParen;
|
|
|
|
|
|
|
+ return Trparen;
|
|
|
case '{':
|
|
case '{':
|
|
|
- return TLBrace;
|
|
|
|
|
|
|
+ return Tlbrace;
|
|
|
case '}':
|
|
case '}':
|
|
|
- return TRBrace;
|
|
|
|
|
|
|
+ return Trbrace;
|
|
|
case '=':
|
|
case '=':
|
|
|
- return TEq;
|
|
|
|
|
|
|
+ return Teq;
|
|
|
case '+':
|
|
case '+':
|
|
|
- return TPlus;
|
|
|
|
|
|
|
+ return Tplus;
|
|
|
case 's':
|
|
case 's':
|
|
|
if (fscanf(inf, "_%f", &tokval.flts) != 1)
|
|
if (fscanf(inf, "_%f", &tokval.flts) != 1)
|
|
|
break;
|
|
break;
|
|
|
- return TFlts;
|
|
|
|
|
|
|
+ return Tflts;
|
|
|
case 'd':
|
|
case 'd':
|
|
|
if (fscanf(inf, "_%lf", &tokval.fltd) != 1)
|
|
if (fscanf(inf, "_%lf", &tokval.fltd) != 1)
|
|
|
break;
|
|
break;
|
|
|
- return TFltd;
|
|
|
|
|
|
|
+ return Tfltd;
|
|
|
case '%':
|
|
case '%':
|
|
|
- t = TTmp;
|
|
|
|
|
|
|
+ t = Ttmp;
|
|
|
goto Alpha;
|
|
goto Alpha;
|
|
|
case '@':
|
|
case '@':
|
|
|
- t = TLbl;
|
|
|
|
|
|
|
+ t = Tlbl;
|
|
|
goto Alpha;
|
|
goto Alpha;
|
|
|
case '$':
|
|
case '$':
|
|
|
- t = TGlo;
|
|
|
|
|
|
|
+ t = Tglo;
|
|
|
goto Alpha;
|
|
goto Alpha;
|
|
|
case ':':
|
|
case ':':
|
|
|
t = TTyp;
|
|
t = TTyp;
|
|
@@ -250,13 +250,13 @@ lex()
|
|
|
;
|
|
;
|
|
|
case '\n':
|
|
case '\n':
|
|
|
lnum++;
|
|
lnum++;
|
|
|
- return TNL;
|
|
|
|
|
|
|
+ return Tnl;
|
|
|
}
|
|
}
|
|
|
if (isdigit(c) || c == '-' || c == '+') {
|
|
if (isdigit(c) || c == '-' || c == '+') {
|
|
|
ungetc(c, inf);
|
|
ungetc(c, inf);
|
|
|
if (fscanf(inf, "%"SCNd64, &tokval.num) != 1)
|
|
if (fscanf(inf, "%"SCNd64, &tokval.num) != 1)
|
|
|
err("invalid integer literal");
|
|
err("invalid integer literal");
|
|
|
- return TInt;
|
|
|
|
|
|
|
+ return Tint;
|
|
|
}
|
|
}
|
|
|
if (c == '"') {
|
|
if (c == '"') {
|
|
|
tokval.str = vnew(0, 1);
|
|
tokval.str = vnew(0, 1);
|
|
@@ -287,7 +287,7 @@ Alpha: c = fgetc(inf);
|
|
|
tok[i] = 0;
|
|
tok[i] = 0;
|
|
|
ungetc(c, inf);
|
|
ungetc(c, inf);
|
|
|
tokval.str = tok;
|
|
tokval.str = tok;
|
|
|
- if (t != TXXX) {
|
|
|
|
|
|
|
+ if (t != Txxx) {
|
|
|
return t;
|
|
return t;
|
|
|
}
|
|
}
|
|
|
for (i=0; i<NPubOp; i++)
|
|
for (i=0; i<NPubOp; i++)
|
|
@@ -298,13 +298,13 @@ Alpha: c = fgetc(inf);
|
|
|
if (strcmp(tok, tmap[i].str) == 0)
|
|
if (strcmp(tok, tmap[i].str) == 0)
|
|
|
return tmap[i].tok;
|
|
return tmap[i].tok;
|
|
|
err("unknown keyword %s", tokval.str);
|
|
err("unknown keyword %s", tokval.str);
|
|
|
- return TXXX;
|
|
|
|
|
|
|
+ return Txxx;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
static int
|
|
|
peek()
|
|
peek()
|
|
|
{
|
|
{
|
|
|
- if (thead == TXXX)
|
|
|
|
|
|
|
+ if (thead == Txxx)
|
|
|
thead = lex();
|
|
thead = lex();
|
|
|
return thead;
|
|
return thead;
|
|
|
}
|
|
}
|
|
@@ -315,7 +315,7 @@ next()
|
|
|
int t;
|
|
int t;
|
|
|
|
|
|
|
|
t = peek();
|
|
t = peek();
|
|
|
- thead = TXXX;
|
|
|
|
|
|
|
+ thead = Txxx;
|
|
|
return t;
|
|
return t;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -324,7 +324,7 @@ nextnl()
|
|
|
{
|
|
{
|
|
|
int t;
|
|
int t;
|
|
|
|
|
|
|
|
- while ((t = next()) == TNL)
|
|
|
|
|
|
|
+ while ((t = next()) == Tnl)
|
|
|
;
|
|
;
|
|
|
return t;
|
|
return t;
|
|
|
}
|
|
}
|
|
@@ -333,15 +333,15 @@ static void
|
|
|
expect(int t)
|
|
expect(int t)
|
|
|
{
|
|
{
|
|
|
static char *ttoa[] = {
|
|
static char *ttoa[] = {
|
|
|
- [TLbl] = "label",
|
|
|
|
|
- [TComma] = ",",
|
|
|
|
|
- [TEq] = "=",
|
|
|
|
|
- [TNL] = "newline",
|
|
|
|
|
- [TLParen] = "(",
|
|
|
|
|
- [TRParen] = ")",
|
|
|
|
|
- [TLBrace] = "{",
|
|
|
|
|
- [TRBrace] = "}",
|
|
|
|
|
- [TEOF] = 0,
|
|
|
|
|
|
|
+ [Tlbl] = "label",
|
|
|
|
|
+ [Tcomma] = ",",
|
|
|
|
|
+ [Teq] = "=",
|
|
|
|
|
+ [Tnl] = "newline",
|
|
|
|
|
+ [Tlparen] = "(",
|
|
|
|
|
+ [Trparen] = ")",
|
|
|
|
|
+ [Tlbrace] = "{",
|
|
|
|
|
+ [Trbrace] = "}",
|
|
|
|
|
+ [Teof] = 0,
|
|
|
};
|
|
};
|
|
|
char buf[128], *s1, *s2;
|
|
char buf[128], *s1, *s2;
|
|
|
int t1;
|
|
int t1;
|
|
@@ -376,23 +376,23 @@ parseref()
|
|
|
|
|
|
|
|
memset(&c, 0, sizeof c);
|
|
memset(&c, 0, sizeof c);
|
|
|
switch (next()) {
|
|
switch (next()) {
|
|
|
- case TTmp:
|
|
|
|
|
|
|
+ case Ttmp:
|
|
|
return tmpref(tokval.str);
|
|
return tmpref(tokval.str);
|
|
|
- case TInt:
|
|
|
|
|
|
|
+ case Tint:
|
|
|
c.type = CBits;
|
|
c.type = CBits;
|
|
|
c.bits.i = tokval.num;
|
|
c.bits.i = tokval.num;
|
|
|
goto Look;
|
|
goto Look;
|
|
|
- case TFlts:
|
|
|
|
|
|
|
+ case Tflts:
|
|
|
c.type = CBits;
|
|
c.type = CBits;
|
|
|
c.bits.s = tokval.flts;
|
|
c.bits.s = tokval.flts;
|
|
|
c.flt = 1;
|
|
c.flt = 1;
|
|
|
goto Look;
|
|
goto Look;
|
|
|
- case TFltd:
|
|
|
|
|
|
|
+ case Tfltd:
|
|
|
c.type = CBits;
|
|
c.type = CBits;
|
|
|
c.bits.d = tokval.fltd;
|
|
c.bits.d = tokval.fltd;
|
|
|
c.flt = 2;
|
|
c.flt = 2;
|
|
|
goto Look;
|
|
goto Look;
|
|
|
- case TGlo:
|
|
|
|
|
|
|
+ case Tglo:
|
|
|
c.type = CAddr;
|
|
c.type = CAddr;
|
|
|
strcpy(c.label, tokval.str);
|
|
strcpy(c.label, tokval.str);
|
|
|
Look:
|
|
Look:
|
|
@@ -424,13 +424,13 @@ parsecls(int *tyn)
|
|
|
return 4;
|
|
return 4;
|
|
|
}
|
|
}
|
|
|
err("undefined type");
|
|
err("undefined type");
|
|
|
- case TW:
|
|
|
|
|
|
|
+ case Tw:
|
|
|
return Kw;
|
|
return Kw;
|
|
|
- case TL:
|
|
|
|
|
|
|
+ case Tl:
|
|
|
return Kl;
|
|
return Kl;
|
|
|
- case TS:
|
|
|
|
|
|
|
+ case Ts:
|
|
|
return Ks;
|
|
return Ks;
|
|
|
- case TD:
|
|
|
|
|
|
|
+ case Td:
|
|
|
return Kd;
|
|
return Kd;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -441,8 +441,8 @@ parserefl(int arg)
|
|
|
int k, ty;
|
|
int k, ty;
|
|
|
Ref r;
|
|
Ref r;
|
|
|
|
|
|
|
|
- expect(TLParen);
|
|
|
|
|
- while (peek() != TRParen) {
|
|
|
|
|
|
|
+ expect(Tlparen);
|
|
|
|
|
+ while (peek() != Trparen) {
|
|
|
if (curi - insb >= NIns)
|
|
if (curi - insb >= NIns)
|
|
|
err("too many instructions (1)");
|
|
err("too many instructions (1)");
|
|
|
k = parsecls(&ty);
|
|
k = parsecls(&ty);
|
|
@@ -462,9 +462,9 @@ parserefl(int arg)
|
|
|
else
|
|
else
|
|
|
*curi = (Ins){Opar, r, {R}, k};
|
|
*curi = (Ins){Opar, r, {R}, k};
|
|
|
curi++;
|
|
curi++;
|
|
|
- if (peek() == TRParen)
|
|
|
|
|
|
|
+ if (peek() == Trparen)
|
|
|
break;
|
|
break;
|
|
|
- expect(TComma);
|
|
|
|
|
|
|
+ expect(Tcomma);
|
|
|
}
|
|
}
|
|
|
next();
|
|
next();
|
|
|
}
|
|
}
|
|
@@ -504,23 +504,23 @@ parseline(PState ps)
|
|
|
int t, op, i, k, ty;
|
|
int t, op, i, k, ty;
|
|
|
|
|
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (ps == PLbl && t != TLbl && t != TRBrace)
|
|
|
|
|
|
|
+ if (ps == PLbl && t != Tlbl && t != Trbrace)
|
|
|
err("label or } expected");
|
|
err("label or } expected");
|
|
|
switch (t) {
|
|
switch (t) {
|
|
|
default:
|
|
default:
|
|
|
if (isstore(t)) {
|
|
if (isstore(t)) {
|
|
|
/* operations without result */
|
|
/* operations without result */
|
|
|
r = R;
|
|
r = R;
|
|
|
- k = 0;
|
|
|
|
|
|
|
+ k = Kw;
|
|
|
op = t;
|
|
op = t;
|
|
|
goto DoOp;
|
|
goto DoOp;
|
|
|
}
|
|
}
|
|
|
err("label, instruction or jump expected");
|
|
err("label, instruction or jump expected");
|
|
|
- case TRBrace:
|
|
|
|
|
|
|
+ case Trbrace:
|
|
|
return PEnd;
|
|
return PEnd;
|
|
|
- case TTmp:
|
|
|
|
|
|
|
+ case Ttmp:
|
|
|
break;
|
|
break;
|
|
|
- case TLbl:
|
|
|
|
|
|
|
+ case Tlbl:
|
|
|
b = findblk(tokval.str);
|
|
b = findblk(tokval.str);
|
|
|
if (curb && curb->jmp.type == Jxxx) {
|
|
if (curb && curb->jmp.type == Jxxx) {
|
|
|
closeblk();
|
|
closeblk();
|
|
@@ -532,9 +532,9 @@ parseline(PState ps)
|
|
|
*blink = b;
|
|
*blink = b;
|
|
|
curb = b;
|
|
curb = b;
|
|
|
plink = &curb->phi;
|
|
plink = &curb->phi;
|
|
|
- expect(TNL);
|
|
|
|
|
|
|
+ expect(Tnl);
|
|
|
return PPhi;
|
|
return PPhi;
|
|
|
- case TRet:
|
|
|
|
|
|
|
+ case Tret:
|
|
|
curb->jmp.type = (int[]){
|
|
curb->jmp.type = (int[]){
|
|
|
Jretw, Jretl,
|
|
Jretw, Jretl,
|
|
|
Jrets, Jretd,
|
|
Jrets, Jretd,
|
|
@@ -547,45 +547,45 @@ parseline(PState ps)
|
|
|
curb->jmp.arg = r;
|
|
curb->jmp.arg = r;
|
|
|
}
|
|
}
|
|
|
goto Close;
|
|
goto Close;
|
|
|
- case TJmp:
|
|
|
|
|
|
|
+ case Tjmp:
|
|
|
curb->jmp.type = Jjmp;
|
|
curb->jmp.type = Jjmp;
|
|
|
goto Jump;
|
|
goto Jump;
|
|
|
- case TJnz:
|
|
|
|
|
|
|
+ case Tjnz:
|
|
|
curb->jmp.type = Jjnz;
|
|
curb->jmp.type = Jjnz;
|
|
|
r = parseref();
|
|
r = parseref();
|
|
|
if (req(r, R))
|
|
if (req(r, R))
|
|
|
err("invalid argument for jnz jump");
|
|
err("invalid argument for jnz jump");
|
|
|
curb->jmp.arg = r;
|
|
curb->jmp.arg = r;
|
|
|
- expect(TComma);
|
|
|
|
|
|
|
+ expect(Tcomma);
|
|
|
Jump:
|
|
Jump:
|
|
|
- expect(TLbl);
|
|
|
|
|
|
|
+ expect(Tlbl);
|
|
|
curb->s1 = findblk(tokval.str);
|
|
curb->s1 = findblk(tokval.str);
|
|
|
if (curb->jmp.type != Jjmp) {
|
|
if (curb->jmp.type != Jjmp) {
|
|
|
- expect(TComma);
|
|
|
|
|
- expect(TLbl);
|
|
|
|
|
|
|
+ expect(Tcomma);
|
|
|
|
|
+ expect(Tlbl);
|
|
|
curb->s2 = findblk(tokval.str);
|
|
curb->s2 = findblk(tokval.str);
|
|
|
}
|
|
}
|
|
|
if (curb->s1 == curf->start || curb->s2 == curf->start)
|
|
if (curb->s1 == curf->start || curb->s2 == curf->start)
|
|
|
err("invalid jump to the start node");
|
|
err("invalid jump to the start node");
|
|
|
Close:
|
|
Close:
|
|
|
- expect(TNL);
|
|
|
|
|
|
|
+ expect(Tnl);
|
|
|
closeblk();
|
|
closeblk();
|
|
|
return PLbl;
|
|
return PLbl;
|
|
|
}
|
|
}
|
|
|
r = tmpref(tokval.str);
|
|
r = tmpref(tokval.str);
|
|
|
- expect(TEq);
|
|
|
|
|
|
|
+ expect(Teq);
|
|
|
k = parsecls(&ty);
|
|
k = parsecls(&ty);
|
|
|
op = next();
|
|
op = next();
|
|
|
DoOp:
|
|
DoOp:
|
|
|
- if (op == TPhi) {
|
|
|
|
|
|
|
+ if (op == Tphi) {
|
|
|
if (ps != PPhi)
|
|
if (ps != PPhi)
|
|
|
err("unexpected phi instruction");
|
|
err("unexpected phi instruction");
|
|
|
op = -1;
|
|
op = -1;
|
|
|
}
|
|
}
|
|
|
- if (op == TCall) {
|
|
|
|
|
|
|
+ if (op == Tcall) {
|
|
|
arg[0] = parseref();
|
|
arg[0] = parseref();
|
|
|
parserefl(1);
|
|
parserefl(1);
|
|
|
- expect(TNL);
|
|
|
|
|
|
|
+ expect(Tnl);
|
|
|
op = Ocall;
|
|
op = Ocall;
|
|
|
if (k == 4) {
|
|
if (k == 4) {
|
|
|
k = Kl;
|
|
k = Kl;
|
|
@@ -599,12 +599,12 @@ DoOp:
|
|
|
if (op >= NPubOp)
|
|
if (op >= NPubOp)
|
|
|
err("invalid instruction");
|
|
err("invalid instruction");
|
|
|
i = 0;
|
|
i = 0;
|
|
|
- if (peek() != TNL)
|
|
|
|
|
|
|
+ if (peek() != Tnl)
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
if (i == NPred)
|
|
if (i == NPred)
|
|
|
err("too many arguments");
|
|
err("too many arguments");
|
|
|
if (op == -1) {
|
|
if (op == -1) {
|
|
|
- expect(TLbl);
|
|
|
|
|
|
|
+ expect(Tlbl);
|
|
|
blk[i] = findblk(tokval.str);
|
|
blk[i] = findblk(tokval.str);
|
|
|
}
|
|
}
|
|
|
arg[i] = parseref();
|
|
arg[i] = parseref();
|
|
@@ -612,9 +612,9 @@ DoOp:
|
|
|
err("invalid instruction argument");
|
|
err("invalid instruction argument");
|
|
|
i++;
|
|
i++;
|
|
|
t = peek();
|
|
t = peek();
|
|
|
- if (t == TNL)
|
|
|
|
|
|
|
+ if (t == Tnl)
|
|
|
break;
|
|
break;
|
|
|
- if (t != TComma)
|
|
|
|
|
|
|
+ if (t != Tcomma)
|
|
|
err(", or end of line expected");
|
|
err(", or end of line expected");
|
|
|
next();
|
|
next();
|
|
|
}
|
|
}
|
|
@@ -759,15 +759,15 @@ parsefn(int export)
|
|
|
curf->export = export;
|
|
curf->export = export;
|
|
|
blink = &curf->start;
|
|
blink = &curf->start;
|
|
|
curf->retty = Kx;
|
|
curf->retty = Kx;
|
|
|
- if (peek() != TGlo)
|
|
|
|
|
|
|
+ if (peek() != Tglo)
|
|
|
rcls = parsecls(&curf->retty);
|
|
rcls = parsecls(&curf->retty);
|
|
|
else
|
|
else
|
|
|
rcls = 5;
|
|
rcls = 5;
|
|
|
- if (next() != TGlo)
|
|
|
|
|
|
|
+ if (next() != Tglo)
|
|
|
err("function name expected");
|
|
err("function name expected");
|
|
|
strcpy(curf->name, tokval.str);
|
|
strcpy(curf->name, tokval.str);
|
|
|
parserefl(0);
|
|
parserefl(0);
|
|
|
- if (nextnl() != TLBrace)
|
|
|
|
|
|
|
+ if (nextnl() != Tlbrace)
|
|
|
err("function body must start with {");
|
|
err("function body must start with {");
|
|
|
ps = PLbl;
|
|
ps = PLbl;
|
|
|
do
|
|
do
|
|
@@ -795,22 +795,22 @@ parsetyp()
|
|
|
err("too many type definitions");
|
|
err("too many type definitions");
|
|
|
ty = &typ[ntyp++];
|
|
ty = &typ[ntyp++];
|
|
|
ty->align = -1;
|
|
ty->align = -1;
|
|
|
- if (nextnl() != TTyp || nextnl() != TEq)
|
|
|
|
|
|
|
+ if (nextnl() != TTyp || nextnl() != Teq)
|
|
|
err("type name, then = expected");
|
|
err("type name, then = expected");
|
|
|
strcpy(ty->name, tokval.str);
|
|
strcpy(ty->name, tokval.str);
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (t == TAlign) {
|
|
|
|
|
- if (nextnl() != TInt)
|
|
|
|
|
|
|
+ if (t == Talign) {
|
|
|
|
|
+ if (nextnl() != Tint)
|
|
|
err("alignment expected");
|
|
err("alignment expected");
|
|
|
for (al=0; tokval.num /= 2; al++)
|
|
for (al=0; tokval.num /= 2; al++)
|
|
|
;
|
|
;
|
|
|
ty->align = al;
|
|
ty->align = al;
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
}
|
|
}
|
|
|
- if (t != TLBrace)
|
|
|
|
|
|
|
+ if (t != Tlbrace)
|
|
|
err("type body must start with {");
|
|
err("type body must start with {");
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (t == TInt) {
|
|
|
|
|
|
|
+ if (t == Tint) {
|
|
|
ty->dark = 1;
|
|
ty->dark = 1;
|
|
|
ty->size = tokval.num;
|
|
ty->size = tokval.num;
|
|
|
if (ty->align == -1)
|
|
if (ty->align == -1)
|
|
@@ -821,16 +821,16 @@ parsetyp()
|
|
|
n = -1;
|
|
n = -1;
|
|
|
sz = 0;
|
|
sz = 0;
|
|
|
al = 0;
|
|
al = 0;
|
|
|
- while (t != TRBrace) {
|
|
|
|
|
|
|
+ while (t != Trbrace) {
|
|
|
flt = 0;
|
|
flt = 0;
|
|
|
switch (t) {
|
|
switch (t) {
|
|
|
default: err("invalid size specifier %c", tokval.chr);
|
|
default: err("invalid size specifier %c", tokval.chr);
|
|
|
- case TD: flt = 1;
|
|
|
|
|
- case TL: s = 8; a = 3; break;
|
|
|
|
|
- case TS: flt = 1;
|
|
|
|
|
- case TW: s = 4; a = 2; break;
|
|
|
|
|
- case TH: s = 2; a = 1; break;
|
|
|
|
|
- case TB: s = 1; a = 0; break;
|
|
|
|
|
|
|
+ case Td: flt = 1;
|
|
|
|
|
+ case Tl: s = 8; a = 3; break;
|
|
|
|
|
+ case Ts: flt = 1;
|
|
|
|
|
+ case Tw: s = 4; a = 2; break;
|
|
|
|
|
+ case Th: s = 2; a = 1; break;
|
|
|
|
|
+ case Tb: s = 1; a = 0; break;
|
|
|
}
|
|
}
|
|
|
if (a > al)
|
|
if (a > al)
|
|
|
al = a;
|
|
al = a;
|
|
@@ -843,7 +843,7 @@ parsetyp()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (t == TInt) {
|
|
|
|
|
|
|
+ if (t == Tint) {
|
|
|
c = tokval.num;
|
|
c = tokval.num;
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
} else
|
|
} else
|
|
@@ -856,7 +856,7 @@ parsetyp()
|
|
|
}
|
|
}
|
|
|
sz += a + s;
|
|
sz += a + s;
|
|
|
}
|
|
}
|
|
|
- if (t != TComma)
|
|
|
|
|
|
|
+ if (t != Tcomma)
|
|
|
break;
|
|
break;
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
}
|
|
}
|
|
@@ -871,7 +871,7 @@ parsetyp()
|
|
|
a = (1 << al) - 1;
|
|
a = (1 << al) - 1;
|
|
|
ty->size = (sz + a) & ~a;
|
|
ty->size = (sz + a) & ~a;
|
|
|
}
|
|
}
|
|
|
- if (t != TRBrace)
|
|
|
|
|
|
|
+ if (t != Trbrace)
|
|
|
err(", or } expected");
|
|
err(", or } expected");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -884,9 +884,9 @@ parsedatref(Dat *d)
|
|
|
d->u.ref.nam = tokval.str;
|
|
d->u.ref.nam = tokval.str;
|
|
|
d->u.ref.off = 0;
|
|
d->u.ref.off = 0;
|
|
|
t = peek();
|
|
t = peek();
|
|
|
- if (t == TPlus) {
|
|
|
|
|
|
|
+ if (t == Tplus) {
|
|
|
next();
|
|
next();
|
|
|
- if (next() != TInt)
|
|
|
|
|
|
|
+ if (next() != Tint)
|
|
|
err("invalid token after offset in ref");
|
|
err("invalid token after offset in ref");
|
|
|
d->u.ref.off = tokval.num;
|
|
d->u.ref.off = tokval.num;
|
|
|
}
|
|
}
|
|
@@ -911,12 +911,12 @@ parsedat(void cb(Dat *), int export)
|
|
|
d.isref = 0;
|
|
d.isref = 0;
|
|
|
d.export = export;
|
|
d.export = export;
|
|
|
cb(&d);
|
|
cb(&d);
|
|
|
- if (nextnl() != TGlo || nextnl() != TEq)
|
|
|
|
|
|
|
+ if (nextnl() != Tglo || nextnl() != Teq)
|
|
|
err("data name, then = expected");
|
|
err("data name, then = expected");
|
|
|
strcpy(s, tokval.str);
|
|
strcpy(s, tokval.str);
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (t == TAlign) {
|
|
|
|
|
- if (nextnl() != TInt)
|
|
|
|
|
|
|
+ if (t == Talign) {
|
|
|
|
|
+ if (nextnl() != Tint)
|
|
|
err("alignment expected");
|
|
err("alignment expected");
|
|
|
d.type = DAlign;
|
|
d.type = DAlign;
|
|
|
d.u.num = tokval.num;
|
|
d.u.num = tokval.num;
|
|
@@ -927,32 +927,32 @@ parsedat(void cb(Dat *), int export)
|
|
|
d.u.str = s;
|
|
d.u.str = s;
|
|
|
cb(&d);
|
|
cb(&d);
|
|
|
|
|
|
|
|
- if (t != TLBrace)
|
|
|
|
|
|
|
+ if (t != Tlbrace)
|
|
|
err("expected data contents in { .. }");
|
|
err("expected data contents in { .. }");
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
switch (nextnl()) {
|
|
switch (nextnl()) {
|
|
|
default: err("invalid size specifier %c in data", tokval.chr);
|
|
default: err("invalid size specifier %c in data", tokval.chr);
|
|
|
- case TRBrace: goto Done;
|
|
|
|
|
- case TL: d.type = DL; break;
|
|
|
|
|
- case TW: d.type = DW; break;
|
|
|
|
|
- case TH: d.type = DH; break;
|
|
|
|
|
- case TB: d.type = DB; break;
|
|
|
|
|
- case TS: d.type = DW; break;
|
|
|
|
|
- case TD: d.type = DL; break;
|
|
|
|
|
- case TZ: d.type = DZ; break;
|
|
|
|
|
|
|
+ case Trbrace: goto Done;
|
|
|
|
|
+ case Tl: d.type = DL; break;
|
|
|
|
|
+ case Tw: d.type = DW; break;
|
|
|
|
|
+ case Th: d.type = DH; break;
|
|
|
|
|
+ case Tb: d.type = DB; break;
|
|
|
|
|
+ case Ts: d.type = DW; break;
|
|
|
|
|
+ case Td: d.type = DL; break;
|
|
|
|
|
+ case Tz: d.type = DZ; break;
|
|
|
}
|
|
}
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
do {
|
|
do {
|
|
|
d.isref = 0;
|
|
d.isref = 0;
|
|
|
d.isstr = 0;
|
|
d.isstr = 0;
|
|
|
memset(&d.u, 0, sizeof d.u);
|
|
memset(&d.u, 0, sizeof d.u);
|
|
|
- if (t == TFlts)
|
|
|
|
|
|
|
+ if (t == Tflts)
|
|
|
d.u.flts = tokval.flts;
|
|
d.u.flts = tokval.flts;
|
|
|
- else if (t == TFltd)
|
|
|
|
|
|
|
+ else if (t == Tfltd)
|
|
|
d.u.fltd = tokval.fltd;
|
|
d.u.fltd = tokval.fltd;
|
|
|
- else if (t == TInt)
|
|
|
|
|
|
|
+ else if (t == Tint)
|
|
|
d.u.num = tokval.num;
|
|
d.u.num = tokval.num;
|
|
|
- else if (t == TGlo)
|
|
|
|
|
|
|
+ else if (t == Tglo)
|
|
|
parsedatref(&d);
|
|
parsedatref(&d);
|
|
|
else if (t == TStr)
|
|
else if (t == TStr)
|
|
|
parsedatstr(&d);
|
|
parsedatstr(&d);
|
|
@@ -960,10 +960,10 @@ parsedat(void cb(Dat *), int export)
|
|
|
err("constant literal expected");
|
|
err("constant literal expected");
|
|
|
cb(&d);
|
|
cb(&d);
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- } while (t == TInt || t == TFlts || t == TFltd);
|
|
|
|
|
- if (t == TRBrace)
|
|
|
|
|
|
|
+ } while (t == Tint || t == Tflts || t == Tfltd);
|
|
|
|
|
+ if (t == Trbrace)
|
|
|
break;
|
|
break;
|
|
|
- if (t != TComma)
|
|
|
|
|
|
|
+ if (t != Tcomma)
|
|
|
err(", or } expected");
|
|
err(", or } expected");
|
|
|
}
|
|
}
|
|
|
Done:
|
|
Done:
|
|
@@ -979,32 +979,32 @@ parse(FILE *f, char *path, void data(Dat *), void func(Fn *))
|
|
|
inf = f;
|
|
inf = f;
|
|
|
inpath = path;
|
|
inpath = path;
|
|
|
lnum = 1;
|
|
lnum = 1;
|
|
|
- thead = TXXX;
|
|
|
|
|
|
|
+ thead = Txxx;
|
|
|
ntyp = 0;
|
|
ntyp = 0;
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
export = 0;
|
|
export = 0;
|
|
|
switch (nextnl()) {
|
|
switch (nextnl()) {
|
|
|
default:
|
|
default:
|
|
|
err("top-level definition expected");
|
|
err("top-level definition expected");
|
|
|
- case TExport:
|
|
|
|
|
|
|
+ case Texport:
|
|
|
export = 1;
|
|
export = 1;
|
|
|
t = nextnl();
|
|
t = nextnl();
|
|
|
- if (t == TFunc) {
|
|
|
|
|
- case TFunc:
|
|
|
|
|
|
|
+ if (t == Tfunc) {
|
|
|
|
|
+ case Tfunc:
|
|
|
func(parsefn(export));
|
|
func(parsefn(export));
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- else if (t == TData) {
|
|
|
|
|
- case TData:
|
|
|
|
|
|
|
+ else if (t == Tdata) {
|
|
|
|
|
+ case Tdata:
|
|
|
parsedat(data, export);
|
|
parsedat(data, export);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
err("export can only qualify data and function");
|
|
err("export can only qualify data and function");
|
|
|
- case TType:
|
|
|
|
|
|
|
+ case Ttype:
|
|
|
parsetyp();
|
|
parsetyp();
|
|
|
break;
|
|
break;
|
|
|
- case TEOF:
|
|
|
|
|
|
|
+ case Teof:
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|