mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: add Func type to replace "curfn any"
This adds a modicum of type safety to these APIs, which are otherwise quite confusing to follow. Change-Id: I268a9a1a99a47dcfef6dc1e9e5be13673af3fb85 Reviewed-on: https://go-review.googlesource.com/c/go/+/523396 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
98c26afa8c
commit
ad74bc4a92
4 changed files with 18 additions and 15 deletions
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) (scopes []dwarf.Scope, inlcalls dwarf.InlCalls, startPos src.XPos) {
|
func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn obj.Func) (scopes []dwarf.Scope, inlcalls dwarf.InlCalls) {
|
||||||
fn := curfn.(*ir.Func)
|
fn := curfn.(*ir.Func)
|
||||||
|
|
||||||
if fn.Nname != nil {
|
if fn.Nname != nil {
|
||||||
|
|
@ -128,7 +128,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) (scopes []dwarf
|
||||||
if base.Flag.GenDwarfInl > 0 {
|
if base.Flag.GenDwarfInl > 0 {
|
||||||
inlcalls = assembleInlines(fnsym, dwarfVars)
|
inlcalls = assembleInlines(fnsym, dwarfVars)
|
||||||
}
|
}
|
||||||
return scopes, inlcalls, fn.Pos()
|
return scopes, inlcalls
|
||||||
}
|
}
|
||||||
|
|
||||||
func declPos(decl *ir.Name) src.XPos {
|
func declPos(decl *ir.Name) src.XPos {
|
||||||
|
|
|
||||||
|
|
@ -345,7 +345,7 @@ func (ctxt *Link) fileSymbol(fn *LSym) *LSym {
|
||||||
// populateDWARF fills in the DWARF Debugging Information Entries for
|
// populateDWARF fills in the DWARF Debugging Information Entries for
|
||||||
// TEXT symbol 's'. The various DWARF symbols must already have been
|
// TEXT symbol 's'. The various DWARF symbols must already have been
|
||||||
// initialized in InitTextSym.
|
// initialized in InitTextSym.
|
||||||
func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym) {
|
func (ctxt *Link) populateDWARF(curfn Func, s *LSym) {
|
||||||
myimportpath := ctxt.Pkgpath
|
myimportpath := ctxt.Pkgpath
|
||||||
if myimportpath == "" {
|
if myimportpath == "" {
|
||||||
return
|
return
|
||||||
|
|
@ -358,9 +358,7 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym) {
|
||||||
var scopes []dwarf.Scope
|
var scopes []dwarf.Scope
|
||||||
var inlcalls dwarf.InlCalls
|
var inlcalls dwarf.InlCalls
|
||||||
if ctxt.DebugInfo != nil {
|
if ctxt.DebugInfo != nil {
|
||||||
// Don't need startPos because s.Func().StartLine is populated,
|
scopes, inlcalls = ctxt.DebugInfo(s, info, curfn)
|
||||||
// as s is in this package.
|
|
||||||
scopes, inlcalls, _ = ctxt.DebugInfo(s, info, curfn)
|
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
dwctxt := dwCtxt{ctxt}
|
dwctxt := dwCtxt{ctxt}
|
||||||
|
|
@ -427,7 +425,7 @@ func (ctxt *Link) DwarfGlobal(typename string, varSym *LSym) {
|
||||||
dwarf.PutGlobal(dwCtxt{ctxt}, dieSym, typeSym, varSym, varname)
|
dwarf.PutGlobal(dwCtxt{ctxt}, dieSym, typeSym, varSym, varname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym) {
|
func (ctxt *Link) DwarfAbstractFunc(curfn Func, s *LSym) {
|
||||||
absfn := ctxt.DwFixups.AbsFuncDwarfSym(s)
|
absfn := ctxt.DwFixups.AbsFuncDwarfSym(s)
|
||||||
if absfn.Size != 0 {
|
if absfn.Size != 0 {
|
||||||
ctxt.Diag("internal error: DwarfAbstractFunc double process %v", s)
|
ctxt.Diag("internal error: DwarfAbstractFunc double process %v", s)
|
||||||
|
|
@ -435,8 +433,8 @@ func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym) {
|
||||||
if s.Func() == nil {
|
if s.Func() == nil {
|
||||||
s.NewFuncInfo()
|
s.NewFuncInfo()
|
||||||
}
|
}
|
||||||
scopes, _, startPos := ctxt.DebugInfo(s, absfn, curfn)
|
scopes, _ := ctxt.DebugInfo(s, absfn, curfn)
|
||||||
_, startLine := ctxt.getFileSymbolAndLine(startPos)
|
_, startLine := ctxt.getFileSymbolAndLine(curfn.Pos())
|
||||||
dwctxt := dwCtxt{ctxt}
|
dwctxt := dwCtxt{ctxt}
|
||||||
fnstate := dwarf.FnState{
|
fnstate := dwarf.FnState{
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
|
|
@ -515,8 +513,8 @@ type relFixup struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type fnState struct {
|
type fnState struct {
|
||||||
// precursor function (really *gc.Node)
|
// precursor function
|
||||||
precursor interface{}
|
precursor Func
|
||||||
// abstract function symbol
|
// abstract function symbol
|
||||||
absfn *LSym
|
absfn *LSym
|
||||||
}
|
}
|
||||||
|
|
@ -529,14 +527,14 @@ func NewDwarfFixupTable(ctxt *Link) *DwarfFixupTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ft *DwarfFixupTable) GetPrecursorFunc(s *LSym) interface{} {
|
func (ft *DwarfFixupTable) GetPrecursorFunc(s *LSym) Func {
|
||||||
if fnstate, found := ft.precursor[s]; found {
|
if fnstate, found := ft.precursor[s]; found {
|
||||||
return fnstate.precursor
|
return fnstate.precursor
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ft *DwarfFixupTable) SetPrecursorFunc(s *LSym, fn interface{}) {
|
func (ft *DwarfFixupTable) SetPrecursorFunc(s *LSym, fn Func) {
|
||||||
if _, found := ft.precursor[s]; found {
|
if _, found := ft.precursor[s]; found {
|
||||||
ft.ctxt.Diag("internal error: DwarfFixupTable.SetPrecursorFunc double call on %v", s)
|
ft.ctxt.Diag("internal error: DwarfFixupTable.SetPrecursorFunc double call on %v", s)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1001,6 +1001,11 @@ type RegSpill struct {
|
||||||
Spill, Unspill As
|
Spill, Unspill As
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Func represents a Go function. If non-nil, it must be a *ir.Func.
|
||||||
|
type Func interface {
|
||||||
|
Pos() src.XPos
|
||||||
|
}
|
||||||
|
|
||||||
// Link holds the context for writing object code from a compiler
|
// Link holds the context for writing object code from a compiler
|
||||||
// to be linker input or for reading that input into the linker.
|
// to be linker input or for reading that input into the linker.
|
||||||
type Link struct {
|
type Link struct {
|
||||||
|
|
@ -1030,7 +1035,7 @@ type Link struct {
|
||||||
Imports []goobj.ImportedPkg
|
Imports []goobj.ImportedPkg
|
||||||
DiagFunc func(string, ...interface{})
|
DiagFunc func(string, ...interface{})
|
||||||
DiagFlush func()
|
DiagFlush func()
|
||||||
DebugInfo func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls, src.XPos) // if non-nil, curfn is a *ir.Func
|
DebugInfo func(fn *LSym, info *LSym, curfn Func) ([]dwarf.Scope, dwarf.InlCalls)
|
||||||
GenAbstractFunc func(fn *LSym)
|
GenAbstractFunc func(fn *LSym)
|
||||||
Errors int
|
Errors int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
type Plist struct {
|
type Plist struct {
|
||||||
Firstpc *Prog
|
Firstpc *Prog
|
||||||
Curfn interface{} // holds a *gc.Node, if non-nil
|
Curfn Func
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProgAlloc is a function that allocates Progs.
|
// ProgAlloc is a function that allocates Progs.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue