package pkgbits
Import Path
internal/pkgbits (on go.dev)
Dependency Relation
imports 13 packages, and imported by one package
Involved Source Files
codes.go
decoder.go
Package pkgbits implements low-level coding abstractions for
Unified IR's export data format.
At a low-level, a package is a collection of bitstream elements.
Each element has a "kind" and a dense, non-negative index.
Elements can be randomly accessed given their kind and index.
Individual elements are sequences of variable-length values (e.g.,
integers, booleans, strings, go/constant values, cross-references
to other elements). Package pkgbits provides APIs for encoding and
decoding these low-level values, but the details of mapping
higher-level Go constructs into elements is left to higher-level
abstractions.
Elements may cross-reference each other with "relocations." For
example, an element representing a pointer type has a relocation
referring to the element type.
Go constructs may be composed as a constellation of multiple
elements. For example, a declared function may have one element to
describe the object (e.g., its name, type, position), and a
separate element to describe its function body. This allows readers
some flexibility in efficiently seeking or re-reading data (e.g.,
inlining requires re-reading the function body for each inlined
call, without needing to re-read the object-level details).
encoder.go
flags.go
reloc.go
support.go
sync.go
syncmarker_string.go
Package-Level Type Names (total 12)
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.
Marker returns the SyncMarker for the Code's dynamic type.
Value returns the Code's ordinal value.
CodeObj
CodeType
CodeVal
func (*Encoder).Code(c Code)
A CodeObj distinguishes among go/types.Object encodings.
( CodeObj) Marker() SyncMarker
( CodeObj) Value() int
CodeObj : Code
func (*PkgDecoder).PeekObj(idx Index) (string, string, CodeObj)
const ObjAlias
const ObjConst
const ObjFunc
const ObjStub
const ObjType
const ObjVar
A CodeType distinguishes among go/types.Type encodings.
( CodeType) Marker() SyncMarker
( CodeType) Value() int
CodeType : Code
const TypeArray
const TypeBasic
const TypeChan
const TypeInterface
const TypeMap
const TypeNamed
const TypePointer
const TypeSignature
const TypeSlice
const TypeStruct
const TypeTypeParam
const TypeUnion
A CodeVal distinguishes among go/constant.Value encodings.
( CodeVal) Marker() SyncMarker
( CodeVal) Value() int
CodeVal : Code
const ValBigFloat
const ValBigInt
const ValBigRat
const ValBool
const ValInt64
const ValString
A Decoder provides methods for decoding an individual element's
bitstream data.
Data strings.Reader
Idx Index
Relocs []RelocEnt
Bool decodes and returns a bool value from the element bitstream.
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.
Int decodes and returns an int value from the element bitstream.
Int64 decodes and returns an int64 value from the element bitstream.
Len decodes and returns a non-negative int value from the element bitstream.
Reloc decodes a relocation of expected section k from the element
bitstream and returns an index to the referenced element.
String decodes and returns a string value from the element
bitstream.
Strings decodes and returns a variable-length slice of strings from
the element bitstream.
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.
Uint decodes and returns a uint value from the element bitstream.
Int64 decodes and returns a uint64 value from the element bitstream.
Value decodes and returns a constant.Value from the element
bitstream.
*Decoder : expvar.Var
*Decoder : fmt.Stringer
*Decoder : math/rand/v2.Source
func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder
func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder
func (*PkgDecoder).RetireDecoder(d *Decoder)
An Encoder provides methods for encoding an individual element's
bitstream data.
// accumulated element bitstream data
// index within relocation section
RelocMap map[RelocEnt]uint32
Relocs []RelocEnt
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.
Code encodes and writes a Code value into the element bitstream.
Flush finalizes the element's bitstream and returns its Index.
Int encodes and writes an int value into the element bitstream.
Int64 encodes and writes an int64 value into the element bitstream.
Len encodes and writes a non-negative int value into the element bitstream.
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.
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.
StringRef writes a reference to the given index, which must be a
previously encoded string value.
Strings encodes and writes a variable-length slice of strings into
the element bitstream.
(*Encoder) Sync(m SyncMarker)
Len encodes and writes a uint value into the element bitstream.
Uint64 encodes and writes a uint64 value into the element bitstream.
Value encodes and writes a constant.Value into the element
bitstream.
func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder
func (*PkgEncoder).NewEncoderRaw(k RelocKind) Encoder
An Index represents a bitstream element index within a particular
section.
func (*Decoder).Reloc(k RelocKind) Index
func (*Encoder).Flush() Index
func (*PkgEncoder).StringIdx(s string) Index
func (*Encoder).Reloc(r RelocKind, idx Index)
func (*Encoder).StringRef(idx Index)
func (*PkgDecoder).AbsIdx(k RelocKind, idx Index) int
func (*PkgDecoder).DataIdx(k RelocKind, idx Index) string
func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder
func (*PkgDecoder).PeekObj(idx Index) (string, string, CodeObj)
func (*PkgDecoder).PeekPkgPath(idx Index) string
func (*PkgDecoder).StringIdx(idx Index) string
func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder
const PrivateRootIdx
const PublicRootIdx
A PkgDecoder provides methods for decoding a package's Unified IR
export data.
AbsIdx returns the absolute index for the given (section, index)
pair.
DataIdx returns the raw element bitstream for the given (section,
index) pair.
Fingerprint returns the package fingerprint.
NewDecoder returns a Decoder for the given (section, index) pair,
and decodes the given SyncMarker from the element bitstream.
NewDecoderRaw returns a Decoder for the given (section, index) pair.
Most callers should use NewDecoder instead.
NumElems returns the number of elements in section k.
PeekObj returns the package path, object name, and CodeObj for the
specified object index.
PeekPkgPath returns the package path for the specified package
index.
PkgPath returns the package path for the package
TODO(mdempsky): Remove; unneeded since CL 391014.
(*PkgDecoder) RetireDecoder(d *Decoder)
StringIdx returns the string value for the given string index.
SyncMarkers reports whether pr uses sync markers.
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.
(*PkgDecoder) TempDecoderRaw(k RelocKind, idx Index) Decoder
TotalElems returns the total number of elements across all sections.
func NewPkgDecoder(pkgPath, input string) PkgDecoder
A PkgEncoder provides methods for encoding a package's Unified IR
export data.
DumpTo writes the package's encoded data to out0 and returns the
package fingerprint.
NewEncoder returns an Encoder for a new element within the given
section, and encodes the given SyncMarker as the start of the
element bitstream.
NewEncoderRaw returns an Encoder for a new element within the given
section.
Most callers should use NewEncoder instead.
StringIdx adds a string value to the strings section, if not
already present, and returns its index.
SyncMarkers reports whether pw uses sync markers.
func NewPkgEncoder(syncFrames int) PkgEncoder
A relocEnt (relocation entry) is an entry in an element's local
reference table.
TODO(mdempsky): Rename this too.
Idx Index
Kind RelocKind
A RelocKind indicates a particular section within a unified IR export.
func (*Decoder).Reloc(k RelocKind) Index
func (*Encoder).Reloc(r RelocKind, idx Index)
func (*PkgDecoder).AbsIdx(k RelocKind, idx Index) int
func (*PkgDecoder).DataIdx(k RelocKind, idx Index) string
func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder
func (*PkgDecoder).NumElems(k RelocKind) int
func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder
func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder
func (*PkgEncoder).NewEncoderRaw(k RelocKind) Encoder
const RelocBody
const RelocMeta
const RelocName
const RelocObj
const RelocObjDict
const RelocObjExt
const RelocPkg
const RelocPosBase
const RelocString
const RelocType
SyncMarker is an enum type that represents markers that may be
written to export data to ensure the reader and writer stay
synchronized.
( SyncMarker) String() string
SyncMarker : expvar.Var
SyncMarker : fmt.Stringer
func Code.Marker() SyncMarker
func CodeObj.Marker() SyncMarker
func CodeType.Marker() SyncMarker
func CodeVal.Marker() SyncMarker
func (*Decoder).Code(mark SyncMarker) int
func (*Decoder).Sync(mWant SyncMarker)
func (*Encoder).Sync(m SyncMarker)
func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder
func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder
const SyncAddLocal
const SyncAssign
const SyncBlockStmt
const SyncBool
const SyncCaseClause
const SyncCloseAnotherScope
const SyncCloseScope
const SyncCodeObj
const SyncCommClause
const SyncCompLit
const SyncConvRTTI
const SyncDecl
const SyncDeclName
const SyncDeclNames
const SyncDecls
const SyncEOF
const SyncExpr
const SyncExprList
const SyncExprs
const SyncExprType
const SyncForStmt
const SyncFuncBody
const SyncFuncExt
const SyncFuncLit
const SyncIfStmt
const SyncInt64
const SyncLabel
const SyncLabeledStmt
const SyncLinkname
const SyncLocalIdent
const SyncMethod
const SyncMultiExpr
const SyncObject
const SyncObject1
const SyncOp
const SyncOpenScope
const SyncOptLabel
const SyncParam
const SyncParams
const SyncPkg
const SyncPkgDef
const SyncPos
const SyncPosBase
const SyncPragma
const SyncPrivate
const SyncPublic
const SyncRangeStmt
const SyncReloc
const SyncRelocs
const SyncRType
const SyncSelector
const SyncSelectStmt
const SyncSignature
const SyncStmt1
const SyncStmts
const SyncStmtsEnd
const SyncString
const SyncSwitchStmt
const SyncSym
const SyncType
const SyncTypeExt
const SyncTypeIdx
const SyncTypeParamNames
const SyncUint64
const SyncUseObjLocal
const SyncUseReloc
const SyncVal
const SyncValue
const SyncVarExt
Package-Level Functions (total 2)
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.
TODO(mdempsky): Remove pkgPath parameter; unneeded since CL 391014.
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.
Package-Level Constants (total 105)
Reserved indices within the meta relocation section.
Reserved indices within the meta relocation section.
const RelocObjDict RelocKind = 8 const RelocObjExt RelocKind = 7 const RelocPosBase RelocKind = 2 const RelocString RelocKind = 0 const SyncAddLocal SyncMarker = 61 const SyncAssign SyncMarker = 38 const SyncBlockStmt SyncMarker = 50 const SyncBool SyncMarker = 2 const SyncCaseClause SyncMarker = 55 const SyncCloseAnotherScope SyncMarker = 46 const SyncCloseScope SyncMarker = 45 const SyncCodeObj SyncMarker = 25 const SyncCommClause SyncMarker = 56 const SyncCompLit SyncMarker = 41 const SyncConvRTTI SyncMarker = 69 const SyncDecl SyncMarker = 42 const SyncDeclName SyncMarker = 48 const SyncDeclNames SyncMarker = 47 const SyncDecls SyncMarker = 58
Low-level coding markers.
const SyncExpr SyncMarker = 36 const SyncExprList SyncMarker = 34 const SyncExprs SyncMarker = 35 const SyncExprType SyncMarker = 37 const SyncForStmt SyncMarker = 52 const SyncFuncBody SyncMarker = 43 const SyncFuncExt SyncMarker = 30 const SyncFuncLit SyncMarker = 40 const SyncIfStmt SyncMarker = 51 const SyncInt64 SyncMarker = 3 const SyncLabel SyncMarker = 65 const SyncLabeledStmt SyncMarker = 59 const SyncLinkname SyncMarker = 62 const SyncLocalIdent SyncMarker = 27 const SyncMethod SyncMarker = 18 const SyncMultiExpr SyncMarker = 67 const SyncObject SyncMarker = 14 const SyncObject1 SyncMarker = 15 const SyncOp SyncMarker = 39 const SyncOpenScope SyncMarker = 44 const SyncOptLabel SyncMarker = 66 const SyncParam SyncMarker = 24 const SyncParams SyncMarker = 23 const SyncPkg SyncMarker = 16 const SyncPkgDef SyncMarker = 17 const SyncPos SyncMarker = 12 const SyncPosBase SyncMarker = 13 const SyncPragma SyncMarker = 33
Private markers (only known to cmd/compile).
Higher-level object and type markers.
const SyncRangeStmt SyncMarker = 54 const SyncReloc SyncMarker = 9 const SyncRelocs SyncMarker = 8 const SyncRType SyncMarker = 68 const SyncSelector SyncMarker = 28 const SyncSelectStmt SyncMarker = 57 const SyncSignature SyncMarker = 22 const SyncStmt1 SyncMarker = 63 const SyncStmts SyncMarker = 49 const SyncStmtsEnd SyncMarker = 64 const SyncString SyncMarker = 5 const SyncSwitchStmt SyncMarker = 53 const SyncSym SyncMarker = 26 const SyncType SyncMarker = 19 const SyncTypeExt SyncMarker = 32 const SyncTypeIdx SyncMarker = 20 const SyncTypeParamNames SyncMarker = 21 const SyncUint64 SyncMarker = 4 const SyncUseObjLocal SyncMarker = 60 const SyncUseReloc SyncMarker = 10 const SyncVal SyncMarker = 7 const SyncValue SyncMarker = 6 const SyncVarExt SyncMarker = 31 const TypeInterface CodeType = 9 const TypePointer CodeType = 2 const TypeSignature CodeType = 7 const TypeStruct CodeType = 8 const TypeTypeParam CodeType = 11 const ValBigFloat CodeVal = 5
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |