ref: 38a9a613da37d102a13585857bda2b314f8b12c6
parent: ad9a766a56aa6bc4aacad97f4e65462fb182ec54
author: ISSOtm <[email protected]>
date: Sat May 1 19:34:28 EDT 2021
Make data output outside of a SECTION non-fatal
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -44,10 +44,13 @@
/*
* A quick check to see if we have an initialized section
*/
-static void checksection(void)
+static bool checksection(void)
{
- if (currentSection == NULL)
- fatalerror("Cannot output data outside of a SECTION\n");
+ if (currentSection)
+ return true;
+
+ error("Cannot output data outside of a SECTION\n");
+ return false;
}
/*
@@ -54,13 +57,17 @@
* A quick check to see if we have an initialized section that can contain
* this much initialized data
*/
-static void checkcodesection(void)
+static bool checkcodesection(void)
{
- checksection();
+ if (!checksection())
+ return false;
- if (!sect_HasData(currentSection->type))
- fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
- currentSection->name);
+ if (sect_HasData(currentSection->type))
+ return true;
+
+ error("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
+ currentSection->name);
+ return false;
}
static void checkSectionSize(struct Section const *sect, uint32_t size)
@@ -407,7 +414,8 @@
struct SectionSpec const *attribs,
enum SectionModifier mod)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
if (currentLoadSection)
fatalerror("`LOAD` blocks cannot be nested\n");
@@ -454,7 +462,9 @@
void sect_AlignPC(uint8_t alignment, uint16_t offset)
{
- checksection();
+ if (!checksection())
+ return;
+
struct Section *sect = sect_GetSymbolSection();
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
@@ -566,7 +576,8 @@
*/
void out_AbsByte(uint8_t b)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(1);
writebyte(b);
@@ -574,7 +585,8 @@
void out_AbsByteGroup(uint8_t const *s, int32_t length)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(length);
while (length--)
@@ -583,7 +595,8 @@
void out_AbsWordGroup(uint8_t const *s, int32_t length)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(length * 2);
while (length--)
@@ -592,7 +605,8 @@
void out_AbsLongGroup(uint8_t const *s, int32_t length)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(length * 4);
while (length--)
@@ -604,7 +618,8 @@
*/
void out_Skip(int32_t skip, bool ds)
{
- checksection();
+ if (!checksection())
+ return;
reserveSpace(skip);
if (!ds && sect_HasData(currentSection->type))
@@ -614,7 +629,8 @@
if (!sect_HasData(currentSection->type)) {
growSection(skip);
} else {
- checkcodesection();
+ if (!checkcodesection())
+ return;
while (skip--)
writebyte(fillByte);
}
@@ -625,7 +641,8 @@
*/
void out_String(char const *s)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(strlen(s));
while (*s)
@@ -638,7 +655,8 @@
*/
void out_RelByte(struct Expression *expr, uint32_t pcShift)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(1);
if (!rpn_isKnown(expr)) {
@@ -656,7 +674,8 @@
*/
void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(n);
for (uint32_t i = 0; i < n; i++) {
@@ -680,7 +699,8 @@
*/
void out_RelWord(struct Expression *expr, uint32_t pcShift)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(2);
if (!rpn_isKnown(expr)) {
@@ -698,7 +718,8 @@
*/
void out_RelLong(struct Expression *expr, uint32_t pcShift)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(2);
if (!rpn_isKnown(expr)) {
@@ -716,7 +737,8 @@
*/
void out_PCRelByte(struct Expression *expr, uint32_t pcShift)
{
- checkcodesection();
+ if (!checkcodesection())
+ return;
reserveSpace(1);
struct Symbol const *pc = sym_GetPC();
@@ -754,6 +776,8 @@
error("Start position cannot be negative (%" PRId32 ")\n", startPos);
startPos = 0;
}
+ if (!checkcodesection())
+ return;
char *fullPath = NULL;
size_t size = 0;
@@ -777,7 +801,6 @@
int32_t fsize = -1;
int byte;
- checkcodesection();
if (fseek(f, 0, SEEK_END) != -1) {
fsize = ftell(f);
@@ -821,8 +844,12 @@
error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
length = 0;
}
+
+ if (!checkcodesection())
+ return;
if (length == 0) /* Don't even bother with 0-byte slices */
return;
+ reserveSpace(length);
char *fullPath = NULL;
size_t size = 0;
@@ -842,9 +869,6 @@
}
return;
}
-
- checkcodesection();
- reserveSpace(length);
int32_t fsize;
--- a/test/asm/align-pc-outside-section.err
+++ b/test/asm/align-pc-outside-section.err
@@ -1,2 +1,3 @@
-FATAL: align-pc-outside-section.asm(1):
+ERROR: align-pc-outside-section.asm(1):
Cannot output data outside of a SECTION
+error: Assembly aborted (1 error)!
--- a/test/asm/incbin-end-0.err
+++ b/test/asm/incbin-end-0.err
@@ -1,0 +1,3 @@
+ERROR: incbin-end-0.asm(1):
+ Cannot output data outside of a SECTION
+error: Assembly aborted (1 error)!
--- a/test/asm/pops-restore-no-section.err
+++ b/test/asm/pops-restore-no-section.err
@@ -1,4 +1,5 @@
ERROR: pops-restore-no-section.asm(9):
Label "DisallowedContent" created outside of a SECTION
-FATAL: pops-restore-no-section.asm(10):
+ERROR: pops-restore-no-section.asm(10):
Cannot output data outside of a SECTION
+error: Assembly aborted (2 errors)!
--- a/test/asm/pushs.err
+++ b/test/asm/pushs.err
@@ -1,2 +1,3 @@
-FATAL: pushs.asm(5):
+ERROR: pushs.asm(5):
Cannot output data outside of a SECTION
+error: Assembly aborted (1 error)!