Skip to content

Commit 5c1f441

Browse files
authored
[RISCV] Simplify PrintExtension. NFC (#75427)
Instead of using a format string that needs to be parsed, we can use left_justify to print each string with padding.
1 parent 2c668fd commit 5c1f441

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ static void verifyTables() {
215215
#endif
216216
}
217217

218-
static void PrintExtension(const std::string Name, const std::string Version,
219-
const std::string Description) {
220-
outs() << " "
221-
<< format(Description.empty() ? "%-20s%s\n" : "%-20s%-10s%s\n",
222-
Name.c_str(), Version.c_str(), Description.c_str());
218+
static void PrintExtension(StringRef Name, StringRef Version,
219+
StringRef Description) {
220+
outs().indent(4);
221+
unsigned VersionWidth = Description.empty() ? 0 : 10;
222+
outs() << left_justify(Name, 20) << left_justify(Version, VersionWidth)
223+
<< Description << "\n";
223224
}
224225

225226
void llvm::riscvExtensionsHelp(StringMap<StringRef> DescMap) {
@@ -233,7 +234,7 @@ void llvm::riscvExtensionsHelp(StringMap<StringRef> DescMap) {
233234
for (const auto &E : ExtMap) {
234235
std::string Version = std::to_string(E.second.MajorVersion) + "." +
235236
std::to_string(E.second.MinorVersion);
236-
PrintExtension(E.first, Version, DescMap[E.first].str());
237+
PrintExtension(E.first, Version, DescMap[E.first]);
237238
}
238239

239240
outs() << "\nExperimental extensions\n";
@@ -243,7 +244,7 @@ void llvm::riscvExtensionsHelp(StringMap<StringRef> DescMap) {
243244
for (const auto &E : ExtMap) {
244245
std::string Version = std::to_string(E.second.MajorVersion) + "." +
245246
std::to_string(E.second.MinorVersion);
246-
PrintExtension(E.first, Version, DescMap["experimental-" + E.first].str());
247+
PrintExtension(E.first, Version, DescMap["experimental-" + E.first]);
247248
}
248249

249250
outs() << "\nUse -march to specify the target's extension.\n"

0 commit comments

Comments
 (0)