Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,28 @@ MatchTableRecord MatchTable::JumpTarget(unsigned LabelID) {
void MatchTable::emitUse(raw_ostream &OS) const { OS << "MatchTable" << ID; }

void MatchTable::emitDeclaration(raw_ostream &OS) const {
unsigned Indentation = 4;
static constexpr unsigned BaseIndent = 4;
unsigned Indentation = 0;
OS << " constexpr static uint8_t MatchTable" << ID << "[] = {";
LineBreak.emit(OS, true, *this);
OS << std::string(Indentation, ' ');

// We want to display the table index of each line in a consistent
// manner. It has to appear as a column on the left side of the table.
// To determine how wide the column needs to be, check how many characters
// we need to fit the largest possible index in the current table.
const unsigned NumColsForIdx = llvm::to_string(CurrentSize).size();

unsigned CurIndex = 0;
const auto BeginLine = [&]() {
OS.indent(BaseIndent);
std::string IdxStr = llvm::to_string(CurIndex);
// Pad the string with spaces to keep the size of the prefix consistent.
OS << " /* ";
OS.indent(NumColsForIdx - IdxStr.size()) << IdxStr << " */ ";
OS.indent(Indentation);
};

BeginLine();
for (auto I = Contents.begin(), E = Contents.end(); I != E; ++I) {
bool LineBreakIsNext = false;
const auto &NextI = std::next(I);
Expand All @@ -306,11 +323,14 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {

I->emit(OS, LineBreakIsNext, *this);
if (I->Flags & MatchTableRecord::MTRF_LineBreakFollows)
OS << std::string(Indentation, ' ');
BeginLine();

if (I->Flags & MatchTableRecord::MTRF_Outdent)
Indentation -= 2;

CurIndex += I->size();
}
assert(CurIndex == CurrentSize);
OS << "}; // Size: " << CurrentSize << " bytes\n";
}

Expand Down