From ff2321a8ce30c6d0af0e38b0383361b8841914a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Sat, 29 Apr 2017 15:02:57 +0100 Subject: [PATCH] Make fatalerror and yyerror consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two ways in which the assembly process can fail: 1. If there is a really big problem that compromises the whole process, the assembler has to stop right there and generate an error message. This happens with unterminated REPT loops, macros, etc. 2. If the problem isn't that big and the process can still continue, even though the final result is invalid, the assembler can try to continue and warn the user about all errors it finds in the code. This patch clarifies the use of each function and replaces the function used in two places by the correct one. Signed-off-by: Antonio Niño Díaz --- include/asm/main.h | 17 +++++++++++++++++ src/asm/lexer.c | 4 ++-- src/asm/output.c | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/asm/main.h b/include/asm/main.h index 8ea718a4..7fa446bb 100644 --- a/include/asm/main.h +++ b/include/asm/main.h @@ -26,8 +26,25 @@ extern void opt_Push(void); extern void opt_Pop(void); extern void opt_Parse(char *s); +/* + * Used for errors that compromise the whole assembly process by affecting the + * folliwing code, potencially making the assembler generate errors caused by + * the first one and unrelated to the code that the assembler complains about. + * It is also used when the assembler goes into an invalid state (for example, + * when it fails to allocate memory). + */ noreturn void fatalerror(const char *fmt, ...); +/* + * Used for errors that make it impossible to assemble correctly, but don't + * affect the following code. The code will fail to assemble but the user will + * get a list of all errors at the end, making it easier to fix all of them at + * once. + */ void yyerror(const char *fmt, ...); +/* + * Used to warn the user about problems that don't prevent the generation of + * valid code. + */ void warning(const char *fmt, ...); #define YY_FATAL_ERROR fatalerror diff --git a/src/asm/lexer.c b/src/asm/lexer.c index f456636e..a650273e 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -535,7 +535,7 @@ yylex_ReadBracketedSymbol(char *dest, size_t index) if (*pLexBuffer == '}') pLexBuffer++; else - yyerror("Missing }"); + fatalerror("Missing }"); return length; } @@ -601,7 +601,7 @@ yylex_ReadQuotedString() if (*pLexBuffer == '"') pLexBuffer++; else - yyerror("Unterminated string"); + fatalerror("Unterminated string"); } ULONG diff --git a/src/asm/output.c b/src/asm/output.c index 4bc1ae9e..35961dc8 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -480,7 +480,8 @@ checksectionoverflow(ULONG delta_size) /* * This check is here to trap broken code that generates * sections that are too big and to prevent the assembler from - * generating huge object files. + * generating huge object files or trying to allocate too much + * memory. * The real check must be done at the linking stage. */ fatalerror("Section '%s' is too big (max size = 0x%X bytes).",