Update some names and comments

This commit is contained in:
Rangi42
2024-08-27 14:04:52 -04:00
parent 26fcff831d
commit 15f0871683
2 changed files with 72 additions and 73 deletions

View File

@@ -85,10 +85,10 @@ void sect_NextUnionMember();
void sect_EndUnion(); void sect_EndUnion();
void sect_CheckUnionClosed(); void sect_CheckUnionClosed();
void sect_ConstByte(uint8_t b); void sect_ConstByte(uint8_t byte);
void sect_ByteString(std::vector<int32_t> const &s); void sect_ByteString(std::vector<int32_t> const &string);
void sect_WordString(std::vector<int32_t> const &s); void sect_WordString(std::vector<int32_t> const &string);
void sect_LongString(std::vector<int32_t> const &s); void sect_LongString(std::vector<int32_t> const &string);
void sect_Skip(uint32_t skip, bool ds); void sect_Skip(uint32_t skip, bool ds);
void sect_RelByte(Expression &expr, uint32_t pcShift); void sect_RelByte(Expression &expr, uint32_t pcShift);
void sect_RelBytes(uint32_t n, std::vector<Expression> &exprs); void sect_RelBytes(uint32_t n, std::vector<Expression> &exprs);

View File

@@ -48,7 +48,7 @@ std::optional<std::string> currentLoadScope = std::nullopt;
int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset) int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset)
// A quick check to see if we have an initialized section // A quick check to see if we have an initialized section
[[nodiscard]] static bool checksection() { [[nodiscard]] static bool requireSection() {
if (currentSection) if (currentSection)
return true; return true;
@@ -58,8 +58,8 @@ int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutput
// A quick check to see if we have an initialized section that can contain // A quick check to see if we have an initialized section that can contain
// this much initialized data // this much initialized data
[[nodiscard]] static bool checkcodesection() { [[nodiscard]] static bool requireCodeSection() {
if (!checksection()) if (!requireSection())
return false; return false;
if (sect_HasData(currentSection->type)) if (sect_HasData(currentSection->type))
@@ -451,7 +451,7 @@ void sect_SetLoadSection(
// Therefore, any interactions are NOT TESTED, so lift either of those restrictions at // Therefore, any interactions are NOT TESTED, so lift either of those restrictions at
// your own peril! ^^ // your own peril! ^^
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (currentLoadSection) { if (currentLoadSection) {
@@ -525,7 +525,7 @@ uint32_t sect_GetAlignBytes(uint8_t alignment, uint16_t offset) {
} }
void sect_AlignPC(uint8_t alignment, uint16_t offset) { void sect_AlignPC(uint8_t alignment, uint16_t offset) {
if (!checksection()) if (!requireSection())
return; return;
Section *sect = sect_GetSymbolSection(); Section *sect = sect_GetSymbolSection();
@@ -537,7 +537,8 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
"Section's fixed address fails required alignment (PC = $%04" PRIx32 ")\n", "Section's fixed address fails required alignment (PC = $%04" PRIx32 ")\n",
sect->org + curOffset sect->org + curOffset
); );
} else if (sect->align != 0 && (((sect->alignOfs + curOffset) % (1u << sect->align)) - offset) % alignSize) { } else if (sect->align != 0
&& (((sect->alignOfs + curOffset) % (1u << sect->align)) - offset) % alignSize) {
error( error(
"Section's alignment fails required alignment (offset from section start = $%04" PRIx32 "Section's alignment fails required alignment (offset from section start = $%04" PRIx32
")\n", ")\n",
@@ -562,28 +563,28 @@ static void growSection(uint32_t growth) {
if (growth > 0 && curOffset > UINT32_MAX - growth) if (growth > 0 && curOffset > UINT32_MAX - growth)
fatalerror("Section size would overflow internal counter\n"); fatalerror("Section size would overflow internal counter\n");
curOffset += growth; curOffset += growth;
if (curOffset + loadOffset > currentSection->size) if (uint32_t outOffset = sect_GetOutputOffset(); outOffset > currentSection->size)
currentSection->size = curOffset + loadOffset; currentSection->size = outOffset;
if (currentLoadSection && curOffset > currentLoadSection->size) if (currentLoadSection && curOffset > currentLoadSection->size)
currentLoadSection->size = curOffset; currentLoadSection->size = curOffset;
} }
static void writebyte(uint8_t byte) { static void writeByte(uint8_t byte) {
if (uint32_t index = sect_GetOutputOffset(); index < currentSection->data.size()) if (uint32_t index = sect_GetOutputOffset(); index < currentSection->data.size())
currentSection->data[index] = byte; currentSection->data[index] = byte;
growSection(1); growSection(1);
} }
static void writeword(uint16_t b) { static void writeWord(uint16_t value) {
writebyte(b & 0xFF); writeByte(value & 0xFF);
writebyte(b >> 8); writeByte(value >> 8);
} }
static void writelong(uint32_t b) { static void writeLong(uint32_t value) {
writebyte(b & 0xFF); writeByte(value & 0xFF);
writebyte(b >> 8); writeByte(value >> 8);
writebyte(b >> 16); writeByte(value >> 16);
writebyte(b >> 24); writeByte(value >> 24);
} }
static void createPatch(PatchType type, Expression const &expr, uint32_t pcShift) { static void createPatch(PatchType type, Expression const &expr, uint32_t pcShift) {
@@ -640,51 +641,54 @@ void sect_CheckUnionClosed() {
error("Unterminated UNION construct\n"); error("Unterminated UNION construct\n");
} }
// Output an absolute byte // Output a constant byte
void sect_ConstByte(uint8_t b) { void sect_ConstByte(uint8_t byte) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
writebyte(b); writeByte(byte);
} }
void sect_ByteString(std::vector<int32_t> const &s) { // Output a string's character units as bytes
if (!checkcodesection()) void sect_ByteString(std::vector<int32_t> const &string) {
if (!requireCodeSection())
return; return;
for (int32_t v : s) { for (int32_t unit : string) {
if (!checkNBit(v, 8, "All character units")) if (!checkNBit(unit, 8, "All character units"))
break; break;
} }
for (int32_t v : s) for (int32_t unit : string)
writebyte(static_cast<uint8_t>(v)); writeByte(static_cast<uint8_t>(unit));
} }
void sect_WordString(std::vector<int32_t> const &s) { // Output a string's character units as words
if (!checkcodesection()) void sect_WordString(std::vector<int32_t> const &string) {
if (!requireCodeSection())
return; return;
for (int32_t v : s) { for (int32_t unit : string) {
if (!checkNBit(v, 16, "All character units")) if (!checkNBit(unit, 16, "All character units"))
break; break;
} }
for (int32_t v : s) for (int32_t unit : string)
writeword(static_cast<uint16_t>(v)); writeWord(static_cast<uint16_t>(unit));
} }
void sect_LongString(std::vector<int32_t> const &s) { // Output a string's character units as longs
if (!checkcodesection()) void sect_LongString(std::vector<int32_t> const &string) {
if (!requireCodeSection())
return; return;
for (int32_t v : s) for (int32_t unit : string)
writelong(static_cast<uint32_t>(v)); writeLong(static_cast<uint32_t>(unit));
} }
// Skip this many bytes // Skip this many bytes
void sect_Skip(uint32_t skip, bool ds) { void sect_Skip(uint32_t skip, bool ds) {
if (!checksection()) if (!requireSection())
return; return;
if (!sect_HasData(currentSection->type)) { if (!sect_HasData(currentSection->type)) {
@@ -700,28 +704,26 @@ void sect_Skip(uint32_t skip, bool ds) {
); );
// We know we're in a code SECTION // We know we're in a code SECTION
while (skip--) while (skip--)
writebyte(fillByte); writeByte(fillByte);
} }
} }
// Output a relocatable byte. Checking will be done to see if it // Output a byte that can be relocatable or constant
// is an absolute value in disguise.
void sect_RelByte(Expression &expr, uint32_t pcShift) { void sect_RelByte(Expression &expr, uint32_t pcShift) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (!expr.isKnown()) { if (!expr.isKnown()) {
createPatch(PATCHTYPE_BYTE, expr, pcShift); createPatch(PATCHTYPE_BYTE, expr, pcShift);
writebyte(0); writeByte(0);
} else { } else {
writebyte(expr.value()); writeByte(expr.value());
} }
} }
// Output several copies of a relocatable byte. Checking will be done to see if // Output several bytes that can be relocatable or constant
// it is an absolute value in disguise.
void sect_RelBytes(uint32_t n, std::vector<Expression> &exprs) { void sect_RelBytes(uint32_t n, std::vector<Expression> &exprs) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
for (uint32_t i = 0; i < n; i++) { for (uint32_t i = 0; i < n; i++) {
@@ -729,50 +731,47 @@ void sect_RelBytes(uint32_t n, std::vector<Expression> &exprs) {
if (!expr.isKnown()) { if (!expr.isKnown()) {
createPatch(PATCHTYPE_BYTE, expr, i); createPatch(PATCHTYPE_BYTE, expr, i);
writebyte(0); writeByte(0);
} else { } else {
writebyte(expr.value()); writeByte(expr.value());
} }
} }
} }
// Output a relocatable word. Checking will be done to see if // Output a word that can be relocatable or constant
// it's an absolute value in disguise.
void sect_RelWord(Expression &expr, uint32_t pcShift) { void sect_RelWord(Expression &expr, uint32_t pcShift) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (!expr.isKnown()) { if (!expr.isKnown()) {
createPatch(PATCHTYPE_WORD, expr, pcShift); createPatch(PATCHTYPE_WORD, expr, pcShift);
writeword(0); writeWord(0);
} else { } else {
writeword(expr.value()); writeWord(expr.value());
} }
} }
// Output a relocatable longword. Checking will be done to see if // Output a long that can be relocatable or constant
// is an absolute value in disguise.
void sect_RelLong(Expression &expr, uint32_t pcShift) { void sect_RelLong(Expression &expr, uint32_t pcShift) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (!expr.isKnown()) { if (!expr.isKnown()) {
createPatch(PATCHTYPE_LONG, expr, pcShift); createPatch(PATCHTYPE_LONG, expr, pcShift);
writelong(0); writeLong(0);
} else { } else {
writelong(expr.value()); writeLong(expr.value());
} }
} }
// Output a PC-relative relocatable byte. Checking will be done to see if it // Output a PC-relative byte that can be relocatable or constant
// is an absolute value in disguise.
void sect_PCRelByte(Expression &expr, uint32_t pcShift) { void sect_PCRelByte(Expression &expr, uint32_t pcShift) {
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (Symbol const *pc = sym_GetPC(); !expr.isDiffConstant(pc)) { if (Symbol const *pc = sym_GetPC(); !expr.isDiffConstant(pc)) {
createPatch(PATCHTYPE_JR, expr, pcShift); createPatch(PATCHTYPE_JR, expr, pcShift);
writebyte(0); writeByte(0);
} else { } else {
Symbol const *sym = expr.symbolOf(); Symbol const *sym = expr.symbolOf();
// The offset wraps (jump from ROM to HRAM, for example) // The offset wraps (jump from ROM to HRAM, for example)
@@ -790,9 +789,9 @@ void sect_PCRelByte(Expression &expr, uint32_t pcShift) {
"; use jp instead\n", "; use jp instead\n",
offset offset
); );
writebyte(0); writeByte(0);
} else { } else {
writebyte(offset); writeByte(offset);
} }
} }
} }
@@ -803,7 +802,7 @@ void sect_BinaryFile(std::string const &name, int32_t startPos) {
error("Start position cannot be negative (%" PRId32 ")\n", startPos); error("Start position cannot be negative (%" PRId32 ")\n", startPos);
startPos = 0; startPos = 0;
} }
if (!checkcodesection()) if (!requireCodeSection())
return; return;
FILE *file = nullptr; FILE *file = nullptr;
@@ -845,7 +844,7 @@ void sect_BinaryFile(std::string const &name, int32_t startPos) {
} }
for (int byte; (byte = fgetc(file)) != EOF;) for (int byte; (byte = fgetc(file)) != EOF;)
writebyte(byte); writeByte(byte);
if (ferror(file)) if (ferror(file))
error("Error reading INCBIN file '%s': %s\n", name.c_str(), strerror(errno)); error("Error reading INCBIN file '%s': %s\n", name.c_str(), strerror(errno));
@@ -861,7 +860,7 @@ void sect_BinaryFileSlice(std::string const &name, int32_t startPos, int32_t len
error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length); error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
length = 0; length = 0;
} }
if (!checkcodesection()) if (!requireCodeSection())
return; return;
if (length == 0) // Don't even bother with 0-byte slices if (length == 0) // Don't even bother with 0-byte slices
return; return;
@@ -916,7 +915,7 @@ void sect_BinaryFileSlice(std::string const &name, int32_t startPos, int32_t len
while (length--) { while (length--) {
if (int byte = fgetc(file); byte != EOF) { if (int byte = fgetc(file); byte != EOF) {
writebyte(byte); writeByte(byte);
} else if (ferror(file)) { } else if (ferror(file)) {
error("Error reading INCBIN file '%s': %s\n", name.c_str(), strerror(errno)); error("Error reading INCBIN file '%s': %s\n", name.c_str(), strerror(errno));
} else { } else {