@@ -174,82 +174,92 @@ void RenderLayer::ApplyToLinearViewObject(
174174 std::vector<LinearDisassemblyLine> finalLines;
175175 Ref<BasicBlock> lastBlock;
176176
177- for ( auto & line: lines )
177+ auto finishBlock = [&]( )
178178 {
179- // Assume we've finished a block when the line's block changes
180- if (line.block != lastBlock)
179+ if (!blockLines.empty ())
181180 {
182- if (!blockLines. empty () )
181+ if (lastBlock )
183182 {
184- if (lastBlock)
183+ // Convert linear lines to disassembly lines for the apply()
184+ // and then convert back for linear view
185+ std::vector<LinearDisassemblyLine> newBlockLines;
186+ std::vector<DisassemblyTextLine> disasmLines;
187+ std::vector<LinearDisassemblyLine> miscLines;
188+
189+ auto processDisasm = [&]()
185190 {
186- // Convert linear lines to disassembly lines for the apply()
187- // and then convert back for linear view
188- std::vector<DisassemblyTextLine> disasmLines;
189- for (auto & blockLine: blockLines)
191+ if (!disasmLines.empty ())
190192 {
191- disasmLines.push_back (blockLine.contents );
193+ ApplyToBlock (lastBlock, disasmLines);
194+ Ref<Function> func = blockLines[0 ].function ;
195+ Ref<BasicBlock> block = blockLines[0 ].block ;
196+ for (auto & blockLine: disasmLines)
197+ {
198+ LinearDisassemblyLine newLine;
199+ newLine.type = CodeDisassemblyLineType;
200+ newLine.function = func;
201+ newLine.block = block;
202+ newLine.contents = blockLine;
203+ newBlockLines.push_back (newLine);
204+ }
205+ disasmLines.clear ();
192206 }
193- ApplyToBlock (lastBlock, disasmLines) ;
207+ } ;
194208
195- Ref<BasicBlock> block = blockLines[0 ].block ;
196- Ref<Function> func = blockLines[0 ].function ;
197- blockLines.clear ();
198- for (auto & blockLine: disasmLines)
209+ auto processMisc = [&]()
210+ {
211+ if (!miscLines.empty ())
199212 {
200- LinearDisassemblyLine newLine ;
201- // todo: losing this information (might not matter)
202- newLine. type = CodeDisassemblyLineType;
203- newLine. block = block;
204- newLine. function = func;
205- newLine. contents = blockLine ;
206- blockLines. push_back (newLine );
213+ ApplyToMiscLinearLines (obj, prev, next, miscLines) ;
214+ std::move (
215+ miscLines. begin (),
216+ miscLines. end (),
217+ std::back_inserter (newBlockLines)
218+ ) ;
219+ miscLines. clear ( );
207220 }
208- }
209- else
221+ };
222+
223+ for (auto & blockLine: blockLines)
210224 {
211- ApplyToMiscLinearLines (obj, prev, next, blockLines);
225+ // Lines in the block get sent to processDisasm, anything else goes
226+ // to processMisc so we preserve line information
227+ if (blockLine.type == CodeDisassemblyLineType)
228+ {
229+ processMisc ();
230+ disasmLines.push_back (blockLine.contents );
231+ }
232+ else
233+ {
234+ processDisasm ();
235+ miscLines.push_back (blockLine);
236+ }
212237 }
238+ // At the end, zero or one of these has lines in it
239+ processMisc ();
240+ processDisasm ();
241+ blockLines = newBlockLines;
213242 }
214- lastBlock = line.block ;
215- std::move (blockLines.begin (), blockLines.end (), std::back_inserter (finalLines));
216- }
217- blockLines.push_back (line);
218- }
219- // And we've finished a block when we're done with every line
220- if (!blockLines.empty ())
221- {
222- if (lastBlock)
223- {
224- // Convert linear lines to disassembly lines for the apply()
225- // and then convert back for linear view
226- std::vector<DisassemblyTextLine> disasmLines;
227- for (auto & blockLine: blockLines)
228- {
229- disasmLines.push_back (blockLine.contents );
230- }
231- ApplyToBlock (lastBlock, disasmLines);
232-
233- Ref<BasicBlock> block = blockLines[0 ].block ;
234- Ref<Function> func = blockLines[0 ].function ;
235- blockLines.clear ();
236- for (auto & blockLine: disasmLines)
243+ else
237244 {
238- LinearDisassemblyLine newLine;
239- // todo: losing this information (might not matter)
240- newLine.type = CodeDisassemblyLineType;
241- newLine.block = block;
242- newLine.function = func;
243- newLine.contents = blockLine;
244- blockLines.push_back (newLine);
245+ ApplyToMiscLinearLines (obj, prev, next, blockLines);
245246 }
246247 }
247- else
248+ std::move (blockLines.begin (), blockLines.end (), std::back_inserter (finalLines));
249+ };
250+
251+ for (auto & line: lines)
252+ {
253+ // Assume we've finished a block when the line's block changes
254+ if (line.block != lastBlock)
248255 {
249- ApplyToMiscLinearLines (obj, prev, next, blockLines );
256+ finishBlock ( );
250257 }
258+ blockLines.push_back (line);
259+ lastBlock = line.block ;
251260 }
252- std::move (blockLines.begin (), blockLines.end (), std::back_inserter (finalLines));
261+ // And we've finished a block when we're done with every line
262+ finishBlock ();
253263
254264 lines = finalLines;
255265}
0 commit comments