Commit d69d0fe9 authored by Shenghou Ma's avatar Shenghou Ma

liblink, cmd/dist, cmd/5l: introduce %^ and move C_* constants.

The helps certain diagnostics and also removed duplicated enums as a side effect.

LGTM=dave, rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/115060044
parent ae027f52
......@@ -107,7 +107,7 @@ struct Prog
uchar back; // 6l, 8l
uchar ft; /* 6l, 8l oclass cache */
uchar tt; // 6l, 8l
uchar optab; // 5l
uint16 optab; // 5l
uchar isize; // 6l, 8l
char width; /* fake for DATA */
......@@ -405,7 +405,7 @@ struct Link
int asmode;
uchar* andptr;
uchar and[100];
int32 instoffset;
int64 instoffset;
int32 autosize;
int32 armsize;
......@@ -608,6 +608,8 @@ extern char* anames5[];
extern char* anames6[];
extern char* anames8[];
extern char* cnames5[];
extern LinkArch link386;
extern LinkArch linkamd64;
extern LinkArch linkamd64p32;
......@@ -618,6 +620,7 @@ extern LinkArch linkarm;
#pragma varargck type "lD" Addr*
#pragma varargck type "P" Prog*
#pragma varargck type "R" int
#pragma varargck type "^" int
// TODO(ality): remove this workaround.
// It's here because Pconv in liblink/list?.c references %L.
......
......@@ -64,6 +64,57 @@ enum
/* compiler allocates register variables F0 up */
/* compiler allocates external registers F7 down */
enum
{
C_NONE,
C_REG,
C_REGREG,
C_REGREG2,
C_SHIFT,
C_FREG,
C_PSR,
C_FCR,
C_RCON, /* 0xff rotated */
C_NCON, /* ~RCON */
C_SCON, /* 0xffff */
C_LCON,
C_LCONADDR,
C_ZFCON,
C_SFCON,
C_LFCON,
C_RACON,
C_LACON,
C_SBRA,
C_LBRA,
C_HAUTO, /* halfword insn offset (-0xff to 0xff) */
C_FAUTO, /* float insn offset (0 to 0x3fc, word aligned) */
C_HFAUTO, /* both H and F */
C_SAUTO, /* -0xfff to 0xfff */
C_LAUTO,
C_HOREG,
C_FOREG,
C_HFOREG,
C_SOREG,
C_ROREG,
C_SROREG, /* both nil and R */
C_LOREG,
C_PC,
C_SP,
C_HREG,
C_ADDR, /* reference to relocatable address */
C_GOK,
C_NCLASS, /* must be the last */
};
enum
{
AXXX,
......
......@@ -59,52 +59,6 @@ enum
LEAF = 1<<2,
MINLC = 4,
C_NONE = 0,
C_REG,
C_REGREG,
C_REGREG2,
C_SHIFT,
C_FREG,
C_PSR,
C_FCR,
C_RCON, /* 0xff rotated */
C_NCON, /* ~RCON */
C_SCON, /* 0xffff */
C_LCON,
C_LCONADDR,
C_ZFCON,
C_SFCON,
C_LFCON,
C_RACON,
C_LACON,
C_SBRA,
C_LBRA,
C_HAUTO, /* halfword insn offset (-0xff to 0xff) */
C_FAUTO, /* float insn offset (0 to 0x3fc, word aligned) */
C_HFAUTO, /* both H and F */
C_SAUTO, /* -0xfff to 0xfff */
C_LAUTO,
C_HOREG,
C_FOREG,
C_HFOREG,
C_SOREG,
C_ROREG,
C_SROREG, /* both nil and R */
C_LOREG,
C_PC,
C_SP,
C_HREG,
C_ADDR, /* reference to relocatable address */
C_GOK,
};
EXTERN int32 autosize;
......
......@@ -65,17 +65,19 @@ gcopnames(char *dir, char *file)
// mkanames reads [568].out.h and writes anames[568].c
// The format is much the same as the Go opcodes above.
// it also writes out cnames array for C_* constants.
void
mkanames(char *dir, char *file)
{
int i, ch;
Buf in, b, out;
Buf in, b, out, out2;
Vec lines;
char *p;
binit(&b);
binit(&in);
binit(&out);
binit(&out2);
vinit(&lines);
ch = file[xstrlen(file)-3];
......@@ -105,10 +107,28 @@ mkanames(char *dir, char *file)
}
}
bwritestr(&out, "};\n");
bprintf(&out2, "char* cnames%c[] = {\n", ch);
for(i=0; i<lines.len; i++) {
if(hasprefix(lines.p[i], "\tC_")) {
p = xstrstr(lines.p[i], ",");
if(p)
*p = '\0';
p = xstrstr(lines.p[i], "\n");
if(p)
*p = '\0';
p = lines.p[i] + 3;
bwritestr(&out2, bprintf(&b, "\t\"%s\",\n", p));
}
}
bwritestr(&out2, "};\n");
bwriteb(&out, &out2);
writefile(&out, file, 0);
bfree(&b);
bfree(&in);
bfree(&out);
bfree(&out2);
vfree(&lines);
}
......@@ -65,52 +65,6 @@ enum
LTO = 1<<1,
LPOOL = 1<<2,
LPCREL = 1<<3,
C_NONE = 0,
C_REG,
C_REGREG,
C_REGREG2,
C_SHIFT,
C_FREG,
C_PSR,
C_FCR,
C_RCON, /* 0xff rotated */
C_NCON, /* ~RCON */
C_SCON, /* 0xffff */
C_LCON,
C_LCONADDR,
C_ZFCON,
C_SFCON,
C_LFCON,
C_RACON,
C_LACON,
C_SBRA,
C_LBRA,
C_HAUTO, /* halfword insn offset (-0xff to 0xff) */
C_FAUTO, /* float insn offset (0 to 0x3fc, word aligned) */
C_HFAUTO, /* both H and F */
C_SAUTO, /* -0xfff to 0xfff */
C_LAUTO,
C_HOREG,
C_FOREG,
C_HFOREG,
C_SOREG,
C_ROREG,
C_SROREG, /* both nil and R */
C_LOREG,
C_PC,
C_SP,
C_HREG,
C_ADDR, /* reference to relocatable address */
C_GOK,
};
static Optab optab[] =
......@@ -1264,7 +1218,7 @@ oplook(Link *ctxt, Prog *p)
o = oprange[r].stop; /* just generate an error */
}
if(0 /*debug['O']*/) {
print("oplook %A %d %d %d\n",
print("oplook %A %^ %^ %^\n",
(int)p->as, a1, a2, a3);
print(" %d %d\n", p->from.type, p->to.type);
}
......@@ -1278,7 +1232,7 @@ oplook(Link *ctxt, Prog *p)
p->optab = (o-optab)+1;
return o;
}
ctxt->diag("illegal combination %P; %d %d %d, %d %d",
ctxt->diag("illegal combination %P; %^ %^ %^, %d %d",
p, a1, a2, a3, p->from.type, p->to.type);
ctxt->diag("from %d %d to %d %d\n", p->from.type, p->from.name, p->to.type, p->to.name);
prasm(p);
......
......@@ -46,6 +46,7 @@ static int Pconv(Fmt *fp);
static int Rconv(Fmt *fp);
static int RAconv(Fmt *fp);
static int DSconv(Fmt *fp);
static int DRconv(Fmt*);
#pragma varargck type "$" char*
#pragma varargck type "M" Addr*
......@@ -59,6 +60,9 @@ listinit5(void)
fmtinstall('P', Pconv);
fmtinstall('R', Rconv);
// for liblink internal use
fmtinstall('^', DRconv);
// for internal use
fmtinstall('$', DSconv);
fmtinstall('M', Mconv);
......@@ -313,6 +317,19 @@ Rconv(Fmt *fp)
return fmtstrcpy(fp, str);
}
static int
DRconv(Fmt *fp)
{
char *s;
int a;
a = va_arg(fp->args, int);
s = "C_??";
if(a >= C_NONE && a <= C_NCLASS)
s = cnames5[a];
return fmtstrcpy(fp, s);
}
static int
Mconv(Fmt *fp)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment