added "--dialect" CLI switch to set which older version to mimic

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@207 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-05-31 20:55:38 +00:00
parent 8e4857de4c
commit 8a3bdb265f
4 changed files with 75 additions and 29 deletions

View File

@ -65,6 +65,7 @@ static const char arg_vicelabels[] = "VICE labels filename";
#define OPTION_FULLSTOP "fullstop"
#define OPTION_IGNORE_ZEROES "ignore-zeroes"
#define OPTION_STRICT_SEGMENTS "strict-segments"
#define OPTION_DIALECT "dialect"
#define OPTION_TEST "test"
// options for "-W"
#define OPTIONWNO_LABEL_INDENT "no-label-indent"
@ -147,6 +148,7 @@ static void show_help_and_exit(void)
" --" OPTION_MSVC " output errors in MS VS format\n"
" --" OPTION_COLOR " uses ANSI color codes for error output\n"
" --" OPTION_FULLSTOP " use '.' as pseudo opcode prefix\n"
" --" OPTION_DIALECT " VERSION behave like different version\n"
" --" OPTION_TEST " enable experimental features\n"
PLATFORM_OPTION_HELP
" -V, --" OPTION_VERSION " show version and exit\n");
@ -439,6 +441,57 @@ static void define_symbol(const char definition[])
}
struct dialect {
enum version dialect;
const char *version;
const char *description;
};
struct dialect dialects[] = {
{VER_OLDEST_SUPPORTED, "0.85", "(the oldest version supported)"},
{VER_DEPRECATE_REALPC, "0.86", "\"!realpc\" gives a warning, \"!to\" wants a file format"},
{VER_ALLOW_SETPC_IN_PSEUDOPC, "0.93", "\"*=\" no longer ends offset assembly"},
{VER_RIGHTASSOCIATIVEPOWEROF, "0.94.6", "\"power of\" is now right-associative"},
// {VER_, "0.94.7", "empty code segments are no longer included in output file"},
{VER_DISABLED_OBSOLETE_STUFF, "0.94.8", "disabled \"!cbm\", \"!realpc\" and \"!subzone\""},
{VER_NEWFORSYNTAX, "0.94.12", "new \"!for\" syntax"},
// {VER_, "0.95.2", "changed ANC#8 from 0x2b to 0x0b"},
// {VER_CURRENT, "default", "default"},
// {VER_BACKSLASHESCAPING, "", "backslash escaping and strings"},
{VER_FUTURE, "future", "enable all experimental features"},
{0, NULL, NULL} // NULLs terminate
};
// choose dialect (mimic behaviour of different version)
static void set_dialect(const char version[])
{
struct dialect *dia;
// caution, version may be NULL!
if (version) {
// scan array
for (dia = dialects; dia->version; ++dia) {
if (strcmp(version, dia->version) == 0) {
config.wanted_version = dia->dialect;
return; // found
}
}
fputs("Error: Unknown dialect specifier.\n", stderr);
} else {
fputs("Error: No dialect specified.\n", stderr);
}
// output table of possible versions and die
fputs(
"Supported dialects are:\n"
"\n"
"\tdialect\t\tdescription\n"
"\t-------\t\t-----------\n", stderr);
for (dia = dialects; dia->version; ++dia)
fprintf(stderr, "\t%s\t\t%s\n", dia->version, dia->description);
fputc('\n', stderr);
exit(EXIT_FAILURE);
}
// handle long options (like "--example"). Return unknown string.
static const char *long_option(const char *string)
{
@ -478,6 +531,8 @@ static const char *long_option(const char *string)
config.honor_leading_zeroes = FALSE;
else if (strcmp(string, OPTION_STRICT_SEGMENTS) == 0)
config.segment_warning_is_error = TRUE;
else if (strcmp(string, OPTION_DIALECT) == 0)
set_dialect(cliargs_get_next()); // NULL is ok (handled like unknown)
else if (strcmp(string, OPTION_TEST) == 0) {
if (config.test_new_features)
config.wanted_version = VER_FUTURE; // giving "--test" twice enables every new feature

View File

@ -127,7 +127,7 @@ void config_default(struct config *conf)
conf->honor_leading_zeroes = TRUE; // disabled by --ignore-zeroes
conf->segment_warning_is_error = FALSE; // enabled by --strict-segments TODO - toggle default?
conf->test_new_features = FALSE; // enabled by --test
conf->wanted_version = VER_NEWFORSYNTAX; // TODO - add switch to change
conf->wanted_version = VER_CURRENT; // changed by --dialect
}
// memory allocation stuff

View File

@ -57,6 +57,23 @@ extern const char global_byte_flags[];
// TODO - put in runtime struct:
extern char GotByte; // Last byte read (processed)
enum version {
VER_OLDEST_SUPPORTED, // v0.85 looks like the oldest version it makes sense to actually support
VER_DEPRECATE_REALPC, // v0.86 made !pseudopc/!realpc give a warning to use !pseudopc{} instead, and !to wants a file format
VER_ALLOW_SETPC_IN_PSEUDOPC, // v0.93 allowed *= inside !pseudopc blocks
VER_RIGHTASSOCIATIVEPOWEROF, // v0.94.6 made "power of" operator right-associative
// v0.94.7 fixed a bug: empty code segments no longer included in output file
VER_DISABLED_OBSOLETE_STUFF, // v0.94.8 disabled !cbm, !pseudopc/!realpc, !subzone
VER_NEWFORSYNTAX, // v0.94.12 introduced the new "!for" syntax
// v0.95.2 changed ANC#8 from 0x2b to 0x0b
VER_CURRENT, // "RELEASE"
VER_BACKSLASHESCAPING, // backslash escaping (and therefore strings)
// possible changes in future versions:
// paths should be relative to file, not start dir
// ignore leading zeroes?
VER_FUTURE // far future
};
// configuration
struct config {
char pseudoop_prefix; // '!' or '.'
@ -70,35 +87,9 @@ struct config {
boolean honor_leading_zeroes; // TRUE, disabled by --ignore-zeroes
boolean segment_warning_is_error; // FALSE, enabled by --strict-segments
boolean test_new_features; // FALSE, enabled by --test
int wanted_version; // TODO - add switch to set this (in addition to "--test --test")
enum version wanted_version; // TODO - add switch to set this (in addition to "--test --test")
};
extern struct config config;
/* versions that could be supported by "wanted_version":
v0.05:
...would be the syntax before any changes
(how was offset assembly ended? '*' in a line on its own?)
BIT without any arg would output $2c, masking the next two bytes
v0.07:
"leading zeroes" info is now stored in symbols as well
changed argument order of mvp/mvn
!cbm outputs warning to use !ct pet instead
!end changed to !eof
*= is now segment change instead of offset assembly
added !pseudopc/!realpc
*/
#define VER_OLDEST_SUPPORTED 8500 // v0.85 looks like the oldest version it makes sense to actually support
#define VER_DEPRECATE_REALPC 8600 // v0.86 made !pseudopc/!realpc give a warning to use !pseudopc{} instead, and !to wants a file format
#define VER_ALLOW_SETPC_IN_PSEUDOPC 9300 // v0.93 allowed *= inside !pseudopc blocks
#define VER_RIGHTASSOCIATIVEPOWEROF 9406 // v0.94.6 made "power of" operator right-associative
// 9407 // v0.94.7 fixed a bug: empty code segments no longer included in output file
#define VER_DISABLED_OBSOLETE_STUFF 9408 // v0.94.8 disabled !cbm, !pseudopc/!realpc, !subzone
#define VER_NEWFORSYNTAX 9412 // v0.94.12 introduced the new "!for" syntax
// 9502 // v0.95.2 changed ANC#8 from 0x2b to 0x0b
#define VER_BACKSLASHESCAPING 10000 // not yet: backslash escaping (and therefore strings) FIXME - value is bogus!
#define VER_FUTURE 32767
// possible changes in future versions:
// paths should be relative to file, not start dir
// ignore leading zeroes?
struct pass {
int number; // counts up from zero

View File

@ -154,7 +154,7 @@ static enum eos po_to(void)
if (Input_accept_comma() == FALSE) {
if (outputfile_prefer_cbm_format()) {
// output deprecation warning (unless user requests really old behaviour)
if (config.wanted_version > VER_DEPRECATE_REALPC)
if (config.wanted_version >= VER_DEPRECATE_REALPC)
Throw_warning("Used \"!to\" without file format indicator. Defaulting to \"cbm\".");
}
return ENSURE_EOS;