Skip to content

Commit fdaf57d

Browse files
committed
[RISCV-LLDB] RISCV feature attribute support and allows overriding additional(default) feature #147990
Addressed review comments.
1 parent 62c98e5 commit fdaf57d

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,31 +1449,28 @@ bool DisassemblerLLVMC::MCDisasmInstance::IsAuthenticated(
14491449
void DisassemblerLLVMC::UpdateFeatureString(llvm::StringRef additional_features,
14501450
std::string &features) {
14511451
// Allow users to override default additional features.
1452-
size_t start = 0, end;
1453-
while (!additional_features.empty() && start < additional_features.size()) {
1454-
end = additional_features.find(',', start);
1455-
if (end == llvm::StringRef::npos) {
1456-
end = additional_features.size();
1452+
for (llvm::StringRef flag : llvm::split(additional_features, ",")) {
1453+
flag = flag.trim();
1454+
if (flag.empty()) {
1455+
continue;
14571456
}
1458-
llvm::StringRef flag =
1459-
additional_features.substr(start, end - start).trim();
1460-
if (!flag.empty()) {
1461-
if (flag.starts_with('+')) {
1462-
std::string dissable_flag = "-" + flag.substr(1).str();
1463-
if (features.find(dissable_flag) == std::string::npos) {
1464-
if (flag.back() != ',') {
1465-
features = ',' + features;
1466-
}
1467-
features = flag.str() + features;
1468-
}
1469-
} else {
1470-
if (flag.back() != ',') {
1457+
// Check if disable (-c) is already present before adding default enable
1458+
// (+c), since enable (+c) takes precedence whether disable (-c) appears
1459+
// before or after in the feature string.
1460+
if (flag.starts_with('+')) {
1461+
std::string disable_flag = "-" + flag.substr(1).str();
1462+
if (features.find(disable_flag) == std::string::npos) {
1463+
if (!features.empty() && flag.back() != ',') {
14711464
features = ',' + features;
14721465
}
14731466
features = flag.str() + features;
14741467
}
1468+
} else {
1469+
if (flag.back() != ',') {
1470+
features = ',' + features;
1471+
}
1472+
features = flag.str() + features;
14751473
}
1476-
start = end + 1;
14771474
}
14781475
}
14791476

@@ -1628,8 +1625,7 @@ DisassemblerLLVMC::DisassemblerLLVMC(const ArchSpec &arch,
16281625
arch.GetAdditionalDisassemblyFeatureStr().data();
16291626
// Prepend the additional_features if it's not already in the features_str to
16301627
// avoid duplicates.
1631-
if (additional_features &&
1632-
features_str.find(additional_features) == std::string::npos) {
1628+
if (additional_features) {
16331629
UpdateFeatureString(additional_features, features_str);
16341630
}
16351631

0 commit comments

Comments
 (0)