// AbsIdx returns the absolute index for the given (section, index)
// pair.
-func (pr *PkgDecoder) AbsIdx(k RelocKind, idx Index) int {
+func (pr *PkgDecoder) AbsIdx(k RelocKind, idx RelIndex) int {
absIdx := int(idx)
if k > 0 {
absIdx += int(pr.elemEndsEnds[k-1])
// DataIdx returns the raw element bitstream for the given (section,
// index) pair.
-func (pr *PkgDecoder) DataIdx(k RelocKind, idx Index) string {
+func (pr *PkgDecoder) DataIdx(k RelocKind, idx RelIndex) string {
absIdx := pr.AbsIdx(k, idx)
var start uint32
}
// StringIdx returns the string value for the given string index.
-func (pr *PkgDecoder) StringIdx(idx Index) string {
+func (pr *PkgDecoder) StringIdx(idx RelIndex) string {
return pr.DataIdx(RelocString, idx)
}
// 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 {
+func (pr *PkgDecoder) NewDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.NewDecoderRaw(k, idx)
r.Sync(marker)
return r
// 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 {
+func (pr *PkgDecoder) TempDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.TempDecoderRaw(k, idx)
r.Sync(marker)
return r
// 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 {
+func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
r.Relocs = make([]RelocEnt, r.Len())
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), Index(r.Len())}
+ r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
}
return r
}
-func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx Index) Decoder {
+func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
}
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), Index(r.Len())}
+ r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
}
return r
Data strings.Reader
k RelocKind
- Idx Index
+ Idx RelIndex
}
func (r *Decoder) checkErr(err error) {
return x
}
-func (r *Decoder) rawReloc(k RelocKind, idx int) Index {
+func (r *Decoder) rawReloc(k RelocKind, idx int) RelIndex {
e := r.Relocs[idx]
assert(e.Kind == k)
return e.Idx
// 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 {
+func (r *Decoder) Reloc(k RelocKind) RelIndex {
r.Sync(SyncUseReloc)
return r.rawReloc(k, r.Len())
}
// PeekPkgPath returns the package path for the specified package
// index.
-func (pr *PkgDecoder) PeekPkgPath(idx Index) string {
+func (pr *PkgDecoder) PeekPkgPath(idx RelIndex) string {
var path string
{
r := pr.TempDecoder(RelocPkg, idx, SyncPkgDef)
// PeekObj returns the package path, object name, and CodeObj for the
// specified object index.
-func (pr *PkgDecoder) PeekObj(idx Index) (string, string, CodeObj) {
- var ridx Index
+func (pr *PkgDecoder) PeekObj(idx RelIndex) (string, string, CodeObj) {
+ var ridx RelIndex
var name string
var rcode int
{
// stringsIdx maps previously encoded strings to their index within
// the RelocString section, to allow deduplication. That is,
// elems[RelocString][stringsIdx[s]] == s (if present).
- stringsIdx map[string]Index
+ stringsIdx map[string]RelIndex
// syncFrames is the number of frames to write at each sync
// marker. A negative value means sync markers are omitted.
func NewPkgEncoder(version Version, syncFrames int) PkgEncoder {
return PkgEncoder{
version: version,
- stringsIdx: make(map[string]Index),
+ stringsIdx: make(map[string]RelIndex),
syncFrames: syncFrames,
}
}
// StringIdx adds a string value to the strings section, if not
// already present, and returns its index.
-func (pw *PkgEncoder) StringIdx(s string) Index {
+func (pw *PkgEncoder) StringIdx(s string) RelIndex {
if idx, ok := pw.stringsIdx[s]; ok {
assert(pw.elems[RelocString][idx] == s)
return idx
}
- idx := Index(len(pw.elems[RelocString]))
+ idx := RelIndex(len(pw.elems[RelocString]))
pw.elems[RelocString] = append(pw.elems[RelocString], s)
pw.stringsIdx[s] = idx
return idx
//
// Most callers should use NewEncoder instead.
func (pw *PkgEncoder) NewEncoderRaw(k RelocKind) Encoder {
- idx := Index(len(pw.elems[k]))
+ idx := RelIndex(len(pw.elems[k]))
pw.elems[k] = append(pw.elems[k], "") // placeholder
return Encoder{
encodingRelocHeader bool
k RelocKind
- Idx Index // index within relocation section
+ Idx RelIndex // index within relocation section
}
-// Flush finalizes the element's bitstream and returns its Index.
-func (w *Encoder) Flush() Index {
+// Flush finalizes the element's bitstream and returns its [RelIndex].
+func (w *Encoder) Flush() RelIndex {
var sb strings.Builder
// Backup the data so we write the relocations at the front.
w.rawUvarint(ux)
}
-func (w *Encoder) rawReloc(r RelocKind, idx Index) int {
+func (w *Encoder) rawReloc(r RelocKind, idx RelIndex) int {
e := RelocEnt{r, idx}
if w.RelocMap != nil {
if i, ok := w.RelocMap[e]; ok {
// 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) {
+func (w *Encoder) Reloc(r RelocKind, idx RelIndex) {
w.Sync(SyncUseReloc)
w.Len(w.rawReloc(r, idx))
}
// StringRef writes a reference to the given index, which must be a
// previously encoded string value.
-func (w *Encoder) StringRef(idx Index) {
+func (w *Encoder) StringRef(idx RelIndex) {
w.Sync(SyncString)
w.Reloc(RelocString, idx)
}