Commit b13b249f authored by Frits van Bommel's avatar Frits van Bommel Committed by Josh Bleecher Snyder

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/22641Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarFrits van Bommel <fvbommel@gmail.com>
parent 98139510
......@@ -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 += " &lt;" + html.EscapeString(v.Type.String()) + "&gt;"
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,48 +98,58 @@ 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() + ">"
s += v.auxString()
for _, a := range v.Args {
s += fmt.Sprintf(" %v", a)
}
r := v.Block.Func.RegAlloc
if int(v.ID) < len(r) && r[v.ID] != nil {
s += " : " + r[v.ID].Name()
}
return s
}
func (v *Value) auxString() string {
switch opcodeTable[v.Op].auxType {
case auxBool:
if v.AuxInt == 0 {
s += " [false]"
return " [false]"
} else {
s += " [true]"
return " [true]"
}
case auxInt8:
s += fmt.Sprintf(" [%d]", v.AuxInt8())
return fmt.Sprintf(" [%d]", v.AuxInt8())
case auxInt16:
s += fmt.Sprintf(" [%d]", v.AuxInt16())
return fmt.Sprintf(" [%d]", v.AuxInt16())
case auxInt32:
s += fmt.Sprintf(" [%d]", v.AuxInt32())
case auxInt64:
s += fmt.Sprintf(" [%d]", v.AuxInt)
return fmt.Sprintf(" [%d]", v.AuxInt32())
case auxInt64, auxInt128:
return fmt.Sprintf(" [%d]", v.AuxInt)
case auxFloat32, auxFloat64:
s += fmt.Sprintf(" [%g]", v.AuxFloat())
return fmt.Sprintf(" [%g]", v.AuxFloat())
case auxString:
s += fmt.Sprintf(" {%s}", v.Aux)
return fmt.Sprintf(" {%q}", v.Aux)
case auxSym:
if v.Aux != nil {
s += fmt.Sprintf(" {%s}", v.Aux)
return fmt.Sprintf(" {%s}", v.Aux)
}
case auxSymOff:
case auxSymOff, auxSymInt32:
s := ""
if v.Aux != nil {
s += fmt.Sprintf(" {%s}", v.Aux)
s = fmt.Sprintf(" {%s}", v.Aux)
}
s += fmt.Sprintf(" [%d]", v.AuxInt)
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)
s = fmt.Sprintf(" {%s}", v.Aux)
}
s += fmt.Sprintf(" [%s]", v.AuxValAndOff())
return s + fmt.Sprintf(" [%s]", v.AuxValAndOff())
}
for _, a := range v.Args {
s += fmt.Sprintf(" %v", a)
}
r := v.Block.Func.RegAlloc
if int(v.ID) < len(r) && r[v.ID] != nil {
s += " : " + r[v.ID].Name()
}
return s
return ""
}
func (v *Value) AddArg(w *Value) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment