mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Allow OPT to modify -W
Warning flags are processed individually; PUSHO and POPO (re)store all the warning states.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
warning: opt.asm(12): [-Wdiv]
|
||||
Division of -2147483648 by -1 yields -2147483648
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
$80000000
|
||||
$80000000
|
||||
|
||||
Reference in New Issue
Block a user