pkgbits

Imports

Imports #

"bytes"
"crypto/sha256"
"encoding/binary"
"go/constant"
"io"
"math/big"
"runtime"
"strings"
"fmt"
"fmt"
"runtime"
"strings"
"strconv"
"encoding/binary"
"errors"
"fmt"
"go/constant"
"go/token"
"io"
"math/big"
"os"
"runtime"
"strings"

Constants & Variables

AliasTypeParamNames const #

ObjAlias has a list of TypeParamNames.

const AliasTypeParamNames

DerivedFuncInstance const #

Deprecated: DerivedFuncInstance was a bool indicating whether an object was a function instance.

const DerivedFuncInstance

DerivedInfoNeeded const #

Deprecated: DerivedInfoNeeded was a bool indicating whether a type was a derived type.

const DerivedInfoNeeded

Flags const #

Flags in a uint32 in the header of a bitstream that is used to indicate whether optional features are enabled.

const Flags Field = iota

HasInit const #

Deprecated: HasInit was a bool indicating whether a package has any init functions.

const HasInit

ObjAlias const #

const ObjAlias CodeObj = iota

ObjConst const #

const ObjConst

ObjFunc const #

const ObjFunc

ObjStub const #

const ObjStub

ObjType const #

const ObjType

ObjVar const #

const ObjVar

PrivateRootIdx const #

Reserved indices within the meta relocation section.

const PrivateRootIdx Index = 1

PublicRootIdx const #

Reserved indices within the meta relocation section.

const PublicRootIdx Index = 0

RelocBody const #

const RelocBody

RelocMeta const #

const RelocMeta

RelocName const #

const RelocName

RelocObj const #

const RelocObj

RelocObjDict const #

const RelocObjDict

RelocObjExt const #

const RelocObjExt

RelocPkg const #

const RelocPkg

RelocPosBase const #

const RelocPosBase

RelocString const #

const RelocString RelocKind = iota

RelocType const #

const RelocType

SyncAddLocal const #

const SyncAddLocal

SyncAssign const #

const SyncAssign

SyncBlockStmt const #

const SyncBlockStmt

SyncBool const #

const SyncBool

SyncCaseClause const #

const SyncCaseClause

SyncCloseAnotherScope const #

const SyncCloseAnotherScope

SyncCloseScope const #

const SyncCloseScope

SyncCodeObj const #

const SyncCodeObj

SyncCommClause const #

const SyncCommClause

SyncCompLit const #

const SyncCompLit

SyncConvRTTI const #

const SyncConvRTTI

SyncDecl const #

const SyncDecl

SyncDeclName const #

const SyncDeclName

SyncDeclNames const #

const SyncDeclNames

SyncDecls const #

const SyncDecls

SyncEOF const #

Low-level coding markers.

const SyncEOF

SyncExpr const #

const SyncExpr

SyncExprList const #

const SyncExprList

SyncExprType const #

const SyncExprType

SyncExprs const #

const SyncExprs

SyncForStmt const #

const SyncForStmt

SyncFuncBody const #

const SyncFuncBody

SyncFuncExt const #

const SyncFuncExt

SyncFuncLit const #

const SyncFuncLit

SyncIfStmt const #

const SyncIfStmt

SyncInt64 const #

const SyncInt64

SyncLabel const #

const SyncLabel

SyncLabeledStmt const #

const SyncLabeledStmt

SyncLinkname const #

const SyncLinkname

SyncLocalIdent const #

const SyncLocalIdent

SyncMethod const #

const SyncMethod

SyncMultiExpr const #

const SyncMultiExpr

SyncObject const #

const SyncObject

SyncObject1 const #

const SyncObject1

SyncOp const #

const SyncOp

SyncOpenScope const #

const SyncOpenScope

SyncOptLabel const #

const SyncOptLabel

SyncParam const #

const SyncParam

SyncParams const #

const SyncParams

SyncPkg const #

const SyncPkg

SyncPkgDef const #

const SyncPkgDef

SyncPos const #

const SyncPos

SyncPosBase const #

const SyncPosBase

SyncPragma const #

const SyncPragma

SyncPrivate const #

Private markers (only known to cmd/compile).

const SyncPrivate

SyncPublic const #

Higher-level object and type markers.

const SyncPublic

SyncRType const #

const SyncRType

SyncRangeStmt const #

const SyncRangeStmt

SyncReloc const #

const SyncReloc

SyncRelocs const #

const SyncRelocs

SyncSelectStmt const #

const SyncSelectStmt

SyncSelector const #

const SyncSelector

SyncSignature const #

const SyncSignature

SyncStmt1 const #

const SyncStmt1

SyncStmts const #

const SyncStmts

SyncStmtsEnd const #

const SyncStmtsEnd

SyncString const #

const SyncString

SyncSwitchStmt const #

const SyncSwitchStmt

SyncSym const #

const SyncSym

SyncType const #

const SyncType

SyncTypeExt const #

const SyncTypeExt

SyncTypeIdx const #

const SyncTypeIdx

SyncTypeParamNames const #

const SyncTypeParamNames

SyncUint64 const #

const SyncUint64

SyncUseObjLocal const #

const SyncUseObjLocal

SyncUseReloc const #

const SyncUseReloc

SyncVal const #

const SyncVal

SyncValue const #

const SyncValue

SyncVarExt const #

const SyncVarExt

TypeArray const #

const TypeArray

TypeBasic const #

const TypeBasic CodeType = iota

TypeChan const #

const TypeChan

TypeInterface const #

const TypeInterface

TypeMap const #

const TypeMap

TypeNamed const #

const TypeNamed

TypePointer const #

const TypePointer

TypeSignature const #

const TypeSignature

TypeSlice const #

const TypeSlice

TypeStruct const #

const TypeStruct

TypeTypeParam const #

const TypeTypeParam

TypeUnion const #

const TypeUnion

V0 const #

V0: initial prototype. All data that is not assigned a Field is in version V0 and has not been deprecated.

const V0 Version = iota

V1 const #

V1: adds the Flags uint32 word

const V1

V2 const #

V2: removes unused legacy fields and supports type parameters for aliases. - remove the legacy "has init" bool from the public root - remove obj's "derived func instance" bool - add a TypeParamNames field to ObjAlias - remove derived info "needed" bool

const V2

ValBigFloat const #

const ValBigFloat

ValBigInt const #

const ValBigInt

ValBigRat const #

const ValBigRat

ValBool const #

const ValBool CodeVal = iota

ValInt64 const #

const ValInt64

ValString const #

const ValString

_ const #

const _ SyncMarker = iota

_SyncMarker_index var #

var _SyncMarker_index = [...]uint16{...}

_SyncMarker_name const #

const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprExprTypeAssignOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabelMultiExprRTypeConvRTTI"

flagSyncMarkers const #

const flagSyncMarkers = *ast.BinaryExpr

introduced var #

introduced is the version a field was added.

var introduced = [numFields]Version{...}

numFields const #

const numFields = iota

numRelocs const #

const numRelocs = iota

numVersions const #

const numVersions = iota

overflow var #

var overflow = *ast.CallExpr

removed var #

removed is the version a field was removed in or 0 for fields that have not yet been deprecated. (So removed[f]-1 is the last version it is included in.)

var removed = [numFields]Version{...}

Type Aliases

CodeObj type #

A CodeObj distinguishes among go/types.Object encodings.

type CodeObj int

CodeType type #

A CodeType distinguishes among go/types.Type encodings.

type CodeType int

CodeVal type #

A CodeVal distinguishes among go/constant.Value encodings.

type CodeVal int

Field type #

Field denotes a unit of data in the serialized unified IR bitstream. It is conceptually a like field in a structure. We only really need Fields when the data may or may not be present in a stream based on the Version of the bitstream. Unlike much of pkgbits, Fields are not serialized and can change values as needed.

type Field int

Index type #

An Index represents a bitstream element index within a particular section.

type Index int32

RelocKind type #

A RelocKind indicates a particular section within a unified IR export.

type RelocKind int32

SyncMarker type #

SyncMarker is an enum type that represents markers that may be written to export data to ensure the reader and writer stay synchronized.

type SyncMarker int

Version type #

Version indicates a version of a unified IR bitstream. Each Version indicates the addition, removal, or change of new data in the bitstream. These are serialized to disk and the interpretation remains fixed.

type Version uint32

frameVisitor type #

type frameVisitor func(file string, line int, name string, offset uintptr)

Interfaces

Code interface #

A Code is an enum value that can be encoded into bitstreams. Code types are preferable for enum types, because they allow Decoder to detect desyncs.

type Code interface {
Marker() SyncMarker
Value() int
}

Structs

Decoder struct #

A Decoder provides methods for decoding an individual element's bitstream data.

type Decoder struct {
common *PkgDecoder
Relocs []RelocEnt
Data strings.Reader
k RelocKind
Idx Index
}

Encoder struct #

An Encoder provides methods for encoding an individual element's bitstream data.

type Encoder struct {
p *PkgEncoder
Relocs []RelocEnt
RelocMap map[RelocEnt]uint32
Data bytes.Buffer
encodingRelocHeader bool
k RelocKind
Idx Index
}

PkgDecoder struct #

A PkgDecoder provides methods for decoding a package's Unified IR export data.

type PkgDecoder struct {
version Version
sync bool
pkgPath string
elemData string
elemEnds []uint32
elemEndsEnds [numRelocs]uint32
scratchRelocEnt []RelocEnt
}

PkgEncoder struct #

A PkgEncoder provides methods for encoding a package's Unified IR export data.

type PkgEncoder struct {
version Version
elems [numRelocs][]string
stringsIdx map[string]Index
syncFrames int
}

RelocEnt struct #

A relocEnt (relocation entry) is an entry in an element's local reference table. TODO(mdempsky): Rename this too.

type RelocEnt struct {
Kind RelocKind
Idx Index
}

Functions

AbsIdx method #

AbsIdx returns the absolute index for the given (section, index) pair.

func (pr *PkgDecoder) AbsIdx(k RelocKind, idx Index) int

Bool method #

Bool decodes and returns a bool value from the element bitstream.

func (r *Decoder) Bool() bool

Bool method #

Bool encodes and writes a bool value into the element bitstream, and then returns the bool value. For simple, 2-alternative encodings, the idiomatic way to call Bool is something like: if w.Bool(x != 0) { // alternative #1 } else { // alternative #2 } For multi-alternative encodings, use Code instead.

func (w *Encoder) Bool(b bool) bool

Code method #

Code encodes and writes a Code value into the element bitstream.

func (w *Encoder) Code(c Code)

Code method #

Code decodes a Code value from the element bitstream and returns its ordinal value. It's the caller's responsibility to convert the result to an appropriate Code type. TODO(mdempsky): Ideally this method would have signature "Code[T Code] T" instead, but we don't allow generic methods and the compiler can't depend on generics yet anyway.

func (r *Decoder) Code(mark SyncMarker) int

DataIdx method #

DataIdx returns the raw element bitstream for the given (section, index) pair.

func (pr *PkgDecoder) DataIdx(k RelocKind, idx Index) string

DumpTo method #

DumpTo writes the package's encoded data to out0 and returns the package fingerprint.

func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte)

Fingerprint method #

Fingerprint returns the package fingerprint.

func (pr *PkgDecoder) Fingerprint() [8]byte

Flush method #

Flush finalizes the element's bitstream and returns its Index.

func (w *Encoder) Flush() Index

Has method #

Has reports whether field f is present in a bitstream at version v.

func (v Version) Has(f Field) bool

Int method #

Int decodes and returns an int value from the element bitstream.

func (r *Decoder) Int() int

Int method #

Int encodes and writes an int value into the element bitstream.

func (w *Encoder) Int(x int)

Int64 method #

Int64 decodes and returns an int64 value from the element bitstream.

func (r *Decoder) Int64() int64

Int64 method #

Int64 encodes and writes an int64 value into the element bitstream.

func (w *Encoder) Int64(x int64)

Len method #

Len encodes and writes a non-negative int value into the element bitstream.

func (w *Encoder) Len(x int)

Len method #

Len decodes and returns a non-negative int value from the element bitstream.

func (r *Decoder) Len() int

Marker method #

func (c CodeObj) Marker() SyncMarker

Marker method #

func (c CodeVal) Marker() SyncMarker

Marker method #

func (c CodeType) Marker() SyncMarker

NewDecoder method #

NewDecoder returns a Decoder for the given (section, index) pair, and decodes the given SyncMarker from the element bitstream.

func (pr *PkgDecoder) NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder

NewDecoderRaw method #

NewDecoderRaw returns a Decoder for the given (section, index) pair. Most callers should use NewDecoder instead.

func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx Index) Decoder

NewEncoder method #

NewEncoder returns an Encoder for a new element within the given section, and encodes the given SyncMarker as the start of the element bitstream.

func (pw *PkgEncoder) NewEncoder(k RelocKind, marker SyncMarker) Encoder

NewEncoderRaw method #

NewEncoderRaw returns an Encoder for a new element within the given section. Most callers should use NewEncoder instead.

func (pw *PkgEncoder) NewEncoderRaw(k RelocKind) Encoder

NewPkgDecoder function #

NewPkgDecoder returns a PkgDecoder initialized to read the Unified IR export data from input. pkgPath is the package path for the compilation unit that produced the export data.

func NewPkgDecoder(pkgPath string, input string) PkgDecoder

NewPkgEncoder function #

NewPkgEncoder returns an initialized PkgEncoder. syncFrames is the number of caller frames that should be serialized at Sync points. Serializing additional frames results in larger export data files, but can help diagnosing desync errors in higher-level Unified IR reader/writer code. If syncFrames is negative, then sync markers are omitted entirely.

func NewPkgEncoder(version Version, syncFrames int) PkgEncoder

NumElems method #

NumElems returns the number of elements in section k.

func (pr *PkgDecoder) NumElems(k RelocKind) int

PeekObj method #

PeekObj returns the package path, object name, and CodeObj for the specified object index.

func (pr *PkgDecoder) PeekObj(idx Index) (string, string, CodeObj)

PeekPkgPath method #

PeekPkgPath returns the package path for the specified package index.

func (pr *PkgDecoder) PeekPkgPath(idx Index) string

PkgPath method #

PkgPath returns the package path for the package TODO(mdempsky): Remove; unneeded since CL 391014.

func (pr *PkgDecoder) PkgPath() string

Reloc method #

Reloc encodes and writes a relocation for the given (section, index) pair into the element bitstream. Note: Only the index is formally written into the element bitstream, so bitstream decoders must know from context which section an encoded relocation refers to.

func (w *Encoder) Reloc(r RelocKind, idx Index)

Reloc method #

Reloc decodes a relocation of expected section k from the element bitstream and returns an index to the referenced element.

func (r *Decoder) Reloc(k RelocKind) Index

RetireDecoder method #

func (pr *PkgDecoder) RetireDecoder(d *Decoder)

String method #

String encodes and writes a string value into the element bitstream. Internally, strings are deduplicated by adding them to the strings section (if not already present), and then writing a relocation into the element bitstream.

func (w *Encoder) String(s string)

String method #

func (i SyncMarker) String() string

String method #

String decodes and returns a string value from the element bitstream.

func (r *Decoder) String() string

StringIdx method #

StringIdx returns the string value for the given string index.

func (pr *PkgDecoder) StringIdx(idx Index) string

StringIdx method #

StringIdx adds a string value to the strings section, if not already present, and returns its index.

func (pw *PkgEncoder) StringIdx(s string) Index

StringRef method #

StringRef writes a reference to the given index, which must be a previously encoded string value.

func (w *Encoder) StringRef(idx Index)

Strings method #

Strings encodes and writes a variable-length slice of strings into the element bitstream.

func (w *Encoder) Strings(ss []string)

Strings method #

Strings decodes and returns a variable-length slice of strings from the element bitstream.

func (r *Decoder) Strings() []string

Sync method #

Sync decodes a sync marker from the element bitstream and asserts that it matches the expected marker. If EnableSync is false, then Sync is a no-op.

func (r *Decoder) Sync(mWant SyncMarker)

Sync method #

func (w *Encoder) Sync(m SyncMarker)

SyncMarkers method #

SyncMarkers reports whether pr uses sync markers.

func (pr *PkgDecoder) SyncMarkers() bool

SyncMarkers method #

SyncMarkers reports whether pw uses sync markers.

func (pw *PkgEncoder) SyncMarkers() bool

TempDecoder method #

TempDecoder returns a Decoder for the given (section, index) pair, and decodes the given SyncMarker from the element bitstream. If possible the Decoder should be RetireDecoder'd when it is no longer needed, this will avoid heap allocations.

func (pr *PkgDecoder) TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder

TempDecoderRaw method #

func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx Index) Decoder

TotalElems method #

TotalElems returns the total number of elements across all sections.

func (pr *PkgDecoder) TotalElems() int

Uint method #

Uint encodes and writes a uint value into the element bitstream.

func (w *Encoder) Uint(x uint)

Uint method #

Uint decodes and returns a uint value from the element bitstream.

func (r *Decoder) Uint() uint

Uint64 method #

Uint64 encodes and writes a uint64 value into the element bitstream.

func (w *Encoder) Uint64(x uint64)

Uint64 method #

Uint64 decodes and returns a uint64 value from the element bitstream.

func (r *Decoder) Uint64() uint64

Value method #

Value decodes and returns a constant.Value from the element bitstream.

func (r *Decoder) Value() constant.Value

Value method #

Value encodes and writes a constant.Value into the element bitstream.

func (w *Encoder) Value(val constant.Value)

Value method #

func (c CodeObj) Value() int

Value method #

func (c CodeType) Value() int

Value method #

func (c CodeVal) Value() int

Version method #

Version reports the version of the bitstream.

func (w *Decoder) Version() Version

Version method #

Version reports the version of the bitstream.

func (w *Encoder) Version() Version

_ function #

func _()

assert function #

func assert(b bool)

bigFloat method #

func (r *Decoder) bigFloat() *big.Float

bigFloat method #

func (w *Encoder) bigFloat(v *big.Float)

bigInt method #

func (r *Decoder) bigInt() *big.Int

bigInt method #

func (w *Encoder) bigInt(v *big.Int)

checkErr method #

func (r *Decoder) checkErr(err error)

checkErr method #

func (w *Encoder) checkErr(err error)

fmtFrames function #

fmtFrames formats a backtrace for reporting reader/writer desyncs.

func fmtFrames(pcs ...uintptr) []string

panicf function #

func panicf(format string, args ...any)

rawReloc method #

func (w *Encoder) rawReloc(r RelocKind, idx Index) int

rawReloc method #

func (r *Decoder) rawReloc(k RelocKind, idx int) Index

rawUvarint method #

func (r *Decoder) rawUvarint() uint64

rawUvarint method #

func (w *Encoder) rawUvarint(x uint64)

rawVarint method #

func (r *Decoder) rawVarint() int64

rawVarint method #

func (w *Encoder) rawVarint(x int64)

readUvarint function #

readUvarint is a type-specialized copy of encoding/binary.ReadUvarint. This avoids the interface conversion and thus has better escape properties, which flows up the stack.

func readUvarint(r *strings.Reader) (uint64, error)

scalar method #

func (w *Encoder) scalar(val constant.Value)

scalar method #

func (r *Decoder) scalar() constant.Value

walkFrames function #

walkFrames calls visit for each call frame represented by pcs. pcs should be a slice of PCs, as returned by runtime.Callers.

func walkFrames(pcs []uintptr, visit frameVisitor)

Generated with Arrow