From 045a9e8b93048379b60afc9992d6f245d5129a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Mon, 12 Oct 2020 03:32:49 +0200 Subject: [PATCH] Report only one error when invalid shift has argument Not to mention that incrementing a variable in a loop is kinda dumb. --- include/asm/macro.h | 2 +- src/asm/macro.c | 9 ++++++--- src/asm/parser.y | 9 ++------- test/asm/shift-outside-macro.asm | 1 + test/asm/shift-outside-macro.err | 4 +++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/asm/macro.h b/include/asm/macro.h index 855133f8..6ec997b6 100644 --- a/include/asm/macro.h +++ b/include/asm/macro.h @@ -29,7 +29,7 @@ uint32_t macro_GetUniqueID(void); char const *macro_GetUniqueIDStr(void); void macro_SetUniqueID(uint32_t id); uint32_t macro_UseNewUniqueID(void); -void macro_ShiftCurrentArgs(void); +void macro_ShiftCurrentArgs(int32_t count); uint32_t macro_NbArgs(void); #endif diff --git a/src/asm/macro.c b/src/asm/macro.c index aa4903c4..49f38fc1 100644 --- a/src/asm/macro.c +++ b/src/asm/macro.c @@ -128,12 +128,15 @@ uint32_t macro_UseNewUniqueID(void) return maxUniqueID; } -void macro_ShiftCurrentArgs(void) +void macro_ShiftCurrentArgs(int32_t count) { if (!macroArgs) error("Cannot shift macro arguments outside of a macro\n"); - else if (macroArgs->shift != macroArgs->nbArgs) - macroArgs->shift++; + else if (macroArgs->shift < macroArgs->nbArgs) { + macroArgs->shift += count; + if (macroArgs->shift > macroArgs->nbArgs) + macroArgs->shift = macroArgs->nbArgs; + } } uint32_t macro_NbArgs(void) diff --git a/src/asm/parser.y b/src/asm/parser.y index 183adcbb..9ebf4775 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -579,13 +579,8 @@ assert : T_POP_ASSERT assert_type relocexpr } ; -shift : T_POP_SHIFT { macro_ShiftCurrentArgs(); } - | T_POP_SHIFT uconst - { - int32_t i = $2; - while (i--) - macro_ShiftCurrentArgs(); - } +shift : T_POP_SHIFT { macro_ShiftCurrentArgs(1); } + | T_POP_SHIFT uconst { macro_ShiftCurrentArgs($2); } ; load : T_POP_LOAD string ',' sectiontype sectorg sectattrs { diff --git a/test/asm/shift-outside-macro.asm b/test/asm/shift-outside-macro.asm index b46387d6..ca859616 100644 --- a/test/asm/shift-outside-macro.asm +++ b/test/asm/shift-outside-macro.asm @@ -1 +1,2 @@ shift +shift 3 diff --git a/test/asm/shift-outside-macro.err b/test/asm/shift-outside-macro.err index 5f050f3d..42cf6c9b 100644 --- a/test/asm/shift-outside-macro.err +++ b/test/asm/shift-outside-macro.err @@ -1,3 +1,5 @@ ERROR: shift-outside-macro.asm(1): Cannot shift macro arguments outside of a macro -error: Assembly aborted (1 errors)! +ERROR: shift-outside-macro.asm(2): + Cannot shift macro arguments outside of a macro +error: Assembly aborted (2 errors)!