mirror of https://github.com/golang/go.git
cmd/compile: Improve readability of HTML produced by GOSSAFUNC
Factor out the Aux/AuxInt handling in (*Value).LongString() and use it in (*Value).LongHTML() as well. This especially improves readability of auxFloat32, auxFloat64, and auxSymValAndOff values which would otherwise be printed as opaque integers. This change also makes LongString() slightly less verbose by eliding offsets that are zero (as is very often the case). Additionally, ensure the HTML is interpreted as UTF-8 so that non-ASCII characters (especially the "middle dots" in some symbols) show up correctly. Change-Id: Ie26221df876faa056d322b3e423af63f33cd109d Reviewed-on: https://go-review.googlesource.com/22641 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Frits van Bommel <fvbommel@gmail.com>
This commit is contained in:
parent
981395103e
commit
b13b249f43
|
|
@ -33,6 +33,7 @@ func (w *HTMLWriter) start(name string) {
|
|||
}
|
||||
w.WriteString("<html>")
|
||||
w.WriteString(`<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<style>
|
||||
|
||||
#helplink {
|
||||
|
|
@ -352,16 +353,7 @@ func (v *Value) LongHTML() string {
|
|||
s := fmt.Sprintf("<span class=\"%s ssa-long-value\">", v.String())
|
||||
s += fmt.Sprintf("%s = %s", v.HTML(), v.Op.String())
|
||||
s += " <" + html.EscapeString(v.Type.String()) + ">"
|
||||
if v.AuxInt != 0 {
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt)
|
||||
}
|
||||
if v.Aux != nil {
|
||||
if _, ok := v.Aux.(string); ok {
|
||||
s += html.EscapeString(fmt.Sprintf(" {%q}", v.Aux))
|
||||
} else {
|
||||
s += html.EscapeString(fmt.Sprintf(" {%v}", v.Aux))
|
||||
}
|
||||
}
|
||||
s += html.EscapeString(v.auxString())
|
||||
for _, a := range v.Args {
|
||||
s += fmt.Sprintf(" %s", a.HTML())
|
||||
}
|
||||
|
|
@ -369,7 +361,6 @@ func (v *Value) LongHTML() string {
|
|||
if int(v.ID) < len(r) && r[v.ID] != nil {
|
||||
s += " : " + r[v.ID].Name()
|
||||
}
|
||||
|
||||
s += "</span>"
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,40 +98,7 @@ func (v *Value) AuxValAndOff() ValAndOff {
|
|||
func (v *Value) LongString() string {
|
||||
s := fmt.Sprintf("v%d = %s", v.ID, v.Op.String())
|
||||
s += " <" + v.Type.String() + ">"
|
||||
switch opcodeTable[v.Op].auxType {
|
||||
case auxBool:
|
||||
if v.AuxInt == 0 {
|
||||
s += " [false]"
|
||||
} else {
|
||||
s += " [true]"
|
||||
}
|
||||
case auxInt8:
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt8())
|
||||
case auxInt16:
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt16())
|
||||
case auxInt32:
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt32())
|
||||
case auxInt64:
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt)
|
||||
case auxFloat32, auxFloat64:
|
||||
s += fmt.Sprintf(" [%g]", v.AuxFloat())
|
||||
case auxString:
|
||||
s += fmt.Sprintf(" {%s}", v.Aux)
|
||||
case auxSym:
|
||||
if v.Aux != nil {
|
||||
s += fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
case auxSymOff:
|
||||
if v.Aux != nil {
|
||||
s += fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
s += fmt.Sprintf(" [%d]", v.AuxInt)
|
||||
case auxSymValAndOff:
|
||||
if v.Aux != nil {
|
||||
s += fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
s += fmt.Sprintf(" [%s]", v.AuxValAndOff())
|
||||
}
|
||||
s += v.auxString()
|
||||
for _, a := range v.Args {
|
||||
s += fmt.Sprintf(" %v", a)
|
||||
}
|
||||
|
|
@ -142,6 +109,49 @@ func (v *Value) LongString() string {
|
|||
return s
|
||||
}
|
||||
|
||||
func (v *Value) auxString() string {
|
||||
switch opcodeTable[v.Op].auxType {
|
||||
case auxBool:
|
||||
if v.AuxInt == 0 {
|
||||
return " [false]"
|
||||
} else {
|
||||
return " [true]"
|
||||
}
|
||||
case auxInt8:
|
||||
return fmt.Sprintf(" [%d]", v.AuxInt8())
|
||||
case auxInt16:
|
||||
return fmt.Sprintf(" [%d]", v.AuxInt16())
|
||||
case auxInt32:
|
||||
return fmt.Sprintf(" [%d]", v.AuxInt32())
|
||||
case auxInt64, auxInt128:
|
||||
return fmt.Sprintf(" [%d]", v.AuxInt)
|
||||
case auxFloat32, auxFloat64:
|
||||
return fmt.Sprintf(" [%g]", v.AuxFloat())
|
||||
case auxString:
|
||||
return fmt.Sprintf(" {%q}", v.Aux)
|
||||
case auxSym:
|
||||
if v.Aux != nil {
|
||||
return fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
case auxSymOff, auxSymInt32:
|
||||
s := ""
|
||||
if v.Aux != nil {
|
||||
s = fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
if v.AuxInt != 0 {
|
||||
s += fmt.Sprintf(" [%v]", v.AuxInt)
|
||||
}
|
||||
return s
|
||||
case auxSymValAndOff:
|
||||
s := ""
|
||||
if v.Aux != nil {
|
||||
s = fmt.Sprintf(" {%s}", v.Aux)
|
||||
}
|
||||
return s + fmt.Sprintf(" [%s]", v.AuxValAndOff())
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (v *Value) AddArg(w *Value) {
|
||||
if v.Args == nil {
|
||||
v.resetArgs() // use argstorage
|
||||
|
|
|
|||
Loading…
Reference in New Issue