Skip to content

Commit

Permalink
liblink: adjust format verbs to avoid collisions
Browse files Browse the repository at this point in the history
The %S and %N format verbs are used by cmd/gc to
represent Sym and Node structures, respectively.

In liblink, these two verbs are used only by the %D
format routine and never referenced externally.

This change will allow us to delete the duplicated
code for the %A, %D, %P, and %R format routines in
both the compiler and linker.

R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/49720043
  • Loading branch information
ality committed Jan 10, 2014
1 parent f739dae commit d155f6a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
30 changes: 15 additions & 15 deletions src/liblink/list5.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ enum

static int Aconv(Fmt *fp);
static int Dconv(Fmt *fp);
static int Nconv(Fmt *fp);
static int Mconv(Fmt *fp);
static int Pconv(Fmt *fp);
static int Rconv(Fmt *fp);
static int Sconv(Fmt *fp);
static int DSconv(Fmt *fp);

void
listinit5(void)
{
fmtinstall('A', Aconv);
fmtinstall('P', Pconv);
fmtinstall('S', Sconv);
fmtinstall('N', Nconv);
fmtinstall('$', DSconv);
fmtinstall('M', Mconv);
fmtinstall('D', Dconv);
fmtinstall('R', Rconv);
}
Expand Down Expand Up @@ -139,14 +139,14 @@ Dconv(Fmt *fp)
case D_NONE:
str[0] = 0;
if(a->name != D_NONE || a->reg != NREG || a->sym != nil)
sprint(str, "%N(R%d)(NONE)", a, a->reg);
sprint(str, "%M(R%d)(NONE)", a, a->reg);
break;

case D_CONST:
if(a->reg != NREG)
sprint(str, "$%N(R%d)", a, a->reg);
sprint(str, "$%M(R%d)", a, a->reg);
else
sprint(str, "$%N", a);
sprint(str, "$%M", a);
break;

case D_CONST2:
Expand All @@ -166,27 +166,27 @@ Dconv(Fmt *fp)

case D_OREG:
if(a->reg != NREG)
sprint(str, "%N(R%d)", a, a->reg);
sprint(str, "%M(R%d)", a, a->reg);
else
sprint(str, "%N", a);
sprint(str, "%M", a);
break;

case D_REG:
sprint(str, "R%d", a->reg);
if(a->name != D_NONE || a->sym != nil)
sprint(str, "%N(R%d)(REG)", a, a->reg);
sprint(str, "%M(R%d)(REG)", a, a->reg);
break;

case D_FREG:
sprint(str, "F%d", a->reg);
if(a->name != D_NONE || a->sym != nil)
sprint(str, "%N(R%d)(REG)", a, a->reg);
sprint(str, "%M(R%d)(REG)", a, a->reg);
break;

case D_PSR:
sprint(str, "PSR");
if(a->name != D_NONE || a->sym != nil)
sprint(str, "%N(PSR)(REG)", a);
sprint(str, "%M(PSR)(REG)", a);
break;

case D_BRANCH:
Expand All @@ -203,7 +203,7 @@ Dconv(Fmt *fp)
break;

case D_SCONST:
sprint(str, "$\"%S\"", a->u.sval);
sprint(str, "$\"%$\"", a->u.sval);
break;
}
return fmtstrcpy(fp, str);
Expand Down Expand Up @@ -242,7 +242,7 @@ Rconv(Fmt *fp)
}

static int
Sconv(Fmt *fp)
DSconv(Fmt *fp)
{
int i, c;
char str[STRINGSZ], *p, *a;
Expand Down Expand Up @@ -289,7 +289,7 @@ Sconv(Fmt *fp)
}

static int
Nconv(Fmt *fp)
Mconv(Fmt *fp)
{
char str[STRINGSZ];
Addr *a;
Expand Down
21 changes: 17 additions & 4 deletions src/liblink/list6.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@
#include <link.h>
#include "../cmd/6l/6.out.h"

//
// Format conversions
// %A int Opcodes (instruction mnemonics)
//
// %D Addr* Addresses (instruction operands)
// Flags: "%lD": seperate the high and low words of a constant by "-"
//
// %P Prog* Instructions
//
// %R int Registers
//
// %$ char* String constant addresses (for internal use only)

static int Aconv(Fmt *fp);
static int Dconv(Fmt *fp);
static int Pconv(Fmt *fp);
static int Rconv(Fmt *fp);
static int Sconv(Fmt *fp);
static int DSconv(Fmt *fp);

enum
{
Expand All @@ -50,7 +63,7 @@ listinit6(void)
{
fmtinstall('A', Aconv);
fmtinstall('P', Pconv);
fmtinstall('S', Sconv);
fmtinstall('$', DSconv);
fmtinstall('D', Dconv);
fmtinstall('R', Rconv);
}
Expand Down Expand Up @@ -174,7 +187,7 @@ Dconv(Fmt *fp)
break;

case D_SCONST:
sprint(str, "$\"%S\"", a->u.sval);
sprint(str, "$\"%$\"", a->u.sval);
break;

case D_ADDR:
Expand Down Expand Up @@ -337,7 +350,7 @@ Rconv(Fmt *fp)
}

static int
Sconv(Fmt *fp)
DSconv(Fmt *fp)
{
int i, c;
char str[STRINGSZ], *p, *a;
Expand Down
8 changes: 4 additions & 4 deletions src/liblink/list8.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int Aconv(Fmt *fp);
static int Dconv(Fmt *fp);
static int Pconv(Fmt *fp);
static int Rconv(Fmt *fp);
static int Sconv(Fmt *fp);
static int DSconv(Fmt *fp);

enum
{
Expand All @@ -50,7 +50,7 @@ listinit8(void)
{
fmtinstall('A', Aconv);
fmtinstall('P', Pconv);
fmtinstall('S', Sconv);
fmtinstall('$', DSconv);
fmtinstall('D', Dconv);
fmtinstall('R', Rconv);
}
Expand Down Expand Up @@ -181,7 +181,7 @@ Dconv(Fmt *fp)
break;

case D_SCONST:
sprint(str, "$\"%S\"", a->u.sval);
sprint(str, "$\"%$\"", a->u.sval);
break;

case D_ADDR:
Expand Down Expand Up @@ -298,7 +298,7 @@ Rconv(Fmt *fp)
}

static int
Sconv(Fmt *fp)
DSconv(Fmt *fp)
{
int i, c;
char str[STRINGSZ], *p, *a;
Expand Down

0 comments on commit d155f6a

Please sign in to comment.