Commit f68f2928 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: factor out Pkg, Sym, and Type into package types

- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
  file which contains a handful of functions that must be installed
  early by the gc frontend
- to break cycles, for now we need two functions to convert between
  *gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
  functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
  types.NewPtr, types.NewArray, etc.

Passes toolstash-check -all.

Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 19bd145d
...@@ -557,8 +557,6 @@ func init() { ...@@ -557,8 +557,6 @@ func init() {
// To print out a new table, run: go test -run Formats -v. // To print out a new table, run: go test -run Formats -v.
var knownFormats = map[string]string{ var knownFormats = map[string]string{
"*bytes.Buffer %s": "", "*bytes.Buffer %s": "",
"*cmd/compile/internal/gc.Field %p": "",
"*cmd/compile/internal/gc.Field %v": "",
"*cmd/compile/internal/gc.Mpflt %v": "", "*cmd/compile/internal/gc.Mpflt %v": "",
"*cmd/compile/internal/gc.Mpint %v": "", "*cmd/compile/internal/gc.Mpint %v": "",
"*cmd/compile/internal/gc.Node %#v": "", "*cmd/compile/internal/gc.Node %#v": "",
...@@ -570,20 +568,6 @@ var knownFormats = map[string]string{ ...@@ -570,20 +568,6 @@ var knownFormats = map[string]string{
"*cmd/compile/internal/gc.Node %j": "", "*cmd/compile/internal/gc.Node %j": "",
"*cmd/compile/internal/gc.Node %p": "", "*cmd/compile/internal/gc.Node %p": "",
"*cmd/compile/internal/gc.Node %v": "", "*cmd/compile/internal/gc.Node %v": "",
"*cmd/compile/internal/gc.Sym %+v": "",
"*cmd/compile/internal/gc.Sym %-v": "",
"*cmd/compile/internal/gc.Sym %0S": "",
"*cmd/compile/internal/gc.Sym %S": "",
"*cmd/compile/internal/gc.Sym %p": "",
"*cmd/compile/internal/gc.Sym %v": "",
"*cmd/compile/internal/gc.Type %#v": "",
"*cmd/compile/internal/gc.Type %+v": "",
"*cmd/compile/internal/gc.Type %-S": "",
"*cmd/compile/internal/gc.Type %0S": "",
"*cmd/compile/internal/gc.Type %L": "",
"*cmd/compile/internal/gc.Type %S": "",
"*cmd/compile/internal/gc.Type %p": "",
"*cmd/compile/internal/gc.Type %v": "",
"*cmd/compile/internal/ssa.Block %s": "", "*cmd/compile/internal/ssa.Block %s": "",
"*cmd/compile/internal/ssa.Block %v": "", "*cmd/compile/internal/ssa.Block %v": "",
"*cmd/compile/internal/ssa.Func %s": "", "*cmd/compile/internal/ssa.Func %s": "",
...@@ -591,6 +575,22 @@ var knownFormats = map[string]string{ ...@@ -591,6 +575,22 @@ var knownFormats = map[string]string{
"*cmd/compile/internal/ssa.Value %s": "", "*cmd/compile/internal/ssa.Value %s": "",
"*cmd/compile/internal/ssa.Value %v": "", "*cmd/compile/internal/ssa.Value %v": "",
"*cmd/compile/internal/ssa.sparseTreeMapEntry %v": "", "*cmd/compile/internal/ssa.sparseTreeMapEntry %v": "",
"*cmd/compile/internal/types.Field %p": "",
"*cmd/compile/internal/types.Field %v": "",
"*cmd/compile/internal/types.Sym %+v": "",
"*cmd/compile/internal/types.Sym %-v": "",
"*cmd/compile/internal/types.Sym %0S": "",
"*cmd/compile/internal/types.Sym %S": "",
"*cmd/compile/internal/types.Sym %p": "",
"*cmd/compile/internal/types.Sym %v": "",
"*cmd/compile/internal/types.Type %#v": "",
"*cmd/compile/internal/types.Type %+v": "",
"*cmd/compile/internal/types.Type %-S": "",
"*cmd/compile/internal/types.Type %0S": "",
"*cmd/compile/internal/types.Type %L": "",
"*cmd/compile/internal/types.Type %S": "",
"*cmd/compile/internal/types.Type %p": "",
"*cmd/compile/internal/types.Type %v": "",
"*cmd/internal/obj.Addr %v": "", "*cmd/internal/obj.Addr %v": "",
"*cmd/internal/obj.LSym %v": "", "*cmd/internal/obj.LSym %v": "",
"*cmd/internal/obj.Prog %s": "", "*cmd/internal/obj.Prog %s": "",
...@@ -613,9 +613,6 @@ var knownFormats = map[string]string{ ...@@ -613,9 +613,6 @@ var knownFormats = map[string]string{
"cmd/compile/internal/gc.Class %d": "", "cmd/compile/internal/gc.Class %d": "",
"cmd/compile/internal/gc.Ctype %d": "", "cmd/compile/internal/gc.Ctype %d": "",
"cmd/compile/internal/gc.Ctype %v": "", "cmd/compile/internal/gc.Ctype %v": "",
"cmd/compile/internal/gc.EType %d": "",
"cmd/compile/internal/gc.EType %s": "",
"cmd/compile/internal/gc.EType %v": "",
"cmd/compile/internal/gc.Level %d": "", "cmd/compile/internal/gc.Level %d": "",
"cmd/compile/internal/gc.Level %v": "", "cmd/compile/internal/gc.Level %v": "",
"cmd/compile/internal/gc.Node %#v": "", "cmd/compile/internal/gc.Node %#v": "",
...@@ -652,6 +649,9 @@ var knownFormats = map[string]string{ ...@@ -652,6 +649,9 @@ var knownFormats = map[string]string{
"cmd/compile/internal/syntax.token %d": "", "cmd/compile/internal/syntax.token %d": "",
"cmd/compile/internal/syntax.token %q": "", "cmd/compile/internal/syntax.token %q": "",
"cmd/compile/internal/syntax.token %s": "", "cmd/compile/internal/syntax.token %s": "",
"cmd/compile/internal/types.EType %d": "",
"cmd/compile/internal/types.EType %s": "",
"cmd/compile/internal/types.EType %v": "",
"cmd/internal/src.Pos %s": "", "cmd/internal/src.Pos %s": "",
"cmd/internal/src.Pos %v": "", "cmd/internal/src.Pos %v": "",
"cmd/internal/src.XPos %v": "", "cmd/internal/src.XPos %v": "",
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
package gc package gc
import "fmt" import (
"cmd/compile/internal/types"
"fmt"
)
// AlgKind describes the kind of algorithms used for comparing and // AlgKind describes the kind of algorithms used for comparing and
// hashing a Type. // hashing a Type.
...@@ -35,21 +38,21 @@ const ( ...@@ -35,21 +38,21 @@ const (
) )
// IsComparable reports whether t is a comparable type. // IsComparable reports whether t is a comparable type.
func (t *Type) IsComparable() bool { func IsComparable(t *types.Type) bool {
a, _ := algtype1(t) a, _ := algtype1(t)
return a != ANOEQ return a != ANOEQ
} }
// IsRegularMemory reports whether t can be compared/hashed as regular memory. // IsRegularMemory reports whether t can be compared/hashed as regular memory.
func (t *Type) IsRegularMemory() bool { func IsRegularMemory(t *types.Type) bool {
a, _ := algtype1(t) a, _ := algtype1(t)
return a == AMEM return a == AMEM
} }
// IncomparableField returns an incomparable Field of struct Type t, if any. // IncomparableField returns an incomparable Field of struct Type t, if any.
func (t *Type) IncomparableField() *Field { func IncomparableField(t *types.Type) *types.Field {
for _, f := range t.FieldSlice() { for _, f := range t.FieldSlice() {
if !f.Type.IsComparable() { if !IsComparable(f.Type) {
return f return f
} }
} }
...@@ -58,7 +61,7 @@ func (t *Type) IncomparableField() *Field { ...@@ -58,7 +61,7 @@ func (t *Type) IncomparableField() *Field {
// algtype is like algtype1, except it returns the fixed-width AMEMxx variants // algtype is like algtype1, except it returns the fixed-width AMEMxx variants
// instead of the general AMEM kind when possible. // instead of the general AMEM kind when possible.
func algtype(t *Type) AlgKind { func algtype(t *types.Type) AlgKind {
a, _ := algtype1(t) a, _ := algtype1(t)
if a == AMEM { if a == AMEM {
switch t.Width { switch t.Width {
...@@ -83,7 +86,7 @@ func algtype(t *Type) AlgKind { ...@@ -83,7 +86,7 @@ func algtype(t *Type) AlgKind {
// algtype1 returns the AlgKind used for comparing and hashing Type t. // algtype1 returns the AlgKind used for comparing and hashing Type t.
// If it returns ANOEQ, it also returns the component type of t that // If it returns ANOEQ, it also returns the component type of t that
// makes it incomparable. // makes it incomparable.
func algtype1(t *Type) (AlgKind, *Type) { func algtype1(t *types.Type) (AlgKind, *types.Type) {
if t.Broke() { if t.Broke() {
return AMEM, nil return AMEM, nil
} }
...@@ -181,7 +184,7 @@ func algtype1(t *Type) (AlgKind, *Type) { ...@@ -181,7 +184,7 @@ func algtype1(t *Type) (AlgKind, *Type) {
} }
// Generate a helper function to compute the hash of a value of type t. // Generate a helper function to compute the hash of a value of type t.
func genhash(sym *Sym, t *Type) { func genhash(sym *types.Sym, t *types.Type) {
if Debug['r'] != 0 { if Debug['r'] != 0 {
fmt.Printf("genhash %v %v\n", sym, t) fmt.Printf("genhash %v %v\n", sym, t)
} }
...@@ -198,13 +201,13 @@ func genhash(sym *Sym, t *Type) { ...@@ -198,13 +201,13 @@ func genhash(sym *Sym, t *Type) {
tfn := nod(OTFUNC, nil, nil) tfn := nod(OTFUNC, nil, nil)
fn.Func.Nname.Name.Param.Ntype = tfn fn.Func.Nname.Name.Param.Ntype = tfn
n := namedfield("p", typPtr(t)) n := namedfield("p", types.NewPtr(t))
tfn.List.Append(n) tfn.List.Append(n)
np := n.Left np := n.Left
n = namedfield("h", Types[TUINTPTR]) n = namedfield("h", types.Types[TUINTPTR])
tfn.List.Append(n) tfn.List.Append(n)
nh := n.Left nh := n.Left
n = anonfield(Types[TUINTPTR]) // return value n = anonfield(types.Types[TUINTPTR]) // return value
tfn.Rlist.Append(n) tfn.Rlist.Append(n)
funchdr(fn) funchdr(fn)
...@@ -217,7 +220,7 @@ func genhash(sym *Sym, t *Type) { ...@@ -217,7 +220,7 @@ func genhash(sym *Sym, t *Type) {
default: default:
Fatalf("genhash %v", t) Fatalf("genhash %v", t)
case TARRAY: case types.TARRAY:
// An array of pure memory would be handled by the // An array of pure memory would be handled by the
// standard algorithm, so the element type must not be // standard algorithm, so the element type must not be
// pure memory. // pure memory.
...@@ -225,7 +228,7 @@ func genhash(sym *Sym, t *Type) { ...@@ -225,7 +228,7 @@ func genhash(sym *Sym, t *Type) {
n := nod(ORANGE, nil, nod(OIND, np, nil)) n := nod(ORANGE, nil, nod(OIND, np, nil))
ni := newname(lookup("i")) ni := newname(lookup("i"))
ni.Type = Types[TINT] ni.Type = types.Types[TINT]
n.List.Set1(ni) n.List.Set1(ni)
n.SetColas(true) n.SetColas(true)
colasdefn(n.List.Slice(), n) colasdefn(n.List.Slice(), n)
...@@ -244,7 +247,7 @@ func genhash(sym *Sym, t *Type) { ...@@ -244,7 +247,7 @@ func genhash(sym *Sym, t *Type) {
fn.Nbody.Append(n) fn.Nbody.Append(n)
case TSTRUCT: case types.TSTRUCT:
// Walk the struct using memhash for runs of AMEM // Walk the struct using memhash for runs of AMEM
// and calling specific hash functions for the others. // and calling specific hash functions for the others.
for i, fields := 0, t.FieldSlice(); i < len(fields); { for i, fields := 0, t.FieldSlice(); i < len(fields); {
...@@ -257,7 +260,7 @@ func genhash(sym *Sym, t *Type) { ...@@ -257,7 +260,7 @@ func genhash(sym *Sym, t *Type) {
} }
// Hash non-memory fields with appropriate hash function. // Hash non-memory fields with appropriate hash function.
if !f.Type.IsRegularMemory() { if !IsRegularMemory(f.Type) {
hashel := hashfor(f.Type) hashel := hashfor(f.Type)
call := nod(OCALL, hashel, nil) call := nod(OCALL, hashel, nil)
nx := nodSym(OXDOT, np, f.Sym) // TODO: fields from other packages? nx := nodSym(OXDOT, np, f.Sym) // TODO: fields from other packages?
...@@ -322,8 +325,8 @@ func genhash(sym *Sym, t *Type) { ...@@ -322,8 +325,8 @@ func genhash(sym *Sym, t *Type) {
safemode = old_safemode safemode = old_safemode
} }
func hashfor(t *Type) *Node { func hashfor(t *types.Type) *Node {
var sym *Sym var sym *types.Sym
switch a, _ := algtype1(t); a { switch a, _ := algtype1(t); a {
case AMEM: case AMEM:
...@@ -349,9 +352,9 @@ func hashfor(t *Type) *Node { ...@@ -349,9 +352,9 @@ func hashfor(t *Type) *Node {
n := newname(sym) n := newname(sym)
n.Class = PFUNC n.Class = PFUNC
tfn := nod(OTFUNC, nil, nil) tfn := nod(OTFUNC, nil, nil)
tfn.List.Append(anonfield(typPtr(t))) tfn.List.Append(anonfield(types.NewPtr(t)))
tfn.List.Append(anonfield(Types[TUINTPTR])) tfn.List.Append(anonfield(types.Types[TUINTPTR]))
tfn.Rlist.Append(anonfield(Types[TUINTPTR])) tfn.Rlist.Append(anonfield(types.Types[TUINTPTR]))
tfn = typecheck(tfn, Etype) tfn = typecheck(tfn, Etype)
n.Type = tfn.Type n.Type = tfn.Type
return n return n
...@@ -359,7 +362,7 @@ func hashfor(t *Type) *Node { ...@@ -359,7 +362,7 @@ func hashfor(t *Type) *Node {
// geneq generates a helper function to // geneq generates a helper function to
// check equality of two values of type t. // check equality of two values of type t.
func geneq(sym *Sym, t *Type) { func geneq(sym *types.Sym, t *types.Type) {
if Debug['r'] != 0 { if Debug['r'] != 0 {
fmt.Printf("geneq %v %v\n", sym, t) fmt.Printf("geneq %v %v\n", sym, t)
} }
...@@ -376,13 +379,13 @@ func geneq(sym *Sym, t *Type) { ...@@ -376,13 +379,13 @@ func geneq(sym *Sym, t *Type) {
tfn := nod(OTFUNC, nil, nil) tfn := nod(OTFUNC, nil, nil)
fn.Func.Nname.Name.Param.Ntype = tfn fn.Func.Nname.Name.Param.Ntype = tfn
n := namedfield("p", typPtr(t)) n := namedfield("p", types.NewPtr(t))
tfn.List.Append(n) tfn.List.Append(n)
np := n.Left np := n.Left
n = namedfield("q", typPtr(t)) n = namedfield("q", types.NewPtr(t))
tfn.List.Append(n) tfn.List.Append(n)
nq := n.Left nq := n.Left
n = anonfield(Types[TBOOL]) n = anonfield(types.Types[TBOOL])
tfn.Rlist.Append(n) tfn.Rlist.Append(n)
funchdr(fn) funchdr(fn)
...@@ -404,7 +407,7 @@ func geneq(sym *Sym, t *Type) { ...@@ -404,7 +407,7 @@ func geneq(sym *Sym, t *Type) {
nrange := nod(ORANGE, nil, nod(OIND, np, nil)) nrange := nod(ORANGE, nil, nod(OIND, np, nil))
ni := newname(lookup("i")) ni := newname(lookup("i"))
ni.Type = Types[TINT] ni.Type = types.Types[TINT]
nrange.List.Set1(ni) nrange.List.Set1(ni)
nrange.SetColas(true) nrange.SetColas(true)
colasdefn(nrange.List.Slice(), nrange) colasdefn(nrange.List.Slice(), nrange)
...@@ -452,7 +455,7 @@ func geneq(sym *Sym, t *Type) { ...@@ -452,7 +455,7 @@ func geneq(sym *Sym, t *Type) {
} }
// Compare non-memory fields with field equality. // Compare non-memory fields with field equality.
if !f.Type.IsRegularMemory() { if !IsRegularMemory(f.Type) {
and(eqfield(np, nq, f.Sym)) and(eqfield(np, nq, f.Sym))
i++ i++
continue continue
...@@ -521,7 +524,7 @@ func geneq(sym *Sym, t *Type) { ...@@ -521,7 +524,7 @@ func geneq(sym *Sym, t *Type) {
// eqfield returns the node // eqfield returns the node
// p.field == q.field // p.field == q.field
func eqfield(p *Node, q *Node, field *Sym) *Node { func eqfield(p *Node, q *Node, field *types.Sym) *Node {
nx := nodSym(OXDOT, p, field) nx := nodSym(OXDOT, p, field)
ny := nodSym(OXDOT, q, field) ny := nodSym(OXDOT, q, field)
ne := nod(OEQ, nx, ny) ne := nod(OEQ, nx, ny)
...@@ -530,7 +533,7 @@ func eqfield(p *Node, q *Node, field *Sym) *Node { ...@@ -530,7 +533,7 @@ func eqfield(p *Node, q *Node, field *Sym) *Node {
// eqmem returns the node // eqmem returns the node
// memequal(&p.field, &q.field [, size]) // memequal(&p.field, &q.field [, size])
func eqmem(p *Node, q *Node, field *Sym, size int64) *Node { func eqmem(p *Node, q *Node, field *types.Sym, size int64) *Node {
nx := nod(OADDR, nodSym(OXDOT, p, field), nil) nx := nod(OADDR, nodSym(OXDOT, p, field), nil)
nx.Etype = 1 // does not escape nx.Etype = 1 // does not escape
ny := nod(OADDR, nodSym(OXDOT, q, field), nil) ny := nod(OADDR, nodSym(OXDOT, q, field), nil)
...@@ -549,7 +552,7 @@ func eqmem(p *Node, q *Node, field *Sym, size int64) *Node { ...@@ -549,7 +552,7 @@ func eqmem(p *Node, q *Node, field *Sym, size int64) *Node {
return call return call
} }
func eqmemfunc(size int64, t *Type) (fn *Node, needsize bool) { func eqmemfunc(size int64, t *types.Type) (fn *Node, needsize bool) {
switch size { switch size {
default: default:
fn = syslook("memequal") fn = syslook("memequal")
...@@ -567,7 +570,7 @@ func eqmemfunc(size int64, t *Type) (fn *Node, needsize bool) { ...@@ -567,7 +570,7 @@ func eqmemfunc(size int64, t *Type) (fn *Node, needsize bool) {
// t is the parent struct type, and start is the field index at which to start the run. // t is the parent struct type, and start is the field index at which to start the run.
// size is the length in bytes of the memory included in the run. // size is the length in bytes of the memory included in the run.
// next is the index just after the end of the memory run. // next is the index just after the end of the memory run.
func memrun(t *Type, start int) (size int64, next int) { func memrun(t *types.Type, start int) (size int64, next int) {
next = start next = start
for { for {
next++ next++
...@@ -579,7 +582,7 @@ func memrun(t *Type, start int) (size int64, next int) { ...@@ -579,7 +582,7 @@ func memrun(t *Type, start int) (size int64, next int) {
break break
} }
// Also, stop before a blank or non-memory field. // Also, stop before a blank or non-memory field.
if f := t.Field(next); isblanksym(f.Sym) || !f.Type.IsRegularMemory() { if f := t.Field(next); isblanksym(f.Sym) || !IsRegularMemory(f.Type) {
break break
} }
} }
...@@ -588,7 +591,7 @@ func memrun(t *Type, start int) (size int64, next int) { ...@@ -588,7 +591,7 @@ func memrun(t *Type, start int) (size int64, next int) {
// ispaddedfield reports whether the i'th field of struct type t is followed // ispaddedfield reports whether the i'th field of struct type t is followed
// by padding. // by padding.
func ispaddedfield(t *Type, i int) bool { func ispaddedfield(t *types.Type, i int) bool {
if !t.IsStruct() { if !t.IsStruct() {
Fatalf("ispaddedfield called non-struct %v", t) Fatalf("ispaddedfield called non-struct %v", t)
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"sort" "sort"
) )
...@@ -21,8 +22,8 @@ func Rnd(o int64, r int64) int64 { ...@@ -21,8 +22,8 @@ func Rnd(o int64, r int64) int64 {
// expandiface computes the method set for interface type t by // expandiface computes the method set for interface type t by
// expanding embedded interfaces. // expanding embedded interfaces.
func expandiface(t *Type) { func expandiface(t *types.Type) {
var fields []*Field var fields []*types.Field
for _, m := range t.Methods().Slice() { for _, m := range t.Methods().Slice() {
if m.Sym != nil { if m.Sym != nil {
fields = append(fields, m) fields = append(fields, m)
...@@ -30,7 +31,7 @@ func expandiface(t *Type) { ...@@ -30,7 +31,7 @@ func expandiface(t *Type) {
} }
if !m.Type.IsInterface() { if !m.Type.IsInterface() {
yyerrorl(m.Nname.Pos, "interface contains embedded non-interface %v", m.Type) yyerrorl(asNode(m.Nname).Pos, "interface contains embedded non-interface %v", m.Type)
m.SetBroke(true) m.SetBroke(true)
t.SetBroke(true) t.SetBroke(true)
// Add to fields so that error messages // Add to fields so that error messages
...@@ -45,7 +46,7 @@ func expandiface(t *Type) { ...@@ -45,7 +46,7 @@ func expandiface(t *Type) {
// (including broken ones, if any) and add to t's // (including broken ones, if any) and add to t's
// method set. // method set.
for _, t1 := range m.Type.Fields().Slice() { for _, t1 := range m.Type.Fields().Slice() {
f := newField() f := types.NewField()
f.Type = t1.Type f.Type = t1.Type
f.SetBroke(t1.Broke()) f.SetBroke(t1.Broke())
f.Sym = t1.Sym f.Sym = t1.Sym
...@@ -57,10 +58,10 @@ func expandiface(t *Type) { ...@@ -57,10 +58,10 @@ func expandiface(t *Type) {
// Access fields directly to avoid recursively calling dowidth // Access fields directly to avoid recursively calling dowidth
// within Type.Fields(). // within Type.Fields().
t.Extra.(*InterType).fields.Set(fields) t.Extra.(*types.InterType).Fields.Set(fields)
} }
func offmod(t *Type) { func offmod(t *types.Type) {
o := int32(0) o := int32(0)
for _, f := range t.Fields().Slice() { for _, f := range t.Fields().Slice() {
f.Offset = int64(o) f.Offset = int64(o)
...@@ -72,7 +73,7 @@ func offmod(t *Type) { ...@@ -72,7 +73,7 @@ func offmod(t *Type) {
} }
} }
func widstruct(errtype *Type, t *Type, o int64, flag int) int64 { func widstruct(errtype *types.Type, t *types.Type, o int64, flag int) int64 {
starto := o starto := o
maxalign := int32(flag) maxalign := int32(flag)
if maxalign < 1 { if maxalign < 1 {
...@@ -94,7 +95,7 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 { ...@@ -94,7 +95,7 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 {
o = Rnd(o, int64(f.Type.Align)) o = Rnd(o, int64(f.Type.Align))
} }
f.Offset = o f.Offset = o
if f.Nname != nil { if asNode(f.Nname) != nil {
// addrescapes has similar code to update these offsets. // addrescapes has similar code to update these offsets.
// Usually addrescapes runs after widstruct, // Usually addrescapes runs after widstruct,
// in which case we could drop this, // in which case we could drop this,
...@@ -102,11 +103,11 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 { ...@@ -102,11 +103,11 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 {
// NOTE(rsc): This comment may be stale. // NOTE(rsc): This comment may be stale.
// It's possible the ordering has changed and this is // It's possible the ordering has changed and this is
// now the common case. I'm not sure. // now the common case. I'm not sure.
if f.Nname.Name.Param.Stackcopy != nil { if asNode(f.Nname).Name.Param.Stackcopy != nil {
f.Nname.Name.Param.Stackcopy.Xoffset = o asNode(f.Nname).Name.Param.Stackcopy.Xoffset = o
f.Nname.Xoffset = 0 asNode(f.Nname).Xoffset = 0
} else { } else {
f.Nname.Xoffset = o asNode(f.Nname).Xoffset = o
} }
} }
...@@ -150,7 +151,7 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 { ...@@ -150,7 +151,7 @@ func widstruct(errtype *Type, t *Type, o int64, flag int) int64 {
return o return o
} }
func dowidth(t *Type) { func dowidth(t *types.Type) {
if Widthptr == 0 { if Widthptr == 0 {
Fatalf("dowidth without betypeinit") Fatalf("dowidth without betypeinit")
} }
...@@ -162,7 +163,7 @@ func dowidth(t *Type) { ...@@ -162,7 +163,7 @@ func dowidth(t *Type) {
if t.Width == -2 { if t.Width == -2 {
if !t.Broke() { if !t.Broke() {
t.SetBroke(true) t.SetBroke(true)
yyerrorl(t.nod.Pos, "invalid recursive type %v", t) yyerrorl(asNode(t.Nod).Pos, "invalid recursive type %v", t)
} }
t.Width = 0 t.Width = 0
...@@ -183,8 +184,8 @@ func dowidth(t *Type) { ...@@ -183,8 +184,8 @@ func dowidth(t *Type) {
defercalc++ defercalc++
lno := lineno lno := lineno
if t.nod != nil { if asNode(t.Nod) != nil {
lineno = t.nod.Pos lineno = asNode(t.Nod).Pos
} }
t.Width = -2 t.Width = -2
...@@ -253,7 +254,7 @@ func dowidth(t *Type) { ...@@ -253,7 +254,7 @@ func dowidth(t *Type) {
// make fake type to check later to // make fake type to check later to
// trigger channel argument check. // trigger channel argument check.
t1 := typChanArgs(t) t1 := types.NewChanArgs(t)
checkwidth(t1) checkwidth(t1)
case TCHANARGS: case TCHANARGS:
...@@ -290,7 +291,7 @@ func dowidth(t *Type) { ...@@ -290,7 +291,7 @@ func dowidth(t *Type) {
if t.Elem() == nil { if t.Elem() == nil {
break break
} }
if t.isDDDArray() { if t.IsDDDArray() {
if !t.Broke() { if !t.Broke() {
yyerror("use of [...] array outside of array literal") yyerror("use of [...] array outside of array literal")
t.SetBroke(true) t.SetBroke(true)
...@@ -325,7 +326,7 @@ func dowidth(t *Type) { ...@@ -325,7 +326,7 @@ func dowidth(t *Type) {
// make fake type to check later to // make fake type to check later to
// trigger function argument computation. // trigger function argument computation.
case TFUNC: case TFUNC:
t1 := typFuncArgs(t) t1 := types.NewFuncArgs(t)
checkwidth(t1) checkwidth(t1)
w = int64(Widthptr) // width of func type is pointer w = int64(Widthptr) // width of func type is pointer
...@@ -336,7 +337,7 @@ func dowidth(t *Type) { ...@@ -336,7 +337,7 @@ func dowidth(t *Type) {
w = widstruct(t1, t1.Recvs(), 0, 0) w = widstruct(t1, t1.Recvs(), 0, 0)
w = widstruct(t1, t1.Params(), w, Widthreg) w = widstruct(t1, t1.Params(), w, Widthreg)
w = widstruct(t1, t1.Results(), w, Widthreg) w = widstruct(t1, t1.Results(), w, Widthreg)
t1.Extra.(*FuncType).Argwid = w t1.Extra.(*types.FuncType).Argwid = w
if w%int64(Widthreg) != 0 { if w%int64(Widthreg) != 0 {
Warn("bad type %v %d\n", t1, w) Warn("bad type %v %d\n", t1, w)
} }
...@@ -388,9 +389,9 @@ func dowidth(t *Type) { ...@@ -388,9 +389,9 @@ func dowidth(t *Type) {
// is needed immediately. checkwidth makes sure the // is needed immediately. checkwidth makes sure the
// size is evaluated eventually. // size is evaluated eventually.
var deferredTypeStack []*Type var deferredTypeStack []*types.Type
func checkwidth(t *Type) { func checkwidth(t *types.Type) {
if t == nil { if t == nil {
return return
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
package gc package gc
import "cmd/compile/internal/types"
var runtimeDecls = [...]struct { var runtimeDecls = [...]struct {
name string name string
tag int tag int
...@@ -145,58 +147,58 @@ var runtimeDecls = [...]struct { ...@@ -145,58 +147,58 @@ var runtimeDecls = [...]struct {
{"support_popcnt", varTag, 11}, {"support_popcnt", varTag, 11},
} }
func runtimeTypes() []*Type { func runtimeTypes() []*types.Type {
var typs [112]*Type var typs [112]*types.Type
typs[0] = bytetype typs[0] = types.Bytetype
typs[1] = typPtr(typs[0]) typs[1] = types.NewPtr(typs[0])
typs[2] = Types[TANY] typs[2] = types.Types[TANY]
typs[3] = typPtr(typs[2]) typs[3] = types.NewPtr(typs[2])
typs[4] = functype(nil, []*Node{anonfield(typs[1])}, []*Node{anonfield(typs[3])}) typs[4] = functype(nil, []*Node{anonfield(typs[1])}, []*Node{anonfield(typs[3])})
typs[5] = functype(nil, nil, nil) typs[5] = functype(nil, nil, nil)
typs[6] = Types[TINTER] typs[6] = types.Types[TINTER]
typs[7] = functype(nil, []*Node{anonfield(typs[6])}, nil) typs[7] = functype(nil, []*Node{anonfield(typs[6])}, nil)
typs[8] = Types[TINT32] typs[8] = types.Types[TINT32]
typs[9] = typPtr(typs[8]) typs[9] = types.NewPtr(typs[8])
typs[10] = functype(nil, []*Node{anonfield(typs[9])}, []*Node{anonfield(typs[6])}) typs[10] = functype(nil, []*Node{anonfield(typs[9])}, []*Node{anonfield(typs[6])})
typs[11] = Types[TBOOL] typs[11] = types.Types[TBOOL]
typs[12] = functype(nil, []*Node{anonfield(typs[11])}, nil) typs[12] = functype(nil, []*Node{anonfield(typs[11])}, nil)
typs[13] = Types[TFLOAT64] typs[13] = types.Types[TFLOAT64]
typs[14] = functype(nil, []*Node{anonfield(typs[13])}, nil) typs[14] = functype(nil, []*Node{anonfield(typs[13])}, nil)
typs[15] = Types[TINT64] typs[15] = types.Types[TINT64]
typs[16] = functype(nil, []*Node{anonfield(typs[15])}, nil) typs[16] = functype(nil, []*Node{anonfield(typs[15])}, nil)
typs[17] = Types[TUINT64] typs[17] = types.Types[TUINT64]
typs[18] = functype(nil, []*Node{anonfield(typs[17])}, nil) typs[18] = functype(nil, []*Node{anonfield(typs[17])}, nil)
typs[19] = Types[TCOMPLEX128] typs[19] = types.Types[TCOMPLEX128]
typs[20] = functype(nil, []*Node{anonfield(typs[19])}, nil) typs[20] = functype(nil, []*Node{anonfield(typs[19])}, nil)
typs[21] = Types[TSTRING] typs[21] = types.Types[TSTRING]
typs[22] = functype(nil, []*Node{anonfield(typs[21])}, nil) typs[22] = functype(nil, []*Node{anonfield(typs[21])}, nil)
typs[23] = functype(nil, []*Node{anonfield(typs[2])}, nil) typs[23] = functype(nil, []*Node{anonfield(typs[2])}, nil)
typs[24] = typArray(typs[0], 32) typs[24] = types.NewArray(typs[0], 32)
typs[25] = typPtr(typs[24]) typs[25] = types.NewPtr(typs[24])
typs[26] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])}) typs[26] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])})
typs[27] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])}) typs[27] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])})
typs[28] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])}) typs[28] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])})
typs[29] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])}) typs[29] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[21])})
typs[30] = typSlice(typs[21]) typs[30] = types.NewSlice(typs[21])
typs[31] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[30])}, []*Node{anonfield(typs[21])}) typs[31] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[30])}, []*Node{anonfield(typs[21])})
typs[32] = Types[TINT] typs[32] = types.Types[TINT]
typs[33] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[32])}) typs[33] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[32])})
typs[34] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[11])}) typs[34] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[21])}, []*Node{anonfield(typs[11])})
typs[35] = typArray(typs[0], 4) typs[35] = types.NewArray(typs[0], 4)
typs[36] = typPtr(typs[35]) typs[36] = types.NewPtr(typs[35])
typs[37] = functype(nil, []*Node{anonfield(typs[36]), anonfield(typs[15])}, []*Node{anonfield(typs[21])}) typs[37] = functype(nil, []*Node{anonfield(typs[36]), anonfield(typs[15])}, []*Node{anonfield(typs[21])})
typs[38] = typSlice(typs[0]) typs[38] = types.NewSlice(typs[0])
typs[39] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[38])}, []*Node{anonfield(typs[21])}) typs[39] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[38])}, []*Node{anonfield(typs[21])})
typs[40] = functype(nil, []*Node{anonfield(typs[38])}, []*Node{anonfield(typs[21])}) typs[40] = functype(nil, []*Node{anonfield(typs[38])}, []*Node{anonfield(typs[21])})
typs[41] = runetype typs[41] = types.Runetype
typs[42] = typSlice(typs[41]) typs[42] = types.NewSlice(typs[41])
typs[43] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[42])}, []*Node{anonfield(typs[21])}) typs[43] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[42])}, []*Node{anonfield(typs[21])})
typs[44] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21])}, []*Node{anonfield(typs[38])}) typs[44] = functype(nil, []*Node{anonfield(typs[25]), anonfield(typs[21])}, []*Node{anonfield(typs[38])})
typs[45] = typArray(typs[41], 32) typs[45] = types.NewArray(typs[41], 32)
typs[46] = typPtr(typs[45]) typs[46] = types.NewPtr(typs[45])
typs[47] = functype(nil, []*Node{anonfield(typs[46]), anonfield(typs[21])}, []*Node{anonfield(typs[42])}) typs[47] = functype(nil, []*Node{anonfield(typs[46]), anonfield(typs[21])}, []*Node{anonfield(typs[42])})
typs[48] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[32])}, []*Node{anonfield(typs[41]), anonfield(typs[32])}) typs[48] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[32])}, []*Node{anonfield(typs[41]), anonfield(typs[32])})
typs[49] = Types[TUINTPTR] typs[49] = types.Types[TUINTPTR]
typs[50] = functype(nil, []*Node{anonfield(typs[2]), anonfield(typs[2]), anonfield(typs[49])}, []*Node{anonfield(typs[32])}) typs[50] = functype(nil, []*Node{anonfield(typs[2]), anonfield(typs[2]), anonfield(typs[49])}, []*Node{anonfield(typs[32])})
typs[51] = functype(nil, []*Node{anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])}) typs[51] = functype(nil, []*Node{anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])})
typs[52] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2])}) typs[52] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2])})
...@@ -204,10 +206,10 @@ func runtimeTypes() []*Type { ...@@ -204,10 +206,10 @@ func runtimeTypes() []*Type {
typs[54] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2]), anonfield(typs[11])}) typs[54] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2]), anonfield(typs[11])})
typs[55] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[1])}, nil) typs[55] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[1])}, nil)
typs[56] = functype(nil, []*Node{anonfield(typs[1])}, nil) typs[56] = functype(nil, []*Node{anonfield(typs[1])}, nil)
typs[57] = typPtr(typs[49]) typs[57] = types.NewPtr(typs[49])
typs[58] = Types[TUNSAFEPTR] typs[58] = types.Types[TUNSAFEPTR]
typs[59] = functype(nil, []*Node{anonfield(typs[57]), anonfield(typs[58]), anonfield(typs[58])}, []*Node{anonfield(typs[11])}) typs[59] = functype(nil, []*Node{anonfield(typs[57]), anonfield(typs[58]), anonfield(typs[58])}, []*Node{anonfield(typs[11])})
typs[60] = typMap(typs[2], typs[2]) typs[60] = types.NewMap(typs[2], typs[2])
typs[61] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[60])}) typs[61] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[60])})
typs[62] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[3])}, []*Node{anonfield(typs[3])}) typs[62] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[3])}, []*Node{anonfield(typs[3])})
typs[63] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[2])}, []*Node{anonfield(typs[3])}) typs[63] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[2])}, []*Node{anonfield(typs[3])})
...@@ -218,14 +220,14 @@ func runtimeTypes() []*Type { ...@@ -218,14 +220,14 @@ func runtimeTypes() []*Type {
typs[68] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[3])}, nil) typs[68] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[3])}, nil)
typs[69] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[2])}, nil) typs[69] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[60]), anonfield(typs[2])}, nil)
typs[70] = functype(nil, []*Node{anonfield(typs[3])}, nil) typs[70] = functype(nil, []*Node{anonfield(typs[3])}, nil)
typs[71] = typChan(typs[2], Cboth) typs[71] = types.NewChan(typs[2], types.Cboth)
typs[72] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15])}, []*Node{anonfield(typs[71])}) typs[72] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15])}, []*Node{anonfield(typs[71])})
typs[73] = typChan(typs[2], Crecv) typs[73] = types.NewChan(typs[2], types.Crecv)
typs[74] = functype(nil, []*Node{anonfield(typs[73]), anonfield(typs[3])}, nil) typs[74] = functype(nil, []*Node{anonfield(typs[73]), anonfield(typs[3])}, nil)
typs[75] = functype(nil, []*Node{anonfield(typs[73]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) typs[75] = functype(nil, []*Node{anonfield(typs[73]), anonfield(typs[3])}, []*Node{anonfield(typs[11])})
typs[76] = typChan(typs[2], Csend) typs[76] = types.NewChan(typs[2], types.Csend)
typs[77] = functype(nil, []*Node{anonfield(typs[76]), anonfield(typs[3])}, nil) typs[77] = functype(nil, []*Node{anonfield(typs[76]), anonfield(typs[3])}, nil)
typs[78] = typArray(typs[0], 3) typs[78] = types.NewArray(typs[0], 3)
typs[79] = tostruct([]*Node{namedfield("enabled", typs[11]), namedfield("pad", typs[78]), namedfield("needed", typs[11]), namedfield("cgo", typs[11]), namedfield("alignme", typs[17])}) typs[79] = tostruct([]*Node{namedfield("enabled", typs[11]), namedfield("pad", typs[78]), namedfield("needed", typs[11]), namedfield("cgo", typs[11]), namedfield("alignme", typs[17])})
typs[80] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[2])}, nil) typs[80] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[2])}, nil)
typs[81] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3]), anonfield(typs[3])}, nil) typs[81] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3]), anonfield(typs[3])}, nil)
...@@ -233,13 +235,13 @@ func runtimeTypes() []*Type { ...@@ -233,13 +235,13 @@ func runtimeTypes() []*Type {
typs[83] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])}) typs[83] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])})
typs[84] = functype(nil, []*Node{anonfield(typs[76]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) typs[84] = functype(nil, []*Node{anonfield(typs[76]), anonfield(typs[3])}, []*Node{anonfield(typs[11])})
typs[85] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[73])}, []*Node{anonfield(typs[11])}) typs[85] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[73])}, []*Node{anonfield(typs[11])})
typs[86] = typPtr(typs[11]) typs[86] = types.NewPtr(typs[11])
typs[87] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[86]), anonfield(typs[73])}, []*Node{anonfield(typs[11])}) typs[87] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[86]), anonfield(typs[73])}, []*Node{anonfield(typs[11])})
typs[88] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[8])}, nil) typs[88] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[8])}, nil)
typs[89] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[76]), anonfield(typs[3])}, nil) typs[89] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[76]), anonfield(typs[3])}, nil)
typs[90] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[73]), anonfield(typs[3]), anonfield(typs[86])}, nil) typs[90] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[73]), anonfield(typs[3]), anonfield(typs[86])}, nil)
typs[91] = functype(nil, []*Node{anonfield(typs[1])}, []*Node{anonfield(typs[32])}) typs[91] = functype(nil, []*Node{anonfield(typs[1])}, []*Node{anonfield(typs[32])})
typs[92] = typSlice(typs[2]) typs[92] = types.NewSlice(typs[2])
typs[93] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[32])}, []*Node{anonfield(typs[92])}) typs[93] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[32])}, []*Node{anonfield(typs[92])})
typs[94] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[92])}) typs[94] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[92])})
typs[95] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[92]), anonfield(typs[32])}, []*Node{anonfield(typs[92])}) typs[95] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[92]), anonfield(typs[32])}, []*Node{anonfield(typs[92])})
...@@ -251,7 +253,7 @@ func runtimeTypes() []*Type { ...@@ -251,7 +253,7 @@ func runtimeTypes() []*Type {
typs[101] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])}) typs[101] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])})
typs[102] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])}) typs[102] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])})
typs[103] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])}) typs[103] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])})
typs[104] = Types[TUINT32] typs[104] = types.Types[TUINT32]
typs[105] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[104])}) typs[105] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[104])})
typs[106] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])}) typs[106] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])})
typs[107] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])}) typs[107] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])})
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/src" "cmd/internal/src"
) )
...@@ -76,7 +77,7 @@ func (l *cfLabel) defined() bool { return l.defNode != nil } ...@@ -76,7 +77,7 @@ func (l *cfLabel) defined() bool { return l.defNode != nil }
func (l *cfLabel) used() bool { return l.useNode != nil } func (l *cfLabel) used() bool { return l.useNode != nil }
// label returns the label associated with sym, creating it if necessary. // label returns the label associated with sym, creating it if necessary.
func (c *controlflow) label(sym *Sym) *cfLabel { func (c *controlflow) label(sym *types.Sym) *cfLabel {
lab := c.labels[sym.Name] lab := c.labels[sym.Name]
if lab == nil { if lab == nil {
lab = new(cfLabel) lab = new(cfLabel)
...@@ -253,8 +254,8 @@ func (c *controlflow) checkgoto(from *Node, to *Node) { ...@@ -253,8 +254,8 @@ func (c *controlflow) checkgoto(from *Node, to *Node) {
// Decide what to complain about. Unwind to.Sym until where it // Decide what to complain about. Unwind to.Sym until where it
// forked from from.Sym, and keep track of the innermost block // forked from from.Sym, and keep track of the innermost block
// and declaration we jumped into/over. // and declaration we jumped into/over.
var block *Sym var block *types.Sym
var dcl *Sym var dcl *types.Sym
// If to.Sym is longer, unwind until it's the same length. // If to.Sym is longer, unwind until it's the same length.
ts := to.Sym ts := to.Sym
...@@ -290,7 +291,7 @@ func (c *controlflow) checkgoto(from *Node, to *Node) { ...@@ -290,7 +291,7 @@ func (c *controlflow) checkgoto(from *Node, to *Node) {
// dcldepth returns the declaration depth for a dclstack Sym; that is, // dcldepth returns the declaration depth for a dclstack Sym; that is,
// the sum of the block nesting level and the number of declarations // the sum of the block nesting level and the number of declarations
// in scope. // in scope.
func dcldepth(s *Sym) int { func dcldepth(s *types.Sym) int {
n := 0 n := 0
for ; s != nil; s = s.Link { for ; s != nil; s = s.Link {
n++ n++
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"fmt" "fmt"
) )
...@@ -155,7 +156,7 @@ func typecheckclosure(func_ *Node, top int) { ...@@ -155,7 +156,7 @@ func typecheckclosure(func_ *Node, top int) {
var closurename_closgen int var closurename_closgen int
func closurename(n *Node) *Sym { func closurename(n *Node) *types.Sym {
if n.Sym != nil { if n.Sym != nil {
return n.Sym return n.Sym
} }
...@@ -282,7 +283,7 @@ func capturevars(xfunc *Node) { ...@@ -282,7 +283,7 @@ func capturevars(xfunc *Node) {
} }
if Debug['m'] > 1 { if Debug['m'] > 1 {
var name *Sym var name *types.Sym
if v.Name.Curfn != nil && v.Name.Curfn.Func.Nname != nil { if v.Name.Curfn != nil && v.Name.Curfn.Func.Nname != nil {
name = v.Name.Curfn.Func.Nname.Sym name = v.Name.Curfn.Func.Nname.Sym
} }
...@@ -327,35 +328,35 @@ func transformclosure(xfunc *Node) { ...@@ -327,35 +328,35 @@ func transformclosure(xfunc *Node) {
f := xfunc.Func.Nname f := xfunc.Func.Nname
// We are going to insert captured variables before input args. // We are going to insert captured variables before input args.
var params []*Field var params []*types.Field
var decls []*Node var decls []*Node
for _, v := range func_.Func.Cvars.Slice() { for _, v := range func_.Func.Cvars.Slice() {
if v.Op == OXXX { if v.Op == OXXX {
continue continue
} }
fld := newField() fld := types.NewField()
fld.Funarg = FunargParams fld.Funarg = types.FunargParams
if v.Name.Byval() { if v.Name.Byval() {
// If v is captured by value, we merely downgrade it to PPARAM. // If v is captured by value, we merely downgrade it to PPARAM.
v.Class = PPARAM v.Class = PPARAM
fld.Nname = v fld.Nname = asTypesNode(v)
} else { } else {
// If v of type T is captured by reference, // If v of type T is captured by reference,
// we introduce function param &v *T // we introduce function param &v *T
// and v remains PAUTOHEAP with &v heapaddr // and v remains PAUTOHEAP with &v heapaddr
// (accesses will implicitly deref &v). // (accesses will implicitly deref &v).
addr := newname(lookup("&" + v.Sym.Name)) addr := newname(lookup("&" + v.Sym.Name))
addr.Type = typPtr(v.Type) addr.Type = types.NewPtr(v.Type)
addr.Class = PPARAM addr.Class = PPARAM
v.Name.Param.Heapaddr = addr v.Name.Param.Heapaddr = addr
fld.Nname = addr fld.Nname = asTypesNode(addr)
} }
fld.Type = fld.Nname.Type fld.Type = asNode(fld.Nname).Type
fld.Sym = fld.Nname.Sym fld.Sym = asNode(fld.Nname).Sym
params = append(params, fld) params = append(params, fld)
decls = append(decls, fld.Nname) decls = append(decls, asNode(fld.Nname))
} }
if len(params) > 0 { if len(params) > 0 {
...@@ -380,7 +381,7 @@ func transformclosure(xfunc *Node) { ...@@ -380,7 +381,7 @@ func transformclosure(xfunc *Node) {
cv.Type = v.Type cv.Type = v.Type
if !v.Name.Byval() { if !v.Name.Byval() {
cv.Type = typPtr(v.Type) cv.Type = types.NewPtr(v.Type)
} }
offset = Rnd(offset, int64(cv.Type.Align)) offset = Rnd(offset, int64(cv.Type.Align))
cv.Xoffset = offset cv.Xoffset = offset
...@@ -395,7 +396,7 @@ func transformclosure(xfunc *Node) { ...@@ -395,7 +396,7 @@ func transformclosure(xfunc *Node) {
// Declare variable holding addresses taken from closure // Declare variable holding addresses taken from closure
// and initialize in entry prologue. // and initialize in entry prologue.
addr := newname(lookup("&" + v.Sym.Name)) addr := newname(lookup("&" + v.Sym.Name))
addr.Type = typPtr(v.Type) addr.Type = types.NewPtr(v.Type)
addr.Class = PAUTO addr.Class = PAUTO
addr.SetUsed(true) addr.SetUsed(true)
addr.Name.Curfn = xfunc addr.Name.Curfn = xfunc
...@@ -473,7 +474,7 @@ func walkclosure(func_ *Node, init *Nodes) *Node { ...@@ -473,7 +474,7 @@ func walkclosure(func_ *Node, init *Nodes) *Node {
typ := nod(OTSTRUCT, nil, nil) typ := nod(OTSTRUCT, nil, nil)
typ.List.Set1(namedfield(".F", Types[TUINTPTR])) typ.List.Set1(namedfield(".F", types.Types[TUINTPTR]))
for _, v := range func_.Func.Cvars.Slice() { for _, v := range func_.Func.Cvars.Slice() {
if v.Op == OXXX { if v.Op == OXXX {
continue continue
...@@ -513,7 +514,7 @@ func walkclosure(func_ *Node, init *Nodes) *Node { ...@@ -513,7 +514,7 @@ func walkclosure(func_ *Node, init *Nodes) *Node {
return walkexpr(clos, init) return walkexpr(clos, init)
} }
func typecheckpartialcall(fn *Node, sym *Sym) { func typecheckpartialcall(fn *Node, sym *types.Sym) {
switch fn.Op { switch fn.Op {
case ODOTINTER, ODOTMETH: case ODOTINTER, ODOTMETH:
break break
...@@ -530,9 +531,9 @@ func typecheckpartialcall(fn *Node, sym *Sym) { ...@@ -530,9 +531,9 @@ func typecheckpartialcall(fn *Node, sym *Sym) {
fn.Type = xfunc.Type fn.Type = xfunc.Type
} }
var makepartialcall_gopkg *Pkg var makepartialcall_gopkg *types.Pkg
func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
var p string var p string
rcvrtype := fn.Left.Type rcvrtype := fn.Left.Type
...@@ -549,7 +550,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { ...@@ -549,7 +550,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
Fatalf("missing base type for %v", rcvrtype) Fatalf("missing base type for %v", rcvrtype)
} }
var spkg *Pkg var spkg *types.Pkg
if basetype.Sym != nil { if basetype.Sym != nil {
spkg = basetype.Sym.Pkg spkg = basetype.Sym.Pkg
} }
...@@ -563,7 +564,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { ...@@ -563,7 +564,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
sym := spkg.Lookup(p) sym := spkg.Lookup(p)
if sym.Uniq() { if sym.Uniq() {
return sym.Def return asNode(sym.Def)
} }
sym.SetUniq(true) sym.SetUniq(true)
...@@ -629,7 +630,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { ...@@ -629,7 +630,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
ptr.Type = rcvrtype ptr.Type = rcvrtype
body = append(body, nod(OAS, ptr, cv)) body = append(body, nod(OAS, ptr, cv))
} else { } else {
ptr.Type = typPtr(rcvrtype) ptr.Type = types.NewPtr(rcvrtype)
body = append(body, nod(OAS, ptr, nod(OADDR, cv, nil))) body = append(body, nod(OAS, ptr, nod(OADDR, cv, nil)))
} }
...@@ -650,7 +651,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { ...@@ -650,7 +651,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
xfunc.Nbody.Set(body) xfunc.Nbody.Set(body)
xfunc = typecheck(xfunc, Etop) xfunc = typecheck(xfunc, Etop)
sym.Def = xfunc sym.Def = asTypesNode(xfunc)
xtop = append(xtop, xfunc) xtop = append(xtop, xfunc)
Curfn = savecurfn Curfn = savecurfn
...@@ -674,7 +675,7 @@ func walkpartialcall(n *Node, init *Nodes) *Node { ...@@ -674,7 +675,7 @@ func walkpartialcall(n *Node, init *Nodes) *Node {
} }
typ := nod(OTSTRUCT, nil, nil) typ := nod(OTSTRUCT, nil, nil)
typ.List.Set1(namedfield("F", Types[TUINTPTR])) typ.List.Set1(namedfield("F", types.Types[TUINTPTR]))
typ.List.Append(namedfield("R", n.Left.Type)) typ.List.Append(namedfield("R", n.Left.Type))
clos := nod(OCOMPLIT, nil, nod(OIND, typ, nil)) clos := nod(OCOMPLIT, nil, nod(OIND, typ, nil))
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/src" "cmd/internal/src"
"math/big" "math/big"
"strings" "strings"
...@@ -132,7 +133,7 @@ func (n *Node) Bool() bool { ...@@ -132,7 +133,7 @@ func (n *Node) Bool() bool {
// truncate float literal fv to 32-bit or 64-bit precision // truncate float literal fv to 32-bit or 64-bit precision
// according to type; return truncated value. // according to type; return truncated value.
func truncfltlit(oldv *Mpflt, t *Type) *Mpflt { func truncfltlit(oldv *Mpflt, t *types.Type) *Mpflt {
if t == nil { if t == nil {
return oldv return oldv
} }
...@@ -147,7 +148,7 @@ func truncfltlit(oldv *Mpflt, t *Type) *Mpflt { ...@@ -147,7 +148,7 @@ func truncfltlit(oldv *Mpflt, t *Type) *Mpflt {
// convert large precision literal floating // convert large precision literal floating
// into limited precision (float64 or float32) // into limited precision (float64 or float32)
switch t.Etype { switch t.Etype {
case TFLOAT64: case types.TFLOAT64:
d := fv.Float64() d := fv.Float64()
fv.SetFloat64(d) fv.SetFloat64(d)
...@@ -172,7 +173,7 @@ const ( ...@@ -172,7 +173,7 @@ const (
// implicit conversion. // implicit conversion.
// The result of convlit MUST be assigned back to n, e.g. // The result of convlit MUST be assigned back to n, e.g.
// n.Left = convlit(n.Left, t) // n.Left = convlit(n.Left, t)
func convlit(n *Node, t *Type) *Node { func convlit(n *Node, t *types.Type) *Node {
return convlit1(n, t, false, noReuse) return convlit1(n, t, false, noReuse)
} }
...@@ -180,7 +181,7 @@ func convlit(n *Node, t *Type) *Node { ...@@ -180,7 +181,7 @@ func convlit(n *Node, t *Type) *Node {
// It returns a new node if necessary. // It returns a new node if necessary.
// The result of convlit1 MUST be assigned back to n, e.g. // The result of convlit1 MUST be assigned back to n, e.g.
// n.Left = convlit1(n.Left, t, explicit, reuse) // n.Left = convlit1(n.Left, t, explicit, reuse)
func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
if n == nil || t == nil || n.Type == nil || t.IsUntyped() || n.Type == t { if n == nil || t == nil || n.Type == nil || t.IsUntyped() || n.Type == t {
return n return n
} }
...@@ -198,11 +199,11 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { ...@@ -198,11 +199,11 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node {
switch n.Op { switch n.Op {
default: default:
if n.Type == idealbool { if n.Type == types.Idealbool {
if t.IsBoolean() { if t.IsBoolean() {
n.Type = t n.Type = t
} else { } else {
n.Type = Types[TBOOL] n.Type = types.Types[TBOOL]
} }
} }
...@@ -240,17 +241,17 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { ...@@ -240,17 +241,17 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node {
default: default:
// If trying to convert to non-complex type, // If trying to convert to non-complex type,
// leave as complex128 and let typechecker complain. // leave as complex128 and let typechecker complain.
t = Types[TCOMPLEX128] t = types.Types[TCOMPLEX128]
fallthrough fallthrough
case TCOMPLEX128: case types.TCOMPLEX128:
n.Type = t n.Type = t
n.Left = convlit(n.Left, Types[TFLOAT64]) n.Left = convlit(n.Left, types.Types[TFLOAT64])
n.Right = convlit(n.Right, Types[TFLOAT64]) n.Right = convlit(n.Right, types.Types[TFLOAT64])
case TCOMPLEX64: case TCOMPLEX64:
n.Type = t n.Type = t
n.Left = convlit(n.Left, Types[TFLOAT32]) n.Left = convlit(n.Left, types.Types[TFLOAT32])
n.Right = convlit(n.Right, Types[TFLOAT32]) n.Right = convlit(n.Right, types.Types[TFLOAT32])
} }
} }
...@@ -263,14 +264,14 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { ...@@ -263,14 +264,14 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node {
} }
ct := consttype(n) ct := consttype(n)
var et EType var et types.EType
if ct < 0 { if ct < 0 {
goto bad goto bad
} }
et = t.Etype et = t.Etype
if et == TINTER { if et == TINTER {
if ct == CTNIL && n.Type == Types[TNIL] { if ct == CTNIL && n.Type == types.Types[TNIL] {
n.Type = t n.Type = t
return n return n
} }
...@@ -361,7 +362,7 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { ...@@ -361,7 +362,7 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node {
case CTCPLX: case CTCPLX:
overflow(n.Val(), t) overflow(n.Val(), t)
} }
} else if et == TSTRING && (ct == CTINT || ct == CTRUNE) && explicit { } else if et == types.TSTRING && (ct == CTINT || ct == CTRUNE) && explicit {
n.SetVal(tostr(n.Val())) n.SetVal(tostr(n.Val()))
} else { } else {
goto bad goto bad
...@@ -492,7 +493,7 @@ func toint(v Val) Val { ...@@ -492,7 +493,7 @@ func toint(v Val) Val {
return v return v
} }
func doesoverflow(v Val, t *Type) bool { func doesoverflow(v Val, t *types.Type) bool {
switch u := v.U.(type) { switch u := v.U.(type) {
case *Mpint: case *Mpint:
if !t.IsInteger() { if !t.IsInteger() {
...@@ -517,7 +518,7 @@ func doesoverflow(v Val, t *Type) bool { ...@@ -517,7 +518,7 @@ func doesoverflow(v Val, t *Type) bool {
return false return false
} }
func overflow(v Val, t *Type) { func overflow(v Val, t *types.Type) {
// v has already been converted // v has already been converted
// to appropriate form for t. // to appropriate form for t.
if t == nil || t.Etype == TIDEAL { if t == nil || t.Etype == TIDEAL {
...@@ -702,7 +703,7 @@ func evconst(n *Node) { ...@@ -702,7 +703,7 @@ func evconst(n *Node) {
nr := n.Right nr := n.Right
var rv Val var rv Val
var lno src.XPos var lno src.XPos
var wr EType var wr types.EType
var v Val var v Val
var norig *Node var norig *Node
var nn *Node var nn *Node
...@@ -750,7 +751,7 @@ func evconst(n *Node) { ...@@ -750,7 +751,7 @@ func evconst(n *Node) {
case OCOM_ | CTINT_, case OCOM_ | CTINT_,
OCOM_ | CTRUNE_: OCOM_ | CTRUNE_:
var et EType = Txxx var et types.EType = Txxx
if nl.Type != nil { if nl.Type != nil {
et = nl.Type.Etype et = nl.Type.Etype
} }
...@@ -836,7 +837,7 @@ func evconst(n *Node) { ...@@ -836,7 +837,7 @@ func evconst(n *Node) {
// right must be unsigned. // right must be unsigned.
// left can be ideal. // left can be ideal.
case OLSH, ORSH: case OLSH, ORSH:
nr = defaultlit(nr, Types[TUINT]) nr = defaultlit(nr, types.Types[TUINT])
n.Right = nr n.Right = nr
if nr.Type != nil && (nr.Type.IsSigned() || !nr.Type.IsInteger()) { if nr.Type != nil && (nr.Type.IsSigned() || !nr.Type.IsInteger()) {
...@@ -1219,16 +1220,16 @@ func nodlit(v Val) *Node { ...@@ -1219,16 +1220,16 @@ func nodlit(v Val) *Node {
Fatalf("nodlit ctype %d", v.Ctype()) Fatalf("nodlit ctype %d", v.Ctype())
case CTSTR: case CTSTR:
n.Type = idealstring n.Type = types.Idealstring
case CTBOOL: case CTBOOL:
n.Type = idealbool n.Type = types.Idealbool
case CTINT, CTRUNE, CTFLT, CTCPLX: case CTINT, CTRUNE, CTFLT, CTCPLX:
n.Type = Types[TIDEAL] n.Type = types.Types[TIDEAL]
case CTNIL: case CTNIL:
n.Type = Types[TNIL] n.Type = types.Types[TNIL]
} }
return n return n
...@@ -1240,7 +1241,7 @@ func nodcplxlit(r Val, i Val) *Node { ...@@ -1240,7 +1241,7 @@ func nodcplxlit(r Val, i Val) *Node {
c := new(Mpcplx) c := new(Mpcplx)
n := nod(OLITERAL, nil, nil) n := nod(OLITERAL, nil, nil)
n.Type = Types[TIDEAL] n.Type = types.Types[TIDEAL]
n.SetVal(Val{c}) n.SetVal(Val{c})
if r.Ctype() != CTFLT || i.Ctype() != CTFLT { if r.Ctype() != CTFLT || i.Ctype() != CTFLT {
...@@ -1318,13 +1319,13 @@ func idealkind(n *Node) Ctype { ...@@ -1318,13 +1319,13 @@ func idealkind(n *Node) Ctype {
// The result of defaultlit MUST be assigned back to n, e.g. // The result of defaultlit MUST be assigned back to n, e.g.
// n.Left = defaultlit(n.Left, t) // n.Left = defaultlit(n.Left, t)
func defaultlit(n *Node, t *Type) *Node { func defaultlit(n *Node, t *types.Type) *Node {
return defaultlitreuse(n, t, noReuse) return defaultlitreuse(n, t, noReuse)
} }
// The result of defaultlitreuse MUST be assigned back to n, e.g. // The result of defaultlitreuse MUST be assigned back to n, e.g.
// n.Left = defaultlitreuse(n.Left, t, reuse) // n.Left = defaultlitreuse(n.Left, t, reuse)
func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node { func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
if n == nil || !n.Type.IsUntyped() { if n == nil || !n.Type.IsUntyped() {
return n return n
} }
...@@ -1337,7 +1338,7 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node { ...@@ -1337,7 +1338,7 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node {
lno := setlineno(n) lno := setlineno(n)
ctype := idealkind(n) ctype := idealkind(n)
var t1 *Type var t1 *types.Type
switch ctype { switch ctype {
default: default:
if t != nil { if t != nil {
...@@ -1356,7 +1357,7 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node { ...@@ -1356,7 +1357,7 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node {
} }
if n.Val().Ctype() == CTSTR { if n.Val().Ctype() == CTSTR {
t1 := Types[TSTRING] t1 := types.Types[TSTRING]
n = convlit1(n, t1, false, reuse) n = convlit1(n, t1, false, reuse)
break break
} }
...@@ -1367,26 +1368,26 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node { ...@@ -1367,26 +1368,26 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node {
Fatalf("defaultlit: idealkind is CTxxx: %+v", n) Fatalf("defaultlit: idealkind is CTxxx: %+v", n)
case CTBOOL: case CTBOOL:
t1 := Types[TBOOL] t1 := types.Types[TBOOL]
if t != nil && t.IsBoolean() { if t != nil && t.IsBoolean() {
t1 = t t1 = t
} }
n = convlit1(n, t1, false, reuse) n = convlit1(n, t1, false, reuse)
case CTINT: case CTINT:
t1 = Types[TINT] t1 = types.Types[TINT]
goto num goto num
case CTRUNE: case CTRUNE:
t1 = runetype t1 = types.Runetype
goto num goto num
case CTFLT: case CTFLT:
t1 = Types[TFLOAT64] t1 = types.Types[TFLOAT64]
goto num goto num
case CTCPLX: case CTCPLX:
t1 = Types[TCOMPLEX128] t1 = types.Types[TCOMPLEX128]
goto num goto num
} }
...@@ -1446,32 +1447,32 @@ func defaultlit2(l *Node, r *Node, force bool) (*Node, *Node) { ...@@ -1446,32 +1447,32 @@ func defaultlit2(l *Node, r *Node, force bool) (*Node, *Node) {
} }
if l.Type.IsBoolean() { if l.Type.IsBoolean() {
l = convlit(l, Types[TBOOL]) l = convlit(l, types.Types[TBOOL])
r = convlit(r, Types[TBOOL]) r = convlit(r, types.Types[TBOOL])
} }
lkind := idealkind(l) lkind := idealkind(l)
rkind := idealkind(r) rkind := idealkind(r)
if lkind == CTCPLX || rkind == CTCPLX { if lkind == CTCPLX || rkind == CTCPLX {
l = convlit(l, Types[TCOMPLEX128]) l = convlit(l, types.Types[TCOMPLEX128])
r = convlit(r, Types[TCOMPLEX128]) r = convlit(r, types.Types[TCOMPLEX128])
return l, r return l, r
} }
if lkind == CTFLT || rkind == CTFLT { if lkind == CTFLT || rkind == CTFLT {
l = convlit(l, Types[TFLOAT64]) l = convlit(l, types.Types[TFLOAT64])
r = convlit(r, Types[TFLOAT64]) r = convlit(r, types.Types[TFLOAT64])
return l, r return l, r
} }
if lkind == CTRUNE || rkind == CTRUNE { if lkind == CTRUNE || rkind == CTRUNE {
l = convlit(l, runetype) l = convlit(l, types.Runetype)
r = convlit(r, runetype) r = convlit(r, types.Runetype)
return l, r return l, r
} }
l = convlit(l, Types[TINT]) l = convlit(l, types.Types[TINT])
r = convlit(r, Types[TINT]) r = convlit(r, types.Types[TINT])
return l, r return l, r
} }
...@@ -1673,13 +1674,13 @@ func isgoconst(n *Node) bool { ...@@ -1673,13 +1674,13 @@ func isgoconst(n *Node) bool {
} }
case ONAME: case ONAME:
l := n.Sym.Def l := asNode(n.Sym.Def)
if l != nil && l.Op == OLITERAL && n.Val().Ctype() != CTNIL { if l != nil && l.Op == OLITERAL && n.Val().Ctype() != CTNIL {
return true return true
} }
case ONONAME: case ONONAME:
if n.Sym.Def != nil && n.Sym.Def.Op == OIOTA { if asNode(n.Sym.Def) != nil && asNode(n.Sym.Def).Op == OIOTA {
return true return true
} }
......
This diff is collapsed.
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
...@@ -131,7 +132,7 @@ func (v *bottomUpVisitor) visitcode(n *Node, min uint32) uint32 { ...@@ -131,7 +132,7 @@ func (v *bottomUpVisitor) visitcode(n *Node, min uint32) uint32 {
if n.Op == OCALLFUNC || n.Op == OCALLMETH { if n.Op == OCALLFUNC || n.Op == OCALLMETH {
fn := n.Left fn := n.Left
if n.Op == OCALLMETH { if n.Op == OCALLMETH {
fn = n.Left.Sym.Def fn = asNode(n.Left.Sym.Def)
} }
if fn != nil && fn.Op == ONAME && fn.Class == PFUNC && fn.Name.Defn != nil { if fn != nil && fn.Op == ONAME && fn.Class == PFUNC && fn.Name.Defn != nil {
m := v.visit(fn.Name.Defn) m := v.visit(fn.Name.Defn)
...@@ -458,7 +459,7 @@ func (e *EscState) stepAssignWhere(dst, src *Node, why string, where *Node) *Esc ...@@ -458,7 +459,7 @@ func (e *EscState) stepAssignWhere(dst, src *Node, why string, where *Node) *Esc
} }
// funcSym returns fn.Func.Nname.Sym if no nils are encountered along the way. // funcSym returns fn.Func.Nname.Sym if no nils are encountered along the way.
func funcSym(fn *Node) *Sym { func funcSym(fn *Node) *types.Sym {
if fn == nil || fn.Func.Nname == nil { if fn == nil || fn.Func.Nname == nil {
return nil return nil
} }
...@@ -466,7 +467,7 @@ func funcSym(fn *Node) *Sym { ...@@ -466,7 +467,7 @@ func funcSym(fn *Node) *Sym {
} }
// curfnSym returns n.Curfn.Nname.Sym if no nils are encountered along the way. // curfnSym returns n.Curfn.Nname.Sym if no nils are encountered along the way.
func (e *EscState) curfnSym(n *Node) *Sym { func (e *EscState) curfnSym(n *Node) *types.Sym {
nE := e.nodeEscState(n) nE := e.nodeEscState(n)
return funcSym(nE.Curfn) return funcSym(nE.Curfn)
} }
...@@ -563,7 +564,7 @@ func (e *EscState) escfunc(fn *Node) { ...@@ -563,7 +564,7 @@ func (e *EscState) escfunc(fn *Node) {
case PPARAM: case PPARAM:
lnE.Loopdepth = 1 lnE.Loopdepth = 1
if ln.Type != nil && !haspointers(ln.Type) { if ln.Type != nil && !types.Haspointers(ln.Type) {
break break
} }
if Curfn.Nbody.Len() == 0 && !Curfn.Noescape() { if Curfn.Nbody.Len() == 0 && !Curfn.Noescape() {
...@@ -621,7 +622,7 @@ func (e *EscState) escloopdepth(n *Node) { ...@@ -621,7 +622,7 @@ func (e *EscState) escloopdepth(n *Node) {
// after escape analysis. in the future, maybe pull label & goto analysis out of walk and put before esc // after escape analysis. in the future, maybe pull label & goto analysis out of walk and put before esc
// if(n.Left.Sym.Label != nil) // if(n.Left.Sym.Label != nil)
// fatal("escape analysis messed up analyzing label: %+N", n); // fatal("escape analysis messed up analyzing label: %+N", n);
n.Left.Sym.Label = &nonlooping n.Left.Sym.Label = asTypesNode(&nonlooping)
case OGOTO: case OGOTO:
if n.Left == nil || n.Left.Sym == nil { if n.Left == nil || n.Left.Sym == nil {
...@@ -630,8 +631,8 @@ func (e *EscState) escloopdepth(n *Node) { ...@@ -630,8 +631,8 @@ func (e *EscState) escloopdepth(n *Node) {
// If we come past one that's uninitialized, this must be a (harmless) forward jump // If we come past one that's uninitialized, this must be a (harmless) forward jump
// but if it's set to nonlooping the label must have preceded this goto. // but if it's set to nonlooping the label must have preceded this goto.
if n.Left.Sym.Label == &nonlooping { if asNode(n.Left.Sym.Label) == &nonlooping {
n.Left.Sym.Label = &looping n.Left.Sym.Label = asTypesNode(&looping)
} }
} }
...@@ -720,11 +721,11 @@ func (e *EscState) esc(n *Node, parent *Node) { ...@@ -720,11 +721,11 @@ func (e *EscState) esc(n *Node, parent *Node) {
} }
case OLABEL: case OLABEL:
if n.Left.Sym.Label == &nonlooping { if asNode(n.Left.Sym.Label) == &nonlooping {
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v:%v non-looping label\n", linestr(lineno), n) fmt.Printf("%v:%v non-looping label\n", linestr(lineno), n)
} }
} else if n.Left.Sym.Label == &looping { } else if asNode(n.Left.Sym.Label) == &looping {
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v: %v looping label\n", linestr(lineno), n) fmt.Printf("%v: %v looping label\n", linestr(lineno), n)
} }
...@@ -1158,7 +1159,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) { ...@@ -1158,7 +1159,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) {
a := nod(OADDR, src, nil) a := nod(OADDR, src, nil)
a.Pos = src.Pos a.Pos = src.Pos
e.nodeEscState(a).Loopdepth = e.nodeEscState(src).Loopdepth e.nodeEscState(a).Loopdepth = e.nodeEscState(src).Loopdepth
a.Type = typPtr(src.Type) a.Type = types.NewPtr(src.Type)
e.escflows(dst, a, e.stepAssign(nil, originalDst, src, dstwhy)) e.escflows(dst, a, e.stepAssign(nil, originalDst, src, dstwhy))
// Flowing multiple returns to a single dst happens when // Flowing multiple returns to a single dst happens when
...@@ -1170,7 +1171,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) { ...@@ -1170,7 +1171,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) {
// A non-pointer escaping from a struct does not concern us. // A non-pointer escaping from a struct does not concern us.
case ODOT: case ODOT:
if src.Type != nil && !haspointers(src.Type) { if src.Type != nil && !types.Haspointers(src.Type) {
break break
} }
fallthrough fallthrough
...@@ -1191,7 +1192,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) { ...@@ -1191,7 +1192,7 @@ func (e *EscState) escassign(dst, src *Node, step *EscStep) {
case ODOTTYPE, case ODOTTYPE,
ODOTTYPE2: ODOTTYPE2:
if src.Type != nil && !haspointers(src.Type) { if src.Type != nil && !types.Haspointers(src.Type) {
break break
} }
e.escassign(dst, src.Left, e.stepAssign(step, originalDst, src, dstwhy)) e.escassign(dst, src.Left, e.stepAssign(step, originalDst, src, dstwhy))
...@@ -1396,7 +1397,7 @@ func (e *EscState) addDereference(n *Node) *Node { ...@@ -1396,7 +1397,7 @@ func (e *EscState) addDereference(n *Node) *Node {
e.nodeEscState(ind).Loopdepth = e.nodeEscState(n).Loopdepth e.nodeEscState(ind).Loopdepth = e.nodeEscState(n).Loopdepth
ind.Pos = n.Pos ind.Pos = n.Pos
t := n.Type t := n.Type
if t.IsKind(Tptr) { if t.IsKind(types.Tptr) {
// This should model our own sloppy use of OIND to encode // This should model our own sloppy use of OIND to encode
// decreasing levels of indirection; i.e., "indirecting" an array // decreasing levels of indirection; i.e., "indirecting" an array
// might yield the type of an element. To be enhanced... // might yield the type of an element. To be enhanced...
...@@ -1440,7 +1441,7 @@ func escNoteOutputParamFlow(e uint16, vargen int32, level Level) uint16 { ...@@ -1440,7 +1441,7 @@ func escNoteOutputParamFlow(e uint16, vargen int32, level Level) uint16 {
return (e &^ (bitsMaskForTag << shift)) | encodedFlow return (e &^ (bitsMaskForTag << shift)) | encodedFlow
} }
func (e *EscState) initEscRetval(call *Node, fntype *Type) { func (e *EscState) initEscRetval(call *Node, fntype *types.Type) {
cE := e.nodeEscState(call) cE := e.nodeEscState(call)
cE.Retval.Set(nil) // Suspect this is not nil for indirect calls. cE.Retval.Set(nil) // Suspect this is not nil for indirect calls.
for i, f := range fntype.Results().Fields().Slice() { for i, f := range fntype.Results().Fields().Slice() {
...@@ -1464,7 +1465,7 @@ func (e *EscState) initEscRetval(call *Node, fntype *Type) { ...@@ -1464,7 +1465,7 @@ func (e *EscState) initEscRetval(call *Node, fntype *Type) {
// 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 (e *EscState) esccall(call *Node, parent *Node) { func (e *EscState) esccall(call *Node, parent *Node) {
var fntype *Type var fntype *types.Type
var indirect bool var indirect bool
var fn *Node var fn *Node
switch call.Op { switch call.Op {
...@@ -1477,7 +1478,7 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1477,7 +1478,7 @@ func (e *EscState) esccall(call *Node, parent *Node) {
indirect = fn.Op != ONAME || fn.Class != PFUNC indirect = fn.Op != ONAME || fn.Class != PFUNC
case OCALLMETH: case OCALLMETH:
fn = call.Left.Sym.Def fn = asNode(call.Left.Sym.Def)
if fn != nil { if fn != nil {
fntype = fn.Type fntype = fn.Type
} else { } else {
...@@ -1514,7 +1515,7 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1514,7 +1515,7 @@ func (e *EscState) esccall(call *Node, parent *Node) {
if call.Op != OCALLFUNC { if call.Op != OCALLFUNC {
rf := fntype.Recv() rf := fntype.Recv()
r := call.Left.Left r := call.Left.Left
if haspointers(rf.Type) { if types.Haspointers(rf.Type) {
e.escassignSinkWhy(call, r, "receiver in indirect call") e.escassignSinkWhy(call, r, "receiver in indirect call")
} }
} else { // indirect and OCALLFUNC = could be captured variables, too. (#14409) } else { // indirect and OCALLFUNC = could be captured variables, too. (#14409)
...@@ -1555,8 +1556,8 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1555,8 +1556,8 @@ func (e *EscState) esccall(call *Node, parent *Node) {
if n.Isddd() && !call.Isddd() { if n.Isddd() && !call.Isddd() {
// Introduce ODDDARG node to represent ... allocation. // Introduce ODDDARG node to represent ... allocation.
arg = nod(ODDDARG, nil, nil) arg = nod(ODDDARG, nil, nil)
arr := typArray(n.Type.Elem(), int64(len(args))) arr := types.NewArray(n.Type.Elem(), int64(len(args)))
arg.Type = typPtr(arr) // make pointer so it will be tracked arg.Type = types.NewPtr(arr) // make pointer so it will be tracked
arg.Pos = call.Pos arg.Pos = call.Pos
e.track(arg) e.track(arg)
call.Right = arg call.Right = arg
...@@ -1603,7 +1604,7 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1603,7 +1604,7 @@ func (e *EscState) esccall(call *Node, parent *Node) {
if call.Op != OCALLFUNC { if call.Op != OCALLFUNC {
rf := fntype.Recv() rf := fntype.Recv()
r := call.Left.Left r := call.Left.Left
if haspointers(rf.Type) { if types.Haspointers(rf.Type) {
e.escassignfromtag(rf.Note, cE.Retval, r, call) e.escassignfromtag(rf.Note, cE.Retval, r, call)
} }
} }
...@@ -1620,8 +1621,8 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1620,8 +1621,8 @@ func (e *EscState) esccall(call *Node, parent *Node) {
// Introduce ODDDARG node to represent ... allocation. // Introduce ODDDARG node to represent ... allocation.
arg = nod(ODDDARG, nil, nil) arg = nod(ODDDARG, nil, nil)
arg.Pos = call.Pos arg.Pos = call.Pos
arr := typArray(param.Type.Elem(), int64(len(rest))) arr := types.NewArray(param.Type.Elem(), int64(len(rest)))
arg.Type = typPtr(arr) // make pointer so it will be tracked arg.Type = types.NewPtr(arr) // make pointer so it will be tracked
e.track(arg) e.track(arg)
call.Right = arg call.Right = arg
...@@ -1643,7 +1644,7 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1643,7 +1644,7 @@ func (e *EscState) esccall(call *Node, parent *Node) {
} }
} }
if haspointers(param.Type) && e.escassignfromtag(note, cE.Retval, arg, call)&EscMask == EscNone && parent.Op != ODEFER && parent.Op != OPROC { if types.Haspointers(param.Type) && e.escassignfromtag(note, cE.Retval, arg, call)&EscMask == EscNone && parent.Op != ODEFER && parent.Op != OPROC {
a := arg a := arg
for a.Op == OCONVNOP { for a.Op == OCONVNOP {
a = a.Left a = a.Left
...@@ -1673,7 +1674,7 @@ func (e *EscState) escflows(dst, src *Node, why *EscStep) { ...@@ -1673,7 +1674,7 @@ func (e *EscState) escflows(dst, src *Node, why *EscStep) {
} }
// Don't bother building a graph for scalars. // Don't bother building a graph for scalars.
if src.Type != nil && !haspointers(src.Type) && !isReflectHeaderDataField(src) { if src.Type != nil && !types.Haspointers(src.Type) && !isReflectHeaderDataField(src) {
if Debug['m'] > 3 { if Debug['m'] > 3 {
fmt.Printf("%v::NOT flows:: %S <- %S\n", linestr(lineno), dst, src) fmt.Printf("%v::NOT flows:: %S <- %S\n", linestr(lineno), dst, src)
} }
...@@ -2036,7 +2037,7 @@ const uintptrEscapesTag = "uintptr-escapes" ...@@ -2036,7 +2037,7 @@ const uintptrEscapesTag = "uintptr-escapes"
func (e *EscState) esctag(fn *Node) { func (e *EscState) esctag(fn *Node) {
fn.Esc = EscFuncTagged fn.Esc = EscFuncTagged
name := func(s *Sym, narg int) string { name := func(s *types.Sym, narg int) string {
if s != nil { if s != nil {
return s.Name return s.Name
} }
...@@ -2048,7 +2049,7 @@ func (e *EscState) esctag(fn *Node) { ...@@ -2048,7 +2049,7 @@ func (e *EscState) esctag(fn *Node) {
if fn.Nbody.Len() == 0 { if fn.Nbody.Len() == 0 {
if fn.Noescape() { if fn.Noescape() {
for _, f := range fn.Type.Params().Fields().Slice() { for _, f := range fn.Type.Params().Fields().Slice() {
if haspointers(f.Type) { if types.Haspointers(f.Type) {
f.Note = mktag(EscNone) f.Note = mktag(EscNone)
} }
} }
...@@ -2103,7 +2104,7 @@ func (e *EscState) esctag(fn *Node) { ...@@ -2103,7 +2104,7 @@ func (e *EscState) esctag(fn *Node) {
switch ln.Esc & EscMask { switch ln.Esc & EscMask {
case EscNone, // not touched by escflood case EscNone, // not touched by escflood
EscReturn: EscReturn:
if haspointers(ln.Type) { // don't bother tagging for scalars if types.Haspointers(ln.Type) { // don't bother tagging for scalars
if ln.Name.Param.Field.Note != uintptrEscapesTag { if ln.Name.Param.Field.Note != uintptrEscapesTag {
ln.Name.Param.Field.Note = mktag(int(ln.Esc)) ln.Name.Param.Field.Note = mktag(int(ln.Esc))
} }
......
...@@ -7,6 +7,7 @@ package gc ...@@ -7,6 +7,7 @@ package gc
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"cmd/compile/internal/types"
"cmd/internal/bio" "cmd/internal/bio"
"fmt" "fmt"
"unicode" "unicode"
...@@ -44,8 +45,8 @@ func exportsym(n *Node) { ...@@ -44,8 +45,8 @@ func exportsym(n *Node) {
} }
// Ensure original types are on exportlist before type aliases. // Ensure original types are on exportlist before type aliases.
if n.Sym.isAlias() { if IsAlias(n.Sym) {
exportlist = append(exportlist, n.Sym.Def) exportlist = append(exportlist, asNode(n.Sym.Def))
} }
exportlist = append(exportlist, n) exportlist = append(exportlist, n)
...@@ -65,7 +66,7 @@ func initname(s string) bool { ...@@ -65,7 +66,7 @@ func initname(s string) bool {
// exportedsym reports whether a symbol will be visible // exportedsym reports whether a symbol will be visible
// to files that import our package. // to files that import our package.
func exportedsym(sym *Sym) bool { func exportedsym(sym *types.Sym) bool {
// Builtins are visible everywhere. // Builtins are visible everywhere.
if sym.Pkg == builtinpkg || sym.Origpkg == builtinpkg { if sym.Pkg == builtinpkg || sym.Origpkg == builtinpkg {
return true return true
...@@ -141,7 +142,7 @@ func reexportdep(n *Node) { ...@@ -141,7 +142,7 @@ func reexportdep(n *Node) {
} }
// methodbyname sorts types by symbol name. // methodbyname sorts types by symbol name.
type methodbyname []*Field type methodbyname []*types.Field
func (x methodbyname) Len() int { return len(x) } func (x methodbyname) Len() int { return len(x) }
func (x methodbyname) Swap(i, j int) { x[i], x[j] = x[j], x[i] } func (x methodbyname) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
...@@ -174,7 +175,7 @@ func dumpexport() { ...@@ -174,7 +175,7 @@ func dumpexport() {
// (use empty package map to avoid collisions) // (use empty package map to avoid collisions)
savedPkgMap := pkgMap savedPkgMap := pkgMap
savedPkgs := pkgs savedPkgs := pkgs
pkgMap = make(map[string]*Pkg) pkgMap = make(map[string]*types.Pkg)
pkgs = nil pkgs = nil
Import(mkpkg(""), bufio.NewReader(&copy)) // must not die Import(mkpkg(""), bufio.NewReader(&copy)) // must not die
pkgs = savedPkgs pkgs = savedPkgs
...@@ -191,14 +192,14 @@ func dumpexport() { ...@@ -191,14 +192,14 @@ func dumpexport() {
// importsym declares symbol s as an imported object representable by op. // importsym declares symbol s as an imported object representable by op.
// pkg is the package being imported // pkg is the package being imported
func importsym(pkg *Pkg, s *Sym, op Op) { func importsym(pkg *types.Pkg, s *types.Sym, op Op) {
if s.Def != nil && s.Def.Op != op { if asNode(s.Def) != nil && asNode(s.Def).Op != op {
pkgstr := fmt.Sprintf("during import %q", pkg.Path) pkgstr := fmt.Sprintf("during import %q", pkg.Path)
redeclare(s, pkgstr) redeclare(s, pkgstr)
} }
// mark the symbol so it is not reexported // mark the symbol so it is not reexported
if s.Def == nil { if asNode(s.Def) == nil {
if exportname(s.Name) || initname(s.Name) { if exportname(s.Name) || initname(s.Name) {
s.SetExport(true) s.SetExport(true)
} else { } else {
...@@ -210,28 +211,28 @@ func importsym(pkg *Pkg, s *Sym, op Op) { ...@@ -210,28 +211,28 @@ func importsym(pkg *Pkg, s *Sym, op Op) {
// pkgtype returns the named type declared by symbol s. // pkgtype returns the named type declared by symbol s.
// If no such type has been declared yet, a forward declaration is returned. // If no such type has been declared yet, a forward declaration is returned.
// pkg is the package being imported // pkg is the package being imported
func pkgtype(pkg *Pkg, s *Sym) *Type { func pkgtype(pkg *types.Pkg, s *types.Sym) *types.Type {
importsym(pkg, s, OTYPE) importsym(pkg, s, OTYPE)
if s.Def == nil || s.Def.Op != OTYPE { if asNode(s.Def) == nil || asNode(s.Def).Op != OTYPE {
t := typ(TFORW) t := types.New(TFORW)
t.Sym = s t.Sym = s
s.Def = typenod(t) s.Def = asTypesNode(typenod(t))
s.Def.Name = new(Name) asNode(s.Def).Name = new(Name)
} }
if s.Def.Type == nil { if asNode(s.Def).Type == nil {
Fatalf("pkgtype %v", s) Fatalf("pkgtype %v", s)
} }
return s.Def.Type return asNode(s.Def).Type
} }
// importconst declares symbol s as an imported constant with type t and value n. // importconst declares symbol s as an imported constant with type t and value n.
// pkg is the package being imported // pkg is the package being imported
func importconst(pkg *Pkg, s *Sym, t *Type, n *Node) { func importconst(pkg *types.Pkg, s *types.Sym, t *types.Type, n *Node) {
importsym(pkg, s, OLITERAL) importsym(pkg, s, OLITERAL)
n = convlit(n, t) n = convlit(n, t)
if s.Def != nil { // TODO: check if already the same. if asNode(s.Def) != nil { // TODO: check if already the same.
return return
} }
...@@ -256,13 +257,13 @@ func importconst(pkg *Pkg, s *Sym, t *Type, n *Node) { ...@@ -256,13 +257,13 @@ func importconst(pkg *Pkg, s *Sym, t *Type, n *Node) {
// importvar declares symbol s as an imported variable with type t. // importvar declares symbol s as an imported variable with type t.
// pkg is the package being imported // pkg is the package being imported
func importvar(pkg *Pkg, s *Sym, t *Type) { func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) {
importsym(pkg, s, ONAME) importsym(pkg, s, ONAME)
if s.Def != nil && s.Def.Op == ONAME { if asNode(s.Def) != nil && asNode(s.Def).Op == ONAME {
if eqtype(t, s.Def.Type) { if eqtype(t, asNode(s.Def).Type) {
return return
} }
yyerror("inconsistent definition for var %v during import\n\t%v (in %q)\n\t%v (in %q)", s, s.Def.Type, s.Importdef.Path, t, pkg.Path) yyerror("inconsistent definition for var %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
} }
n := newname(s) n := newname(s)
...@@ -277,13 +278,13 @@ func importvar(pkg *Pkg, s *Sym, t *Type) { ...@@ -277,13 +278,13 @@ func importvar(pkg *Pkg, s *Sym, t *Type) {
// importalias declares symbol s as an imported type alias with type t. // importalias declares symbol s as an imported type alias with type t.
// pkg is the package being imported // pkg is the package being imported
func importalias(pkg *Pkg, s *Sym, t *Type) { func importalias(pkg *types.Pkg, s *types.Sym, t *types.Type) {
importsym(pkg, s, OTYPE) importsym(pkg, s, OTYPE)
if s.Def != nil && s.Def.Op == OTYPE { if asNode(s.Def) != nil && asNode(s.Def).Op == OTYPE {
if eqtype(t, s.Def.Type) { if eqtype(t, asNode(s.Def).Type) {
return return
} }
yyerror("inconsistent definition for type alias %v during import\n\t%v (in %q)\n\t%v (in %q)", s, s.Def.Type, s.Importdef.Path, t, pkg.Path) yyerror("inconsistent definition for type alias %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
} }
n := newname(s) n := newname(s)
......
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
"fmt" "fmt"
...@@ -114,7 +115,7 @@ func moveToHeap(n *Node) { ...@@ -114,7 +115,7 @@ func moveToHeap(n *Node) {
// Allocate a local stack variable to hold the pointer to the heap copy. // Allocate a local stack variable to hold the pointer to the heap copy.
// temp will add it to the function declaration list automatically. // temp will add it to the function declaration list automatically.
heapaddr := temp(typPtr(n.Type)) heapaddr := temp(types.NewPtr(n.Type))
heapaddr.Sym = lookup("&" + n.Sym.Name) heapaddr.Sym = lookup("&" + n.Sym.Name)
heapaddr.Orig.Sym = heapaddr.Sym heapaddr.Orig.Sym = heapaddr.Sym
...@@ -191,11 +192,12 @@ func autotmpname(n int) string { ...@@ -191,11 +192,12 @@ func autotmpname(n int) string {
// Start with a buffer big enough to hold a large n. // Start with a buffer big enough to hold a large n.
b := []byte(prefix + " ")[:len(prefix)] b := []byte(prefix + " ")[:len(prefix)]
b = strconv.AppendInt(b, int64(n), 10) b = strconv.AppendInt(b, int64(n), 10)
return internString(b) _ = b
return types.InternString(b)
} }
// make a new Node off the books // make a new Node off the books
func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) { func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *types.Type) {
if curfn == nil { if curfn == nil {
Fatalf("no curfn for tempname") Fatalf("no curfn for tempname")
} }
...@@ -207,12 +209,12 @@ func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) { ...@@ -207,12 +209,12 @@ func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) {
Fatalf("tempname called with nil type") Fatalf("tempname called with nil type")
} }
s := &Sym{ s := &types.Sym{
Name: autotmpname(len(curfn.Func.Dcl)), Name: autotmpname(len(curfn.Func.Dcl)),
Pkg: localpkg, Pkg: localpkg,
} }
n := newnamel(pos, s) n := newnamel(pos, s)
s.Def = n s.Def = asTypesNode(n)
n.Type = t n.Type = t
n.Class = PAUTO n.Class = PAUTO
n.Esc = EscNever n.Esc = EscNever
...@@ -224,16 +226,16 @@ func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) { ...@@ -224,16 +226,16 @@ func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) {
*nn = *n *nn = *n
} }
func temp(t *Type) *Node { func temp(t *types.Type) *Node {
var n Node var n Node
tempnamel(lineno, Curfn, &n, t) tempnamel(lineno, Curfn, &n, t)
n.Sym.Def.SetUsed(true) asNode(n.Sym.Def).SetUsed(true)
return n.Orig return n.Orig
} }
func tempAt(pos src.XPos, curfn *Node, t *Type) *Node { func tempAt(pos src.XPos, curfn *Node, t *types.Type) *Node {
var n Node var n Node
tempnamel(pos, curfn, &n, t) tempnamel(pos, curfn, &n, t)
n.Sym.Def.SetUsed(true) asNode(n.Sym.Def).SetUsed(true)
return n.Orig return n.Orig
} }
...@@ -6,90 +6,25 @@ package gc ...@@ -6,90 +6,25 @@ package gc
import ( import (
"cmd/compile/internal/ssa" "cmd/compile/internal/ssa"
"cmd/compile/internal/types"
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
) )
const ( const (
BADWIDTH = -1000000000 BADWIDTH = types.BADWIDTH
MaxStackVarSize = 10 * 1024 * 1024 MaxStackVarSize = 10 * 1024 * 1024
) )
type Pkg struct { // isRuntimePkg reports whether p is package runtime.
Name string // package name, e.g. "sys" func isRuntimePkg(p *types.Pkg) bool {
Path string // string literal used in import statement, e.g. "runtime/internal/sys"
Pathsym *obj.LSym
Prefix string // escaped path for use in symbol table
Imported bool // export data of this package was parsed
Direct bool // imported directly
Syms map[string]*Sym
}
// isRuntime reports whether p is package runtime.
func (p *Pkg) isRuntime() bool {
if compiling_runtime && p == localpkg { if compiling_runtime && p == localpkg {
return true return true
} }
return p.Path == "runtime" return p.Path == "runtime"
} }
// Sym represents an object name. Most commonly, this is a Go identifier naming
// an object declared within a package, but Syms are also used to name internal
// synthesized objects.
//
// As an exception, field and method names that are exported use the Sym
// associated with localpkg instead of the package that declared them. This
// allows using Sym pointer equality to test for Go identifier uniqueness when
// handling selector expressions.
type Sym struct {
Link *Sym
Importdef *Pkg // where imported definition was found
Linkname string // link name
// saved and restored by dcopy
Pkg *Pkg
Name string // object name
Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
Lastlineno src.XPos // last declaration for diagnostic
Block int32 // blocknumber to catch redeclaration
flags bitset8
Label *Node // corresponding label (ephemeral)
Origpkg *Pkg // original package for . import
Lsym *obj.LSym
}
const (
symExport = 1 << iota // added to exportlist (no need to add again)
symPackage
symExported // already written out by export
symUniq
symSiggen
symAsm
symAlgGen
)
func (sym *Sym) Export() bool { return sym.flags&symExport != 0 }
func (sym *Sym) Package() bool { return sym.flags&symPackage != 0 }
func (sym *Sym) Exported() bool { return sym.flags&symExported != 0 }
func (sym *Sym) Uniq() bool { return sym.flags&symUniq != 0 }
func (sym *Sym) Siggen() bool { return sym.flags&symSiggen != 0 }
func (sym *Sym) Asm() bool { return sym.flags&symAsm != 0 }
func (sym *Sym) AlgGen() bool { return sym.flags&symAlgGen != 0 }
func (sym *Sym) SetExport(b bool) { sym.flags.set(symExport, b) }
func (sym *Sym) SetPackage(b bool) { sym.flags.set(symPackage, b) }
func (sym *Sym) SetExported(b bool) { sym.flags.set(symExported, b) }
func (sym *Sym) SetUniq(b bool) { sym.flags.set(symUniq, b) }
func (sym *Sym) SetSiggen(b bool) { sym.flags.set(symSiggen, b) }
func (sym *Sym) SetAsm(b bool) { sym.flags.set(symAsm, b) }
func (sym *Sym) SetAlgGen(b bool) { sym.flags.set(symAlgGen, b) }
func (sym *Sym) isAlias() bool {
return sym.Def != nil && sym.Def.Sym != sym
}
// The Class of a variable/function describes the "storage class" // The Class of a variable/function describes the "storage class"
// of a variable or function. During parsing, storage classes are // of a variable or function. During parsing, storage classes are
// called declaration contexts. // called declaration contexts.
...@@ -165,38 +100,36 @@ var debugstr string ...@@ -165,38 +100,36 @@ var debugstr string
var Debug_checknil int var Debug_checknil int
var Debug_typeassert int var Debug_typeassert int
var localpkg *Pkg // package being compiled var localpkg *types.Pkg // package being compiled
var inimport bool // set during import var inimport bool // set during import
var itabpkg *Pkg // fake pkg for itab entries var itabpkg *types.Pkg // fake pkg for itab entries
var itablinkpkg *Pkg // fake package for runtime itab entries var itablinkpkg *types.Pkg // fake package for runtime itab entries
var Runtimepkg *Pkg // fake package runtime var Runtimepkg *types.Pkg // fake package runtime
var racepkg *Pkg // package runtime/race var racepkg *types.Pkg // package runtime/race
var msanpkg *Pkg // package runtime/msan var msanpkg *types.Pkg // package runtime/msan
var typepkg *Pkg // fake package for runtime type info (headers) var typepkg *types.Pkg // fake package for runtime type info (headers)
var unsafepkg *Pkg // package unsafe var unsafepkg *types.Pkg // package unsafe
var trackpkg *Pkg // fake package for field tracking var trackpkg *types.Pkg // fake package for field tracking
var mappkg *Pkg // fake package for map zero value var mappkg *types.Pkg // fake package for map zero value
var zerosize int64 var zerosize int64
var Tptr EType // either TPTR32 or TPTR64
var myimportpath string var myimportpath string
var localimport string var localimport string
var asmhdr string var asmhdr string
var simtype [NTYPE]EType var simtype [NTYPE]types.EType
var ( var (
isforw [NTYPE]bool isforw [NTYPE]bool
...@@ -238,7 +171,7 @@ var exportlist []*Node ...@@ -238,7 +171,7 @@ var exportlist []*Node
var importlist []*Node // imported functions and methods with inlinable bodies var importlist []*Node // imported functions and methods with inlinable bodies
var funcsyms []*Sym var funcsyms []*types.Sym
var dclcontext Class // PEXTERN/PAUTO var dclcontext Class // PEXTERN/PAUTO
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
) )
...@@ -194,13 +195,13 @@ func ggloblnod(nam *Node) { ...@@ -194,13 +195,13 @@ func ggloblnod(nam *Node) {
if nam.Name.Readonly() { if nam.Name.Readonly() {
flags = obj.RODATA flags = obj.RODATA
} }
if nam.Type != nil && !haspointers(nam.Type) { if nam.Type != nil && !types.Haspointers(nam.Type) {
flags |= obj.NOPTR flags |= obj.NOPTR
} }
Ctxt.Globl(s, nam.Type.Width, flags) Ctxt.Globl(s, nam.Type.Width, flags)
} }
func ggloblsym(s *Sym, width int32, flags int16) { func ggloblsym(s *types.Sym, width int32, flags int16) {
ggloblLSym(Linksym(s), width, flags) ggloblLSym(Linksym(s), width, flags)
} }
...@@ -212,7 +213,7 @@ func ggloblLSym(s *obj.LSym, width int32, flags int16) { ...@@ -212,7 +213,7 @@ func ggloblLSym(s *obj.LSym, width int32, flags int16) {
Ctxt.Globl(s, int64(width), int(flags)) Ctxt.Globl(s, int64(width), int(flags))
} }
func isfat(t *Type) bool { func isfat(t *types.Type) bool {
if t != nil { if t != nil {
switch t.Etype { switch t.Etype {
case TSTRUCT, TARRAY, TSLICE, TSTRING, case TSTRUCT, TARRAY, TSLICE, TSTRING,
...@@ -231,8 +232,8 @@ func Addrconst(a *obj.Addr, v int64) { ...@@ -231,8 +232,8 @@ func Addrconst(a *obj.Addr, v int64) {
} }
// nodarg returns a Node for the function argument denoted by t, // nodarg returns a Node for the function argument denoted by t,
// which is either the entire function argument or result struct (t is a struct *Type) // which is either the entire function argument or result struct (t is a struct *types.Type)
// or a specific argument (t is a *Field within a struct *Type). // or a specific argument (t is a *types.Field within a struct *types.Type).
// //
// If fp is 0, the node is for use by a caller invoking the given // If fp is 0, the node is for use by a caller invoking the given
// function, preparing the arguments before the call // function, preparing the arguments before the call
...@@ -247,12 +248,12 @@ func Addrconst(a *obj.Addr, v int64) { ...@@ -247,12 +248,12 @@ func Addrconst(a *obj.Addr, v int64) {
func nodarg(t interface{}, fp int) *Node { func nodarg(t interface{}, fp int) *Node {
var n *Node var n *Node
var funarg Funarg var funarg types.Funarg
switch t := t.(type) { switch t := t.(type) {
default: default:
Fatalf("bad nodarg %T(%v)", t, t) Fatalf("bad nodarg %T(%v)", t, t)
case *Type: case *types.Type:
// Entire argument struct, not just one arg // Entire argument struct, not just one arg
if !t.IsFuncArgStruct() { if !t.IsFuncArgStruct() {
Fatalf("nodarg: bad type %v", t) Fatalf("nodarg: bad type %v", t)
...@@ -271,7 +272,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -271,7 +272,7 @@ func nodarg(t interface{}, fp int) *Node {
} }
n.Xoffset = first.Offset n.Xoffset = first.Offset
case *Field: case *types.Field:
funarg = t.Funarg funarg = t.Funarg
if fp == 1 { if fp == 1 {
// NOTE(rsc): This should be using t.Nname directly, // NOTE(rsc): This should be using t.Nname directly,
...@@ -285,7 +286,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -285,7 +286,7 @@ func nodarg(t interface{}, fp int) *Node {
// toward time for the Go 1.7 beta). // toward time for the Go 1.7 beta).
// At some quieter time (assuming we've never seen these Fatalfs happen) // At some quieter time (assuming we've never seen these Fatalfs happen)
// we could change this code to use "expect" directly. // we could change this code to use "expect" directly.
expect := t.Nname expect := asNode(t.Nname)
if expect.isParamHeapCopy() { if expect.isParamHeapCopy() {
expect = expect.Name.Param.Stackcopy expect = expect.Name.Param.Stackcopy
} }
...@@ -293,7 +294,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -293,7 +294,7 @@ func nodarg(t interface{}, fp int) *Node {
for _, n := range Curfn.Func.Dcl { for _, n := range Curfn.Func.Dcl {
if (n.Class == PPARAM || n.Class == PPARAMOUT) && !isblanksym(t.Sym) && n.Sym == t.Sym { if (n.Class == PPARAM || n.Class == PPARAMOUT) && !isblanksym(t.Sym) && n.Sym == t.Sym {
if n != expect { if n != expect {
Fatalf("nodarg: unexpected node: %v (%p %v) vs %v (%p %v)", n, n, n.Op, t.Nname, t.Nname, t.Nname.Op) Fatalf("nodarg: unexpected node: %v (%p %v) vs %v (%p %v)", n, n, n.Op, asNode(t.Nname), asNode(t.Nname), asNode(t.Nname).Op)
} }
return n return n
} }
...@@ -313,7 +314,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -313,7 +314,7 @@ func nodarg(t interface{}, fp int) *Node {
Fatalf("nodarg: offset not computed for %v", t) Fatalf("nodarg: offset not computed for %v", t)
} }
n.Xoffset = t.Offset n.Xoffset = t.Offset
n.Orig = t.Nname n.Orig = asNode(t.Nname)
} }
// Rewrite argument named _ to __, // Rewrite argument named _ to __,
...@@ -333,7 +334,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -333,7 +334,7 @@ func nodarg(t interface{}, fp int) *Node {
case 1: // reading arguments inside call case 1: // reading arguments inside call
n.Class = PPARAM n.Class = PPARAM
if funarg == FunargResults { if funarg == types.FunargResults {
n.Class = PPARAMOUT n.Class = PPARAMOUT
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package gc package gc
import "cmd/compile/internal/types"
// a function named init is a special case. // a function named init is a special case.
// it is called by the initialization before // it is called by the initialization before
// main is run. to make it unique within a // main is run. to make it unique within a
...@@ -12,7 +14,7 @@ package gc ...@@ -12,7 +14,7 @@ package gc
var renameinit_initgen int var renameinit_initgen int
func renameinit() *Sym { func renameinit() *types.Sym {
renameinit_initgen++ renameinit_initgen++
return lookupN("init.", renameinit_initgen) return lookupN("init.", renameinit_initgen)
} }
...@@ -42,7 +44,7 @@ func anyinit(n []*Node) bool { ...@@ -42,7 +44,7 @@ func anyinit(n []*Node) bool {
} }
// are there any imported init functions // are there any imported init functions
for _, s := range initSyms { for _, s := range types.InitSyms {
if s.Def != nil { if s.Def != nil {
return true return true
} }
...@@ -81,7 +83,7 @@ func fninit(n []*Node) { ...@@ -81,7 +83,7 @@ func fninit(n []*Node) {
// (1) // (1)
gatevar := newname(lookup("initdone·")) gatevar := newname(lookup("initdone·"))
addvar(gatevar, Types[TUINT8], PEXTERN) addvar(gatevar, types.Types[TUINT8], PEXTERN)
// (2) // (2)
fn := nod(ODCLFUNC, nil, nil) fn := nod(ODCLFUNC, nil, nil)
...@@ -116,10 +118,10 @@ func fninit(n []*Node) { ...@@ -116,10 +118,10 @@ func fninit(n []*Node) {
r = append(r, a) r = append(r, a)
// (6) // (6)
for _, s := range initSyms { for _, s := range types.InitSyms {
if s.Def != nil && s != initsym { if s.Def != nil && s != initsym {
// could check that it is fn of no args/returns // could check that it is fn of no args/returns
a = nod(OCALL, s.Def, nil) a = nod(OCALL, asNode(s.Def), nil)
r = append(r, a) r = append(r, a)
} }
} }
...@@ -134,7 +136,7 @@ func fninit(n []*Node) { ...@@ -134,7 +136,7 @@ func fninit(n []*Node) {
if s.Def == nil { if s.Def == nil {
break break
} }
a = nod(OCALL, s.Def, nil) a = nod(OCALL, asNode(s.Def), nil)
r = append(r, a) r = append(r, a)
} }
......
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/src" "cmd/internal/src"
"fmt" "fmt"
) )
// Get the function's package. For ordinary functions it's on the ->sym, but for imported methods // Get the function's package. For ordinary functions it's on the ->sym, but for imported methods
// the ->sym can be re-used in the local package, so peel it off the receiver's type. // the ->sym can be re-used in the local package, so peel it off the receiver's type.
func fnpkg(fn *Node) *Pkg { func fnpkg(fn *Node) *types.Pkg {
if fn.IsMethod() { if fn.IsMethod() {
// method // method
rcvr := fn.Type.Recv().Type rcvr := fn.Type.Recv().Type
...@@ -171,7 +172,7 @@ func caninl(fn *Node) { ...@@ -171,7 +172,7 @@ func caninl(fn *Node) {
// hack, TODO, check for better way to link method nodes back to the thing with the ->inl // hack, TODO, check for better way to link method nodes back to the thing with the ->inl
// this is so export can find the body of a method // this is so export can find the body of a method
fn.Type.SetNname(n) fn.Type.FuncType().Nname = asTypesNode(n)
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v: can inline %#v as: %#v { %#v }\n", fn.Line(), n, fn.Type, n.Func.Inl) fmt.Printf("%v: can inline %#v as: %#v { %#v }\n", fn.Line(), n, fn.Type, n.Func.Inl)
...@@ -210,7 +211,7 @@ func ishairy(n *Node, budget *int32, reason *string) bool { ...@@ -210,7 +211,7 @@ func ishairy(n *Node, budget *int32, reason *string) bool {
} }
if n.isMethodCalledAsFunction() { if n.isMethodCalledAsFunction() {
if d := n.Left.Sym.Def; d != nil && d.Func.Inl.Len() != 0 { if d := asNode(n.Left.Sym.Def); d != nil && d.Func.Inl.Len() != 0 {
*budget -= d.Func.InlCost *budget -= d.Func.InlCost
break break
} }
...@@ -229,7 +230,7 @@ func ishairy(n *Node, budget *int32, reason *string) bool { ...@@ -229,7 +230,7 @@ func ishairy(n *Node, budget *int32, reason *string) bool {
if t.Nname() == nil { if t.Nname() == nil {
Fatalf("no function definition for [%p] %+v\n", t, t) Fatalf("no function definition for [%p] %+v\n", t, t)
} }
if inlfn := t.Nname().Func; inlfn.Inl.Len() != 0 { if inlfn := asNode(t.FuncType().Nname).Func; inlfn.Inl.Len() != 0 {
*budget -= inlfn.InlCost *budget -= inlfn.InlCost
break break
} }
...@@ -507,8 +508,8 @@ func inlnode(n *Node) *Node { ...@@ -507,8 +508,8 @@ func inlnode(n *Node) *Node {
} }
if n.Left.Func != nil && n.Left.Func.Inl.Len() != 0 && !isIntrinsicCall(n) { // normal case if n.Left.Func != nil && n.Left.Func.Inl.Len() != 0 && !isIntrinsicCall(n) { // normal case
n = mkinlcall(n, n.Left, n.Isddd()) n = mkinlcall(n, n.Left, n.Isddd())
} else if n.isMethodCalledAsFunction() && n.Left.Sym.Def != nil { } else if n.isMethodCalledAsFunction() && asNode(n.Left.Sym.Def) != nil {
n = mkinlcall(n, n.Left.Sym.Def, n.Isddd()) n = mkinlcall(n, asNode(n.Left.Sym.Def), n.Isddd())
} }
case OCALLMETH: case OCALLMETH:
...@@ -525,7 +526,7 @@ func inlnode(n *Node) *Node { ...@@ -525,7 +526,7 @@ func inlnode(n *Node) *Node {
Fatalf("no function definition for [%p] %+v\n", n.Left.Type, n.Left.Type) Fatalf("no function definition for [%p] %+v\n", n.Left.Type, n.Left.Type)
} }
n = mkinlcall(n, n.Left.Type.Nname(), n.Isddd()) n = mkinlcall(n, asNode(n.Left.Type.FuncType().Nname), n.Isddd())
} }
lineno = lno lineno = lno
...@@ -549,11 +550,11 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node { ...@@ -549,11 +550,11 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node {
return n return n
} }
func tinlvar(t *Field, inlvars map[*Node]*Node) *Node { func tinlvar(t *types.Field, inlvars map[*Node]*Node) *Node {
if t.Nname != nil && !isblank(t.Nname) { if asNode(t.Nname) != nil && !isblank(asNode(t.Nname)) {
inlvar := inlvars[t.Nname] inlvar := inlvars[asNode(t.Nname)]
if inlvar == nil { if inlvar == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", asNode(t.Nname))
} }
return inlvar return inlvar
} }
...@@ -631,10 +632,10 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -631,10 +632,10 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// temporaries for return values. // temporaries for return values.
var m *Node var m *Node
for _, t := range fn.Type.Results().Fields().Slice() { for _, t := range fn.Type.Results().Fields().Slice() {
if t != nil && t.Nname != nil && !isblank(t.Nname) { if t != nil && asNode(t.Nname) != nil && !isblank(asNode(t.Nname)) {
m = inlvar(t.Nname) m = inlvar(asNode(t.Nname))
m = typecheck(m, Erv) m = typecheck(m, Erv)
inlvars[t.Nname] = m inlvars[asNode(t.Nname)] = m
} else { } else {
// anonymous return values, synthesize names for use in assignment that replaces return // anonymous return values, synthesize names for use in assignment that replaces return
m = retvar(t, i) m = retvar(t, i)
...@@ -650,8 +651,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -650,8 +651,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// method call with a receiver. // method call with a receiver.
t := fn.Type.Recv() t := fn.Type.Recv()
if t != nil && t.Nname != nil && !isblank(t.Nname) && inlvars[t.Nname] == nil { if t != nil && t.Nname != nil && !isblank(asNode(t.Nname)) && inlvars[asNode(t.Nname)] == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", asNode(t.Nname))
} }
if n.Left.Left == nil { if n.Left.Left == nil {
Fatalf("method call without receiver: %+v", n) Fatalf("method call without receiver: %+v", n)
...@@ -669,7 +670,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -669,7 +670,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// check if inlined function is variadic. // check if inlined function is variadic.
variadic := false variadic := false
var varargtype *Type var varargtype *types.Type
varargcount := 0 varargcount := 0
for _, t := range fn.Type.Params().Fields().Slice() { for _, t := range fn.Type.Params().Fields().Slice() {
if t.Isddd() { if t.Isddd() {
...@@ -719,8 +720,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -719,8 +720,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// append receiver inlvar to LHS. // append receiver inlvar to LHS.
t := fn.Type.Recv() t := fn.Type.Recv()
if t != nil && t.Nname != nil && !isblank(t.Nname) && inlvars[t.Nname] == nil { if t != nil && t.Nname != nil && !isblank(asNode(t.Nname)) && inlvars[asNode(t.Nname)] == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", asNode(t.Nname))
} }
if t == nil { if t == nil {
Fatalf("method call unknown receiver type: %+v", n) Fatalf("method call unknown receiver type: %+v", n)
...@@ -753,7 +754,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -753,7 +754,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
} }
} else { } else {
// match arguments except final variadic (unless the call is dotted itself) // match arguments except final variadic (unless the call is dotted itself)
t, it := iterFields(fn.Type.Params()) t, it := types.IterFields(fn.Type.Params())
for t != nil { for t != nil {
if li >= n.List.Len() { if li >= n.List.Len() {
break break
...@@ -799,7 +800,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -799,7 +800,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
as.Right = nodnil() as.Right = nodnil()
as.Right.Type = varargtype as.Right.Type = varargtype
} else { } else {
varslicetype := typSlice(varargtype.Elem()) varslicetype := types.NewSlice(varargtype.Elem())
as.Right = nod(OCOMPLIT, nil, typenod(varslicetype)) as.Right = nod(OCOMPLIT, nil, typenod(varslicetype))
as.Right.List.Set(varargs) as.Right.List.Set(varargs)
} }
...@@ -911,7 +912,7 @@ func inlvar(var_ *Node) *Node { ...@@ -911,7 +912,7 @@ func inlvar(var_ *Node) *Node {
} }
// Synthesize a variable to store the inlined function's results in. // Synthesize a variable to store the inlined function's results in.
func retvar(t *Field, i int) *Node { func retvar(t *types.Field, i int) *Node {
n := newname(lookupN("~r", i)) n := newname(lookupN("~r", i))
n.Type = t.Type n.Type = t.Type
n.Class = PAUTO n.Class = PAUTO
...@@ -923,7 +924,7 @@ func retvar(t *Field, i int) *Node { ...@@ -923,7 +924,7 @@ func retvar(t *Field, i int) *Node {
// Synthesize a variable to store the inlined function's arguments // Synthesize a variable to store the inlined function's arguments
// when they come from a multiple return call. // when they come from a multiple return call.
func argvar(t *Type, i int) *Node { func argvar(t *types.Type, i int) *Node {
n := newname(lookupN("~arg", i)) n := newname(lookupN("~arg", i))
n.Type = t.Elem() n.Type = t.Elem()
n.Class = PAUTO n.Class = PAUTO
......
...@@ -104,17 +104,6 @@ func pragmaValue(verb string) syntax.Pragma { ...@@ -104,17 +104,6 @@ func pragmaValue(verb string) syntax.Pragma {
return 0 return 0
} }
var internedStrings = map[string]string{}
func internString(b []byte) string {
s, ok := internedStrings[string(b)] // string(b) here doesn't allocate
if !ok {
s = string(b)
internedStrings[s] = s
}
return s
}
// pragcgo is called concurrently if files are parsed concurrently. // pragcgo is called concurrently if files are parsed concurrently.
func (p *noder) pragcgo(pos src.Pos, text string) string { func (p *noder) pragcgo(pos src.Pos, text string) string {
f := pragmaFields(text) f := pragmaFields(text)
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"cmd/compile/internal/ssa" "cmd/compile/internal/ssa"
"cmd/compile/internal/types"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
"cmd/internal/sys" "cmd/internal/sys"
...@@ -347,6 +348,35 @@ func Main(archInit func(*Arch)) { ...@@ -347,6 +348,35 @@ func Main(archInit func(*Arch)) {
Widthptr = thearch.LinkArch.PtrSize Widthptr = thearch.LinkArch.PtrSize
Widthreg = thearch.LinkArch.RegSize Widthreg = thearch.LinkArch.RegSize
// initialize types package
// (we need to do this to break dependencies that otherwise
// would lead to import cycles)
types.Widthptr = Widthptr
types.Dowidth = dowidth
types.Fatalf = Fatalf
types.Sconv = func(s *types.Sym, flag, mode int) string {
return sconv(s, FmtFlag(flag), fmtMode(mode))
}
types.Tconv = func(t *types.Type, flag, mode, depth int) string {
return tconv(t, FmtFlag(flag), fmtMode(mode), depth)
}
types.FormatSym = func(sym *types.Sym, s fmt.State, verb rune, mode int) {
symFormat(sym, s, verb, fmtMode(mode))
}
types.FormatType = func(t *types.Type, s fmt.State, verb rune, mode int) {
typeFormat(t, s, verb, fmtMode(mode))
}
types.Cmptyp = cmptyp
types.FieldName = func(f *types.Field) string {
return f.Sym.Name
}
types.TypeLinkSym = func(t *types.Type) *obj.LSym {
return Linksym(typenamesym(t))
}
types.FmtLeft = int(FmtLeft)
types.FmtUnsigned = int(FmtUnsigned)
types.FErr = FErr
initUniverse() initUniverse()
blockgen = 1 blockgen = 1
...@@ -752,7 +782,7 @@ func loadsys() { ...@@ -752,7 +782,7 @@ func loadsys() {
inimport = false inimport = false
} }
func importfile(f *Val) *Pkg { func importfile(f *Val) *types.Pkg {
path_, ok := f.U.(string) path_, ok := f.U.(string)
if !ok { if !ok {
yyerror("import path must be a string") yyerror("import path must be a string")
...@@ -964,28 +994,28 @@ func mkpackage(pkgname string) { ...@@ -964,28 +994,28 @@ func mkpackage(pkgname string) {
func clearImports() { func clearImports() {
for _, s := range localpkg.Syms { for _, s := range localpkg.Syms {
if s.Def == nil { if asNode(s.Def) == nil {
continue continue
} }
if s.Def.Op == OPACK { if asNode(s.Def).Op == OPACK {
// throw away top-level package name leftover // throw away top-level package name leftover
// from previous file. // from previous file.
// leave s->block set to cause redeclaration // leave s->block set to cause redeclaration
// errors if a conflicting top-level name is // errors if a conflicting top-level name is
// introduced by a different file. // introduced by a different file.
if !s.Def.Used() && nsyntaxerrors == 0 { if !asNode(s.Def).Used() && nsyntaxerrors == 0 {
pkgnotused(s.Def.Pos, s.Def.Name.Pkg.Path, s.Name) pkgnotused(asNode(s.Def).Pos, asNode(s.Def).Name.Pkg.Path, s.Name)
} }
s.Def = nil s.Def = nil
continue continue
} }
if s.isAlias() { if IsAlias(s) {
// throw away top-level name left over // throw away top-level name left over
// from previous import . "x" // from previous import . "x"
if s.Def.Name != nil && s.Def.Name.Pack != nil && !s.Def.Name.Pack.Used() && nsyntaxerrors == 0 { if asNode(s.Def).Name != nil && asNode(s.Def).Name.Pack != nil && !asNode(s.Def).Name.Pack.Used() && nsyntaxerrors == 0 {
pkgnotused(s.Def.Name.Pack.Pos, s.Def.Name.Pack.Name.Pkg.Path, "") pkgnotused(asNode(s.Def).Name.Pack.Pos, asNode(s.Def).Name.Pack.Name.Pkg.Path, "")
s.Def.Name.Pack.SetUsed(true) asNode(s.Def).Name.Pack.SetUsed(true)
} }
s.Def = nil s.Def = nil
...@@ -993,3 +1023,7 @@ func clearImports() { ...@@ -993,3 +1023,7 @@ func clearImports() {
} }
} }
} }
func IsAlias(sym *types.Sym) bool {
return sym.Def != nil && asNode(sym.Def).Sym != sym
}
...@@ -34,6 +34,8 @@ func main() { ...@@ -34,6 +34,8 @@ func main() {
fmt.Fprintln(&b, "// Code generated by mkbuiltin.go. DO NOT EDIT.") fmt.Fprintln(&b, "// Code generated by mkbuiltin.go. DO NOT EDIT.")
fmt.Fprintln(&b) fmt.Fprintln(&b)
fmt.Fprintln(&b, "package gc") fmt.Fprintln(&b, "package gc")
fmt.Fprintln(&b)
fmt.Fprintln(&b, `import "cmd/compile/internal/types"`)
mkbuiltin(&b, "runtime") mkbuiltin(&b, "runtime")
...@@ -98,8 +100,8 @@ func mkbuiltin(w io.Writer, name string) { ...@@ -98,8 +100,8 @@ func mkbuiltin(w io.Writer, name string) {
fmt.Fprintln(w, "}") fmt.Fprintln(w, "}")
fmt.Fprintln(w) fmt.Fprintln(w)
fmt.Fprintf(w, "func %sTypes() []*Type {\n", name) fmt.Fprintf(w, "func %sTypes() []*types.Type {\n", name)
fmt.Fprintf(w, "var typs [%d]*Type\n", len(interner.typs)) fmt.Fprintf(w, "var typs [%d]*types.Type\n", len(interner.typs))
for i, typ := range interner.typs { for i, typ := range interner.typs {
fmt.Fprintf(w, "typs[%d] = %s\n", i, typ) fmt.Fprintf(w, "typs[%d] = %s\n", i, typ)
} }
...@@ -138,42 +140,42 @@ func (i *typeInterner) mktype(t ast.Expr) string { ...@@ -138,42 +140,42 @@ func (i *typeInterner) mktype(t ast.Expr) string {
case *ast.Ident: case *ast.Ident:
switch t.Name { switch t.Name {
case "byte": case "byte":
return "bytetype" return "types.Bytetype"
case "rune": case "rune":
return "runetype" return "types.Runetype"
} }
return fmt.Sprintf("Types[T%s]", strings.ToUpper(t.Name)) return fmt.Sprintf("types.Types[T%s]", strings.ToUpper(t.Name))
case *ast.SelectorExpr: case *ast.SelectorExpr:
if t.X.(*ast.Ident).Name != "unsafe" || t.Sel.Name != "Pointer" { if t.X.(*ast.Ident).Name != "unsafe" || t.Sel.Name != "Pointer" {
log.Fatalf("unhandled type: %#v", t) log.Fatalf("unhandled type: %#v", t)
} }
return "Types[TUNSAFEPTR]" return "types.Types[TUNSAFEPTR]"
case *ast.ArrayType: case *ast.ArrayType:
if t.Len == nil { if t.Len == nil {
return fmt.Sprintf("typSlice(%s)", i.subtype(t.Elt)) return fmt.Sprintf("types.NewSlice(%s)", i.subtype(t.Elt))
} }
return fmt.Sprintf("typArray(%s, %d)", i.subtype(t.Elt), intconst(t.Len)) return fmt.Sprintf("types.NewArray(%s, %d)", i.subtype(t.Elt), intconst(t.Len))
case *ast.ChanType: case *ast.ChanType:
dir := "Cboth" dir := "types.Cboth"
switch t.Dir { switch t.Dir {
case ast.SEND: case ast.SEND:
dir = "Csend" dir = "types.Csend"
case ast.RECV: case ast.RECV:
dir = "Crecv" dir = "types.Crecv"
} }
return fmt.Sprintf("typChan(%s, %s)", i.subtype(t.Value), dir) return fmt.Sprintf("types.NewChan(%s, %s)", i.subtype(t.Value), dir)
case *ast.FuncType: case *ast.FuncType:
return fmt.Sprintf("functype(nil, %s, %s)", i.fields(t.Params, false), i.fields(t.Results, false)) return fmt.Sprintf("functype(nil, %s, %s)", i.fields(t.Params, false), i.fields(t.Results, false))
case *ast.InterfaceType: case *ast.InterfaceType:
if len(t.Methods.List) != 0 { if len(t.Methods.List) != 0 {
log.Fatal("non-empty interfaces unsupported") log.Fatal("non-empty interfaces unsupported")
} }
return "Types[TINTER]" return "types.Types[TINTER]"
case *ast.MapType: case *ast.MapType:
return fmt.Sprintf("typMap(%s, %s)", i.subtype(t.Key), i.subtype(t.Value)) return fmt.Sprintf("types.NewMap(%s, %s)", i.subtype(t.Key), i.subtype(t.Value))
case *ast.StarExpr: case *ast.StarExpr:
return fmt.Sprintf("typPtr(%s)", i.subtype(t.X)) return fmt.Sprintf("types.NewPtr(%s)", i.subtype(t.X))
case *ast.StructType: case *ast.StructType:
return fmt.Sprintf("tostruct(%s)", i.fields(t.Fields, true)) return fmt.Sprintf("tostruct(%s)", i.fields(t.Fields, true))
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"unicode/utf8" "unicode/utf8"
"cmd/compile/internal/syntax" "cmd/compile/internal/syntax"
"cmd/compile/internal/types"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
) )
...@@ -147,7 +148,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) { ...@@ -147,7 +148,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
ipkg.Direct = true ipkg.Direct = true
var my *Sym var my *types.Sym
if imp.LocalPkgName != nil { if imp.LocalPkgName != nil {
my = p.name(imp.LocalPkgName) my = p.name(imp.LocalPkgName)
} else { } else {
...@@ -173,7 +174,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) { ...@@ -173,7 +174,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
lineno = pack.Pos lineno = pack.Pos
redeclare(my, "as imported package name") redeclare(my, "as imported package name")
} }
my.Def = pack my.Def = asTypesNode(pack)
my.Lastlineno = pack.Pos my.Lastlineno = pack.Pos
my.Block = 1 // at top level my.Block = 1 // at top level
} }
...@@ -521,7 +522,7 @@ func (p *noder) expr(expr syntax.Expr) *Node { ...@@ -521,7 +522,7 @@ func (p *noder) expr(expr syntax.Expr) *Node {
return p.nod(expr, OTMAP, p.typeExpr(expr.Key), p.typeExpr(expr.Value)) return p.nod(expr, OTMAP, p.typeExpr(expr.Key), p.typeExpr(expr.Value))
case *syntax.ChanType: case *syntax.ChanType:
n := p.nod(expr, OTCHAN, p.typeExpr(expr.Elem), nil) n := p.nod(expr, OTCHAN, p.typeExpr(expr.Elem), nil)
n.Etype = EType(p.chanDir(expr.Dir)) n.Etype = types.EType(p.chanDir(expr.Dir))
return n return n
case *syntax.TypeSwitchGuard: case *syntax.TypeSwitchGuard:
...@@ -549,14 +550,14 @@ func (p *noder) typeExprOrNil(typ syntax.Expr) *Node { ...@@ -549,14 +550,14 @@ func (p *noder) typeExprOrNil(typ syntax.Expr) *Node {
return nil return nil
} }
func (p *noder) chanDir(dir syntax.ChanDir) ChanDir { func (p *noder) chanDir(dir syntax.ChanDir) types.ChanDir {
switch dir { switch dir {
case 0: case 0:
return Cboth return types.Cboth
case syntax.SendOnly: case syntax.SendOnly:
return Csend return types.Csend
case syntax.RecvOnly: case syntax.RecvOnly:
return Crecv return types.Crecv
} }
panic("unhandled ChanDir") panic("unhandled ChanDir")
} }
...@@ -605,7 +606,7 @@ func (p *noder) interfaceType(expr *syntax.InterfaceType) *Node { ...@@ -605,7 +606,7 @@ func (p *noder) interfaceType(expr *syntax.InterfaceType) *Node {
return n return n
} }
func (p *noder) packname(expr syntax.Expr) *Sym { func (p *noder) packname(expr syntax.Expr) *types.Sym {
switch expr := expr.(type) { switch expr := expr.(type) {
case *syntax.Name: case *syntax.Name:
name := p.name(expr) name := p.name(expr)
...@@ -615,13 +616,13 @@ func (p *noder) packname(expr syntax.Expr) *Sym { ...@@ -615,13 +616,13 @@ func (p *noder) packname(expr syntax.Expr) *Sym {
return name return name
case *syntax.SelectorExpr: case *syntax.SelectorExpr:
name := p.name(expr.X.(*syntax.Name)) name := p.name(expr.X.(*syntax.Name))
var pkg *Pkg var pkg *types.Pkg
if name.Def == nil || name.Def.Op != OPACK { if asNode(name.Def) == nil || asNode(name.Def).Op != OPACK {
yyerror("%v is not a package", name) yyerror("%v is not a package", name)
pkg = localpkg pkg = localpkg
} else { } else {
name.Def.SetUsed(true) asNode(name.Def).SetUsed(true)
pkg = name.Def.Name.Pkg pkg = asNode(name.Def).Name.Pkg
} }
return restrictlookup(expr.Sel.Value, pkg) return restrictlookup(expr.Sel.Value, pkg)
} }
...@@ -681,7 +682,7 @@ func (p *noder) stmt(stmt syntax.Stmt) *Node { ...@@ -681,7 +682,7 @@ func (p *noder) stmt(stmt syntax.Stmt) *Node {
if stmt.Op != 0 && stmt.Op != syntax.Def { if stmt.Op != 0 && stmt.Op != syntax.Def {
n := p.nod(stmt, OASOP, p.expr(stmt.Lhs), p.expr(stmt.Rhs)) n := p.nod(stmt, OASOP, p.expr(stmt.Lhs), p.expr(stmt.Rhs))
n.SetImplicit(stmt.Rhs == syntax.ImplicitOne) n.SetImplicit(stmt.Rhs == syntax.ImplicitOne)
n.Etype = EType(p.binOp(stmt.Op)) n.Etype = types.EType(p.binOp(stmt.Op))
return n return n
} }
...@@ -757,7 +758,7 @@ func (p *noder) stmt(stmt syntax.Stmt) *Node { ...@@ -757,7 +758,7 @@ func (p *noder) stmt(stmt syntax.Stmt) *Node {
if ln.Class != PPARAMOUT { if ln.Class != PPARAMOUT {
break break
} }
if ln.Sym.Def != ln { if asNode(ln.Sym.Def) != ln {
yyerror("%s is shadowed during return", ln.Sym.Name) yyerror("%s is shadowed during return", ln.Sym.Name)
} }
} }
...@@ -1030,7 +1031,7 @@ func (p *noder) basicLit(lit *syntax.BasicLit) Val { ...@@ -1030,7 +1031,7 @@ func (p *noder) basicLit(lit *syntax.BasicLit) Val {
} }
} }
func (p *noder) name(name *syntax.Name) *Sym { func (p *noder) name(name *syntax.Name) *types.Sym {
return lookup(name.Value) return lookup(name.Value)
} }
...@@ -1125,7 +1126,7 @@ func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma { ...@@ -1125,7 +1126,7 @@ func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma {
return 0 return 0
} }
func mkname(sym *Sym) *Node { func mkname(sym *types.Sym) *Node {
n := oldname(sym) n := oldname(sym)
if n.Name != nil && n.Name.Pack != nil { if n.Name != nil && n.Name.Pack != nil {
n.Name.Pack.SetUsed(true) n.Name.Pack.SetUsed(true)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/obj" "cmd/internal/obj"
"crypto/sha256" "crypto/sha256"
...@@ -173,7 +174,7 @@ func dumpptabs() { ...@@ -173,7 +174,7 @@ func dumpptabs() {
} }
for _, exportn := range exportlist { for _, exportn := range exportlist {
s := exportn.Sym s := exportn.Sym
n := s.Def n := asNode(s.Def)
if n == nil { if n == nil {
continue continue
} }
...@@ -188,10 +189,10 @@ func dumpptabs() { ...@@ -188,10 +189,10 @@ func dumpptabs() {
} }
if n.Type.Etype == TFUNC && n.Class == PFUNC { if n.Type.Etype == TFUNC && n.Class == PFUNC {
// function // function
ptabs = append(ptabs, ptabEntry{s: s, t: s.Def.Type}) ptabs = append(ptabs, ptabEntry{s: s, t: asNode(s.Def).Type})
} else { } else {
// variable // variable
ptabs = append(ptabs, ptabEntry{s: s, t: typPtr(s.Def.Type)}) ptabs = append(ptabs, ptabEntry{s: s, t: types.NewPtr(asNode(s.Def).Type)})
} }
} }
} }
...@@ -217,7 +218,7 @@ func dumpglobls() { ...@@ -217,7 +218,7 @@ func dumpglobls() {
} }
for _, s := range funcsyms { for _, s := range funcsyms {
sf := s.Pkg.Lookup(s.funcsymname()) sf := s.Pkg.Lookup(funcsymname(s))
dsymptr(sf, 0, s, 0) dsymptr(sf, 0, s, 0)
ggloblsym(sf, int32(Widthptr), obj.DUPOK|obj.RODATA) ggloblsym(sf, int32(Widthptr), obj.DUPOK|obj.RODATA)
} }
...@@ -226,7 +227,7 @@ func dumpglobls() { ...@@ -226,7 +227,7 @@ func dumpglobls() {
funcsyms = nil funcsyms = nil
} }
func Linksym(s *Sym) *obj.LSym { func Linksym(s *types.Sym) *obj.LSym {
if s == nil { if s == nil {
return nil return nil
} }
...@@ -247,7 +248,7 @@ func Linksym(s *Sym) *obj.LSym { ...@@ -247,7 +248,7 @@ func Linksym(s *Sym) *obj.LSym {
return ls return ls
} }
func duintxx(s *Sym, off int, v uint64, wid int) int { func duintxx(s *types.Sym, off int, v uint64, wid int) int {
return duintxxLSym(Linksym(s), off, v, wid) return duintxxLSym(Linksym(s), off, v, wid)
} }
...@@ -260,23 +261,23 @@ func duintxxLSym(s *obj.LSym, off int, v uint64, wid int) int { ...@@ -260,23 +261,23 @@ func duintxxLSym(s *obj.LSym, off int, v uint64, wid int) int {
return int(obj.Setuintxx(Ctxt, s, int64(off), v, int64(wid))) return int(obj.Setuintxx(Ctxt, s, int64(off), v, int64(wid)))
} }
func duint8(s *Sym, off int, v uint8) int { func duint8(s *types.Sym, off int, v uint8) int {
return duintxx(s, off, uint64(v), 1) return duintxx(s, off, uint64(v), 1)
} }
func duint16(s *Sym, off int, v uint16) int { func duint16(s *types.Sym, off int, v uint16) int {
return duintxx(s, off, uint64(v), 2) return duintxx(s, off, uint64(v), 2)
} }
func duint32(s *Sym, off int, v uint32) int { func duint32(s *types.Sym, off int, v uint32) int {
return duintxx(s, off, uint64(v), 4) return duintxx(s, off, uint64(v), 4)
} }
func duintptr(s *Sym, off int, v uint64) int { func duintptr(s *types.Sym, off int, v uint64) int {
return duintxx(s, off, v, Widthptr) return duintxx(s, off, v, Widthptr)
} }
func dbvec(s *Sym, off int, bv bvec) int { func dbvec(s *types.Sym, off int, bv bvec) int {
// Runtime reads the bitmaps as byte arrays. Oblige. // Runtime reads the bitmaps as byte arrays. Oblige.
for j := 0; int32(j) < bv.n; j += 8 { for j := 0; int32(j) < bv.n; j += 8 {
word := bv.b[j/32] word := bv.b[j/32]
...@@ -319,7 +320,7 @@ func slicebytes(nam *Node, s string, len int) { ...@@ -319,7 +320,7 @@ func slicebytes(nam *Node, s string, len int) {
slicebytes_gen++ slicebytes_gen++
symname := fmt.Sprintf(".gobytes.%d", slicebytes_gen) symname := fmt.Sprintf(".gobytes.%d", slicebytes_gen)
sym := localpkg.Lookup(symname) sym := localpkg.Lookup(symname)
sym.Def = newname(sym) sym.Def = asTypesNode(newname(sym))
off := dsname(sym, 0, s) off := dsname(sym, 0, s)
ggloblsym(sym, int32(off), obj.NOPTR|obj.LOCAL) ggloblsym(sym, int32(off), obj.NOPTR|obj.LOCAL)
...@@ -333,7 +334,7 @@ func slicebytes(nam *Node, s string, len int) { ...@@ -333,7 +334,7 @@ func slicebytes(nam *Node, s string, len int) {
duintxx(nam.Sym, off, uint64(len), Widthint) duintxx(nam.Sym, off, uint64(len), Widthint)
} }
func dsname(s *Sym, off int, t string) int { func dsname(s *types.Sym, off int, t string) int {
return dsnameLSym(Linksym(s), off, t) return dsnameLSym(Linksym(s), off, t)
} }
...@@ -342,7 +343,7 @@ func dsnameLSym(s *obj.LSym, off int, t string) int { ...@@ -342,7 +343,7 @@ func dsnameLSym(s *obj.LSym, off int, t string) int {
return off + len(t) return off + len(t)
} }
func dsymptr(s *Sym, off int, x *Sym, xoff int) int { func dsymptr(s *types.Sym, off int, x *types.Sym, xoff int) int {
return dsymptrLSym(Linksym(s), off, Linksym(x), xoff) return dsymptrLSym(Linksym(s), off, Linksym(x), xoff)
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/src" "cmd/internal/src"
"fmt" "fmt"
) )
...@@ -59,7 +60,7 @@ func order(fn *Node) { ...@@ -59,7 +60,7 @@ func order(fn *Node) {
// Ordertemp allocates a new temporary with the given type, // Ordertemp allocates a new temporary with the given type,
// pushes it onto the temp stack, and returns it. // pushes it onto the temp stack, and returns it.
// If clear is true, ordertemp emits code to zero the temporary. // If clear is true, ordertemp emits code to zero the temporary.
func ordertemp(t *Type, order *Order, clear bool) *Node { func ordertemp(t *types.Type, order *Order, clear bool) *Node {
var_ := temp(t) var_ := temp(t)
if clear { if clear {
a := nod(OAS, var_, nil) a := nod(OAS, var_, nil)
...@@ -83,7 +84,7 @@ func ordertemp(t *Type, order *Order, clear bool) *Node { ...@@ -83,7 +84,7 @@ func ordertemp(t *Type, order *Order, clear bool) *Node {
// (The other candidate would be map access, but map access // (The other candidate would be map access, but map access
// returns a pointer to the result data instead of taking a pointer // returns a pointer to the result data instead of taking a pointer
// to be filled in.) // to be filled in.)
func ordercopyexpr(n *Node, t *Type, order *Order, clear int) *Node { func ordercopyexpr(n *Node, t *types.Type, order *Order, clear int) *Node {
var_ := ordertemp(t, order, clear != 0) var_ := ordertemp(t, order, clear != 0)
a := nod(OAS, var_, n) a := nod(OAS, var_, n)
a = typecheck(a, Etop) a = typecheck(a, Etop)
...@@ -208,7 +209,7 @@ func orderaddrtemp(n *Node, order *Order) *Node { ...@@ -208,7 +209,7 @@ func orderaddrtemp(n *Node, order *Order) *Node {
// ordermapkeytemp prepares n to be a key in a map runtime call and returns n. // ordermapkeytemp prepares n to be a key in a map runtime call and returns n.
// It should only be used for map runtime calls which have *_fast* versions. // It should only be used for map runtime calls which have *_fast* versions.
func ordermapkeytemp(t *Type, n *Node, order *Order) *Node { func ordermapkeytemp(t *types.Type, n *Node, order *Order) *Node {
// Most map calls need to take the address of the key. // Most map calls need to take the address of the key.
// Exception: map*_fast* calls. See golang.org/issue/19015. // Exception: map*_fast* calls. See golang.org/issue/19015.
if mapfast(t) == mapslow { if mapfast(t) == mapslow {
...@@ -595,8 +596,8 @@ func orderstmt(n *Node, order *Order) { ...@@ -595,8 +596,8 @@ func orderstmt(n *Node, order *Order) {
orderexprlist(n.List, order) orderexprlist(n.List, order)
n.Rlist.First().Left = orderexpr(n.Rlist.First().Left, order, nil) // arg to recv n.Rlist.First().Left = orderexpr(n.Rlist.First().Left, order, nil) // arg to recv
ch := n.Rlist.First().Left.Type ch := n.Rlist.First().Left.Type
tmp1 := ordertemp(ch.Elem(), order, haspointers(ch.Elem())) tmp1 := ordertemp(ch.Elem(), order, types.Haspointers(ch.Elem()))
tmp2 := ordertemp(Types[TBOOL], order, false) tmp2 := ordertemp(types.Types[TBOOL], order, false)
order.out = append(order.out, n) order.out = append(order.out, n)
r := nod(OAS, n.List.First(), tmp1) r := nod(OAS, n.List.First(), tmp1)
r = typecheck(r, Etop) r = typecheck(r, Etop)
...@@ -745,9 +746,9 @@ func orderstmt(n *Node, order *Order) { ...@@ -745,9 +746,9 @@ func orderstmt(n *Node, order *Order) {
// make copy. // make copy.
r := n.Right r := n.Right
if r.Type.IsString() && r.Type != Types[TSTRING] { if r.Type.IsString() && r.Type != types.Types[TSTRING] {
r = nod(OCONV, r, nil) r = nod(OCONV, r, nil)
r.Type = Types[TSTRING] r.Type = types.Types[TSTRING]
r = typecheck(r, Erv) r = typecheck(r, Erv)
} }
...@@ -761,7 +762,7 @@ func orderstmt(n *Node, order *Order) { ...@@ -761,7 +762,7 @@ func orderstmt(n *Node, order *Order) {
n.Right = ordercopyexpr(r, r.Type, order, 0) n.Right = ordercopyexpr(r, r.Type, order, 0)
// n->alloc is the temp for the iterator. // n->alloc is the temp for the iterator.
prealloc[n] = ordertemp(Types[TUINT8], order, true) prealloc[n] = ordertemp(types.Types[TUINT8], order, true)
} }
for i := range n.List.Slice() { for i := range n.List.Slice() {
n.List.SetIndex(i, orderexprinplace(n.List.Index(i), order)) n.List.SetIndex(i, orderexprinplace(n.List.Index(i), order))
...@@ -862,7 +863,7 @@ func orderstmt(n *Node, order *Order) { ...@@ -862,7 +863,7 @@ func orderstmt(n *Node, order *Order) {
n2.Ninit.Append(tmp2) n2.Ninit.Append(tmp2)
} }
r.Left = ordertemp(r.Right.Left.Type.Elem(), order, haspointers(r.Right.Left.Type.Elem())) r.Left = ordertemp(r.Right.Left.Type.Elem(), order, types.Haspointers(r.Right.Left.Type.Elem()))
tmp2 = nod(OAS, tmp1, r.Left) tmp2 = nod(OAS, tmp1, r.Left)
tmp2 = typecheck(tmp2, Etop) tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2) n2.Ninit.Append(tmp2)
...@@ -879,7 +880,7 @@ func orderstmt(n *Node, order *Order) { ...@@ -879,7 +880,7 @@ func orderstmt(n *Node, order *Order) {
n2.Ninit.Append(tmp2) n2.Ninit.Append(tmp2)
} }
r.List.Set1(ordertemp(Types[TBOOL], order, false)) r.List.Set1(ordertemp(types.Types[TBOOL], order, false))
tmp2 = okas(tmp1, r.List.First()) tmp2 = okas(tmp1, r.List.First())
tmp2 = typecheck(tmp2, Etop) tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2) n2.Ninit.Append(tmp2)
...@@ -1012,7 +1013,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node { ...@@ -1012,7 +1013,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node {
orderexprlist(n.List, order) orderexprlist(n.List, order)
if n.List.Len() > 5 { if n.List.Len() > 5 {
t := typArray(Types[TSTRING], int64(n.List.Len())) t := types.NewArray(types.Types[TSTRING], int64(n.List.Len()))
prealloc[n] = ordertemp(t, order, false) prealloc[n] = ordertemp(t, order, false)
} }
...@@ -1165,7 +1166,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node { ...@@ -1165,7 +1166,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node {
case OCLOSURE: case OCLOSURE:
if n.Noescape() && n.Func.Cvars.Len() > 0 { if n.Noescape() && n.Func.Cvars.Len() > 0 {
prealloc[n] = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type prealloc[n] = ordertemp(types.Types[TUINT8], order, false) // walk will fill in correct type
} }
case OARRAYLIT, OSLICELIT, OCALLPART: case OARRAYLIT, OSLICELIT, OCALLPART:
...@@ -1174,7 +1175,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node { ...@@ -1174,7 +1175,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node {
orderexprlist(n.List, order) orderexprlist(n.List, order)
orderexprlist(n.Rlist, order) orderexprlist(n.Rlist, order)
if n.Noescape() { if n.Noescape() {
prealloc[n] = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type prealloc[n] = ordertemp(types.Types[TUINT8], order, false) // walk will fill in correct type
} }
case ODDDARG: case ODDDARG:
...@@ -1237,7 +1238,7 @@ func orderas2(n *Node, order *Order) { ...@@ -1237,7 +1238,7 @@ func orderas2(n *Node, order *Order) {
left := []*Node{} left := []*Node{}
for _, l := range n.List.Slice() { for _, l := range n.List.Slice() {
if !isblank(l) { if !isblank(l) {
tmp := ordertemp(l.Type, order, haspointers(l.Type)) tmp := ordertemp(l.Type, order, types.Haspointers(l.Type))
tmplist = append(tmplist, tmp) tmplist = append(tmplist, tmp)
left = append(left, l) left = append(left, l)
} }
...@@ -1266,11 +1267,11 @@ func orderokas2(n *Node, order *Order) { ...@@ -1266,11 +1267,11 @@ func orderokas2(n *Node, order *Order) {
var tmp1, tmp2 *Node var tmp1, tmp2 *Node
if !isblank(n.List.First()) { if !isblank(n.List.First()) {
typ := n.Rlist.First().Type typ := n.Rlist.First().Type
tmp1 = ordertemp(typ, order, haspointers(typ)) tmp1 = ordertemp(typ, order, types.Haspointers(typ))
} }
if !isblank(n.List.Second()) { if !isblank(n.List.Second()) {
tmp2 = ordertemp(Types[TBOOL], order, false) tmp2 = ordertemp(types.Types[TBOOL], order, false)
} }
order.out = append(order.out, n) order.out = append(order.out, n)
......
...@@ -6,6 +6,7 @@ package gc ...@@ -6,6 +6,7 @@ package gc
import ( import (
"cmd/compile/internal/ssa" "cmd/compile/internal/ssa"
"cmd/compile/internal/types"
"cmd/internal/dwarf" "cmd/internal/dwarf"
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
// "Portable" code generation. // "Portable" code generation.
func makefuncdatasym(pp *Progs, nameprefix string, funcdatakind int64, curfn *Node) *Sym { func makefuncdatasym(pp *Progs, nameprefix string, funcdatakind int64, curfn *Node) *types.Sym {
// This symbol requires a unique, reproducible name; // This symbol requires a unique, reproducible name;
// unique to avoid duplicate symbols, // unique to avoid duplicate symbols,
// and reproducible for reproducible builds and toolstash. // and reproducible for reproducible builds and toolstash.
...@@ -165,8 +166,8 @@ func cmpstackvarlt(a, b *Node) bool { ...@@ -165,8 +166,8 @@ func cmpstackvarlt(a, b *Node) bool {
return a.Used() return a.Used()
} }
ap := haspointers(a.Type) ap := types.Haspointers(a.Type)
bp := haspointers(b.Type) bp := types.Haspointers(b.Type)
if ap != bp { if ap != bp {
return ap return ap
} }
...@@ -230,7 +231,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) { ...@@ -230,7 +231,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
} }
if f.Config.NeedsFpScratch && scratchUsed { if f.Config.NeedsFpScratch && scratchUsed {
s.scratchFpMem = tempAt(src.NoXPos, s.curfn, Types[TUINT64]) s.scratchFpMem = tempAt(src.NoXPos, s.curfn, types.Types[TUINT64])
} }
sort.Sort(byStackVar(fn.Dcl)) sort.Sort(byStackVar(fn.Dcl))
...@@ -252,7 +253,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) { ...@@ -252,7 +253,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
} }
s.stksize += w s.stksize += w
s.stksize = Rnd(s.stksize, int64(n.Type.Align)) s.stksize = Rnd(s.stksize, int64(n.Type.Align))
if haspointers(n.Type) { if types.Haspointers(n.Type) {
s.stkptrsize = s.stksize s.stkptrsize = s.stksize
} }
if thearch.LinkArch.InFamily(sys.MIPS, sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) { if thearch.LinkArch.InFamily(sys.MIPS, sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) {
...@@ -379,7 +380,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var { ...@@ -379,7 +380,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
// fieldtrack adds R_USEFIELD relocations to fnsym to record any // fieldtrack adds R_USEFIELD relocations to fnsym to record any
// struct fields that it used. // struct fields that it used.
func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) { func fieldtrack(fnsym *obj.LSym, tracked map[*types.Sym]struct{}) {
if fnsym == nil { if fnsym == nil {
return return
} }
...@@ -387,7 +388,7 @@ func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) { ...@@ -387,7 +388,7 @@ func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) {
return return
} }
trackSyms := make([]*Sym, 0, len(tracked)) trackSyms := make([]*types.Sym, 0, len(tracked))
for sym := range tracked { for sym := range tracked {
trackSyms = append(trackSyms, sym) trackSyms = append(trackSyms, sym)
} }
...@@ -399,7 +400,7 @@ func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) { ...@@ -399,7 +400,7 @@ func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) {
} }
} }
type symByName []*Sym type symByName []*types.Sym
func (a symByName) Len() int { return len(a) } func (a symByName) Len() int { return len(a) }
func (a symByName) Less(i, j int) bool { return a[i].Name < a[j].Name } func (a symByName) Less(i, j int) bool { return a[i].Name < a[j].Name }
......
...@@ -5,22 +5,23 @@ ...@@ -5,22 +5,23 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"reflect" "reflect"
"sort" "sort"
"testing" "testing"
) )
func typeWithoutPointers() *Type { func typeWithoutPointers() *types.Type {
t := typ(TSTRUCT) t := types.New(TSTRUCT)
f := &Field{Type: typ(TINT)} f := &types.Field{Type: types.New(TINT)}
t.SetFields([]*Field{f}) t.SetFields([]*types.Field{f})
return t return t
} }
func typeWithPointers() *Type { func typeWithPointers() *types.Type {
t := typ(TSTRUCT) t := types.New(TSTRUCT)
f := &Field{Type: typ(TPTR64)} f := &types.Field{Type: types.New(TPTR64)}
t.SetFields([]*Field{f}) t.SetFields([]*types.Field{f})
return t return t
} }
...@@ -86,38 +87,38 @@ func TestCmpstackvar(t *testing.T) { ...@@ -86,38 +87,38 @@ func TestCmpstackvar(t *testing.T) {
true, true,
}, },
{ {
Node{Class: PAUTO, Type: &Type{}, Name: &Name{flags: nameNeedzero}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{flags: nameNeedzero}},
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}},
true, true,
}, },
{ {
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}},
Node{Class: PAUTO, Type: &Type{}, Name: &Name{flags: nameNeedzero}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{flags: nameNeedzero}},
false, false,
}, },
{ {
Node{Class: PAUTO, Type: &Type{Width: 1}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{Width: 1}, Name: &Name{}},
Node{Class: PAUTO, Type: &Type{Width: 2}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{Width: 2}, Name: &Name{}},
false, false,
}, },
{ {
Node{Class: PAUTO, Type: &Type{Width: 2}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{Width: 2}, Name: &Name{}},
Node{Class: PAUTO, Type: &Type{Width: 1}, Name: &Name{}}, Node{Class: PAUTO, Type: &types.Type{Width: 1}, Name: &Name{}},
true, true,
}, },
{ {
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "xyz"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "xyz"}},
true, true,
}, },
{ {
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
false, false,
}, },
{ {
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "xyz"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "xyz"}},
Node{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, Node{Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
false, false,
}, },
} }
...@@ -135,41 +136,41 @@ func TestCmpstackvar(t *testing.T) { ...@@ -135,41 +136,41 @@ func TestCmpstackvar(t *testing.T) {
func TestStackvarSort(t *testing.T) { func TestStackvarSort(t *testing.T) {
inp := []*Node{ inp := []*Node{
{Class: PFUNC, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 0, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 0, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 10, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 10, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 20, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 20, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, flags: nodeUsed, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, flags: nodeUsed, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: typeWithoutPointers(), Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: typeWithoutPointers(), Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{flags: nameNeedzero}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{flags: nameNeedzero}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{Width: 1}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{Width: 1}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{Width: 2}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{Width: 2}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "xyz"}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "xyz"}},
} }
want := []*Node{ want := []*Node{
{Class: PFUNC, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 0, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 0, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 10, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 10, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PFUNC, Xoffset: 20, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PFUNC, Xoffset: 20, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, flags: nodeUsed, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, flags: nodeUsed, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{flags: nameNeedzero}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{flags: nameNeedzero}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{Width: 2}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{Width: 2}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{Width: 1}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{Width: 1}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "abc"}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "abc"}},
{Class: PAUTO, Type: &Type{}, Name: &Name{}, Sym: &Sym{Name: "xyz"}}, {Class: PAUTO, Type: &types.Type{}, Name: &Name{}, Sym: &types.Sym{Name: "xyz"}},
{Class: PAUTO, Type: typeWithoutPointers(), Name: &Name{}, Sym: &Sym{}}, {Class: PAUTO, Type: typeWithoutPointers(), Name: &Name{}, Sym: &types.Sym{}},
} }
// haspointers updates Type.Haspointers as a side effect, so // haspointers updates Type.Haspointers as a side effect, so
// exercise this function on all inputs so that reflect.DeepEqual // exercise this function on all inputs so that reflect.DeepEqual
// doesn't produce false positives. // doesn't produce false positives.
for i := range want { for i := range want {
haspointers(want[i].Type) types.Haspointers(want[i].Type)
haspointers(inp[i].Type) types.Haspointers(inp[i].Type)
} }
sort.Sort(byStackVar(inp)) sort.Sort(byStackVar(inp))
......
...@@ -16,6 +16,7 @@ package gc ...@@ -16,6 +16,7 @@ package gc
import ( import (
"cmd/compile/internal/ssa" "cmd/compile/internal/ssa"
"cmd/compile/internal/types"
"cmd/internal/obj" "cmd/internal/obj"
"crypto/md5" "crypto/md5"
"fmt" "fmt"
...@@ -84,7 +85,7 @@ type progeffectscache struct { ...@@ -84,7 +85,7 @@ type progeffectscache struct {
// nor do we care about empty structs (handled by the pointer check), // nor do we care about empty structs (handled by the pointer check),
// nor do we care about the fake PAUTOHEAP variables. // nor do we care about the fake PAUTOHEAP variables.
func livenessShouldTrack(n *Node) bool { func livenessShouldTrack(n *Node) bool {
return n.Op == ONAME && (n.Class == PAUTO || n.Class == PPARAM || n.Class == PPARAMOUT) && haspointers(n.Type) return n.Op == ONAME && (n.Class == PAUTO || n.Class == PPARAM || n.Class == PPARAMOUT) && types.Haspointers(n.Type)
} }
// getvariables returns the list of on-stack variables that we need to track. // getvariables returns the list of on-stack variables that we need to track.
...@@ -320,7 +321,7 @@ func (lv *Liveness) blockEffects(b *ssa.Block) *BlockEffects { ...@@ -320,7 +321,7 @@ func (lv *Liveness) blockEffects(b *ssa.Block) *BlockEffects {
// and then simply copied into bv at the correct offset on future calls with // and then simply copied into bv at the correct offset on future calls with
// the same type t. On https://rsc.googlecode.com/hg/testdata/slow.go, onebitwalktype1 // the same type t. On https://rsc.googlecode.com/hg/testdata/slow.go, onebitwalktype1
// accounts for 40% of the 6g execution time. // accounts for 40% of the 6g execution time.
func onebitwalktype1(t *Type, xoffset *int64, bv bvec) { func onebitwalktype1(t *types.Type, xoffset *int64, bv bvec) {
if t.Align > 0 && *xoffset&int64(t.Align-1) != 0 { if t.Align > 0 && *xoffset&int64(t.Align-1) != 0 {
Fatalf("onebitwalktype1: invalid initial alignment, %v", t) Fatalf("onebitwalktype1: invalid initial alignment, %v", t)
} }
...@@ -1050,7 +1051,7 @@ func livenessprintdebug(lv *Liveness) { ...@@ -1050,7 +1051,7 @@ func livenessprintdebug(lv *Liveness) {
fmt.Printf("\n") fmt.Printf("\n")
} }
func finishgclocals(sym *Sym) { func finishgclocals(sym *types.Sym) {
ls := Linksym(sym) ls := Linksym(sym)
ls.Name = fmt.Sprintf("gclocals·%x", md5.Sum(ls.P)) ls.Name = fmt.Sprintf("gclocals·%x", md5.Sum(ls.P))
ls.Set(obj.AttrDuplicateOK, true) ls.Set(obj.AttrDuplicateOK, true)
...@@ -1068,7 +1069,7 @@ func finishgclocals(sym *Sym) { ...@@ -1068,7 +1069,7 @@ func finishgclocals(sym *Sym) {
// first word dumped is the total number of bitmaps. The second word is the // first word dumped is the total number of bitmaps. The second word is the
// length of the bitmaps. All bitmaps are assumed to be of equal length. The // length of the bitmaps. All bitmaps are assumed to be of equal length. The
// remaining bytes are the raw bitmaps. // remaining bytes are the raw bitmaps.
func livenessemit(lv *Liveness, argssym, livesym *Sym) { func livenessemit(lv *Liveness, argssym, livesym *types.Sym) {
args := bvalloc(argswords(lv)) args := bvalloc(argswords(lv))
aoff := duint32(argssym, 0, uint32(len(lv.livevars))) // number of bitmaps aoff := duint32(argssym, 0, uint32(len(lv.livevars))) // number of bitmaps
aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap
...@@ -1095,7 +1096,7 @@ func livenessemit(lv *Liveness, argssym, livesym *Sym) { ...@@ -1095,7 +1096,7 @@ func livenessemit(lv *Liveness, argssym, livesym *Sym) {
// pointer variables in the function and emits a runtime data // pointer variables in the function and emits a runtime data
// structure read by the garbage collector. // structure read by the garbage collector.
// Returns a map from GC safe points to their corresponding stack map index. // Returns a map from GC safe points to their corresponding stack map index.
func liveness(e *ssafn, f *ssa.Func, argssym, livesym *Sym) map[*ssa.Value]int { func liveness(e *ssafn, f *ssa.Func, argssym, livesym *types.Sym) map[*ssa.Value]int {
// Construct the global liveness state. // Construct the global liveness state.
vars := getvariables(e.curfn) vars := getvariables(e.curfn)
lv := newliveness(e.curfn, f, vars, e.stkptrsize) lv := newliveness(e.curfn, f, vars, e.stkptrsize)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"cmd/internal/src" "cmd/internal/src"
"fmt" "fmt"
"strings" "strings"
...@@ -67,7 +68,7 @@ func instrument(fn *Node) { ...@@ -67,7 +68,7 @@ func instrument(fn *Node) {
// getcallerpc. We use -widthptr(FP) for x86. // getcallerpc. We use -widthptr(FP) for x86.
// BUG: this will not work on arm. // BUG: this will not work on arm.
nodpc := *nodfp nodpc := *nodfp
nodpc.Type = Types[TUINTPTR] nodpc.Type = types.Types[TUINTPTR]
nodpc.Xoffset = int64(-Widthptr) nodpc.Xoffset = int64(-Widthptr)
nd := mkcall("racefuncenter", nil, nil, &nodpc) nd := mkcall("racefuncenter", nil, nil, &nodpc)
fn.Func.Enter.Prepend(nd) fn.Func.Enter.Prepend(nd)
...@@ -216,7 +217,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { ...@@ -216,7 +217,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, 0, 0)
if n.Left.Type.IsMap() { if n.Left.Type.IsMap() {
n1 := nod(OCONVNOP, n.Left, nil) n1 := nod(OCONVNOP, n.Left, nil)
n1.Type = typPtr(Types[TUINT8]) n1.Type = types.NewPtr(types.Types[TUINT8])
n1 = nod(OIND, n1, nil) n1 = nod(OIND, n1, nil)
n1 = typecheck(n1, Erv) n1 = typecheck(n1, Erv)
callinstr(&n1, init, 0, skip) callinstr(&n1, init, 0, skip)
...@@ -561,14 +562,14 @@ func makeaddable(n *Node) { ...@@ -561,14 +562,14 @@ func makeaddable(n *Node) {
func uintptraddr(n *Node) *Node { func uintptraddr(n *Node) *Node {
r := nod(OADDR, n, nil) r := nod(OADDR, n, nil)
r.SetBounded(true) r.SetBounded(true)
r = conv(r, Types[TUNSAFEPTR]) r = conv(r, types.Types[TUNSAFEPTR])
r = conv(r, Types[TUINTPTR]) r = conv(r, types.Types[TUINTPTR])
return r return r
} }
func detachexpr(n *Node, init *Nodes) *Node { func detachexpr(n *Node, init *Nodes) *Node {
addr := nod(OADDR, n, nil) addr := nod(OADDR, n, nil)
l := temp(typPtr(n.Type)) l := temp(types.NewPtr(n.Type))
as := nod(OAS, l, addr) as := nod(OAS, l, addr)
as = typecheck(as, Etop) as = typecheck(as, Etop)
as = walkexpr(as, init) as = walkexpr(as, init)
......
...@@ -4,14 +4,17 @@ ...@@ -4,14 +4,17 @@
package gc package gc
import "unicode/utf8" import (
"cmd/compile/internal/types"
"unicode/utf8"
)
// range // range
func typecheckrange(n *Node) { func typecheckrange(n *Node) {
var toomany int var toomany int
var why string var why string
var t1 *Type var t1 *types.Type
var t2 *Type var t2 *types.Type
var v1 *Node var v1 *Node
var v2 *Node var v2 *Node
var ls []*Node var ls []*Node
...@@ -52,7 +55,7 @@ func typecheckrange(n *Node) { ...@@ -52,7 +55,7 @@ func typecheckrange(n *Node) {
goto out goto out
case TARRAY, TSLICE: case TARRAY, TSLICE:
t1 = Types[TINT] t1 = types.Types[TINT]
t2 = t.Elem() t2 = t.Elem()
case TMAP: case TMAP:
...@@ -72,8 +75,8 @@ func typecheckrange(n *Node) { ...@@ -72,8 +75,8 @@ func typecheckrange(n *Node) {
} }
case TSTRING: case TSTRING:
t1 = Types[TINT] t1 = types.Types[TINT]
t2 = runetype t2 = types.Runetype
} }
if n.List.Len() > 2 || toomany != 0 { if n.List.Len() > 2 || toomany != 0 {
...@@ -187,15 +190,15 @@ func walkrange(n *Node) *Node { ...@@ -187,15 +190,15 @@ func walkrange(n *Node) *Node {
// orderstmt arranged for a copy of the array/slice variable if needed. // orderstmt arranged for a copy of the array/slice variable if needed.
ha := a ha := a
hv1 := temp(Types[TINT]) hv1 := temp(types.Types[TINT])
hn := temp(Types[TINT]) hn := temp(types.Types[TINT])
var hp *Node var hp *Node
init = append(init, nod(OAS, hv1, nil)) init = append(init, nod(OAS, hv1, nil))
init = append(init, nod(OAS, hn, nod(OLEN, ha, nil))) init = append(init, nod(OAS, hn, nod(OLEN, ha, nil)))
if v2 != nil { if v2 != nil {
hp = temp(typPtr(n.Type.Elem())) hp = temp(types.NewPtr(n.Type.Elem()))
tmp := nod(OINDEX, ha, nodintconst(0)) tmp := nod(OINDEX, ha, nodintconst(0))
tmp.SetBounded(true) tmp.SetBounded(true)
init = append(init, nod(OAS, hp, nod(OADDR, tmp, nil))) init = append(init, nod(OAS, hp, nod(OADDR, tmp, nil)))
...@@ -229,7 +232,7 @@ func walkrange(n *Node) *Node { ...@@ -229,7 +232,7 @@ func walkrange(n *Node) *Node {
tmp.Type = hp.Type tmp.Type = hp.Type
tmp.Typecheck = 1 tmp.Typecheck = 1
tmp.Right.Type = Types[Tptr] tmp.Right.Type = types.Types[types.Tptr]
tmp.Right.Typecheck = 1 tmp.Right.Typecheck = 1
a = nod(OAS, hp, tmp) a = nod(OAS, hp, tmp)
a = typecheck(a, Etop) a = typecheck(a, Etop)
...@@ -281,10 +284,10 @@ func walkrange(n *Node) *Node { ...@@ -281,10 +284,10 @@ func walkrange(n *Node) *Node {
hv1 := temp(t.Elem()) hv1 := temp(t.Elem())
hv1.Typecheck = 1 hv1.Typecheck = 1
if haspointers(t.Elem()) { if types.Haspointers(t.Elem()) {
init = append(init, nod(OAS, hv1, nil)) init = append(init, nod(OAS, hv1, nil))
} }
hb := temp(Types[TBOOL]) hb := temp(types.Types[TBOOL])
n.Left = nod(ONE, hb, nodbool(false)) n.Left = nod(ONE, hb, nodbool(false))
a := nod(OAS2RECV, nil, nil) a := nod(OAS2RECV, nil, nil)
...@@ -321,9 +324,9 @@ func walkrange(n *Node) *Node { ...@@ -321,9 +324,9 @@ func walkrange(n *Node) *Node {
// orderstmt arranged for a copy of the string variable. // orderstmt arranged for a copy of the string variable.
ha := a ha := a
hv1 := temp(Types[TINT]) hv1 := temp(types.Types[TINT])
hv1t := temp(Types[TINT]) hv1t := temp(types.Types[TINT])
hv2 := temp(runetype) hv2 := temp(types.Runetype)
// hv1 := 0 // hv1 := 0
init = append(init, nod(OAS, hv1, nil)) init = append(init, nod(OAS, hv1, nil))
...@@ -339,7 +342,7 @@ func walkrange(n *Node) *Node { ...@@ -339,7 +342,7 @@ func walkrange(n *Node) *Node {
// hv2 := rune(ha[hv1]) // hv2 := rune(ha[hv1])
nind := nod(OINDEX, ha, hv1) nind := nod(OINDEX, ha, hv1)
nind.SetBounded(true) nind.SetBounded(true)
body = append(body, nod(OAS, hv2, conv(nind, runetype))) body = append(body, nod(OAS, hv2, conv(nind, types.Runetype)))
// if hv2 < utf8.RuneSelf // if hv2 < utf8.RuneSelf
nif := nod(OIF, nil, nil) nif := nod(OIF, nil, nil)
...@@ -448,25 +451,25 @@ func memclrrange(n, v1, v2, a *Node) bool { ...@@ -448,25 +451,25 @@ func memclrrange(n, v1, v2, a *Node) bool {
n.Left = nod(ONE, nod(OLEN, a, nil), nodintconst(0)) n.Left = nod(ONE, nod(OLEN, a, nil), nodintconst(0))
// hp = &a[0] // hp = &a[0]
hp := temp(Types[TUNSAFEPTR]) hp := temp(types.Types[TUNSAFEPTR])
tmp := nod(OINDEX, a, nodintconst(0)) tmp := nod(OINDEX, a, nodintconst(0))
tmp.SetBounded(true) tmp.SetBounded(true)
tmp = nod(OADDR, tmp, nil) tmp = nod(OADDR, tmp, nil)
tmp = nod(OCONVNOP, tmp, nil) tmp = nod(OCONVNOP, tmp, nil)
tmp.Type = Types[TUNSAFEPTR] tmp.Type = types.Types[TUNSAFEPTR]
n.Nbody.Append(nod(OAS, hp, tmp)) n.Nbody.Append(nod(OAS, hp, tmp))
// hn = len(a) * sizeof(elem(a)) // hn = len(a) * sizeof(elem(a))
hn := temp(Types[TUINTPTR]) hn := temp(types.Types[TUINTPTR])
tmp = nod(OLEN, a, nil) tmp = nod(OLEN, a, nil)
tmp = nod(OMUL, tmp, nodintconst(elemsize)) tmp = nod(OMUL, tmp, nodintconst(elemsize))
tmp = conv(tmp, Types[TUINTPTR]) tmp = conv(tmp, types.Types[TUINTPTR])
n.Nbody.Append(nod(OAS, hn, tmp)) n.Nbody.Append(nod(OAS, hn, tmp))
var fn *Node var fn *Node
if haspointers(a.Type.Elem()) { if types.Haspointers(a.Type.Elem()) {
// memclrHasPointers(hp, hn) // memclrHasPointers(hp, hn)
fn = mkcall("memclrHasPointers", nil, nil, hp, hn) fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
} else { } else {
......
This diff is collapsed.
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"reflect" "reflect"
"sort" "sort"
"testing" "testing"
...@@ -12,24 +13,24 @@ import ( ...@@ -12,24 +13,24 @@ import (
func TestSortingByMethodNameAndPackagePath(t *testing.T) { func TestSortingByMethodNameAndPackagePath(t *testing.T) {
data := []*Sig{ data := []*Sig{
&Sig{name: "b", pkg: &Pkg{Path: "abc"}}, &Sig{name: "b", pkg: &types.Pkg{Path: "abc"}},
&Sig{name: "b", pkg: nil}, &Sig{name: "b", pkg: nil},
&Sig{name: "c", pkg: nil}, &Sig{name: "c", pkg: nil},
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}}, &Sig{name: "c", pkg: &types.Pkg{Path: "uvw"}},
&Sig{name: "c", pkg: nil}, &Sig{name: "c", pkg: nil},
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}}, &Sig{name: "b", pkg: &types.Pkg{Path: "xyz"}},
&Sig{name: "a", pkg: &Pkg{Path: "abc"}}, &Sig{name: "a", pkg: &types.Pkg{Path: "abc"}},
&Sig{name: "b", pkg: nil}, &Sig{name: "b", pkg: nil},
} }
want := []*Sig{ want := []*Sig{
&Sig{name: "a", pkg: &Pkg{Path: "abc"}}, &Sig{name: "a", pkg: &types.Pkg{Path: "abc"}},
&Sig{name: "b", pkg: nil}, &Sig{name: "b", pkg: nil},
&Sig{name: "b", pkg: nil}, &Sig{name: "b", pkg: nil},
&Sig{name: "b", pkg: &Pkg{Path: "abc"}}, &Sig{name: "b", pkg: &types.Pkg{Path: "abc"}},
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}}, &Sig{name: "b", pkg: &types.Pkg{Path: "xyz"}},
&Sig{name: "c", pkg: nil}, &Sig{name: "c", pkg: nil},
&Sig{name: "c", pkg: nil}, &Sig{name: "c", pkg: nil},
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}}, &Sig{name: "c", pkg: &types.Pkg{Path: "uvw"}},
} }
if len(data) != len(want) { if len(data) != len(want) {
t.Fatal("want and data must match") t.Fatal("want and data must match")
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package gc package gc
import "cmd/compile/internal/types"
// select // select
func typecheckselect(sel *Node) { func typecheckselect(sel *Node) {
var ncase *Node var ncase *Node
...@@ -225,21 +227,21 @@ func walkselect(sel *Node) { ...@@ -225,21 +227,21 @@ func walkselect(sel *Node) {
case OSEND: case OSEND:
// if selectnbsend(c, v) { body } else { default body } // if selectnbsend(c, v) { body } else { default body }
ch := n.Left ch := n.Left
r.Left = mkcall1(chanfn("selectnbsend", 2, ch.Type), Types[TBOOL], &r.Ninit, ch, n.Right) r.Left = mkcall1(chanfn("selectnbsend", 2, ch.Type), types.Types[TBOOL], &r.Ninit, ch, n.Right)
case OSELRECV: case OSELRECV:
// if c != nil && selectnbrecv(&v, c) { body } else { default body } // if c != nil && selectnbrecv(&v, c) { body } else { default body }
r = nod(OIF, nil, nil) r = nod(OIF, nil, nil)
r.Ninit.Set(cas.Ninit.Slice()) r.Ninit.Set(cas.Ninit.Slice())
ch := n.Right.Left ch := n.Right.Left
r.Left = mkcall1(chanfn("selectnbrecv", 2, ch.Type), Types[TBOOL], &r.Ninit, n.Left, ch) r.Left = mkcall1(chanfn("selectnbrecv", 2, ch.Type), types.Types[TBOOL], &r.Ninit, n.Left, ch)
case OSELRECV2: case OSELRECV2:
// if c != nil && selectnbrecv2(&v, c) { body } else { default body } // if c != nil && selectnbrecv2(&v, c) { body } else { default body }
r = nod(OIF, nil, nil) r = nod(OIF, nil, nil)
r.Ninit.Set(cas.Ninit.Slice()) r.Ninit.Set(cas.Ninit.Slice())
ch := n.Right.Left ch := n.Right.Left
r.Left = mkcall1(chanfn("selectnbrecv2", 2, ch.Type), Types[TBOOL], &r.Ninit, n.Left, n.List.First(), ch) r.Left = mkcall1(chanfn("selectnbrecv2", 2, ch.Type), types.Types[TBOOL], &r.Ninit, n.Left, n.List.First(), ch)
} }
r.Left = typecheck(r.Left, Erv) r.Left = typecheck(r.Left, Erv)
...@@ -258,7 +260,7 @@ func walkselect(sel *Node) { ...@@ -258,7 +260,7 @@ func walkselect(sel *Node) {
r = nod(OAS, selv, nil) r = nod(OAS, selv, nil)
r = typecheck(r, Etop) r = typecheck(r, Etop)
init = append(init, r) init = append(init, r)
var_ = conv(conv(nod(OADDR, selv, nil), Types[TUNSAFEPTR]), typPtr(Types[TUINT8])) var_ = conv(conv(nod(OADDR, selv, nil), types.Types[TUNSAFEPTR]), types.NewPtr(types.Types[TUINT8]))
r = mkcall("newselect", nil, nil, var_, nodintconst(selv.Type.Width), nodintconst(sel.Xoffset)) r = mkcall("newselect", nil, nil, var_, nodintconst(selv.Type.Width), nodintconst(sel.Xoffset))
r = typecheck(r, Etop) r = typecheck(r, Etop)
init = append(init, r) init = append(init, r)
...@@ -297,8 +299,8 @@ func walkselect(sel *Node) { ...@@ -297,8 +299,8 @@ func walkselect(sel *Node) {
// run the select // run the select
setlineno(sel) setlineno(sel)
chosen = temp(Types[TINT]) chosen = temp(types.Types[TINT])
r = nod(OAS, chosen, mkcall("selectgo", Types[TINT], nil, var_)) r = nod(OAS, chosen, mkcall("selectgo", types.Types[TINT], nil, var_))
r = typecheck(r, Etop) r = typecheck(r, Etop)
init = append(init, r) init = append(init, r)
...@@ -327,29 +329,29 @@ out: ...@@ -327,29 +329,29 @@ out:
} }
// Keep in sync with src/runtime/select.go. // Keep in sync with src/runtime/select.go.
func selecttype(size int64) *Type { func selecttype(size int64) *types.Type {
// TODO(dvyukov): it's possible to generate Scase only once // TODO(dvyukov): it's possible to generate Scase only once
// and then cache; and also cache Select per size. // and then cache; and also cache Select per size.
scase := tostruct([]*Node{ scase := tostruct([]*Node{
namedfield("elem", typPtr(Types[TUINT8])), namedfield("elem", types.NewPtr(types.Types[TUINT8])),
namedfield("chan", typPtr(Types[TUINT8])), namedfield("chan", types.NewPtr(types.Types[TUINT8])),
namedfield("pc", Types[TUINTPTR]), namedfield("pc", types.Types[TUINTPTR]),
namedfield("kind", Types[TUINT16]), namedfield("kind", types.Types[TUINT16]),
namedfield("receivedp", typPtr(Types[TUINT8])), namedfield("receivedp", types.NewPtr(types.Types[TUINT8])),
namedfield("releasetime", Types[TUINT64]), namedfield("releasetime", types.Types[TUINT64]),
}) })
scase.SetNoalg(true) scase.SetNoalg(true)
scase.SetLocal(true) scase.SetLocal(true)
sel := tostruct([]*Node{ sel := tostruct([]*Node{
namedfield("tcase", Types[TUINT16]), namedfield("tcase", types.Types[TUINT16]),
namedfield("ncase", Types[TUINT16]), namedfield("ncase", types.Types[TUINT16]),
namedfield("pollorder", typPtr(Types[TUINT8])), namedfield("pollorder", types.NewPtr(types.Types[TUINT8])),
namedfield("lockorder", typPtr(Types[TUINT8])), namedfield("lockorder", types.NewPtr(types.Types[TUINT8])),
namedfield("scase", typArray(scase, size)), namedfield("scase", types.NewArray(scase, size)),
namedfield("lockorderarr", typArray(Types[TUINT16], size)), namedfield("lockorderarr", types.NewArray(types.Types[TUINT16], size)),
namedfield("pollorderarr", typArray(Types[TUINT16], size)), namedfield("pollorderarr", types.NewArray(types.Types[TUINT16], size)),
}) })
sel.SetNoalg(true) sel.SetNoalg(true)
sel.SetLocal(true) sel.SetLocal(true)
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
package gc package gc
import "fmt" import (
"cmd/compile/internal/types"
"fmt"
)
// static initialization // static initialization
const ( const (
...@@ -43,7 +46,7 @@ func init1(n *Node, out *[]*Node) { ...@@ -43,7 +46,7 @@ func init1(n *Node, out *[]*Node) {
if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC { if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC {
// Methods called as Type.Method(receiver, ...). // Methods called as Type.Method(receiver, ...).
// Definitions for method expressions are stored in type->nname. // Definitions for method expressions are stored in type->nname.
init1(n.Type.Nname(), out) init1(asNode(n.Type.FuncType().Nname), out)
} }
if n.Op != ONAME { if n.Op != ONAME {
...@@ -214,7 +217,7 @@ func init2(n *Node, out *[]*Node) { ...@@ -214,7 +217,7 @@ func init2(n *Node, out *[]*Node) {
init2list(n.Func.Closure.Nbody, out) init2list(n.Func.Closure.Nbody, out)
} }
if n.Op == ODOTMETH || n.Op == OCALLPART { if n.Op == ODOTMETH || n.Op == OCALLPART {
init2(n.Type.Nname(), out) init2(asNode(n.Type.FuncType().Nname), out)
} }
} }
...@@ -424,7 +427,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { ...@@ -424,7 +427,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
initplan(r) initplan(r)
// Init slice. // Init slice.
bound := r.Right.Int64() bound := r.Right.Int64()
ta := typArray(r.Type.Elem(), bound) ta := types.NewArray(r.Type.Elem(), bound)
a := staticname(ta) a := staticname(ta)
inittemps[r] = a inittemps[r] = a
n := *l n := *l
...@@ -535,7 +538,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { ...@@ -535,7 +538,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
*out = append(*out, nod(OAS, a, val)) *out = append(*out, nod(OAS, a, val))
} }
ptr := nod(OADDR, a, nil) ptr := nod(OADDR, a, nil)
n.Type = typPtr(val.Type) n.Type = types.NewPtr(val.Type)
gdata(&n, ptr, Widthptr) gdata(&n, ptr, Widthptr)
} }
...@@ -574,7 +577,7 @@ var statuniqgen int // name generator for static temps ...@@ -574,7 +577,7 @@ var statuniqgen int // name generator for static temps
// staticname returns a name backed by a static data symbol. // staticname returns a name backed by a static data symbol.
// Callers should call n.Name.SetReadonly(true) on the // Callers should call n.Name.SetReadonly(true) on the
// returned node for readonly nodes. // returned node for readonly nodes.
func staticname(t *Type) *Node { func staticname(t *types.Type) *Node {
// Don't use lookupN; it interns the resulting string, but these are all unique. // Don't use lookupN; it interns the resulting string, but these are all unique.
n := newname(lookup(fmt.Sprintf("statictmp_%d", statuniqgen))) n := newname(lookup(fmt.Sprintf("statictmp_%d", statuniqgen)))
statuniqgen++ statuniqgen++
...@@ -768,7 +771,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes) ...@@ -768,7 +771,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
// make an array type corresponding the number of elements we have // make an array type corresponding the number of elements we have
t := typArray(n.Type.Elem(), n.Right.Int64()) t := types.NewArray(n.Type.Elem(), n.Right.Int64())
dowidth(t) dowidth(t)
if ctxt == inNonInitFunction { if ctxt == inNonInitFunction {
...@@ -786,7 +789,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -786,7 +789,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
} }
var v Node var v Node
nodconst(&v, Types[TINT], t.NumElem()) nodconst(&v, types.Types[TINT], t.NumElem())
nam.Xoffset += int64(array_array) nam.Xoffset += int64(array_array)
gdata(&nam, nod(OADDR, vstat, nil), Widthptr) gdata(&nam, nod(OADDR, vstat, nil), Widthptr)
...@@ -831,7 +834,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -831,7 +834,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
} }
// make new auto *array (3 declare) // make new auto *array (3 declare)
vauto := temp(typPtr(t)) vauto := temp(types.NewPtr(t))
// set auto to point at new temp or heap (3 assign) // set auto to point at new temp or heap (3 assign)
var a *Node var a *Node
...@@ -946,8 +949,8 @@ func maplit(n *Node, m *Node, init *Nodes) { ...@@ -946,8 +949,8 @@ func maplit(n *Node, m *Node, init *Nodes) {
// For a large number of static entries, put them in an array and loop. // For a large number of static entries, put them in an array and loop.
// build types [count]Tindex and [count]Tvalue // build types [count]Tindex and [count]Tvalue
tk := typArray(n.Type.Key(), int64(len(stat))) tk := types.NewArray(n.Type.Key(), int64(len(stat)))
tv := typArray(n.Type.Val(), int64(len(stat))) tv := types.NewArray(n.Type.Val(), int64(len(stat)))
// TODO(josharian): suppress alg generation for these types? // TODO(josharian): suppress alg generation for these types?
dowidth(tk) dowidth(tk)
...@@ -982,7 +985,7 @@ func maplit(n *Node, m *Node, init *Nodes) { ...@@ -982,7 +985,7 @@ func maplit(n *Node, m *Node, init *Nodes) {
// for i = 0; i < len(vstatk); i++ { // for i = 0; i < len(vstatk); i++ {
// map[vstatk[i]] = vstatv[i] // map[vstatk[i]] = vstatv[i]
// } // }
i := temp(Types[TINT]) i := temp(types.Types[TINT])
rhs := nod(OINDEX, vstatv, i) rhs := nod(OINDEX, vstatv, i)
rhs.SetBounded(true) rhs.SetBounded(true)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"reflect" "reflect"
"testing" "testing"
"unsafe" "unsafe"
...@@ -26,20 +27,21 @@ func TestSizeof(t *testing.T) { ...@@ -26,20 +27,21 @@ func TestSizeof(t *testing.T) {
{Name{}, 36, 56}, {Name{}, 36, 56},
{Param{}, 28, 56}, {Param{}, 28, 56},
{Node{}, 84, 136}, {Node{}, 84, 136},
{Sym{}, 60, 104}, // TODO(gri) test the ones below in the types package
{Type{}, 52, 88}, {types.Sym{}, 60, 104},
{MapType{}, 20, 40}, {types.Type{}, 52, 88},
{ForwardType{}, 20, 32}, {types.MapType{}, 20, 40},
{FuncType{}, 28, 48}, {types.ForwardType{}, 20, 32},
{StructType{}, 12, 24}, {types.FuncType{}, 28, 48},
{InterType{}, 4, 8}, {types.StructType{}, 12, 24},
{ChanType{}, 8, 16}, {types.InterType{}, 4, 8},
{ArrayType{}, 12, 16}, {types.ChanType{}, 8, 16},
{DDDFieldType{}, 4, 8}, {types.ArrayType{}, 12, 16},
{FuncArgsType{}, 4, 8}, {types.DDDFieldType{}, 4, 8},
{ChanArgsType{}, 4, 8}, {types.FuncArgsType{}, 4, 8},
{PtrType{}, 4, 8}, {types.ChanArgsType{}, 4, 8},
{SliceType{}, 4, 8}, {types.PtrType{}, 4, 8},
{types.SliceType{}, 4, 8},
} }
for _, tt := range tests { for _, tt := range tests {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file implements convertions between *types.Node and *Node.
// TODO(gri) try to eliminate these soon
package gc
import (
"cmd/compile/internal/types"
"unsafe"
)
func asNode(n *types.Node) *Node { return (*Node)(unsafe.Pointer(n)) }
func asTypesNode(n *Node) *types.Node { return (*types.Node)(unsafe.Pointer(n)) }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -40,6 +40,7 @@ var bootstrapDirs = []string{ ...@@ -40,6 +40,7 @@ var bootstrapDirs = []string{
"cmd/compile/internal/mips", "cmd/compile/internal/mips",
"cmd/compile/internal/mips64", "cmd/compile/internal/mips64",
"cmd/compile/internal/ppc64", "cmd/compile/internal/ppc64",
"cmd/compile/internal/types",
"cmd/compile/internal/s390x", "cmd/compile/internal/s390x",
"cmd/compile/internal/ssa", "cmd/compile/internal/ssa",
"cmd/compile/internal/syntax", "cmd/compile/internal/syntax",
......
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