Skip to content

Commit

Permalink
cmd/cc, cmd/gc, cmd/ld: consolidate print format routines
Browse files Browse the repository at this point in the history
We now use the %A, %D, %P, and %R routines from liblink
across the board.

Fixes golang#7178.
Fixes golang#7055.

LGTM=iant
R=golang-codereviews, gobot, rsc, dave, iant, remyoudompheng
CC=golang-codereviews
https://golang.org/cl/49170043
  • Loading branch information
ality authored and rsc committed Feb 12, 2014
1 parent 14c5c8a commit 2cae059
Show file tree
Hide file tree
Showing 45 changed files with 216 additions and 2,477 deletions.
11 changes: 10 additions & 1 deletion include/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ struct Prog
Addr to;

// for 5g, 6g, 8g internal use
uint32 loc; // TODO: merge with pc?
void* opt;

// for 5l, 6l, 8l internal use
Expand Down Expand Up @@ -565,3 +564,13 @@ extern char* anames8[];
extern LinkArch link386;
extern LinkArch linkamd64;
extern LinkArch linkarm;

#pragma varargck type "A" int
#pragma varargck type "D" Addr*
#pragma varargck type "lD" Addr*
#pragma varargck type "P" Prog*
#pragma varargck type "R" int

// TODO(ality): remove this workaround.
// It's here because Pconv in liblink/list?.c references %L.
#pragma varargck type "L" int32
12 changes: 0 additions & 12 deletions include/plan9/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@
// license that can be found in the LICENSE file.

#include "../link.h"

#pragma varargck type "@" Addr*
#pragma varargck type "A" int
#pragma varargck type "$" char*
#pragma varargck type "D" Addr*
#pragma varargck type "lD" Addr*
#pragma varargck type "L" int
#pragma varargck type "lS" LSym*
#pragma varargck type "M" Addr*
#pragma varargck type "P" Prog*
#pragma varargck type "R" int
#pragma varargck type "S" char*
7 changes: 7 additions & 0 deletions src/cmd/5a/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ systemtype(int sys)
#endif
}

int
Lconv(Fmt *fp)
{
return linklinefmt(ctxt, fp);
}

void
main(int argc, char *argv[])
{
Expand All @@ -65,6 +71,7 @@ main(int argc, char *argv[])
ctxt->bso = &bstdout;
Binit(&bstdout, 1, OWRITE);
listinit5();
fmtinstall('L', Lconv);

ensuresymb(NSYMB);
memset(debug, 0, sizeof(debug));
Expand Down
25 changes: 0 additions & 25 deletions src/cmd/5c/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ typedef struct Case Case;
typedef struct C1 C1;
typedef struct Multab Multab;
typedef struct Hintab Hintab;
typedef struct Var Var;
typedef struct Reg Reg;
typedef struct Rgn Rgn;

Expand Down Expand Up @@ -90,14 +89,6 @@ struct Hintab
char hint[10];
};

struct Var
{
int32 offset;
LSym* sym;
char name;
char etype;
};

struct Reg
{
int32 pc;
Expand Down Expand Up @@ -203,7 +194,6 @@ EXTERN Reg* firstr;
EXTERN Reg* lastr;
EXTERN Reg zreg;
EXTERN Reg* freer;
EXTERN Var var[NVAR];
EXTERN int32* idom;
EXTERN Reg** rpo2r;
EXTERN int32 maxnr;
Expand Down Expand Up @@ -292,13 +282,6 @@ void outcode(void);
* list
*/
void listinit(void);
int Pconv(Fmt*);
int Aconv(Fmt*);
int Dconv(Fmt*);
int Sconv(Fmt*);
int Nconv(Fmt*);
int Bconv(Fmt*);
int Rconv(Fmt*);

/*
* reg.c
Expand Down Expand Up @@ -349,11 +332,3 @@ void predicate(void);
int isbranch(Prog *);
int predicable(Prog *p);
int modifiescpsr(Prog *p);

#pragma varargck type "A" int
#pragma varargck type "B" Bits
#pragma varargck type "D" Addr*
#pragma varargck type "N" Addr*
#pragma varargck type "R" Addr*
#pragma varargck type "P" Prog*
#pragma varargck type "S" char*
27 changes: 0 additions & 27 deletions src/cmd/5c/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,5 @@
void
listinit(void)
{
fmtinstall('B', Bconv);
listinit5();
}

int
Bconv(Fmt *fp)
{
char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;

str[0] = 0;
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
if(str[0])
strcat(str, " ");
if(var[i].sym == nil) {
sprint(ss, "$%d", var[i].offset);
s = ss;
} else
s = var[i].sym->name;
if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
break;
strcat(str, s);
bits.b[i/32] &= ~(1L << (i%32));
}
return fmtstrcpy(fp, str);
}
2 changes: 1 addition & 1 deletion src/cmd/5g/galign.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ betypeinit(void)
zprog.from.reg = NREG;
zprog.to = zprog.from;

listinit();
listinit5();
}
10 changes: 0 additions & 10 deletions src/cmd/5g/gg.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ void datastring(char*, int, Addr*);
/*
* list.c
*/
int Aconv(Fmt*);
int Cconv(Fmt*);
int Dconv(Fmt*);
int Mconv(Fmt*);
int Pconv(Fmt*);
int Rconv(Fmt*);
int Yconv(Fmt*);
void listinit(void);

void zaddr(Biobuf*, Addr*, int, int);

#pragma varargck type "D" Addr*
#pragma varargck type "M" Addr*
2 changes: 1 addition & 1 deletion src/cmd/5g/ggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ expandchecks(Prog *firstp)
p1->link = p->link;
p->link = p1;
p1->lineno = p->lineno;
p1->loc = 9999;
p1->pc = 9999;
p1->as = AMOVW;
p1->from.type = D_REG;
p1->from.reg = reg;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/5g/gsubr.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ clearp(Prog *p)
p->to.type = D_NONE;
p->to.name = D_NONE;
p->to.reg = NREG;
p->loc = pcloc;
p->pc = pcloc;
pcloc++;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ patch(Prog *p, Prog *to)
if(p->to.type != D_BRANCH)
fatal("patch: not a branch");
p->to.u.branch = to;
p->to.offset = to->loc;
p->to.offset = to->pc;
}

Prog*
Expand Down
Loading

0 comments on commit 2cae059

Please sign in to comment.