From d69d0fe92b547d85e16485c68a0b5bf463d6ae91 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 6 Aug 2014 00:31:22 -0400 Subject: [PATCH] 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 --- include/link.h | 7 ++++-- src/cmd/5l/5.out.h | 51 ++++++++++++++++++++++++++++++++++++++++++ src/cmd/5l/l.h | 46 ------------------------------------- src/cmd/dist/buildgc.c | 22 +++++++++++++++++- src/liblink/asm5.c | 50 ++--------------------------------------- src/liblink/list5.c | 17 ++++++++++++++ 6 files changed, 96 insertions(+), 97 deletions(-) diff --git a/include/link.h b/include/link.h index c5f4841d32..2b4de789d5 100644 --- a/include/link.h +++ b/include/link.h @@ -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. diff --git a/src/cmd/5l/5.out.h b/src/cmd/5l/5.out.h index 7099c2769b..7b16ac4468 100644 --- a/src/cmd/5l/5.out.h +++ b/src/cmd/5l/5.out.h @@ -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, diff --git a/src/cmd/5l/l.h b/src/cmd/5l/l.h index 2a7200e758..c881a544af 100644 --- a/src/cmd/5l/l.h +++ b/src/cmd/5l/l.h @@ -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; diff --git a/src/cmd/dist/buildgc.c b/src/cmd/dist/buildgc.c index 3bb0a9da10..178fbf9137 100644 --- a/src/cmd/dist/buildgc.c +++ b/src/cmd/dist/buildgc.c @@ -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; ias, 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); diff --git a/src/liblink/list5.c b/src/liblink/list5.c index 4a4e8c71f0..a91df55e69 100644 --- a/src/liblink/list5.c +++ b/src/liblink/list5.c @@ -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) { -- 2.48.1