From d43408f4f3dc7b8375e43ea5de77075726dcecfc Mon Sep 17 00:00:00 2001 From: Rangi Date: Mon, 15 Mar 2021 10:30:40 -0400 Subject: [PATCH] Allow OPT to modify -W Warning flags are processed individually; PUSHO and POPO (re)store all the warning states. --- include/asm/opt.h | 1 + include/asm/warning.h | 10 ++++++++++ src/asm/opt.c | 23 +++++++++++++++++++++++ src/asm/rgbasm.5 | 16 +++++++++------- src/asm/warning.c | 11 ++--------- test/asm/opt.asm | 4 +++- test/asm/opt.err | 2 ++ test/asm/opt.out | 2 ++ 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/include/asm/opt.h b/include/asm/opt.h index af25c2a6..d5054277 100644 --- a/include/asm/opt.h +++ b/include/asm/opt.h @@ -15,6 +15,7 @@ void opt_B(char chars[2]); 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); diff --git a/include/asm/warning.h b/include/asm/warning.h index 2185d0e9..1bd9f53d 100644 --- 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 */ @@ -43,6 +50,9 @@ enum WarningID { #define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS) }; +extern enum WarningState warningStates[NB_WARNINGS]; +extern bool warningsAreErrors; + void processWarningFlag(char const *flag); /* diff --git a/src/asm/opt.c b/src/asm/opt.c index c8563de5..657e08e3 100644 --- a/src/asm/opt.c +++ b/src/asm/opt.c @@ -15,6 +15,8 @@ struct OptStackEntry { char gbgfx[4]; int32_t fillByte; bool optimizeLoads; + bool warningsAreErrors; + enum WarningState warningStates[NB_WARNINGS]; struct OptStackEntry *next; }; @@ -40,6 +42,11 @@ void opt_L(bool optimize) optimizeLoads = optimize; } +void opt_W(char const *flag) +{ + processWarningFlag(flag); +} + void opt_Parse(char *s) { switch (s[0]) { @@ -79,6 +86,13 @@ void opt_Parse(char *s) 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 @@ void opt_Push(void) 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 @@ void opt_Pop(void) 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); } diff --git a/src/asm/rgbasm.5 b/src/asm/rgbasm.5 index 9378873f..9fcee20d 100644 --- a/src/asm/rgbasm.5 +++ b/src/asm/rgbasm.5 @@ -1883,18 +1883,20 @@ can be used to change some of the options during assembling from within the sour 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 diff --git a/src/asm/warning.c b/src/asm/warning.c index 40d7661a..4e709b2c 100644 --- 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 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = { [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) { diff --git a/test/asm/opt.asm b/test/asm/opt.asm index 9191288d..256b91ab 100644 --- 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 diff --git a/test/asm/opt.err b/test/asm/opt.err index e69de29b..50eb8bbd 100644 --- a/test/asm/opt.err +++ b/test/asm/opt.err @@ -0,0 +1,2 @@ +warning: opt.asm(12): [-Wdiv] + Division of -2147483648 by -1 yields -2147483648 diff --git a/test/asm/opt.out b/test/asm/opt.out index e69de29b..62e5a6fb 100644 --- a/test/asm/opt.out +++ b/test/asm/opt.out @@ -0,0 +1,2 @@ +$80000000 +$80000000