mirror of https://github.com/golang/go.git
cmd/compile: factor out code to generate equal func
So next CL can use it for generating equal func during walk compare. Passes toolstash-check. Change-Id: I76545c1d471eb496be352908db1b05feae83fc33 Reviewed-on: https://go-review.googlesource.com/c/go/+/436435 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
32284526c8
commit
ea3054aecc
|
|
@ -342,17 +342,27 @@ func geneq(t *types.Type) *obj.LSym {
|
|||
if len(closure.P) > 0 { // already generated
|
||||
return closure
|
||||
}
|
||||
sym := TypeSymPrefix(".eq", t)
|
||||
|
||||
if base.Flag.LowerR != 0 {
|
||||
fmt.Printf("geneq %v\n", t)
|
||||
}
|
||||
|
||||
fn := eqFunc(t)
|
||||
|
||||
// Generate a closure which points at the function we just generated.
|
||||
objw.SymPtr(closure, 0, fn.Linksym(), 0)
|
||||
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
||||
return closure
|
||||
}
|
||||
|
||||
func eqFunc(t *types.Type) *ir.Func {
|
||||
// Autogenerate code for equality of structs and arrays.
|
||||
|
||||
base.Pos = base.AutogeneratedPos // less confusing than end of input
|
||||
typecheck.DeclContext = ir.PEXTERN
|
||||
|
||||
// func sym(p, q *T) bool
|
||||
sym := TypeSymPrefix(".eq", t)
|
||||
fn := typecheck.DeclFunc(sym, nil,
|
||||
[]*ir.Field{ir.NewField(base.Pos, typecheck.Lookup("p"), types.NewPtr(t)), ir.NewField(base.Pos, typecheck.Lookup("q"), types.NewPtr(t))},
|
||||
[]*ir.Field{ir.NewField(base.Pos, typecheck.Lookup("r"), types.Types[types.TBOOL])},
|
||||
|
|
@ -554,11 +564,7 @@ func geneq(t *types.Type) *obj.LSym {
|
|||
// are shallow.
|
||||
fn.SetNilCheckDisabled(true)
|
||||
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
||||
|
||||
// Generate a closure which points at the function we just generated.
|
||||
objw.SymPtr(closure, 0, fn.Linksym(), 0)
|
||||
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
||||
return closure
|
||||
return fn
|
||||
}
|
||||
|
||||
func anyCall(fn *ir.Func) bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue