35 int64_t LineDelta,
uint64_t AddrDelta,
37 if (LineDelta < MinLineDelta)
39 if (LineDelta > MaxLineDelta)
41 int64_t LineRange = MaxLineDelta - MinLineDelta + 1;
42 int64_t AdjustedOp = ((LineDelta - MinLineDelta) + AddrDelta * LineRange);
128 "attempted to encode invalid LineTable object");
132 std::vector<DeltaInfo> DeltaInfos;
133 if (Lines.size() == 1) {
137 int64_t PrevLine = 1;
139 for (
const auto &line_entry : Lines) {
143 int64_t LineDelta = (int64_t)line_entry.Line - PrevLine;
144 auto End = DeltaInfos.end();
145 auto Pos = std::lower_bound(DeltaInfos.begin(), End, LineDelta);
146 if (Pos != End && Pos->Delta == LineDelta)
149 DeltaInfos.insert(Pos,
DeltaInfo(LineDelta, 1));
150 if (LineDelta < MinLineDelta)
151 MinLineDelta = LineDelta;
152 if (LineDelta > MaxLineDelta)
153 MaxLineDelta = LineDelta;
155 PrevLine = (int64_t)line_entry.Line;
157 assert(MinLineDelta <= MaxLineDelta);
161 const int64_t MaxLineRange = 14;
162 if (MaxLineDelta - MinLineDelta > MaxLineRange) {
166 const size_t NumDeltaInfos = DeltaInfos.size();
168 const int64_t FirstDelta = DeltaInfos[
I].Delta;
171 for (J =
I; J < NumDeltaInfos; ++J) {
172 auto LineRange = DeltaInfos[J].Delta - FirstDelta;
173 if (LineRange > MaxLineRange)
175 CurrCount += DeltaInfos[J].Count;
177 if (CurrCount > BestCount) {
179 BestEndIndex = J - 1;
180 BestCount = CurrCount;
183 MinLineDelta = DeltaInfos[BestIndex].Delta;
184 MaxLineDelta = DeltaInfos[BestEndIndex].Delta;
186 if (MinLineDelta == MaxLineDelta && MinLineDelta > 0 &&
187 MinLineDelta < MaxLineRange)
189 assert(MinLineDelta <= MaxLineDelta);
193 LineEntry Prev(BaseAddr, 1, Lines.front().Line);
196 Out.writeSLEB(MinLineDelta);
197 Out.writeSLEB(MaxLineDelta);
199 Out.writeULEB(Prev.
Line);
201 for (
const auto &Curr : Lines) {
202 if (Curr.Addr < BaseAddr)
204 "LineEntry has address 0x%" PRIx64
" which is "
205 "less than the function start address 0x%"
206 PRIx64, Curr.Addr, BaseAddr);
207 if (Curr.Addr < Prev.
Addr)
209 "LineEntry in LineTable not in ascending order");
210 const uint64_t AddrDelta = Curr.Addr - Prev.
Addr;
211 int64_t LineDelta = 0;
212 if (Curr.Line > Prev.
Line)
213 LineDelta = Curr.Line - Prev.
Line;
214 else if (Prev.
Line > Curr.Line)
215 LineDelta = -((int32_t)(Prev.
Line - Curr.Line));
218 if (Curr.File != Prev.
File) {
220 Out.writeULEB(Curr.File);
224 if (
encodeSpecial(MinLineDelta, MaxLineDelta, LineDelta, AddrDelta,
227 Out.writeU8(SpecialOp);
233 if (LineDelta != 0) {
235 Out.writeSLEB(LineDelta);
240 Out.writeULEB(AddrDelta);
static bool encodeSpecial(int64_t MinLineDelta, int64_t MaxLineDelta, int64_t LineDelta, uint64_t AddrDelta, uint8_t &SpecialOp)
Line entries are used to encode the line tables in FunctionInfo objects.
uint32_t File
1 based index of file in FileTable
uint64_t Addr
Start address of this line entry.