Remove deprecated RGBASM features (#1215)

- Escaped commas "\," inside strings
- `name: MACRO` syntax
- `__FILE__` and `__LINE__`
- `-H/--nop-after-halt` and `-l/--auto-ldh` on by default
This commit is contained in:
Rangi
2023-11-04 18:22:46 -04:00
committed by GitHub
parent 28d92b7be3
commit 46e67ee078
20 changed files with 60 additions and 152 deletions

View File

@@ -15,7 +15,7 @@
#include "helpers.h" #include "helpers.h"
extern bool haltnop; extern bool haltNop;
extern bool warnOnHaltNop; extern bool warnOnHaltNop;
extern bool optimizeLoads; extern bool optimizeLoads;
extern bool warnOnLdOpt; extern bool warnOnLdOpt;

View File

@@ -71,24 +71,14 @@ Export all labels, including unreferenced and local labels.
Change the four characters used for gfx constants. Change the four characters used for gfx constants.
The defaults are 0123. The defaults are 0123.
.It Fl H , Fl Fl nop-after-halt .It Fl H , Fl Fl nop-after-halt
By default, Inserts a
.Nm
inserts a
.Ic nop
instruction immediately after any
.Ic halt
instruction,
but this has been deprecated and prints a warning message the first time it occurs.
The
.Fl H
option opts into this insertion,
so no warning will be printed.
.It Fl h , Fl Fl halt-without-nop
Disables inserting a
.Ic nop .Ic nop
instruction immediately after any instruction immediately after any
.Ic halt .Ic halt
instruction. instruction.
This option is deprecated and will be removed in the next version.
.It Fl h , Fl Fl halt-without-nop
This option is redundant and will be removed in the next version.
.It Fl I Ar path , Fl Fl include Ar path .It Fl I Ar path , Fl Fl include Ar path
Add a new Add a new
.Dq include path ; .Dq include path ;
@@ -105,21 +95,13 @@ first looks up the provided path from its working directory; if this fails, it t
.Dq include path .Dq include path
directories, in the order they were provided. directories, in the order they were provided.
.It Fl L , Fl Fl preserve-ld .It Fl L , Fl Fl preserve-ld
By default, This option is redundant and will be removed in the next version.
.Nm
optimizes loads of the form
.Ic LD [$FF00+n8],A
into the opcode
.Ic LDH [$FF00+n8],A ,
but this has been deprecated and prints a warning message the first time it occurs.
The
.Fl L
option disables this optimization.
.It Fl l , Fl Fl auto-ldh .It Fl l , Fl Fl auto-ldh
Optimize loads of the form Optimize loads of the form
.Ic LD [$FF00+n8],A .Ic LD [$FF00+n8],A
into the opcode into the opcode
.Ic LDH [$FF00+n8],A . .Ic LDH [$FF00+n8],A .
This option is deprecated and will be removed in the next version.
.It Fl M Ar depend_file , Fl Fl dependfile Ar depend_file .It Fl M Ar depend_file , Fl Fl dependfile Ar depend_file
Print Print
.Xr make 1 .Xr make 1

View File

@@ -1249,16 +1249,6 @@ The example above defines
as a new macro. as a new macro.
String constants are not expanded within the name of the macro. String constants are not expanded within the name of the macro.
.Pp .Pp
(Using the
.Em deprecated
older syntax
.Ql MyMacro: MACRO
instead of
.Ql MACRO MyMacro ,
with a single colon
.Ql \&:
following the macro's name, string constants may be expanded for the name.)
.Pp
Macros can't be exported or imported. Macros can't be exported or imported.
.Pp .Pp
Plainly nesting macro definitions is not allowed, but this can be worked around using Plainly nesting macro definitions is not allowed, but this can be worked around using

View File

@@ -1722,12 +1722,6 @@ static size_t appendStringLiteral(size_t i)
c = '\\'; c = '\\';
break; break;
case ',': // `\,` inside a macro arg string literal
warning(WARNING_OBSOLETE,
"`\\,` is deprecated inside strings\n");
shiftChar();
break;
default: default:
error("Illegal character escape %s\n", printChar(c)); error("Illegal character escape %s\n", printChar(c));
shiftChar(); shiftChar();

View File

@@ -59,7 +59,7 @@ bool failedOnMissingInclude = false;
bool generatePhonyDeps = false; bool generatePhonyDeps = false;
char *targetFileName = NULL; char *targetFileName = NULL;
bool haltnop; bool haltNop;
bool warnOnHaltNop; bool warnOnHaltNop;
bool optimizeLoads; bool optimizeLoads;
bool warnOnLdOpt; bool warnOnLdOpt;
@@ -164,9 +164,9 @@ int main(int argc, char *argv[])
opt_G("0123"); opt_G("0123");
opt_P(0); opt_P(0);
opt_Q(16); opt_Q(16);
haltnop = true; haltNop = false;
warnOnHaltNop = true; warnOnHaltNop = true;
optimizeLoads = true; optimizeLoads = false;
warnOnLdOpt = true; warnOnLdOpt = true;
verbose = false; verbose = false;
warnings = true; warnings = true;
@@ -209,32 +209,39 @@ int main(int argc, char *argv[])
break; break;
case 'H': case 'H':
if (!haltnop) if (warnOnHaltNop)
warning(WARNING_OBSOLETE,
"Automatic `nop` after `halt` is deprecated\n");
else
errx("`-H` and `-h` don't make sense together"); errx("`-H` and `-h` don't make sense together");
haltNop = true;
warnOnHaltNop = false; warnOnHaltNop = false;
break; break;
case 'h': case 'h':
if (!warnOnHaltNop) if (haltNop)
errx("`-H` and `-h` don't make sense together"); errx("`-H` and `-h` don't make sense together");
haltnop = false;
break; break;
// `-i` was the only short option for `--include` until `-I` was // `-i` was the only short option for `--include` until `-I` was
// introduced to better match the `-I dir` option of gcc and clang. // introduced to better match the `-I dir` option of gcc and clang.
// `-i` is now undocumented but still supported for now.
case 'I':
case 'i': case 'i':
warning(WARNING_OBSOLETE, "`-i` is deprecated; use `-I`\n");
// fallthrough
case 'I':
fstk_AddIncludePath(musl_optarg); fstk_AddIncludePath(musl_optarg);
break; break;
case 'L': case 'L':
if (!warnOnLdOpt) if (optimizeLoads)
errx("`-L` and `-l` don't make sense together"); errx("`-L` and `-l` don't make sense together");
optimizeLoads = false;
break; break;
case 'l': case 'l':
if (!optimizeLoads) if (warnOnLdOpt)
warning(WARNING_OBSOLETE,
"Automatic `ld` to `ldh` optimization is deprecated\n");
else
errx("`-L` and `-l` don't make sense together"); errx("`-L` and `-l` don't make sense together");
optimizeLoads = true;
warnOnLdOpt = false; warnOnLdOpt = false;
break; break;

View File

@@ -26,7 +26,7 @@ struct OptStackEntry {
char gbgfx[4]; char gbgfx[4];
uint8_t fixPrecision; uint8_t fixPrecision;
uint8_t fillByte; uint8_t fillByte;
bool haltnop; bool haltNop;
bool warnOnHaltNop; bool warnOnHaltNop;
bool optimizeLoads; bool optimizeLoads;
bool warnOnLdOpt; bool warnOnLdOpt;
@@ -72,7 +72,7 @@ void opt_H(bool warn)
void opt_h(bool halt) void opt_h(bool halt)
{ {
haltnop = halt; haltNop = halt;
} }
void opt_L(bool optimize) void opt_L(bool optimize)
@@ -265,7 +265,7 @@ void opt_Push(void)
entry->fillByte = fillByte; // Pulled from section.h entry->fillByte = fillByte; // Pulled from section.h
entry->haltnop = haltnop; // Pulled from main.h entry->haltNop = haltNop; // Pulled from main.h
entry->warnOnHaltNop = warnOnHaltNop; entry->warnOnHaltNop = warnOnHaltNop;
entry->optimizeLoads = optimizeLoads; // Pulled from main.h entry->optimizeLoads = optimizeLoads; // Pulled from main.h
@@ -295,7 +295,7 @@ void opt_Pop(void)
opt_P(entry->fillByte); opt_P(entry->fillByte);
opt_Q(entry->fixPrecision); opt_Q(entry->fixPrecision);
opt_H(entry->warnOnHaltNop); opt_H(entry->warnOnHaltNop);
opt_h(entry->haltnop); opt_h(entry->haltNop);
opt_L(entry->optimizeLoads); opt_L(entry->optimizeLoads);
opt_l(entry->warnOnLdOpt); opt_l(entry->warnOnLdOpt);
opt_R(entry->maxRecursionDepth); opt_R(entry->maxRecursionDepth);

View File

@@ -1165,14 +1165,6 @@ macrodef : T_POP_MACRO {
sym_AddMacro($3, captureBody.lineNo, captureBody.body, sym_AddMacro($3, captureBody.lineNo, captureBody.body,
captureBody.size); captureBody.size);
} }
| T_LABEL T_COLON T_POP_MACRO T_NEWLINE {
warning(WARNING_OBSOLETE, "`%s: MACRO` is deprecated; use `MACRO %s`\n", $1, $1);
$<captureTerminated>$ = lexer_CaptureMacroBody(&captureBody);
} endofline {
if ($<captureTerminated>5)
sym_AddMacro($1, captureBody.lineNo, captureBody.body,
captureBody.size);
}
; ;
rsset : T_POP_RSSET uconst { sym_AddVar("_RS", $2); } rsset : T_POP_RSSET uconst { sym_AddVar("_RS", $2); }
@@ -1905,10 +1897,11 @@ z80_ei : T_Z80_EI { sect_AbsByte(0xFB); }
z80_halt : T_Z80_HALT { z80_halt : T_Z80_HALT {
sect_AbsByte(0x76); sect_AbsByte(0x76);
if (haltnop) { if (haltNop) {
if (warnOnHaltNop) { if (warnOnHaltNop) {
warnOnHaltNop = false; warnOnHaltNop = false;
warning(WARNING_OBSOLETE, "`nop` after `halt` will stop being the default; pass `-H` to opt into it\n"); warning(WARNING_OBSOLETE,
"Automatic `nop` after `halt` is deprecated\n");
} }
sect_AbsByte(0x00); sect_AbsByte(0x00);
} }
@@ -2021,7 +2014,8 @@ z80_ld_mem : T_Z80_LD op_mem_ind T_COMMA T_MODE_SP {
&& $2.val >= 0xFF00) { && $2.val >= 0xFF00) {
if (warnOnLdOpt) { if (warnOnLdOpt) {
warnOnLdOpt = false; warnOnLdOpt = false;
warning(WARNING_OBSOLETE, "ld optimization will stop being the default; pass `-l` to opt into it\n"); warning(WARNING_OBSOLETE,
"Automatic `ld` to `ldh` optimization is deprecated\n");
} }
sect_AbsByte(0xE0); sect_AbsByte(0xE0);
sect_AbsByte($2.val & 0xFF); sect_AbsByte($2.val & 0xFF);
@@ -2073,7 +2067,8 @@ z80_ld_a : T_Z80_LD reg_r T_COMMA c_ind {
&& $4.val >= 0xFF00) { && $4.val >= 0xFF00) {
if (warnOnLdOpt) { if (warnOnLdOpt) {
warnOnLdOpt = false; warnOnLdOpt = false;
warning(WARNING_OBSOLETE, "ld optimization will stop being the default; pass `-l` to opt into it\n"); warning(WARNING_OBSOLETE,
"Automatic `ld` to `ldh` optimization is deprecated\n");
} }
sect_AbsByte(0xF0); sect_AbsByte(0xF0);
sect_AbsByte($4.val & 0xFF); sect_AbsByte($4.val & 0xFF);

View File

@@ -77,50 +77,6 @@ static int32_t Callback_NARG(void)
return macro_NbArgs(); return macro_NbArgs();
} }
static int32_t Callback__LINE__(void)
{
warning(WARNING_OBSOLETE, "`__LINE__` is deprecated\n");
return lexer_GetLineNo();
}
static char const *Callback__FILE__(void)
{
warning(WARNING_OBSOLETE, "`__FILE__` is deprecated\n");
// There are only two call sites for this; one copies the contents directly, the other is
// EQUS expansions, which cannot straddle file boundaries. So this should be fine.
static char *buf = NULL;
static size_t bufsize = 0;
char const *fileName = fstk_GetFileName();
size_t j = 1;
assert(fileName[0]);
// The assertion above ensures the loop runs at least once
for (size_t i = 0; fileName[i]; i++, j++) {
// Account for the extra backslash inserted below
if (fileName[i] == '"')
j++;
// Ensure there will be enough room; DO NOT PRINT ANYTHING ABOVE THIS!
if (j + 2 >= bufsize) { // Always keep room for 2 tail chars
bufsize = bufsize ? bufsize * 2 : 64;
buf = realloc(buf, bufsize);
if (!buf)
fatalerror("Failed to grow buffer for file name: %s\n",
strerror(errno));
}
// Escape quotes, since we're returning a string
if (fileName[i] == '"')
buf[j - 1] = '\\';
buf[j] = fileName[i];
}
// Write everything after the loop, to ensure the buffer has been allocated
buf[0] = '"';
buf[j++] = '"';
buf[j] = '\0';
return buf;
}
static int32_t CallbackPC(void) static int32_t CallbackPC(void)
{ {
struct Section const *section = sect_GetSymbolSection(); struct Section const *section = sect_GetSymbolSection();
@@ -687,21 +643,13 @@ static struct Symbol *createBuiltinSymbol(char const *symName)
void sym_Init(time_t now) void sym_Init(time_t now)
{ {
PCSymbol = createBuiltinSymbol("@"); PCSymbol = createBuiltinSymbol("@");
_NARGSymbol = createBuiltinSymbol("_NARG");
// __LINE__ is deprecated
struct Symbol *__LINE__Symbol = createBuiltinSymbol("__LINE__");
// __FILE__ is deprecated
struct Symbol *__FILE__Symbol = createBuiltinSymbol("__FILE__");
PCSymbol->type = SYM_LABEL; PCSymbol->type = SYM_LABEL;
PCSymbol->section = NULL; PCSymbol->section = NULL;
PCSymbol->numCallback = CallbackPC; PCSymbol->numCallback = CallbackPC;
_NARGSymbol = createBuiltinSymbol("_NARG");
_NARGSymbol->type = SYM_EQU; _NARGSymbol->type = SYM_EQU;
_NARGSymbol->numCallback = Callback_NARG; _NARGSymbol->numCallback = Callback_NARG;
__LINE__Symbol->type = SYM_EQU;
__LINE__Symbol->numCallback = Callback__LINE__;
__FILE__Symbol->type = SYM_EQUS;
__FILE__Symbol->strCallback = Callback__FILE__;
sym_AddVar("_RS", 0)->isBuiltin = true; sym_AddVar("_RS", 0)->isBuiltin = true;
@@ -758,4 +706,5 @@ void sym_Init(time_t now)
#undef addSym #undef addSym
sym_SetCurrentSymbolScope(NULL); sym_SetCurrentSymbolScope(NULL);
anonLabelID = 0;} anonLabelID = 0;
}

1
test/asm/.gitignore vendored
View File

@@ -1,3 +1,2 @@
/quote\"file.*
/version.asm /version.asm
/version.out /version.out

View File

@@ -1 +0,0 @@
PRINTLN "{__FILE__}"

View File

@@ -1,2 +0,0 @@
warning: file-sym.asm(1): [-Wobsolete]
`__FILE__` is deprecated

View File

@@ -1 +0,0 @@
"file-sym.asm"

View File

@@ -1,4 +1,3 @@
SECTION "Label testing", WRAMX SECTION "Label testing", WRAMX
Lab: Lab:
@@ -7,7 +6,7 @@ SECTION "Label testing", WRAMX
: ; anonymous : ; anonymous
mac: MACRO MACRO mac
println "\1" println "\1"
ENDM ENDM
mac : mac :

View File

@@ -1,2 +0,0 @@
warning: label-indent.asm(10): [-Wobsolete]
`mac: MACRO` is deprecated; use `MACRO mac`

View File

@@ -1,15 +1,12 @@
MACRO new ; comment
println "in with the ", \1
ENDM ; comment
new 2
old: MACRO ; comment old: MACRO ; comment
println "out with the ", \1 println "out with the ", \1
ENDM ; comment ENDM ; comment
MACRO new ; comment
println "in with the ", \1
ENDM ; comment
old 1 old 1
new 2
bad1: MACRO bad2 ; comment
println "which?"
ENDM ; comment

View File

@@ -1,7 +1,7 @@
warning: macro-syntax.asm(2): [-Wobsolete] error: macro-syntax.asm(7):
`old: MACRO` is deprecated; use `MACRO old` syntax error, unexpected MACRO
error: macro-syntax.asm(13): error: macro-syntax.asm(8):
syntax error, unexpected identifier, expecting newline Macro argument '\1' not defined
error: macro-syntax.asm(15): error: macro-syntax.asm(9):
syntax error, unexpected ENDM syntax error, unexpected ENDM
error: Assembly aborted (2 errors)! error: Assembly aborted (3 errors)!

View File

@@ -1,3 +1,2 @@
out with the $1
in with the $2 in with the $2
which? out with the

View File

@@ -1,5 +1,7 @@
error: macro-syntax.asm(13): error: macro-syntax.asm(7):
syntax error syntax error
error: macro-syntax.asm(15): error: macro-syntax.asm(8):
Macro argument '\1' not defined
error: macro-syntax.asm(9):
syntax error syntax error
error: Assembly aborted (2 errors)! error: Assembly aborted (3 errors)!

View File

@@ -242,6 +242,7 @@ jrlabel:
ei ei
halt halt
nop nop
nop
scf scf
stop stop
FOR BYTE, 256 FOR BYTE, 256