github.com/bir3/gocompiler@v0.3.205/src/cmd/internal/obj/line.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package obj 6 7 import ( 8 "github.com/bir3/gocompiler/src/cmd/internal/goobj" 9 "github.com/bir3/gocompiler/src/cmd/internal/src" 10 ) 11 12 // AddImport adds a package to the list of imported packages. 13 func (ctxt *Link) AddImport(pkg string, fingerprint goobj.FingerprintType) { 14 ctxt.Imports = append(ctxt.Imports, goobj.ImportedPkg{Pkg: pkg, Fingerprint: fingerprint}) 15 } 16 17 // getFileSymbolAndLine returns the relative file symbol and relative line 18 // number for a position (i.e., as adjusted by a //line directive). This is the 19 // file/line visible in the final binary (pcfile, pcln, etc). 20 func (ctxt *Link) getFileSymbolAndLine(xpos src.XPos) (f string, l int32) { 21 pos := ctxt.InnermostPos(xpos) 22 if !pos.IsKnown() { 23 pos = src.Pos{} 24 } 25 return pos.SymFilename(), int32(pos.RelLine()) 26 } 27 28 // getFileIndexAndLine returns the relative file index (local to the CU), and 29 // the relative line number for a position (i.e., as adjusted by a //line 30 // directive). This is the file/line visible in the final binary (pcfile, pcln, 31 // etc). 32 func (ctxt *Link) getFileIndexAndLine(xpos src.XPos) (int, int32) { 33 f, l := ctxt.getFileSymbolAndLine(xpos) 34 return ctxt.PosTable.FileIndex(f), l 35 }