mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +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_G(char chars[4]);
|
||||||
void opt_P(uint8_t fill);
|
void opt_P(uint8_t fill);
|
||||||
void opt_L(bool optimize);
|
void opt_L(bool optimize);
|
||||||
|
void opt_W(char const *flag);
|
||||||
void opt_Parse(char const *option);
|
void opt_Parse(char const *option);
|
||||||
|
|
||||||
void opt_Push(void);
|
void opt_Push(void);
|
||||||
|
|||||||
@@ -13,6 +13,13 @@
|
|||||||
|
|
||||||
extern unsigned int nbErrors;
|
extern unsigned int nbErrors;
|
||||||
|
|
||||||
|
enum WarningState {
|
||||||
|
WARNING_DEFAULT,
|
||||||
|
WARNING_DISABLED,
|
||||||
|
WARNING_ENABLED,
|
||||||
|
WARNING_ERROR
|
||||||
|
};
|
||||||
|
|
||||||
enum WarningID {
|
enum WarningID {
|
||||||
WARNING_ASSERT, /* Assertions */
|
WARNING_ASSERT, /* Assertions */
|
||||||
WARNING_BACKWARDS_FOR, /* `for` loop with backwards range */
|
WARNING_BACKWARDS_FOR, /* `for` loop with backwards range */
|
||||||
@@ -43,6 +50,9 @@ enum WarningID {
|
|||||||
#define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS)
|
#define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern enum WarningState warningStates[NB_WARNINGS];
|
||||||
|
extern bool warningsAreErrors;
|
||||||
|
|
||||||
void processWarningFlag(char const *flag);
|
void processWarningFlag(char const *flag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ struct OptStackEntry {
|
|||||||
char gbgfx[4];
|
char gbgfx[4];
|
||||||
int32_t fillByte;
|
int32_t fillByte;
|
||||||
bool optimizeLoads;
|
bool optimizeLoads;
|
||||||
|
bool warningsAreErrors;
|
||||||
|
enum WarningState warningStates[NB_WARNINGS];
|
||||||
struct OptStackEntry *next;
|
struct OptStackEntry *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,6 +42,11 @@ void opt_L(bool optimize)
|
|||||||
optimizeLoads = optimize;
|
optimizeLoads = optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opt_W(char const *flag)
|
||||||
|
{
|
||||||
|
processWarningFlag(flag);
|
||||||
|
}
|
||||||
|
|
||||||
void opt_Parse(char *s)
|
void opt_Parse(char *s)
|
||||||
{
|
{
|
||||||
switch (s[0]) {
|
switch (s[0]) {
|
||||||
@@ -79,6 +86,13 @@ void opt_Parse(char *s)
|
|||||||
error("Option 'L' does not take an argument\n");
|
error("Option 'L' does not take an argument\n");
|
||||||
break;
|
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
|
case '!': // negates flag options that do not take an argument
|
||||||
switch (s[1]) {
|
switch (s[1]) {
|
||||||
case 'L':
|
case 'L':
|
||||||
@@ -120,6 +134,10 @@ void opt_Push(void)
|
|||||||
|
|
||||||
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
|
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;
|
entry->next = stack;
|
||||||
stack = entry;
|
stack = entry;
|
||||||
}
|
}
|
||||||
@@ -137,6 +155,11 @@ void opt_Pop(void)
|
|||||||
opt_G(entry->gbgfx);
|
opt_G(entry->gbgfx);
|
||||||
opt_P(entry->fillByte);
|
opt_P(entry->fillByte);
|
||||||
opt_L(entry->optimizeLoads);
|
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;
|
stack = entry->next;
|
||||||
free(entry);
|
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:
|
takes a comma-separated list of options as its argument:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
PUSHO
|
PUSHO
|
||||||
OPT g.oOX, !L ; acts like command-line -g.oOX and omitting -L
|
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
|
DW `..ooOOXX ; uses the graphics constant characters from OPT g
|
||||||
LD [$FF88], A ; encoded as LD, not LDH
|
PRINTLN $80000000/-1 ; prints a warning about division
|
||||||
|
LD [$FF88], A ; encoded as LD, not LDH
|
||||||
POPO
|
POPO
|
||||||
DW `00112233 ; uses the default graphics constant characters
|
DW `00112233 ; uses the default graphics constant characters
|
||||||
LD [$FF88], A ; optimized to use LDH if -L was passed
|
PRINTLN $80000000/-1 ; no warning by default
|
||||||
|
LD [$FF88], A ; optimized to use LDH if -L was passed
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The options that OPT can modify are currently:
|
The options that OPT can modify are currently:
|
||||||
.Cm b , g , p ,
|
.Cm b , g , p , L ,
|
||||||
and
|
and
|
||||||
.Cm L .
|
.Cm W .
|
||||||
The Boolean flag option
|
The Boolean flag option
|
||||||
.Cm L
|
.Cm L
|
||||||
can be specified as
|
can be specified as
|
||||||
|
|||||||
@@ -21,13 +21,6 @@
|
|||||||
|
|
||||||
unsigned int nbErrors = 0;
|
unsigned int nbErrors = 0;
|
||||||
|
|
||||||
enum WarningState {
|
|
||||||
WARNING_DEFAULT,
|
|
||||||
WARNING_DISABLED,
|
|
||||||
WARNING_ENABLED,
|
|
||||||
WARNING_ERROR
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
||||||
[WARNING_ASSERT] = WARNING_ENABLED,
|
[WARNING_ASSERT] = WARNING_ENABLED,
|
||||||
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
|
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
|
||||||
@@ -48,9 +41,9 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
|||||||
[WARNING_USER] = WARNING_ENABLED,
|
[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)
|
static enum WarningState warningState(enum WarningID id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
SECTION "test", ROM0
|
SECTION "test", ROM0
|
||||||
|
|
||||||
pusho
|
pusho
|
||||||
opt p42, !L
|
opt p42, !L, Wno-div
|
||||||
ds 1
|
ds 1
|
||||||
ld [$ff88], a
|
ld [$ff88], a
|
||||||
|
println $8000_0000 / -1
|
||||||
popo
|
popo
|
||||||
|
|
||||||
ds 1
|
ds 1
|
||||||
ld [$ff88], a
|
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