Always use braces with InsertBraces: true in .clang-format

This commit is contained in:
Rangi42
2025-01-27 19:31:35 -05:00
committed by Rangi
parent 25c9f8f383
commit cae31005f8
29 changed files with 1350 additions and 717 deletions

View File

@@ -74,14 +74,17 @@ static void assignSection(Section &section, MemoryLocation const &location) {
static bool isLocationSuitable(
Section const &section, FreeSpace const &freeSpace, MemoryLocation const &location
) {
if (section.isAddressFixed && section.org != location.address)
if (section.isAddressFixed && section.org != location.address) {
return false;
}
if (section.isAlignFixed && ((location.address - section.alignOfs) & section.alignMask))
if (section.isAlignFixed && ((location.address - section.alignOfs) & section.alignMask)) {
return false;
}
if (location.address < freeSpace.address)
if (location.address < freeSpace.address) {
return false;
}
return location.address + section.size <= freeSpace.address + freeSpace.size;
}
@@ -102,16 +105,19 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
if (section.isBankFixed) {
location.bank = section.bank;
} else if (scrambleROMX && section.type == SECTTYPE_ROMX) {
if (curScrambleROM < 1)
if (curScrambleROM < 1) {
curScrambleROM = scrambleROMX;
}
location.bank = curScrambleROM--;
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX) {
if (curScrambleWRAM < 1)
if (curScrambleWRAM < 1) {
curScrambleWRAM = scrambleWRAMX;
}
location.bank = curScrambleWRAM--;
} else if (scrambleSRAM && section.type == SECTTYPE_SRAM) {
if (curScrambleSRAM < 0)
if (curScrambleSRAM < 0) {
curScrambleSRAM = scrambleSRAM;
}
location.bank = curScrambleSRAM--;
} else {
location.bank = typeInfo.firstBank;
@@ -128,18 +134,20 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
// Process locations in that bank
while (spaceIdx < bankMem.size()) {
// If that location is OK, return it
if (isLocationSuitable(section, bankMem[spaceIdx], location))
if (isLocationSuitable(section, bankMem[spaceIdx], location)) {
return spaceIdx;
}
// Go to the next *possible* location
if (section.isAddressFixed) {
// If the address is fixed, there can be only
// one candidate block per bank; if we already
// reached it, give up.
if (location.address < section.org)
if (location.address < section.org) {
location.address = section.org;
else
} else {
break; // Try again in next bank
}
} else if (section.isAlignFixed) {
// Move to next aligned location
// Move back to alignment boundary
@@ -151,15 +159,17 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
} else {
// Any location is fine, so, next free block
spaceIdx++;
if (spaceIdx < bankMem.size())
if (spaceIdx < bankMem.size()) {
location.address = bankMem[spaceIdx].address;
}
}
// If that location is past the current block's end,
// go forwards until that is no longer the case.
while (spaceIdx < bankMem.size()
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size)
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size) {
spaceIdx++;
}
// Try again with the new location/free space combo
}
@@ -171,27 +181,30 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
if (section.isBankFixed) {
return -1;
} else if (scrambleROMX && section.type == SECTTYPE_ROMX && location.bank <= scrambleROMX) {
if (location.bank > typeInfo.firstBank)
if (location.bank > typeInfo.firstBank) {
location.bank--;
else if (scrambleROMX < typeInfo.lastBank)
} else if (scrambleROMX < typeInfo.lastBank) {
location.bank = scrambleROMX + 1;
else
} else {
return -1;
}
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX
&& location.bank <= scrambleWRAMX) {
if (location.bank > typeInfo.firstBank)
if (location.bank > typeInfo.firstBank) {
location.bank--;
else if (scrambleWRAMX < typeInfo.lastBank)
} else if (scrambleWRAMX < typeInfo.lastBank) {
location.bank = scrambleWRAMX + 1;
else
} else {
return -1;
}
} else if (scrambleSRAM && section.type == SECTTYPE_SRAM && location.bank <= scrambleSRAM) {
if (location.bank > typeInfo.firstBank)
if (location.bank > typeInfo.firstBank) {
location.bank--;
else if (scrambleSRAM < typeInfo.lastBank)
} else if (scrambleSRAM < typeInfo.lastBank) {
location.bank = scrambleSRAM + 1;
else
} else {
return -1;
}
} else if (location.bank < typeInfo.lastBank) {
location.bank++;
} else {
@@ -251,9 +264,10 @@ static void placeSection(Section &section) {
} else {
// The amount of free spaces doesn't change: resize!
freeSpace.size -= section.size;
if (noLeftSpace)
if (noLeftSpace) {
// The free space is moved *and* resized
freeSpace.address += section.size;
}
}
return;
}
@@ -262,11 +276,11 @@ static void placeSection(Section &section) {
char where[64];
if (section.isBankFixed && nbbanks(section.type) != 1) {
if (section.isAddressFixed)
if (section.isAddressFixed) {
snprintf(
where, sizeof(where), "at $%02" PRIx32 ":%04" PRIx16, section.bank, section.org
);
else if (section.isAlignFixed)
} else if (section.isAlignFixed) {
snprintf(
where,
sizeof(where),
@@ -274,12 +288,13 @@ static void placeSection(Section &section) {
section.bank,
static_cast<uint16_t>(~section.alignMask)
);
else
} else {
snprintf(where, sizeof(where), "in bank $%02" PRIx32, section.bank);
}
} else {
if (section.isAddressFixed)
if (section.isAddressFixed) {
snprintf(where, sizeof(where), "at address $%04" PRIx16, section.org);
else if (section.isAlignFixed)
} else if (section.isAlignFixed) {
snprintf(
where,
sizeof(where),
@@ -287,20 +302,22 @@ static void placeSection(Section &section) {
static_cast<uint16_t>(~section.alignMask),
section.alignOfs
);
else
} else {
strcpy(where, "anywhere");
}
}
// If a section failed to go to several places, nothing we can report
if (!section.isBankFixed || !section.isAddressFixed)
if (!section.isBankFixed || !section.isAddressFixed) {
errx(
"Unable to place \"%s\" (%s section) %s",
section.name.c_str(),
sectionTypeInfo[section.type].name.c_str(),
where
);
}
// If the section just can't fit the bank, report that
else if (section.org + section.size > endaddr(section.type) + 1)
else if (section.org + section.size > endaddr(section.type) + 1) {
errx(
"Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > "
"$%04x)",
@@ -310,8 +327,9 @@ static void placeSection(Section &section) {
section.org + section.size,
endaddr(section.type) + 1
);
}
// Otherwise there is overlap with another section
else
else {
errx(
"Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
section.name.c_str(),
@@ -319,6 +337,7 @@ static void placeSection(Section &section) {
where,
out_OverlappingSection(section)->name.c_str()
);
}
}
// clang-format off: vertically align values
@@ -334,20 +353,24 @@ static std::deque<Section *> unassignedSections[1 << 3];
static void categorizeSection(Section &section) {
uint8_t constraints = 0;
if (section.isBankFixed)
if (section.isBankFixed) {
constraints |= BANK_CONSTRAINED;
if (section.isAddressFixed)
}
if (section.isAddressFixed) {
constraints |= ORG_CONSTRAINED;
}
// Can't have both!
else if (section.isAlignFixed)
else if (section.isAlignFixed) {
constraints |= ALIGN_CONSTRAINED;
}
std::deque<Section *> &sections = unassignedSections[constraints];
auto pos = sections.begin();
// Insert section while keeping the list sorted by decreasing size
while (pos != sections.end() && (*pos)->size > section.size)
while (pos != sections.end() && (*pos)->size > section.size) {
pos++;
}
sections.insert(pos, &section);
nbSectionsToAssign++;
@@ -368,12 +391,14 @@ void assign_AssignSections() {
// Specially process fully-constrained sections because of overlaying
verbosePrint("Assigning bank+org-constrained...\n");
for (Section *section : unassignedSections[BANK_CONSTRAINED | ORG_CONSTRAINED])
for (Section *section : unassignedSections[BANK_CONSTRAINED | ORG_CONSTRAINED]) {
placeSection(*section);
}
// If all sections were fully constrained, we have nothing left to do
if (!nbSectionsToAssign)
if (!nbSectionsToAssign) {
return;
}
// Overlaying requires only fully-constrained sections
verbosePrint("Assigning other sections...\n");
@@ -385,14 +410,16 @@ void assign_AssignSections() {
for (Section *section : unassignedSections[constraints]) {
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';' : ',', section->name.c_str());
nbSections++;
if (nbSections == 10)
if (nbSections == 10) {
goto max_out; // Can't `break` out of a nested loop
}
}
}
max_out:
if (nbSectionsToAssign != nbSections)
if (nbSectionsToAssign != nbSections) {
fprintf(stderr, " and %" PRIu64 " more", nbSectionsToAssign - nbSections);
}
fprintf(stderr, " %sn't\n", nbSectionsToAssign == 1 ? "is" : "are");
exit(1);
}
@@ -400,11 +427,13 @@ max_out:
// Assign all remaining sections by decreasing constraint order
for (int8_t constraints = BANK_CONSTRAINED | ALIGN_CONSTRAINED; constraints >= 0;
constraints--) {
for (Section *section : unassignedSections[constraints])
for (Section *section : unassignedSections[constraints]) {
placeSection(*section);
}
if (!nbSectionsToAssign)
if (!nbSectionsToAssign) {
return;
}
}
unreachable_();