]> Cypherpunks repositories - gostls13.git/commitdiff
liblink, cmd/dist, cmd/5l: introduce %^ and move C_* constants.
authorShenghou Ma <minux@golang.org>
Wed, 6 Aug 2014 04:31:22 +0000 (00:31 -0400)
committerShenghou Ma <minux@golang.org>
Wed, 6 Aug 2014 04:31:22 +0000 (00:31 -0400)
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
src/cmd/5l/5.out.h
src/cmd/5l/l.h
src/cmd/dist/buildgc.c
src/liblink/asm5.c
src/liblink/list5.c

index c5f4841d32c62def11b28727e24fc960de98aa5b..2b4de789d5d11be7d2d29cfaee88e56b77b1c7fc 100644 (file)
@@ -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.
index 7099c2769b874656c8a2d375ba8fcdd9b653dc09..7b16ac4468f87e2f9ee414a403626340610d78fe 100644 (file)
@@ -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,
index 2a7200e758c463d22a4c61a359a4b23361b078e9..c881a544af952cae5e1f0bff20a8bcb761f3640b 100644 (file)
@@ -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;
index 3bb0a9da100a417e2f522869e1e3b169f92afa55..178fbf9137f166b488379d326cce0fa1eb7a4572 100644 (file)
@@ -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);
 }
index 73a31862f51856da69b9b5aa9bbab8d416949341..46aa1c1e3b90d87532edfa600634748b23656c94 100644 (file)
@@ -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);
index 4a4e8c71f0360b53fe3b092a5272e79314431904..a91df55e695386fb9858c400549b0bc5d877e288 100644 (file)
@@ -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)
 {