diff --git a/src/Makefile b/src/Makefile index b588b5e..1d7809a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,7 +18,7 @@ acme: $(OBJS) strip acme -acme.o: config.h platform.h acme.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c +acme.o: config.h platform.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c alu.o: config.h platform.h cpu.h dynabuf.h encoding.h global.h input.h section.h symbol.h tree.h alu.h alu.c @@ -36,7 +36,7 @@ global.o: config.h platform.h acme.h cpu.h dynabuf.h encoding.h input.h macro.h input.o: config.h alu.h dynabuf.h global.h section.h symbol.h tree.h input.h input.c -macro.o: config.h acme.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c +macro.o: config.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c mnemo.o: config.h alu.h cpu.h dynabuf.h global.h input.h output.h tree.h mnemo.h mnemo.c @@ -44,7 +44,7 @@ output.o: config.h global.h output.h output.c platform.o: config.h platform.h platform.c -pseudoopcodes.o: acme.h alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c +pseudoopcodes.o: alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c section.o: config.h dynabuf.h global.h symbol.h tree.h section.h section.c diff --git a/src/Makefile.dos b/src/Makefile.dos index 9b573a4..f9683c5 100644 --- a/src/Makefile.dos +++ b/src/Makefile.dos @@ -18,7 +18,7 @@ acme: $(OBJS) djp acme.exe djp acmepmod.exe -acme.o: config.h platform.h acme.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c +acme.o: config.h platform.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c alu.o: config.h platform.h cpu.h dynabuf.h encoding.h global.h input.h section.h symbol.h tree.h alu.h alu.c @@ -36,7 +36,7 @@ global.o: config.h platform.h acme.h cpu.h dynabuf.h encoding.h input.h macro.h input.o: config.h alu.h dynabuf.h global.h section.h symbol.h tree.h input.h input.c -macro.o: config.h acme.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c +macro.o: config.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c mnemo.o: config.h alu.h cpu.h dynabuf.h global.h input.h output.h tree.h mnemo.h mnemo.c @@ -44,7 +44,7 @@ output.o: config.h global.h output.h output.c platform.o: config.h platform.h platform.c -pseudoopcodes.o: acme.h alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c +pseudoopcodes.o: alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c section.o: config.h dynabuf.h global.h symbol.h tree.h section.h section.c diff --git a/src/Makefile.mingw b/src/Makefile.mingw index ae379a7..f352f8d 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -21,7 +21,7 @@ acme.exe: acme.o alu.o cliargs.o cpu.o dynabuf.o encoding.o flow.o global.o inpu -acme.o: config.h platform.h acme.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h _dos.h acme.c +acme.o: config.h platform.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h _dos.h acme.c alu.o: config.h platform.h cpu.h dynabuf.h encoding.h global.h input.h section.h symbol.h tree.h alu.h alu.c @@ -39,7 +39,7 @@ global.o: config.h platform.h acme.h cpu.h dynabuf.h encoding.h input.h macro.h input.o: config.h alu.h dynabuf.h global.h section.h symbol.h tree.h input.h input.c -macro.o: config.h acme.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c +macro.o: config.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c mnemo.o: config.h alu.h cpu.h dynabuf.h global.h input.h output.h tree.h mnemo.h mnemo.c @@ -47,7 +47,7 @@ output.o: config.h global.h output.h output.c platform.o: config.h platform.h platform.c -pseudoopcodes.o: acme.h alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c +pseudoopcodes.o: alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c section.o: config.h dynabuf.h global.h symbol.h tree.h section.h section.c diff --git a/src/Makefile.riscos b/src/Makefile.riscos index 343df4e..17cca58 100644 --- a/src/Makefile.riscos +++ b/src/Makefile.riscos @@ -17,7 +17,7 @@ acme: $(OBJS) $(CC) $(LINKFLAGS) -o acme $(OBJS) $(LIBS) Squeeze -f -v acme ^.^.output.!ACME.!RunImage -acme.o: config.h platform.h acme.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c +acme.o: config.h platform.h alu.h cpu.h dynabuf.h encoding.h flow.h global.h input.h macro.h mnemo.h output.h pseudoopcodes.h section.h symbol.h version.h acme.h acme.c alu.o: config.h platform.h cpu.h dynabuf.h encoding.h global.h input.h section.h symbol.h tree.h alu.h alu.c @@ -35,7 +35,7 @@ global.o: config.h platform.h acme.h cpu.h dynabuf.h encoding.h input.h macro.h input.o: config.h alu.h dynabuf.h global.h section.h symbol.h tree.h input.h input.c -macro.o: config.h acme.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c +macro.o: config.h alu.h dynabuf.h global.h input.h section.h symbol.h tree.h macro.h macro.c mnemo.o: config.h alu.h cpu.h dynabuf.h global.h input.h output.h tree.h mnemo.h mnemo.c @@ -43,7 +43,7 @@ output.o: config.h global.h output.h output.c platform.o: config.h platform.h platform.c -pseudoopcodes.o: acme.h alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c +pseudoopcodes.o: alu.h flow.h global.h input.h macro.h output.h symbol.h pseudoopcodes.h pseudoopcodes.c section.o: config.h dynabuf.h global.h symbol.h tree.h section.h section.c diff --git a/src/acme.c b/src/acme.c index 0c6ed38..67bf61b 100644 --- a/src/acme.c +++ b/src/acme.c @@ -80,9 +80,6 @@ static const char arg_vicelabels[] = "VICE labels filename"; // variables static const char **toplevel_sources; static int toplevel_src_count = 0; -// maximum recursion depth for macro calls and "!source" -signed long macro_recursions_left = MAX_NESTING; -signed long source_recursions_left = MAX_NESTING; // show release and platform info (and exit, if wanted) @@ -364,6 +361,9 @@ static boolean do_actual_work(void) if (config.process_verbosity > 1) puts("Further pass."); perform_pass(); + if (--sanity.passes_left < 0) { + // FIXME - exit with error + } } // any errors left? if (pass.undefined_count == 0) { // FIXME - use pass.needvalue_count instead! @@ -599,9 +599,7 @@ static const char *long_option(const char *string) else if (strcmp(string, OPTION_MAXERRORS) == 0) config.max_errors = string_to_number(cliargs_safe_get_next("maximum error count")); else if (strcmp(string, OPTION_MAXDEPTH) == 0) - macro_recursions_left = (source_recursions_left = string_to_number(cliargs_safe_get_next("recursion depth"))); -// else if (strcmp(string, "strictsyntax") == 0) -// strict_syntax = TRUE; + config.sanity_limit = string_to_number(cliargs_safe_get_next("recursion depth")); else if (strcmp(string, OPTION_USE_STDOUT) == 0) config.msg_stream = stdout; else if (strcmp(string, OPTION_MSVC) == 0) @@ -738,6 +736,10 @@ int main(int argc, const char *argv[]) exit(EXIT_FAILURE); } + sanity.macro_recursions_left = config.sanity_limit; + sanity.source_recursions_left = config.sanity_limit; + sanity.passes_left = config.sanity_limit; + // init output buffer output_createbuffer(); // do the actual work diff --git a/src/acme.h b/src/acme.h index 25bd282..0566013 100644 --- a/src/acme.h +++ b/src/acme.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2024 Marco Baye // Have a look at "acme.c" for further info // // Main definitions @@ -7,12 +7,7 @@ #define acme_H -#include "config.h" - - -// maximum recursion depth for macro calls and "!source" -extern signed long macro_recursions_left; -extern signed long source_recursions_left; +//#include "config.h" // Prototypes diff --git a/src/config.h b/src/config.h index f79527b..f47897f 100644 --- a/src/config.h +++ b/src/config.h @@ -69,9 +69,9 @@ struct listitem { // debugging flag, should be undefined in release version // #define FDEBUG -// maximum nesting depth of "!src" and macro calls +// maximum nesting depth of "!src" and macro calls, also max number of passes // is not actually a limitation, but a means of finding recursions -#define MAX_NESTING 64 +#define SANITY_LIMIT 64 // default value for "!fill" #define FILLVALUE_FILL 0 diff --git a/src/global.c b/src/global.c index f1aca07..502794c 100644 --- a/src/global.c +++ b/src/global.c @@ -103,6 +103,7 @@ char GotByte; // Last byte read (processed) struct report *report = NULL; struct config config; struct pass pass; +struct sanity sanity; // set configuration to default values void config_default(struct config *conf) @@ -113,6 +114,7 @@ void config_default(struct config *conf) conf->warn_on_type_mismatch = FALSE; // use type-checking system conf->warn_bin_mask = 3; // %11 -> warn if not divisible by four conf->max_errors = MAXERRORS; // errors before giving up + conf->sanity_limit = SANITY_LIMIT; // changed by --maxdepth conf->format_msvc = FALSE; // enabled by --msvc conf->format_color = FALSE; // enabled by --color conf->msg_stream = stderr; // set to stdout by --use-stdout diff --git a/src/global.h b/src/global.h index d3642e1..8049cdb 100644 --- a/src/global.h +++ b/src/global.h @@ -81,7 +81,8 @@ struct config { boolean warn_on_indented_labels; // warn if indented label is encountered boolean warn_on_type_mismatch; // use type-checking system int warn_bin_mask; // bitmask for digit counter of binary literals - signed long max_errors; // errors before giving up + int max_errors; // errors before giving up + int sanity_limit; // max recursion depth for "!src" and macro calls, also max number of passes boolean format_msvc; // enabled by --msvc boolean format_color; // enabled by --color FILE *msg_stream; // defaults to stderr, changed to stdout by --use-stdout @@ -118,6 +119,13 @@ struct pass { extern struct pass pass; #define FIRST_PASS (pass.number == 0) +struct sanity { + int macro_recursions_left; // for macro calls + int source_recursions_left; // for "!src" + int passes_left; +}; +extern struct sanity sanity; + // report stuff #define REPORT_ASCBUFSIZE 1024 #define REPORT_BINBUFSIZE 9 // eight are shown, then "..." diff --git a/src/macro.c b/src/macro.c index bf522fa..e977a71 100644 --- a/src/macro.c +++ b/src/macro.c @@ -7,7 +7,6 @@ #include // needs strlen() + memcpy() #include "config.h" #include "platform.h" -#include "acme.h" #include "alu.h" #include "dynabuf.h" #include "global.h" @@ -230,7 +229,7 @@ void macro_parse_call(void) // Now GotByte = first char of macro name // Enter deeper nesting level // Quit program if recursion too deep. - if (--macro_recursions_left < 0) + if (--sanity.macro_recursions_left < 0) Throw_serious_error("Too deeply nested. Recursive macro calls?"); macro_scope = get_scope_and_title(); // now GotByte = first non-space after title @@ -348,5 +347,5 @@ void macro_parse_call(void) // Now GotByte = first char of macro name input_ensure_EOS(); } - ++macro_recursions_left; // leave this nesting level + ++sanity.macro_recursions_left; // leave this nesting level } diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index 0020640..44f8f34 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -7,7 +7,6 @@ #include #include #include // for memcpy() -#include "acme.h" #include "config.h" #include "cpu.h" #include "alu.h" @@ -920,7 +919,7 @@ static enum eos po_source(void) // now GotByte = illegal char // enter new nesting level // quit program if recursion too deep - if (--source_recursions_left < 0) + if (--sanity.source_recursions_left < 0) Throw_serious_error("Too deeply nested. Recursive \"!source\"?"); // read file name. quit function on error if (input_read_input_filename(&uses_lib)) @@ -948,7 +947,7 @@ static enum eos po_source(void) // now GotByte = illegal char #endif } // leave nesting level - ++source_recursions_left; + ++sanity.source_recursions_left; return ENSURE_EOS; } diff --git a/src/version.h b/src/version.h index 0b57f1a..ed1f15e 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.97" // update before release FIXME #define CODENAME "Zem" // update before release -#define CHANGE_DATE "17 Feb" // update before release FIXME +#define CHANGE_DATE "18 Feb" // update before release FIXME #define CHANGE_YEAR "2024" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME diff --git a/testing/errors/recursive-macro.a b/testing/errors/recursive-macro.a new file mode 100644 index 0000000..f8a6046 --- /dev/null +++ b/testing/errors/recursive-macro.a @@ -0,0 +1,4 @@ + !macro recursive @dummy { + +recursive @dummy + } + +recursive 42 ; -> "Too deeply nested. Recursive macro calls?" diff --git a/testing/errors/recursive-src.a b/testing/errors/recursive-src.a new file mode 100644 index 0000000..decd68e --- /dev/null +++ b/testing/errors/recursive-src.a @@ -0,0 +1 @@ + !src "recursive-src.a" ; -> "Too deeply nested. Recursive "!source"?"