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.
(pkgPath, input string)
| 69 | // IR export data from input. pkgPath is the package path for the |
| 70 | // compilation unit that produced the export data. |
| 71 | func NewPkgDecoder(pkgPath, input string) PkgDecoder { |
| 72 | pr := PkgDecoder{ |
| 73 | pkgPath: pkgPath, |
| 74 | } |
| 75 | |
| 76 | // TODO(mdempsky): Implement direct indexing of input string to |
| 77 | // avoid copying the position information. |
| 78 | |
| 79 | r := strings.NewReader(input) |
| 80 | |
| 81 | var ver uint32 |
| 82 | assert(binary.Read(r, binary.LittleEndian, &ver) == nil) |
| 83 | pr.version = Version(ver) |
| 84 | |
| 85 | if pr.version >= numVersions { |
| 86 | panic(fmt.Errorf("cannot decode %q, export data version %d is greater than maximum supported version %d", pkgPath, pr.version, numVersions-1)) |
| 87 | } |
| 88 | |
| 89 | if pr.version.Has(Flags) { |
| 90 | var flags uint32 |
| 91 | assert(binary.Read(r, binary.LittleEndian, &flags) == nil) |
| 92 | pr.sync = flags&flagSyncMarkers != 0 |
| 93 | } |
| 94 | |
| 95 | assert(binary.Read(r, binary.LittleEndian, pr.elemEndsEnds[:]) == nil) |
| 96 | |
| 97 | pr.elemEnds = make([]uint32, pr.elemEndsEnds[len(pr.elemEndsEnds)-1]) |
| 98 | assert(binary.Read(r, binary.LittleEndian, pr.elemEnds[:]) == nil) |
| 99 | |
| 100 | pos, err := r.Seek(0, io.SeekCurrent) |
| 101 | assert(err == nil) |
| 102 | |
| 103 | pr.elemData = input[pos:] |
| 104 | |
| 105 | const fingerprintSize = 8 |
| 106 | assert(len(pr.elemData)-fingerprintSize == int(pr.elemEnds[len(pr.elemEnds)-1])) |
| 107 | |
| 108 | return pr |
| 109 | } |
| 110 | |
| 111 | // NumElems returns the number of elements in section k. |
| 112 | func (pr *PkgDecoder) NumElems(k RelocKind) int { |