Add formatter support for dump-sem-ir ranges (#5379)

This prints instructions that are inside the range, and entities that
overlap with the range. Note this can lead to incomplete printing of
entity contents.
This commit is contained in:
Jon Ross-Perkins
2025-04-29 22:18:52 +00:00
committed by GitHub
parent 13da710e94
commit 8eae40646a
6 changed files with 305 additions and 29 deletions
+17
View File
@@ -440,4 +440,21 @@ auto TokenizedBuffer::TokenToDiagnosticLoc(TokenIndex token) const
return converted;
}
auto TokenizedBuffer::OverlapsWithDumpSemIRRange(TokenIndex begin,
TokenIndex inclusive_end) const
-> bool {
if (dump_sem_ir_ranges_.empty()) {
return true;
}
// Ranges are ordered, so we can decide overlap as soon as we find a range
// that ends after `begin`.
for (auto range : dump_sem_ir_ranges_) {
if (range.end > begin) {
return range.begin <= inclusive_end;
}
}
return false;
}
} // namespace Carbon::Lex