aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/util.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2015-03-05 10:39:23 -0800
committerRob Pike <r@golang.org>2015-03-05 19:18:46 +0000
commit24a43e6a7542c2aefd1e2f16f0daae8100e4bdce (patch)
tree7102dfdd47ef77116daca5f9a6ed106a0f681d31 /src/cmd/internal/obj/util.go
parentd5b5d6702ad7d64f189c915225b945a2aa471a38 (diff)
downloadgo-24a43e6a7542c2aefd1e2f16f0daae8100e4bdce.tar.xz
cmd/internal/obj: delete all Pconv, replace with Prog.String
Remove the per-achitecture formatter for Prog and replace it with a global String method. Clean up and regularize the output. Update tests affected by the format; some tests are made correct now when they were broken before (and known to be). Also, related: Change the encoding of the (R1+R2) syntax on ppc64 to be equivalent to (R1)(R2*1), which means it needs no special handling. Delete the now unused STRINGSZ constant. Change-Id: I7f6654d11f80065f3914a3f19353f2f12edfe310 Reviewed-on: https://go-review.googlesource.com/6931 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/internal/obj/util.go')
-rw-r--r--src/cmd/internal/obj/util.go82
1 files changed, 81 insertions, 1 deletions
diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go
index d626793475..b2c7df7d56 100644
--- a/src/cmd/internal/obj/util.go
+++ b/src/cmd/internal/obj/util.go
@@ -6,6 +6,7 @@ package obj
import (
"bufio"
+ "bytes"
"fmt"
"io"
"log"
@@ -248,11 +249,90 @@ func (p *Prog) Line() string {
return Linklinefmt(p.Ctxt, int(p.Lineno), false, false)
}
+var armCondCode = []string{
+ ".EQ",
+ ".NE",
+ ".CS",
+ ".CC",
+ ".MI",
+ ".PL",
+ ".VS",
+ ".VC",
+ ".HI",
+ ".LS",
+ ".GE",
+ ".LT",
+ ".GT",
+ ".LE",
+ "",
+ ".NV",
+}
+
+/* ARM scond byte */
+const (
+ C_SCOND = (1 << 4) - 1
+ C_SBIT = 1 << 4
+ C_PBIT = 1 << 5
+ C_WBIT = 1 << 6
+ C_FBIT = 1 << 7
+ C_UBIT = 1 << 7
+ C_SCOND_XOR = 14
+)
+
+// CConv formats ARM condition codes.
+func CConv(s uint8) string {
+ if s == 0 {
+ return ""
+ }
+ sc := armCondCode[(s&C_SCOND)^C_SCOND_XOR]
+ if s&C_SBIT != 0 {
+ sc += ".S"
+ }
+ if s&C_PBIT != 0 {
+ sc += ".P"
+ }
+ if s&C_WBIT != 0 {
+ sc += ".W"
+ }
+ if s&C_UBIT != 0 { /* ambiguous with FBIT */
+ sc += ".U"
+ }
+ return sc
+}
+
func (p *Prog) String() string {
if p.Ctxt == nil {
return "<Prog without ctxt>"
}
- return p.Ctxt.Arch.Pconv(p)
+
+ sc := CConv(p.Scond)
+
+ var buf bytes.Buffer
+
+ fmt.Fprintf(&buf, "%.5d (%v)\t%v%s", p.Pc, p.Line(), Aconv(int(p.As)), sc)
+ sep := "\t"
+ if p.From.Type != TYPE_NONE {
+ fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.From))
+ sep = ", "
+ }
+ if p.Reg != REG_NONE {
+ // Should not happen but might as well show it if it does.
+ fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.Reg)))
+ sep = ", "
+ }
+ if p.From3.Type != TYPE_NONE {
+ if p.From3.Type == TYPE_CONST && (p.As == ADATA || p.As == ATEXT || p.As == AGLOBL) {
+ // Special case - omit $.
+ fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
+ } else {
+ fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.From3))
+ }
+ sep = ", "
+ }
+ if p.To.Type != TYPE_NONE {
+ fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.To))
+ }
+ return buf.String()
}
func (ctxt *Link) NewProg() *Prog {