Commit c8198344 authored by Russ Cox's avatar Russ Cox

cmd/internal/gc: fmt.Sprintf elimination and minor cleanup

Change-Id: Iaf5a7d25e6308b32c17a38afbbd46befa17aa3a4
Reviewed-on: https://go-review.googlesource.com/7629Reviewed-by: default avatarRob Pike <r@golang.org>
parent d7f6d46c
...@@ -58,16 +58,8 @@ func (b *bulkBvec) next() Bvec { ...@@ -58,16 +58,8 @@ func (b *bulkBvec) next() Bvec {
/* difference */ /* difference */
func bvandnot(dst Bvec, src1 Bvec, src2 Bvec) { func bvandnot(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 for i, x := range src1.b {
var w int32 dst.b[i] = x &^ src2.b[i]
if dst.n != src1.n || dst.n != src2.n {
Fatal("bvand: lengths %d, %d, and %d are not equal", dst.n, src1.n, src2.n)
}
i = 0
w = 0
for ; i < dst.n; i, w = i+WORDBITS, w+1 {
dst.b[w] = src1.b[w] &^ src2.b[w]
} }
} }
...@@ -152,11 +144,8 @@ func bvisempty(bv Bvec) bool { ...@@ -152,11 +144,8 @@ func bvisempty(bv Bvec) bool {
} }
func bvnot(bv Bvec) { func bvnot(bv Bvec) {
var i int32 i := int32(0)
var w int32 w := int32(0)
i = 0
w = 0
for ; i < bv.n; i, w = i+WORDBITS, w+1 { for ; i < bv.n; i, w = i+WORDBITS, w+1 {
bv.b[w] = ^bv.b[w] bv.b[w] = ^bv.b[w]
} }
...@@ -164,31 +153,15 @@ func bvnot(bv Bvec) { ...@@ -164,31 +153,15 @@ func bvnot(bv Bvec) {
/* union */ /* union */
func bvor(dst Bvec, src1 Bvec, src2 Bvec) { func bvor(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 for i, x := range src1.b {
var w int32 dst.b[i] = x | src2.b[i]
if dst.n != src1.n || dst.n != src2.n {
Fatal("bvor: lengths %d, %d, and %d are not equal", dst.n, src1.n, src2.n)
}
i = 0
w = 0
for ; i < dst.n; i, w = i+WORDBITS, w+1 {
dst.b[w] = src1.b[w] | src2.b[w]
} }
} }
/* intersection */ /* intersection */
func bvand(dst Bvec, src1 Bvec, src2 Bvec) { func bvand(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 for i, x := range src1.b {
var w int32 dst.b[i] = x & src2.b[i]
if dst.n != src1.n || dst.n != src2.n {
Fatal("bvor: lengths %d, %d, and %d are not equal", dst.n, src1.n, src2.n)
}
i = 0
w = 0
for ; i < dst.n; i, w = i+WORDBITS, w+1 {
dst.b[w] = src1.b[w] & src2.b[w]
} }
} }
......
...@@ -1470,14 +1470,17 @@ func funccompile(n *Node) { ...@@ -1470,14 +1470,17 @@ func funccompile(n *Node) {
} }
func funcsym(s *Sym) *Sym { func funcsym(s *Sym) *Sym {
p := fmt.Sprintf("%s·f", s.Name) if s.Fsym != nil {
s1 := Pkglookup(p, s.Pkg) return s.Fsym
}
s1 := Pkglookup(s.Name+"·f", s.Pkg)
if s1.Def == nil { if s1.Def == nil {
s1.Def = newname(s1) s1.Def = newname(s1)
s1.Def.Shortname = newname(s) s1.Def.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def) funcsyms = list(funcsyms, s1.Def)
} }
s.Fsym = s1
return s1 return s1
} }
...@@ -436,9 +436,6 @@ func esclist(e *EscState, l *NodeList, up *Node) { ...@@ -436,9 +436,6 @@ func esclist(e *EscState, l *NodeList, up *Node) {
} }
func esc(e *EscState, n *Node, up *Node) { func esc(e *EscState, n *Node, up *Node) {
var ll *NodeList
var lr *NodeList
if n == nil { if n == nil {
return return
} }
...@@ -457,7 +454,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -457,7 +454,7 @@ func esc(e *EscState, n *Node, up *Node) {
// must happen before processing of switch body, // must happen before processing of switch body,
// so before recursion. // so before recursion.
if n.Op == OSWITCH && n.Ntest != nil && n.Ntest.Op == OTYPESW { if n.Op == OSWITCH && n.Ntest != nil && n.Ntest.Op == OTYPESW {
for ll = n.List; ll != nil; ll = ll.Next { // cases for ll := n.List; ll != nil; ll = ll.Next { // cases
// ll->n->nname is the variable per case // ll->n->nname is the variable per case
if ll.N.Nname != nil { if ll.N.Nname != nil {
...@@ -522,7 +519,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -522,7 +519,7 @@ func esc(e *EscState, n *Node, up *Node) {
case OSWITCH: case OSWITCH:
if n.Ntest != nil && n.Ntest.Op == OTYPESW { if n.Ntest != nil && n.Ntest.Op == OTYPESW {
for ll = n.List; ll != nil; ll = ll.Next { // cases for ll := n.List; ll != nil; ll = ll.Next { // cases
// ntest->right is the argument of the .(type), // ntest->right is the argument of the .(type),
// ll->n->nname is the variable per case // ll->n->nname is the variable per case
...@@ -574,8 +571,8 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -574,8 +571,8 @@ func esc(e *EscState, n *Node, up *Node) {
case OAS2: // x,y = a,b case OAS2: // x,y = a,b
if count(n.List) == count(n.Rlist) { if count(n.List) == count(n.Rlist) {
ll = n.List ll := n.List
lr = n.Rlist lr := n.Rlist
for ; ll != nil; ll, lr = ll.Next, lr.Next { for ; ll != nil; ll, lr = ll.Next, lr.Next {
escassign(e, ll.N, lr.N) escassign(e, ll.N, lr.N)
} }
...@@ -602,7 +599,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -602,7 +599,7 @@ func esc(e *EscState, n *Node, up *Node) {
escassign(e, &e.theSink, n.Left.Left) escassign(e, &e.theSink, n.Left.Left)
escassign(e, &e.theSink, n.Left.Right) // ODDDARG for call escassign(e, &e.theSink, n.Left.Right) // ODDDARG for call
for ll = n.Left.List; ll != nil; ll = ll.Next { for ll := n.Left.List; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N) escassign(e, &e.theSink, ll.N)
} }
...@@ -613,8 +610,9 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -613,8 +610,9 @@ func esc(e *EscState, n *Node, up *Node) {
// esccall already done on n->rlist->n. tie it's escretval to n->list // esccall already done on n->rlist->n. tie it's escretval to n->list
case OAS2FUNC: // x,y = f() case OAS2FUNC: // x,y = f()
lr = n.Rlist.N.Escretval lr := n.Rlist.N.Escretval
var ll *NodeList
for ll = n.List; lr != nil && ll != nil; lr, ll = lr.Next, ll.Next { for ll = n.List; lr != nil && ll != nil; lr, ll = lr.Next, ll.Next {
escassign(e, ll.N, lr.N) escassign(e, ll.N, lr.N)
} }
...@@ -623,7 +621,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -623,7 +621,7 @@ func esc(e *EscState, n *Node, up *Node) {
} }
case ORETURN: case ORETURN:
ll = n.List ll := n.List
if count(n.List) == 1 && Curfn.Type.Outtuple > 1 { if count(n.List) == 1 && Curfn.Type.Outtuple > 1 {
// OAS2FUNC in disguise // OAS2FUNC in disguise
// esccall already done on n->list->n // esccall already done on n->list->n
...@@ -631,7 +629,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -631,7 +629,7 @@ func esc(e *EscState, n *Node, up *Node) {
ll = n.List.N.Escretval ll = n.List.N.Escretval
} }
for lr = Curfn.Dcl; lr != nil && ll != nil; lr = lr.Next { for lr := Curfn.Dcl; lr != nil && ll != nil; lr = lr.Next {
if lr.N.Op != ONAME || lr.N.Class != PPARAMOUT { if lr.N.Op != ONAME || lr.N.Class != PPARAMOUT {
continue continue
} }
...@@ -649,7 +647,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -649,7 +647,7 @@ func esc(e *EscState, n *Node, up *Node) {
case OAPPEND: case OAPPEND:
if !n.Isddd { if !n.Isddd {
for ll = n.List.Next; ll != nil; ll = ll.Next { for ll := n.List.Next; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N) // lose track of assign to dereference escassign(e, &e.theSink, ll.N) // lose track of assign to dereference
} }
} }
...@@ -666,19 +664,19 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -666,19 +664,19 @@ func esc(e *EscState, n *Node, up *Node) {
n.Escloopdepth = e.loopdepth n.Escloopdepth = e.loopdepth
// Values make it to memory, lose track. // Values make it to memory, lose track.
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N.Right) escassign(e, &e.theSink, ll.N.Right)
} }
} else { } else {
// Link values to array. // Link values to array.
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
escassign(e, n, ll.N.Right) escassign(e, n, ll.N.Right)
} }
} }
// Link values to struct. // Link values to struct.
case OSTRUCTLIT: case OSTRUCTLIT:
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
escassign(e, n, ll.N.Right) escassign(e, n, ll.N.Right)
} }
...@@ -704,7 +702,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -704,7 +702,7 @@ func esc(e *EscState, n *Node, up *Node) {
n.Escloopdepth = e.loopdepth n.Escloopdepth = e.loopdepth
// Keys and values make it to memory, lose track. // Keys and values make it to memory, lose track.
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N.Left) escassign(e, &e.theSink, ll.N.Left)
escassign(e, &e.theSink, ll.N.Right) escassign(e, &e.theSink, ll.N.Right)
} }
...@@ -713,7 +711,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -713,7 +711,7 @@ func esc(e *EscState, n *Node, up *Node) {
case OCLOSURE: case OCLOSURE:
var a *Node var a *Node
var v *Node var v *Node
for ll = n.Cvars; ll != nil; ll = ll.Next { for ll := n.Cvars; ll != nil; ll = ll.Next {
v = ll.N v = ll.N
if v.Op == OXXX { // unnamed out argument; see dcl.c:/^funcargs if v.Op == OXXX { // unnamed out argument; see dcl.c:/^funcargs
continue continue
...@@ -953,9 +951,7 @@ func escassign(e *EscState, dst *Node, src *Node) { ...@@ -953,9 +951,7 @@ func escassign(e *EscState, dst *Node, src *Node) {
} }
func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) int { func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) int {
var em int em := parsetag(note)
em = parsetag(note)
if em == EscUnknown { if em == EscUnknown {
escassign(e, &e.theSink, src) escassign(e, &e.theSink, src)
...@@ -992,8 +988,6 @@ func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) int ...@@ -992,8 +988,6 @@ func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) int
// different for methods vs plain functions and for imported vs // different for methods vs plain functions and for imported vs
// this-package // this-package
func esccall(e *EscState, n *Node, up *Node) { func esccall(e *EscState, n *Node, up *Node) {
var ll *NodeList
var lr *NodeList
var fntype *Type var fntype *Type
var fn *Node var fn *Node
...@@ -1017,7 +1011,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1017,7 +1011,7 @@ func esccall(e *EscState, n *Node, up *Node) {
fntype = n.Left.Type fntype = n.Left.Type
} }
ll = n.List ll := n.List
if n.List != nil && n.List.Next == nil { if n.List != nil && n.List.Next == nil {
a := n.List.N a := n.List.N
if a.Type.Etype == TSTRUCT && a.Type.Funarg != 0 { // f(g()). if a.Type.Etype == TSTRUCT && a.Type.Funarg != 0 { // f(g()).
...@@ -1033,7 +1027,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1033,7 +1027,7 @@ func esccall(e *EscState, n *Node, up *Node) {
} }
// set up out list on this call node // set up out list on this call node
for lr = fn.Ntype.Rlist; lr != nil; lr = lr.Next { for lr := fn.Ntype.Rlist; lr != nil; lr = lr.Next {
n.Escretval = list(n.Escretval, lr.N.Left) // type.rlist -> dclfield -> ONAME (PPARAMOUT) n.Escretval = list(n.Escretval, lr.N.Left) // type.rlist -> dclfield -> ONAME (PPARAMOUT)
} }
...@@ -1043,7 +1037,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1043,7 +1037,7 @@ func esccall(e *EscState, n *Node, up *Node) {
} }
var src *Node var src *Node
for lr = fn.Ntype.List; ll != nil && lr != nil; ll, lr = ll.Next, lr.Next { for lr := fn.Ntype.List; ll != nil && lr != nil; ll, lr = ll.Next, lr.Next {
src = ll.N src = ll.N
if lr.N.Isddd && !n.Isddd { if lr.N.Isddd && !n.Isddd {
// Introduce ODDDARG node to represent ... allocation. // Introduce ODDDARG node to represent ... allocation.
......
This diff is collapsed.
...@@ -126,6 +126,7 @@ type Sym struct { ...@@ -126,6 +126,7 @@ type Sym struct {
Lastlineno int32 // last declaration for diagnostic Lastlineno int32 // last declaration for diagnostic
Origpkg *Pkg // original package for . import Origpkg *Pkg // original package for . import
Lsym *obj.LSym Lsym *obj.LSym
Fsym *Sym // funcsym
} }
type Type struct { type Type struct {
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
func mpcmpfixflt(a *Mpint, b *Mpflt) int { func mpcmpfixflt(a *Mpint, b *Mpflt) int {
var c Mpflt var c Mpflt
buf := fmt.Sprintf("%v", Bconv(a, 0)) buf := Bconv(a, 0)
mpatoflt(&c, buf) mpatoflt(&c, buf)
return mpcmpfltflt(&c, b) return mpcmpfltflt(&c, b)
} }
...@@ -23,7 +23,7 @@ func mpcmpfixflt(a *Mpint, b *Mpflt) int { ...@@ -23,7 +23,7 @@ func mpcmpfixflt(a *Mpint, b *Mpflt) int {
func mpcmpfltfix(a *Mpflt, b *Mpint) int { func mpcmpfltfix(a *Mpflt, b *Mpint) int {
var c Mpflt var c Mpflt
buf := fmt.Sprintf("%v", Bconv(b, 0)) buf := Bconv(b, 0)
mpatoflt(&c, buf) mpatoflt(&c, buf)
return mpcmpfltflt(a, &c) return mpcmpfltflt(a, &c)
} }
......
...@@ -7,6 +7,7 @@ package gc ...@@ -7,6 +7,7 @@ package gc
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"fmt" "fmt"
"strconv"
) )
/* /*
...@@ -155,16 +156,18 @@ func Linksym(s *Sym) *obj.LSym { ...@@ -155,16 +156,18 @@ func Linksym(s *Sym) *obj.LSym {
if s.Lsym != nil { if s.Lsym != nil {
return s.Lsym return s.Lsym
} }
var name string
if isblanksym(s) { if isblanksym(s) {
s.Lsym = obj.Linklookup(Ctxt, "_", 0) name = "_"
} else if s.Linkname != "" { } else if s.Linkname != "" {
s.Lsym = obj.Linklookup(Ctxt, s.Linkname, 0) name = s.Linkname
} else { } else {
p := fmt.Sprintf("%s.%s", s.Pkg.Prefix, s.Name) name = s.Pkg.Prefix + "." + s.Name
s.Lsym = obj.Linklookup(Ctxt, p, 0)
} }
return s.Lsym ls := obj.Linklookup(Ctxt, name, 0)
s.Lsym = ls
return ls
} }
func duintxx(s *Sym, off int, v uint64, wid int) int { func duintxx(s *Sym, off int, v uint64, wid int) int {
...@@ -211,7 +214,7 @@ func stringsym(s string) *Sym { ...@@ -211,7 +214,7 @@ func stringsym(s string) *Sym {
// small strings get named by their contents, // small strings get named by their contents,
// so that multiple modules using the same string // so that multiple modules using the same string
// can share it. // can share it.
symname = fmt.Sprintf("%q", s) symname = strconv.Quote(s)
pkg = gostringpkg pkg = gostringpkg
} }
......
...@@ -477,7 +477,7 @@ func dimportpath(p *Pkg) { ...@@ -477,7 +477,7 @@ func dimportpath(p *Pkg) {
dimportpath_gopkg.Name = "go" dimportpath_gopkg.Name = "go"
} }
nam := fmt.Sprintf("importpath.%s.", p.Prefix) nam := "importpath." + p.Prefix + "."
n := Nod(ONAME, nil, nil) n := Nod(ONAME, nil, nil)
n.Sym = Pkglookup(nam, dimportpath_gopkg) n.Sym = Pkglookup(nam, dimportpath_gopkg)
...@@ -808,7 +808,7 @@ func dcommontype(s *Sym, ot int, t *Type) int { ...@@ -808,7 +808,7 @@ func dcommontype(s *Sym, ot int, t *Type) int {
ot = duintptr(s, ot, 0) ot = duintptr(s, ot, 0)
} }
p := fmt.Sprintf("%v", Tconv(t, obj.FmtLeft|obj.FmtUnsigned)) p := Tconv(t, obj.FmtLeft|obj.FmtUnsigned)
//print("dcommontype: %s\n", p); //print("dcommontype: %s\n", p);
ot = dgostringptr(s, ot, p) // string ot = dgostringptr(s, ot, p) // string
...@@ -825,19 +825,11 @@ func dcommontype(s *Sym, ot int, t *Type) int { ...@@ -825,19 +825,11 @@ func dcommontype(s *Sym, ot int, t *Type) int {
} }
func typesym(t *Type) *Sym { func typesym(t *Type) *Sym {
p := fmt.Sprintf("%v", Tconv(t, obj.FmtLeft)) return Pkglookup(Tconv(t, obj.FmtLeft), typepkg)
s := Pkglookup(p, typepkg)
//print("typesym: %s -> %+S\n", p, s);
return s
} }
func tracksym(t *Type) *Sym { func tracksym(t *Type) *Sym {
p := fmt.Sprintf("%v.%s", Tconv(t.Outer, obj.FmtLeft), t.Sym.Name) return Pkglookup(Tconv(t.Outer, obj.FmtLeft)+"."+t.Sym.Name, trackpkg)
s := Pkglookup(p, trackpkg)
return s
} }
func typelinksym(t *Type) *Sym { func typelinksym(t *Type) *Sym {
...@@ -849,7 +841,7 @@ func typelinksym(t *Type) *Sym { ...@@ -849,7 +841,7 @@ func typelinksym(t *Type) *Sym {
// disambiguate. The names are a little long but they are // disambiguate. The names are a little long but they are
// discarded by the linker and do not end up in the symbol // discarded by the linker and do not end up in the symbol
// table of the final binary. // table of the final binary.
p := fmt.Sprintf("%v/%v", Tconv(t, obj.FmtLeft|obj.FmtUnsigned), Tconv(t, obj.FmtLeft)) p := Tconv(t, obj.FmtLeft|obj.FmtUnsigned) + "/" + Tconv(t, obj.FmtLeft)
s := Pkglookup(p, typelinkpkg) s := Pkglookup(p, typelinkpkg)
...@@ -859,7 +851,7 @@ func typelinksym(t *Type) *Sym { ...@@ -859,7 +851,7 @@ func typelinksym(t *Type) *Sym {
} }
func typesymprefix(prefix string, t *Type) *Sym { func typesymprefix(prefix string, t *Type) *Sym {
p := fmt.Sprintf("%s.%v", prefix, Tconv(t, obj.FmtLeft)) p := prefix + "." + Tconv(t, obj.FmtLeft)
s := Pkglookup(p, typepkg) s := Pkglookup(p, typepkg)
//print("algsym: %s -> %+S\n", p, s); //print("algsym: %s -> %+S\n", p, s);
...@@ -900,7 +892,7 @@ func typename(t *Type) *Node { ...@@ -900,7 +892,7 @@ func typename(t *Type) *Node {
} }
func weaktypesym(t *Type) *Sym { func weaktypesym(t *Type) *Sym {
p := fmt.Sprintf("%v", Tconv(t, obj.FmtLeft)) p := Tconv(t, obj.FmtLeft)
s := Pkglookup(p, weaktypepkg) s := Pkglookup(p, weaktypepkg)
//print("weaktypesym: %s -> %+S\n", p, s); //print("weaktypesym: %s -> %+S\n", p, s);
...@@ -962,9 +954,6 @@ func isreflexive(t *Type) bool { ...@@ -962,9 +954,6 @@ func isreflexive(t *Type) bool {
} }
func dtypesym(t *Type) *Sym { func dtypesym(t *Type) *Sym {
var n int
var t1 *Type
// Replace byte, rune aliases with real type. // Replace byte, rune aliases with real type.
// They've been separate internally to make error messages // They've been separate internally to make error messages
// better, but we have to merge them in the reflect tables. // better, but we have to merge them in the reflect tables.
...@@ -1048,16 +1037,16 @@ ok: ...@@ -1048,16 +1037,16 @@ ok:
ot = duintptr(s, ot, uint64(t.Chan)) ot = duintptr(s, ot, uint64(t.Chan))
case TFUNC: case TFUNC:
for t1 = getthisx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {
dtypesym(t1.Type) dtypesym(t1.Type)
} }
isddd := false isddd := false
for t1 = getinargx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {
isddd = t1.Isddd isddd = t1.Isddd
dtypesym(t1.Type) dtypesym(t1.Type)
} }
for t1 = getoutargx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {
dtypesym(t1.Type) dtypesym(t1.Type)
} }
...@@ -1069,7 +1058,7 @@ ok: ...@@ -1069,7 +1058,7 @@ ok:
ot = int(Rnd(int64(ot), int64(Widthptr))) ot = int(Rnd(int64(ot), int64(Widthptr)))
ot = dsymptr(s, ot, s, ot+2*(Widthptr+2*Widthint)) ot = dsymptr(s, ot, s, ot+2*(Widthptr+2*Widthint))
n = t.Thistuple + t.Intuple n := t.Thistuple + t.Intuple
ot = duintxx(s, ot, uint64(n), Widthint) ot = duintxx(s, ot, uint64(n), Widthint)
ot = duintxx(s, ot, uint64(n), Widthint) ot = duintxx(s, ot, uint64(n), Widthint)
ot = dsymptr(s, ot, s, ot+1*(Widthptr+2*Widthint)+n*Widthptr) ot = dsymptr(s, ot, s, ot+1*(Widthptr+2*Widthint)+n*Widthptr)
...@@ -1077,22 +1066,22 @@ ok: ...@@ -1077,22 +1066,22 @@ ok:
ot = duintxx(s, ot, uint64(t.Outtuple), Widthint) ot = duintxx(s, ot, uint64(t.Outtuple), Widthint)
// slice data // slice data
for t1 = getthisx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0) ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
n++ n++
} }
for t1 = getinargx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0) ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
n++ n++
} }
for t1 = getoutargx(t).Type; t1 != nil; t1 = t1.Down { for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0) ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
n++ n++
} }
case TINTER: case TINTER:
m := imethods(t) m := imethods(t)
n = 0 n := 0
for a := m; a != nil; a = a.link { for a := m; a != nil; a = a.link {
dtypesym(a.type_) dtypesym(a.type_)
n++ n++
...@@ -1164,9 +1153,9 @@ ok: ...@@ -1164,9 +1153,9 @@ ok:
// ../../runtime/type.go:/StructType // ../../runtime/type.go:/StructType
// for security, only the exported fields. // for security, only the exported fields.
case TSTRUCT: case TSTRUCT:
n = 0 n := 0
for t1 = t.Type; t1 != nil; t1 = t1.Down { for t1 := t.Type; t1 != nil; t1 = t1.Down {
dtypesym(t1.Type) dtypesym(t1.Type)
n++ n++
} }
...@@ -1176,7 +1165,7 @@ ok: ...@@ -1176,7 +1165,7 @@ ok:
ot = dsymptr(s, ot, s, ot+Widthptr+2*Widthint) ot = dsymptr(s, ot, s, ot+Widthptr+2*Widthint)
ot = duintxx(s, ot, uint64(n), Widthint) ot = duintxx(s, ot, uint64(n), Widthint)
ot = duintxx(s, ot, uint64(n), Widthint) ot = duintxx(s, ot, uint64(n), Widthint)
for t1 = t.Type; t1 != nil; t1 = t1.Down { for t1 := t.Type; t1 != nil; t1 = t1.Down {
// ../../runtime/type.go:/structField // ../../runtime/type.go:/structField
if t1.Sym != nil && t1.Embedded == 0 { if t1.Sym != nil && t1.Embedded == 0 {
ot = dgostringptr(s, ot, t1.Sym.Name) ot = dgostringptr(s, ot, t1.Sym.Name)
...@@ -1479,11 +1468,9 @@ func proggenskip(g *ProgGen, off int64, v int64) { ...@@ -1479,11 +1468,9 @@ func proggenskip(g *ProgGen, off int64, v int64) {
// Emit insArray instruction. // Emit insArray instruction.
func proggenarray(g *ProgGen, len int64) { func proggenarray(g *ProgGen, len int64) {
var i int32
proggendataflush(g) proggendataflush(g)
proggenemit(g, obj.InsArray) proggenemit(g, obj.InsArray)
for i = 0; i < int32(Widthptr); i, len = i+1, len>>8 { for i := int32(0); i < int32(Widthptr); i, len = i+1, len>>8 {
proggenemit(g, uint8(len)) proggenemit(g, uint8(len))
} }
} }
......
...@@ -243,8 +243,7 @@ func mkvar(f *Flow, a *obj.Addr) Bits { ...@@ -243,8 +243,7 @@ func mkvar(f *Flow, a *obj.Addr) Bits {
} }
} }
var node *Node node, _ := a.Node.(*Node)
node, _ = a.Node.(*Node)
if node == nil || node.Op != ONAME || node.Orig == nil { if node == nil || node.Op != ONAME || node.Orig == nil {
return zbits return zbits
} }
......
...@@ -291,7 +291,9 @@ func LookupBytes(name []byte) *Sym { ...@@ -291,7 +291,9 @@ func LookupBytes(name []byte) *Sym {
var initSyms []*Sym var initSyms []*Sym
var nopkg = new(Pkg) var nopkg = &Pkg{
Syms: make(map[string]*Sym),
}
func (pkg *Pkg) Lookup(name string) *Sym { func (pkg *Pkg) Lookup(name string) *Sym {
if pkg == nil { if pkg == nil {
...@@ -306,12 +308,9 @@ func (pkg *Pkg) Lookup(name string) *Sym { ...@@ -306,12 +308,9 @@ func (pkg *Pkg) Lookup(name string) *Sym {
Pkg: pkg, Pkg: pkg,
Lexical: LNAME, Lexical: LNAME,
} }
if s.Name == "init" { if name == "init" {
initSyms = append(initSyms, s) initSyms = append(initSyms, s)
} }
if pkg.Syms == nil {
pkg.Syms = make(map[string]*Sym)
}
pkg.Syms[name] = s pkg.Syms[name] = s
return s return s
} }
...@@ -1028,16 +1027,13 @@ func eqtype1(t1 *Type, t2 *Type, assumed_equal *TypePairList) bool { ...@@ -1028,16 +1027,13 @@ func eqtype1(t1 *Type, t2 *Type, assumed_equal *TypePairList) bool {
t1 = t1.Type t1 = t1.Type
t2 = t2.Type t2 = t2.Type
for ; t1 != nil && t2 != nil; t1, t2 = t1.Down, t2.Down { for ; t1 != nil && t2 != nil; t1, t2 = t1.Down, t2.Down {
var ta *Type
var tb *Type
if t1.Etype != TSTRUCT || t2.Etype != TSTRUCT { if t1.Etype != TSTRUCT || t2.Etype != TSTRUCT {
Fatal("func missing struct: %v %v", Tconv(t1, 0), Tconv(t2, 0)) Fatal("func missing struct: %v %v", Tconv(t1, 0), Tconv(t2, 0))
} }
// Loop over fields in structs, ignoring argument names. // Loop over fields in structs, ignoring argument names.
ta = t1.Type ta := t1.Type
tb = t2.Type tb := t2.Type
for ; ta != nil && tb != nil; ta, tb = ta.Down, tb.Down { for ; ta != nil && tb != nil; ta, tb = ta.Down, tb.Down {
if ta.Etype != TFIELD || tb.Etype != TFIELD { if ta.Etype != TFIELD || tb.Etype != TFIELD {
Fatal("func struct missing field: %v %v", Tconv(ta, 0), Tconv(tb, 0)) Fatal("func struct missing field: %v %v", Tconv(ta, 0), Tconv(tb, 0))
...@@ -1320,8 +1316,12 @@ func convertop(src *Type, dst *Type, why *string) int { ...@@ -1320,8 +1316,12 @@ func convertop(src *Type, dst *Type, why *string) int {
return 0 return 0
} }
// Convert node n for assignment to type t.
func assignconv(n *Node, t *Type, context string) *Node { func assignconv(n *Node, t *Type, context string) *Node {
return assignconvfn(n, t, func() string { return context })
}
// Convert node n for assignment to type t.
func assignconvfn(n *Node, t *Type, context func() string) *Node {
if n == nil || n.Type == nil || n.Type.Broke != 0 { if n == nil || n.Type == nil || n.Type.Broke != 0 {
return n return n
} }
...@@ -1357,7 +1357,7 @@ func assignconv(n *Node, t *Type, context string) *Node { ...@@ -1357,7 +1357,7 @@ func assignconv(n *Node, t *Type, context string) *Node {
var why string var why string
op := assignop(n.Type, t, &why) op := assignop(n.Type, t, &why)
if op == 0 { if op == 0 {
Yyerror("cannot use %v as type %v in %s%s", Nconv(n, obj.FmtLong), Tconv(t, 0), context, why) Yyerror("cannot use %v as type %v in %s%s", Nconv(n, obj.FmtLong), Tconv(t, 0), context(), why)
op = OCONV op = OCONV
} }
...@@ -1570,10 +1570,10 @@ func typehash(t *Type) uint32 { ...@@ -1570,10 +1570,10 @@ func typehash(t *Type) uint32 {
// hide method receiver from Tpretty // hide method receiver from Tpretty
t.Thistuple = 0 t.Thistuple = 0
p = fmt.Sprintf("%v", Tconv(t, obj.FmtLeft|obj.FmtUnsigned)) p = Tconv(t, obj.FmtLeft|obj.FmtUnsigned)
t.Thistuple = 1 t.Thistuple = 1
} else { } else {
p = fmt.Sprintf("%v", Tconv(t, obj.FmtLeft|obj.FmtUnsigned)) p = Tconv(t, obj.FmtLeft|obj.FmtUnsigned)
} }
//print("typehash: %s\n", p); //print("typehash: %s\n", p);
...@@ -3457,6 +3457,7 @@ func mkpkg(path string) *Pkg { ...@@ -3457,6 +3457,7 @@ func mkpkg(path string) *Pkg {
p := new(Pkg) p := new(Pkg)
p.Path = path p.Path = path
p.Prefix = pathtoprefix(path) p.Prefix = pathtoprefix(path)
p.Syms = make(map[string]*Sym)
pkgMap[path] = p pkgMap[path] = p
pkgs = append(pkgs, p) pkgs = append(pkgs, p)
return p return p
......
...@@ -1362,9 +1362,7 @@ OpSwitch: ...@@ -1362,9 +1362,7 @@ OpSwitch:
} }
} }
descbuf := fmt.Sprintf("argument to %v", Nconv(n.Left, 0)) typecheckaste(OCALL, n.Left, n.Isddd, getinargx(t), n.List, func() string { return fmt.Sprintf("argument to %v", Nconv(n.Left, 0)) })
desc := descbuf
typecheckaste(OCALL, n.Left, n.Isddd, getinargx(t), n.List, desc)
ok |= Etop ok |= Etop
if t.Outtuple == 0 { if t.Outtuple == 0 {
break OpSwitch break OpSwitch
...@@ -2127,7 +2125,7 @@ OpSwitch: ...@@ -2127,7 +2125,7 @@ OpSwitch:
if Curfn.Type.Outnamed != 0 && n.List == nil { if Curfn.Type.Outnamed != 0 && n.List == nil {
break OpSwitch break OpSwitch
} }
typecheckaste(ORETURN, nil, false, getoutargx(Curfn.Type), n.List, "return argument") typecheckaste(ORETURN, nil, false, getoutargx(Curfn.Type), n.List, func() string { return "return argument" })
break OpSwitch break OpSwitch
case ORETJMP: case ORETJMP:
...@@ -2604,7 +2602,7 @@ func downcount(t *Type) int { ...@@ -2604,7 +2602,7 @@ func downcount(t *Type) int {
/* /*
* typecheck assignment: type list = expression list * typecheck assignment: type list = expression list
*/ */
func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, desc string) { func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, desc func() string) {
var t *Type var t *Type
var n *Node var n *Node
var n1 int var n1 int
...@@ -2641,7 +2639,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, ...@@ -2641,7 +2639,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList,
if call != nil { if call != nil {
Yyerror("cannot use %v as type %v in argument to %v%s", Tconv(tn.Type, 0), Tconv(tl.Type.Type, 0), Nconv(call, 0), why) Yyerror("cannot use %v as type %v in argument to %v%s", Tconv(tn.Type, 0), Tconv(tl.Type.Type, 0), Nconv(call, 0), why)
} else { } else {
Yyerror("cannot use %v as type %v in %s%s", Tconv(tn.Type, 0), Tconv(tl.Type.Type, 0), desc, why) Yyerror("cannot use %v as type %v in %s%s", Tconv(tn.Type, 0), Tconv(tl.Type.Type, 0), desc(), why)
} }
} }
} }
...@@ -2656,7 +2654,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, ...@@ -2656,7 +2654,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList,
if call != nil { if call != nil {
Yyerror("cannot use %v as type %v in argument to %v%s", Tconv(tn.Type, 0), Tconv(tl.Type, 0), Nconv(call, 0), why) Yyerror("cannot use %v as type %v in argument to %v%s", Tconv(tn.Type, 0), Tconv(tl.Type, 0), Nconv(call, 0), why)
} else { } else {
Yyerror("cannot use %v as type %v in %s%s", Tconv(tn.Type, 0), Tconv(tl.Type, 0), desc, why) Yyerror("cannot use %v as type %v in %s%s", Tconv(tn.Type, 0), Tconv(tl.Type, 0), desc(), why)
} }
} }
...@@ -2708,7 +2706,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, ...@@ -2708,7 +2706,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList,
n = nl.N n = nl.N
setlineno(n) setlineno(n)
if n.Type != nil { if n.Type != nil {
nl.N = assignconv(n, t, desc) nl.N = assignconvfn(n, t, desc)
} }
goto out goto out
} }
...@@ -2717,7 +2715,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, ...@@ -2717,7 +2715,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList,
n = nl.N n = nl.N
setlineno(nl.N) setlineno(nl.N)
if n.Type != nil { if n.Type != nil {
nl.N = assignconv(n, t.Type, desc) nl.N = assignconvfn(n, t.Type, desc)
} }
} }
...@@ -2730,7 +2728,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, ...@@ -2730,7 +2728,7 @@ func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList,
n = nl.N n = nl.N
setlineno(n) setlineno(n)
if n.Type != nil { if n.Type != nil {
nl.N = assignconv(n, t, desc) nl.N = assignconvfn(n, t, desc)
} }
nl = nl.Next nl = nl.Next
} }
...@@ -3395,10 +3393,7 @@ func checkassignto(src *Type, dst *Node) { ...@@ -3395,10 +3393,7 @@ func checkassignto(src *Type, dst *Node) {
} }
func typecheckas2(n *Node) { func typecheckas2(n *Node) {
var ll *NodeList for ll := n.List; ll != nil; ll = ll.Next {
var lr *NodeList
for ll = n.List; ll != nil; ll = ll.Next {
// delicate little dance. // delicate little dance.
ll.N = resolve(ll.N) ll.N = resolve(ll.N)
...@@ -3420,8 +3415,8 @@ func typecheckas2(n *Node) { ...@@ -3420,8 +3415,8 @@ func typecheckas2(n *Node) {
var r *Node var r *Node
if cl == cr { if cl == cr {
// easy // easy
ll = n.List ll := n.List
lr = n.Rlist lr := n.Rlist
for ; ll != nil; ll, lr = ll.Next, lr.Next { for ; ll != nil; ll, lr = ll.Next, lr.Next {
if ll.N.Type != nil && lr.N.Type != nil { if ll.N.Type != nil && lr.N.Type != nil {
lr.N = assignconv(lr.N, ll.N.Type, "assignment") lr.N = assignconv(lr.N, ll.N.Type, "assignment")
...@@ -3457,7 +3452,7 @@ func typecheckas2(n *Node) { ...@@ -3457,7 +3452,7 @@ func typecheckas2(n *Node) {
n.Op = OAS2FUNC n.Op = OAS2FUNC
var s Iter var s Iter
t := Structfirst(&s, &r.Type) t := Structfirst(&s, &r.Type)
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
if t.Type != nil && ll.N.Type != nil { if t.Type != nil && ll.N.Type != nil {
checkassignto(t.Type, ll.N) checkassignto(t.Type, ll.N)
} }
...@@ -3516,7 +3511,7 @@ mismatch: ...@@ -3516,7 +3511,7 @@ mismatch:
out: out:
n.Typecheck = 1 n.Typecheck = 1
for ll = n.List; ll != nil; ll = ll.Next { for ll := n.List; ll != nil; ll = ll.Next {
if ll.N.Typecheck == 0 { if ll.N.Typecheck == 0 {
typecheck(&ll.N, Erv|Easgn) typecheck(&ll.N, Erv|Easgn)
} }
......
...@@ -948,7 +948,7 @@ func walkexpr(np **Node, init **NodeList) { ...@@ -948,7 +948,7 @@ func walkexpr(np **Node, init **NodeList) {
ll = list(ll, typename(n.Type)) ll = list(ll, typename(n.Type))
} }
if !Isinter(n.Left.Type) && !isnilinter(n.Type) { if !Isinter(n.Left.Type) && !isnilinter(n.Type) {
sym := Pkglookup(fmt.Sprintf("%v.%v", Tconv(n.Left.Type, obj.FmtLeft), Tconv(n.Type, obj.FmtLeft)), itabpkg) sym := Pkglookup(Tconv(n.Left.Type, obj.FmtLeft)+"."+Tconv(n.Type, obj.FmtLeft), itabpkg)
if sym.Def == nil { if sym.Def == nil {
l := Nod(ONAME, nil, nil) l := Nod(ONAME, nil, nil)
l.Sym = sym l.Sym = sym
...@@ -1631,9 +1631,6 @@ func ascompatee1(op int, l *Node, r *Node, init **NodeList) *Node { ...@@ -1631,9 +1631,6 @@ func ascompatee1(op int, l *Node, r *Node, init **NodeList) *Node {
} }
func ascompatee(op int, nl *NodeList, nr *NodeList, init **NodeList) *NodeList { func ascompatee(op int, nl *NodeList, nr *NodeList, init **NodeList) *NodeList {
var ll *NodeList
var lr *NodeList
/* /*
* check assign expression list to * check assign expression list to
* a expression list. called in * a expression list. called in
...@@ -1641,16 +1638,16 @@ func ascompatee(op int, nl *NodeList, nr *NodeList, init **NodeList) *NodeList { ...@@ -1641,16 +1638,16 @@ func ascompatee(op int, nl *NodeList, nr *NodeList, init **NodeList) *NodeList {
*/ */
// ensure order of evaluation for function calls // ensure order of evaluation for function calls
for ll = nl; ll != nil; ll = ll.Next { for ll := nl; ll != nil; ll = ll.Next {
ll.N = safeexpr(ll.N, init) ll.N = safeexpr(ll.N, init)
} }
for lr = nr; lr != nil; lr = lr.Next { for lr := nr; lr != nil; lr = lr.Next {
lr.N = safeexpr(lr.N, init) lr.N = safeexpr(lr.N, init)
} }
var nn *NodeList var nn *NodeList
ll = nl ll := nl
lr = nr lr := nr
for ; ll != nil && lr != nil; ll, lr = ll.Next, lr.Next { for ; ll != nil && lr != nil; ll, lr = ll.Next, lr.Next {
// Do not generate 'x = x' during return. See issue 4014. // Do not generate 'x = x' during return. See issue 4014.
if op == ORETURN && ll.N == lr.N { if op == ORETURN && ll.N == lr.N {
...@@ -1798,7 +1795,7 @@ func dumptypes(nl **Type, what string) string { ...@@ -1798,7 +1795,7 @@ func dumptypes(nl **Type, what string) string {
} else { } else {
fmt_ += ", " fmt_ += ", "
} }
fmt_ += fmt.Sprintf("%v", Tconv(l, 0)) fmt_ += Tconv(l, 0)
} }
if first != 0 { if first != 0 {
...@@ -1820,7 +1817,7 @@ func dumpnodetypes(l *NodeList, what string) string { ...@@ -1820,7 +1817,7 @@ func dumpnodetypes(l *NodeList, what string) string {
} else { } else {
fmt_ += ", " fmt_ += ", "
} }
fmt_ += fmt.Sprintf("%v", Tconv(r.Type, 0)) fmt_ += Tconv(r.Type, 0)
} }
if first != 0 { if first != 0 {
......
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