]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: Improve readability of HTML produced by GOSSAFUNC
authorFrits van Bommel <fvbommel@gmail.com>
Sat, 30 Apr 2016 09:13:29 +0000 (11:13 +0200)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 1 May 2016 02:38:17 +0000 (02:38 +0000)
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>
src/cmd/compile/internal/ssa/html.go
src/cmd/compile/internal/ssa/value.go

index bb88a3ebde4c21cb35134e5e825b454ebcb050f2..fee092519b499135c1ec67baa2c1e57818c6c618 100644 (file)
@@ -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
 }
index 6c364ad932e5ce11f6aada6682adf7fc22553356..867221bf980e4ac1ea282c22a95be5c566187533 100644 (file)
@@ -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) {