Imports #
"bytes"
"fmt"
"io"
"bytes"
"fmt"
"io"
FileSymPrefix is the linker symbol prefix that used to be used for linker pseudo-symbols representing file names.
const FileSymPrefix = "gofile.."NoPos is a valid unknown position.
var NoPos PosNoXPos is a valid unknown position.
var NoXPos XPosconst PosDefaultLogue PosXlogue = iotaIt is expected that the front end or a phase in SSA will usually generate positions tagged with PosDefaultStmt, but note statement boundaries with PosIsStmt. Simple statements will have a single boundary; for loops with initialization may have one for their entry and one for their back edge (this depends on exactly how the loop is compiled; the intent is to provide a good experience to a user debugging a program; the goal is that a breakpoint set on the loop line fires both on entry and on iteration). Proper treatment of non-gofmt input with multiple simple statements on a single line is TBD. Optimizing compilation will move instructions around, and some of these will become known-bad as step targets for debugging purposes (examples: register spills and reloads; code generated into the entry block; invariant code hoisted out of loops) but those instructions will still have interesting positions for profiling purposes. To reflect this these positions will be changed to PosNotStmt. When the optimizer removes an instruction marked PosIsStmt; it should attempt to find a nearby instruction with the same line marked PosDefaultStmt to be the new statement boundary. I.e., the optimizer should make a best-effort to conserve statement boundary positions, and might be enhanced to note when a statement boundary is not conserved. Code cloning, e.g. loop unrolling or loop unswitching, is an exception to the conservation rule because a user running a debugger would expect to see breakpoints active in the copies of the code. In non-optimizing compilation there is still a role for PosNotStmt because of code generation into the entry block. PosIsStmt statement positions should be conserved. When code generation occurs any remaining default-marked positions are replaced with not-statement positions.
const PosDefaultStmt uint = iotaconst PosEpilogueBeginconst PosIsStmtconst PosNotStmtconst PosPrologueEndLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const bogusLine = 1Layout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const colBits = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const colMax = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const colShift = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const isStmtBits = 2Layout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const isStmtMask = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const isStmtMax = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const isStmtShift = 0Layout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const lineBits = 20Layout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const lineMax = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const lineShift = *ast.BinaryExprvar noPos PosLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const xlogueBits = 2Layout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const xlogueMask = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const xlogueMax = *ast.BinaryExprLayout constants: 20 bits for line, 8 bits for column, 2 for isStmt, 2 for pro/epilogue (If this is too tight, we can either make lico 64b wide, or we can introduce a tiered encoding where we remove column information as line numbers grow bigger; similar to what gcc does.) The bitfield order is chosen to make IsStmt be the least significant part of a position; its use is to communicate statement edges through instruction scrambling in code generation, not to impose an order. TODO: Prologue and epilogue are perhaps better handled as pseudo-ops for the assembler, because they have almost no interaction with other uses of the position.
const xlogueShift = *ast.BinaryExprtype PosXlogue uintA lico is a compact encoding of a LIne and COlumn number.
type lico uint32A Pos encodes a source position consisting of a (line, column) number pair and a position base. A zero Pos is a ready to use "unknown" position (nil position base and zero line number). The (line, column) values refer to a position in a file independent of any position base ("absolute" file position). The position base is used to determine the "relative" position, that is the filename and line number relative to the position base. If the base refers to the current file, there is no difference between absolute and relative positions. If it refers to a //line directive, a relative position is relative to that directive. A position base in turn contains the position at which it was introduced in the current file.
type Pos struct {
base *PosBase
lico
}A PosBase encodes a filename and base position. Typically, each file and line directive introduce a PosBase.
type PosBase struct {
pos Pos
filename string
absFilename string
line uint
col uint
inl int
fileIndex int
}A PosTable tracks Pos -> XPos conversions and vice versa. Its zero value is a ready-to-use PosTable.
type PosTable struct {
baseList []*PosBase
indexMap map[*PosBase]int
nameMap map[string]int
}XPos is a more compact representation of Pos.
type XPos struct {
index int32
lico
}AbsFilename returns the absolute filename recorded with the base. If b == nil, the result is the empty string.
func (b *PosBase) AbsFilename() stringAbsFilename() returns the absolute filename recorded with the position's base.
func (p Pos) AbsFilename() stringAfter reports whether the position p comes after q in the source. For positions with different bases, ordering is by base index.
func (p XPos) After(q XPos) boolAfter reports whether the position p comes after q in the source. For positions in different files, ordering is by filename.
func (p Pos) After(q Pos) boolAtColumn1 returns the same location but shifted to column 1.
func (p XPos) AtColumn1() XPosBase returns the position base.
func (p Pos) Base() *PosBaseBefore reports whether the position p comes before q in the source. For positions with different bases, ordering is by base index.
func (p XPos) Before(q XPos) boolBefore reports whether the position p comes before q in the source. For positions in different files, ordering is by filename.
func (p Pos) Before(q Pos) boolfunc (x lico) Col() uintCol returns the column number recorded with the base. If b == nil, the result is 0.
func (b *PosBase) Col() uintFileIndex returns the index of the base's absolute filename within its PosTable's FileTable. It panics if it hasn't been registered with a PosTable. If b == nil, the result is -1.
func (b *PosBase) FileIndex() intFileIndex returns the file index of the position's base's absolute filename within the PosTable that it was registered.
func (p Pos) FileIndex() intFileIndex returns a smallish non-negative integer corresponding to the file for this source position. Smallish is relative; it can be thousands large, but not millions.
func (p XPos) FileIndex() int32FileTable returns a slice of all files used to build this package.
func (t *PosTable) FileTable() []stringFilename returns the filename recorded with the base. If b == nil, the result is the empty string.
func (b *PosBase) Filename() stringFilename returns the name of the actual file containing this position.
func (p Pos) Filename() stringFormat formats a position as "filename:line" or "filename:line:column", controlled by the showCol flag and if the column is known (!= 0). For positions relative to line directives, the original position is shown as well, as in "filename:line[origfile:origline:origcolumn]" if showOrig is set.
func (p Pos) Format(showCol bool, showOrig bool) stringInliningIndex returns the index into the global inlining tree recorded with the base. If b == nil or the base has not been inlined, the result is < 0.
func (b *PosBase) InliningIndex() intIsKnown reports whether the position p is known. XPos.IsKnown() matches Pos.IsKnown() for corresponding positions.
func (p XPos) IsKnown() boolIsKnown reports whether the position p is known. A position is known if it either has a non-nil position base, or a non-zero line number.
func (p Pos) IsKnown() boolfunc (x lico) IsStmt() uintfunc (x lico) Line() uintLine returns the line number recorded with the base. If b == nil, the result is 0.
func (b *PosBase) Line() uintLineNumber returns a string for the line number, "?" if it is not known.
func (p XPos) LineNumber() stringfunc (p Pos) LineNumber() stringfunc (p XPos) LineNumberHTML() stringfunc (p Pos) LineNumberHTML() stringMakePos creates a new Pos value with the given base, and (file-absolute) line and column.
func MakePos(base *PosBase, line uint, col uint) PosNewFileBase returns a new *PosBase for a file with the given (relative and absolute) filenames.
func NewFileBase(filename string, absFilename string) *PosBaseNewInliningBase returns a copy of the orig PosBase with the given inlining index. If orig == nil, NewInliningBase panics.
func NewInliningBase(orig *PosBase, inlTreeIndex int) *PosBaseNewLinePragmaBase returns a new *PosBase for a line directive of the form //line filename:line:col /*line filename:line:col at position pos.
func NewLinePragmaBase(pos Pos, filename string, absFilename string, line uint, col uint) *PosBasePos returns the position at which base is located. If b == nil, the result is the zero position.
func (b *PosBase) Pos() *PosPos returns the corresponding Pos for the given p. If p cannot be translated via t, the function panics.
func (t *PosTable) Pos(p XPos) PosRelCol returns the column number relative to the position's base.
func (p Pos) RelCol() uintRelFilename returns the filename recorded with the position's base.
func (p Pos) RelFilename() stringRelLine returns the line number relative to the position's base.
func (p Pos) RelLine() uintSameFile reports whether p and q are positions in the same file.
func (p XPos) SameFile(q XPos) boolSameFileAndLine reports whether p and q are positions on the same line in the same file.
func (p XPos) SameFileAndLine(q XPos) boolfunc (x lico) SameLine(y lico) boolSetBase sets the position base.
func (p *Pos) SetBase(base *PosBase)func (p Pos) String() stringWithBogusLine returns a bogus line that won't match any recorded for the source code. Its use is to disrupt the statements within an infinite loop so that the debugger will not itself loop infinitely waiting for the line number to change. gdb chooses not to display the bogus line; delve shows it with a complaint, but the alternative behavior is to hang.
func (p XPos) WithBogusLine() XPosWithDefaultStmt returns the same location with undetermined is_stmt
func (p XPos) WithDefaultStmt() XPosWithIsStmt returns the same location to be marked with DWARF is_stmt=1
func (p XPos) WithIsStmt() XPosWithNotStmt returns the same location to be marked with DWARF is_stmt=0
func (p XPos) WithNotStmt() XPosWithXlogue returns the same location but marked with DWARF function prologue/epilogue
func (p XPos) WithXlogue(x PosXlogue) XPosWriteTo a position to w, formatted as Format does.
func (p Pos) WriteTo(w io.Writer, showCol bool, showOrig bool)XPos returns the corresponding XPos for the given pos, adding pos to t if necessary.
func (t *PosTable) XPos(pos Pos) XPosfunc (x lico) Xlogue() PosXloguefunc (x lico) atColumn1() licofunc (t *PosTable) baseIndex(base *PosBase) int32format formats a (filename, line, col) tuple as "filename:line" (showCol is false or col == 0) or "filename:line:column" (showCol is true and col != 0).
func format(w io.Writer, filename string, line uint, col uint, showCol bool)formatstr wraps format to return a string.
func formatstr(filename string, line uint, col uint, showCol bool) stringfunc (x lico) lineNumber() stringfunc (x lico) lineNumberHTML() stringThis is a not-position that will not be elided. Depending on the debugger (gdb or delve) it may or may not be displayed.
func makeBogusLico() licofunc makeLico(line uint, col uint) licofunc makeLicoRaw(line uint, col uint) licowithDefaultStmt returns a lico for the same location, with default isStmt
func (x lico) withDefaultStmt() licowithIsStmt returns a lico for the same location, tagged as definitely a statement
func (x lico) withIsStmt() licowithNotStmt returns a lico for the same location, but not a statement
func (x lico) withNotStmt() licowithStmt returns a lico for the same location with specified is_stmt attribute
func (x lico) withStmt(stmt uint) licowithXlogue attaches a prologue/epilogue attribute to a lico
func (x lico) withXlogue(xlogue PosXlogue) licoGenerated with Arrow