ref: d43408f4f3dc7b8375e43ea5de77075726dcecfc
parent: 2c30ab8731ab1b9f3880b1a8f55e49abe2b625e9
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Mar 15 06:30:40 EDT 2021
Allow OPT to modify -W Warning flags are processed individually; PUSHO and POPO (re)store all the warning states.
--- a/include/asm/opt.h
+++ b/include/asm/opt.h
@@ -15,6 +15,7 @@
void opt_G(char chars[4]);
void opt_P(uint8_t fill);
void opt_L(bool optimize);
+void opt_W(char const *flag);
void opt_Parse(char const *option);
void opt_Push(void);
--- a/include/asm/warning.h
+++ b/include/asm/warning.h
@@ -13,6 +13,13 @@
extern unsigned int nbErrors;
+enum WarningState {
+ WARNING_DEFAULT,
+ WARNING_DISABLED,
+ WARNING_ENABLED,
+ WARNING_ERROR
+};
+
enum WarningID {
WARNING_ASSERT, /* Assertions */
WARNING_BACKWARDS_FOR, /* `for` loop with backwards range */
@@ -42,6 +49,9 @@
NB_WARNINGS_ALL
#define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS)
};
+
+extern enum WarningState warningStates[NB_WARNINGS];
+extern bool warningsAreErrors;
void processWarningFlag(char const *flag);
--- a/src/asm/opt.c
+++ b/src/asm/opt.c
@@ -15,6 +15,8 @@
char gbgfx[4];
int32_t fillByte;
bool optimizeLoads;
+ bool warningsAreErrors;
+ enum WarningState warningStates[NB_WARNINGS];
struct OptStackEntry *next;
};
@@ -40,6 +42,11 @@
optimizeLoads = optimize;
}
+void opt_W(char const *flag)
+{
+ processWarningFlag(flag);
+}
+
void opt_Parse(char *s)
{
switch (s[0]) {
@@ -79,6 +86,13 @@
error("Option 'L' does not take an argument\n");
break;
+ case 'W':
+ if (strlen(&s[1]) > 0)
+ opt_W(&s[1]);
+ else
+ error("Must specify an argument for option 'W'\n");
+ break;
+
case '!': // negates flag options that do not take an argument
switch (s[1]) {
case 'L':
@@ -120,6 +134,10 @@
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
+ // Both of these pulled from warning.h
+ entry->warningsAreErrors = warningsAreErrors;
+ memcpy(entry->warningStates, warningStates, sizeof(warningStates));
+
entry->next = stack;
stack = entry;
}
@@ -137,6 +155,11 @@
opt_G(entry->gbgfx);
opt_P(entry->fillByte);
opt_L(entry->optimizeLoads);
+
+ // opt_W does not apply a whole warning state; it processes one flag string
+ warningsAreErrors = entry->warningsAreErrors;
+ memcpy(warningStates, entry->warningStates, sizeof(warningStates));
+
stack = entry->next;
free(entry);
}
--- a/src/asm/rgbasm.5
+++ b/src/asm/rgbasm.5
@@ -1883,18 +1883,20 @@
takes a comma-separated list of options as its argument:
.Bd -literal -offset indent
PUSHO
- OPT g.oOX, !L ; acts like command-line -g.oOX and omitting -L
- DW `..ooOOXX ; uses the graphics constant characters from OPT g
- LD [$FF88], A ; encoded as LD, not LDH
+ OPT g.oOX, Wdiv, !L ; acts like command-line -g.oOX -Wdiv and omitting -L
+ DW `..ooOOXX ; uses the graphics constant characters from OPT g
+ PRINTLN $80000000/-1 ; prints a warning about division
+ LD [$FF88], A ; encoded as LD, not LDH
POPO
- DW `00112233 ; uses the default graphics constant characters
- LD [$FF88], A ; optimized to use LDH if -L was passed
+ DW `00112233 ; uses the default graphics constant characters
+ PRINTLN $80000000/-1 ; no warning by default
+ LD [$FF88], A ; optimized to use LDH if -L was passed
.Ed
.Pp
The options that OPT can modify are currently:
-.Cm b , g , p ,
+.Cm b , g , p , L ,
and
-.Cm L .
+.Cm W .
The Boolean flag option
.Cm L
can be specified as
--- a/src/asm/warning.c
+++ b/src/asm/warning.c
@@ -21,13 +21,6 @@
unsigned int nbErrors = 0;
-enum WarningState {
- WARNING_DEFAULT,
- WARNING_DISABLED,
- WARNING_ENABLED,
- WARNING_ERROR
-};
-
static enum WarningState const defaultWarnings[NB_WARNINGS] = {
[WARNING_ASSERT] = WARNING_ENABLED,
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
@@ -48,9 +41,9 @@
[WARNING_USER] = WARNING_ENABLED,
};
-static enum WarningState warningStates[NB_WARNINGS];
+enum WarningState warningStates[NB_WARNINGS];
-static bool warningsAreErrors; /* Set if `-Werror` was specified */
+bool warningsAreErrors; /* Set if `-Werror` was specified */
static enum WarningState warningState(enum WarningID id)
{
--- a/test/asm/opt.asm
+++ b/test/asm/opt.asm
@@ -1,10 +1,12 @@
SECTION "test", ROM0
pusho
- opt p42, !L
+ opt p42, !L, Wno-div
ds 1
ld [$ff88], a
+ println $8000_0000 / -1
popo
ds 1
ld [$ff88], a
+ println $8000_0000 / -1
--- a/test/asm/opt.err
+++ b/test/asm/opt.err
@@ -1,0 +1,2 @@
+warning: opt.asm(12): [-Wdiv]
+ Division of -2147483648 by -1 yields -2147483648
--- a/test/asm/opt.out
+++ b/test/asm/opt.out
@@ -1,0 +1,2 @@
+$80000000
+$80000000