From 0fd4b86c9899d254d9aea0660e5046c4234cfd42 Mon Sep 17 00:00:00 2001 From: ggn Date: Wed, 7 Sep 2016 14:18:24 +0300 Subject: [PATCH] Added .opt directive with similar syntax to command line. Example syntax: '.opt "~all" "+o1"' etc. Signed-off-by: Shamus Hammons --- direct.c | 26 ++++++++++++++++++++++++ direct.h | 4 +--- eagen0.c | 4 ++++ mntab | 2 ++ rmac.c | 62 +++++++++++++++++++++++++++++++++----------------------- rmac.h | 1 + 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/direct.c b/direct.c index 70f4469..7010e46 100644 --- a/direct.c +++ b/direct.c @@ -88,6 +88,7 @@ int (*dirtab[])() = { d_nojpad, // 55 .nojpad (deprecated) d_gpumain, // 56 .gpumain (deprecated) d_prgflags, // 57 .prgflags + d_opt, // 58 .opt }; @@ -1589,3 +1590,28 @@ int d_gpumain(void) return error("What the hell? Do you think we adhere to the Goof standard?"); } +// +// .opt - turn a specific (or all) optimisation on or off +// +int d_opt(void) +{ + char * tmpstr; + + while (*tok != EOL) + { + if (*tok == STRING) + { + tok++; + tmpstr = string[*tok++]; + + if (ParseOptimization(tmpstr) != OK) + { + char temperr[256]; + sprintf(temperr, "unknown optimisation flag '%s'.", tmpstr); + return error(temperr); + } + } + else + return error(".opt directive needs every switch enclosed inside quotation marks."); + } +} \ No newline at end of file diff --git a/direct.h b/direct.h index e95b6dd..2c5ce3a 100644 --- a/direct.h +++ b/direct.h @@ -69,9 +69,7 @@ int d_fail(void); int symlist(int(*)()); int abs_expr(VALUE *); int d_cstruct(void); -int d_jpad(void); -int d_nojpad(void); -int d_gpumain(void); int d_prgflags(void); +int d_opt(void); #endif // __DIRECT_H__ diff --git a/eagen0.c b/eagen0.c index 7ec6ccb..bf4ba3d 100644 --- a/eagen0.c +++ b/eagen0.c @@ -65,6 +65,10 @@ int eaNgen(WORD siz) chptr_opcode[0] |= ((0x0080 >> 8) & 255); // slap in 010 bits chptr_opcode[1] |= 0x0080 & 255; // slap in 010 bits } + + if (sbra_flag) + warn("0(An) converted to (An)"); + return OK; } diff --git a/mntab b/mntab index 9bbc003..56a87cf 100644 --- a/mntab +++ b/mntab @@ -98,6 +98,8 @@ nojpad 55 gpumain 56 .prgflags 57 prgflags 57 +opt 58 +.opt 58 .if 500 if 500 .else 501 diff --git a/rmac.c b/rmac.c index 3d1fffa..45cd1d8 100644 --- a/rmac.c +++ b/rmac.c @@ -171,6 +171,42 @@ void DisplayVersion(void) } +// +// Parse optimisation options +// +int ParseOptimization(char * optstring) +{ + int onoff = 0; + + if (*optstring == '+') + onoff = 1; + else if (*optstring != '~') + return ERROR; + + if ((optstring[2] == 'a' || optstring[2] == 'A') && + (optstring[3] == 'l' || optstring[3] == 'L') && + (optstring[4] == 'l' || optstring[4] == 'L')) + { + memset(optim_flags, onoff, OPT_COUNT * sizeof(int)); + return OK; + } + else if (optstring[1] == 'o' || optstring[1] == 'O') //Turn on specific optimisation + { + int opt_no = atoi(&optstring[2]); + if ((opt_no >= 0) && (opt_no < OPT_COUNT)) + optim_flags[opt_no] = onoff; + else + { + return ERROR; + } + } + else + { + return ERROR; + } +} + + // // Process command line arguments and do an assembly // @@ -409,31 +445,7 @@ int Process(int argc, char ** argv) } else if (*argv[argno] == '+' || *argv[argno] == '~') { - int onoff = 0; - - if (*argv[argno] == '+') - onoff = 1; - - if ((argv[argno][2] == 'a' || argv[argno][2] == 'A') - && (argv[argno][3] == 'l' || argv[argno][3] == 'L') - && (argv[argno][4] == 'l' || argv[argno][4] == 'L')) - memset(optim_flags, onoff, OPT_COUNT * sizeof(int)); - else if (argv[argno][1] == 'o' || argv[argno][1] == 'O') // Turn on specific optimisation - { - int opt_no = atoi(&argv[argno][2]); - - if ((opt_no >= 0) && (opt_no < OPT_COUNT)) - optim_flags[opt_no] = onoff; - else - { - DisplayVersion(); - printf("Unknown switch: %s\n\n", argv[argno]); - DisplayHelp(); - errcnt++; - break; - } - } - else + if (ParseOptimization(argv[argno]) != OK) { DisplayVersion(); printf("Unknown switch: %s\n\n", argv[argno]); diff --git a/rmac.h b/rmac.h index 39b8ae6..1fa419b 100644 --- a/rmac.h +++ b/rmac.h @@ -216,6 +216,7 @@ extern int optim_flags[OPT_COUNT]; // Exported functions char * fext(char *, char *, int); int nthpath(char *, int, char *); +int ParseOptimization(char * optstring); #endif // __RMAC_H__ -- 2.37.2