@@ -286,11 +286,25 @@ MatchTableRecord MatchTable::JumpTarget(unsigned LabelID) {
286286void MatchTable::emitUse (raw_ostream &OS) const { OS << " MatchTable" << ID; }
287287
288288void MatchTable::emitDeclaration (raw_ostream &OS) const {
289- unsigned Indentation = 4 ;
289+ static constexpr unsigned BaseIndent = 4 ;
290+ unsigned Indentation = 0 ;
290291 OS << " constexpr static uint8_t MatchTable" << ID << " [] = {" ;
291292 LineBreak.emit (OS, true , *this );
292- OS << std::string (Indentation, ' ' );
293293
294+ const unsigned NumColsForIdx = llvm::to_string (CurrentSize).size ();
295+
296+ unsigned CurIndex = 0 ;
297+ const auto BeginLine = [&](){
298+ OS << std::string (BaseIndent, ' ' );
299+ // To keep the /* index */ column consistent, pad
300+ // the string at the start so we can always fit the
301+ // exact number of characters to print the largest possible index.
302+ std::string IdxStr = llvm::to_string (CurIndex);
303+ OS << " /* " << std::string (NumColsForIdx - IdxStr.size (), ' ' ) << IdxStr << " */ " ;
304+ OS << std::string (Indentation, ' ' );
305+ };
306+
307+ BeginLine ();
294308 for (auto I = Contents.begin (), E = Contents.end (); I != E; ++I) {
295309 bool LineBreakIsNext = false ;
296310 const auto &NextI = std::next (I);
@@ -306,11 +320,14 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {
306320
307321 I->emit (OS, LineBreakIsNext, *this );
308322 if (I->Flags & MatchTableRecord::MTRF_LineBreakFollows)
309- OS << std::string (Indentation, ' ' );
323+ BeginLine ( );
310324
311325 if (I->Flags & MatchTableRecord::MTRF_Outdent)
312326 Indentation -= 2 ;
327+
328+ CurIndex += I->size ();
313329 }
330+ assert (CurIndex == CurrentSize);
314331 OS << " }; // Size: " << CurrentSize << " bytes\n " ;
315332}
316333
0 commit comments