From 16111f46ef95c45603d3929f1174cb7f8e916aee Mon Sep 17 00:00:00 2001 From: Ben Hetherington Date: Fri, 16 Aug 2019 13:20:15 +0100 Subject: [PATCH] Allow PUSHS to be used before a section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, a PUSHS before a SECTION directive would cause rgbasm to crash when encountering a subsequent POPS. This is because the subsequently-called out_setCurrentSection() expected the new section to be non-null, which wasn’t the case in this situation. This has been addressed by allowing the ‘null’ section to be set in this function, and only dereferencing it (to set nPC) if a non-null section is to be set. In practice, this means that PUSHS/POPS can now be used to push/restore a context without a section. --- src/asm/output.c | 4 ++-- test/asm/pops-no-pushed-sections.asm | 1 + test/asm/pops-no-pushed-sections.out | 2 ++ test/asm/pops-no-pushed-sections.out.pipe | 2 ++ test/asm/pops-restore-no-section.asm | 10 ++++++++++ test/asm/pops-restore-no-section.out | 2 ++ test/asm/pops-restore-no-section.out.pipe | 2 ++ test/asm/pushs-outside-section.asm | 2 ++ test/asm/pushs-outside-section.out | 0 test/asm/pushs-outside-section.out.pipe | 0 10 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/asm/pops-no-pushed-sections.asm create mode 100644 test/asm/pops-no-pushed-sections.out create mode 100644 test/asm/pops-no-pushed-sections.out.pipe create mode 100644 test/asm/pops-restore-no-section.asm create mode 100644 test/asm/pops-restore-no-section.out create mode 100644 test/asm/pops-restore-no-section.out.pipe create mode 100644 test/asm/pushs-outside-section.asm create mode 100644 test/asm/pushs-outside-section.out create mode 100644 test/asm/pushs-outside-section.out.pipe diff --git a/src/asm/output.c b/src/asm/output.c index e7c1902a..ed643df7 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -1,7 +1,7 @@ /* * This file is part of RGBDS. * - * Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors. + * Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors. * * SPDX-License-Identifier: MIT */ @@ -655,7 +655,7 @@ void out_SetCurrentSection(struct Section *pSect) fatalerror("Cannot change the section within a UNION"); pCurrentSection = pSect; - nPC = pSect->nPC; + nPC = (pSect != NULL) ? pSect->nPC : 0; pPCSymbol->nValue = nPC; pPCSymbol->pSection = pCurrentSection; diff --git a/test/asm/pops-no-pushed-sections.asm b/test/asm/pops-no-pushed-sections.asm new file mode 100644 index 00000000..4150a093 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.asm @@ -0,0 +1 @@ +POPS diff --git a/test/asm/pops-no-pushed-sections.out b/test/asm/pops-no-pushed-sections.out new file mode 100644 index 00000000..4f8c06c1 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.out @@ -0,0 +1,2 @@ +ERROR: pops-no-pushed-sections.asm(1): + No entries in the section stack diff --git a/test/asm/pops-no-pushed-sections.out.pipe b/test/asm/pops-no-pushed-sections.out.pipe new file mode 100644 index 00000000..9e3a0bf8 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.out.pipe @@ -0,0 +1,2 @@ +ERROR: -(1): + No entries in the section stack diff --git a/test/asm/pops-restore-no-section.asm b/test/asm/pops-restore-no-section.asm new file mode 100644 index 00000000..c6fef881 --- /dev/null +++ b/test/asm/pops-restore-no-section.asm @@ -0,0 +1,10 @@ +PUSHS + +SECTION "Test", ROM0 +SomeContent: + db 1, 2, 3, 4, 5, 6, 7, 8, 9 + +POPS + +DisallowedContent: + db 0 diff --git a/test/asm/pops-restore-no-section.out b/test/asm/pops-restore-no-section.out new file mode 100644 index 00000000..3a0e1cbe --- /dev/null +++ b/test/asm/pops-restore-no-section.out @@ -0,0 +1,2 @@ +ERROR: pops-restore-no-section.asm(10): + Code generation before SECTION directive diff --git a/test/asm/pops-restore-no-section.out.pipe b/test/asm/pops-restore-no-section.out.pipe new file mode 100644 index 00000000..b0a3984a --- /dev/null +++ b/test/asm/pops-restore-no-section.out.pipe @@ -0,0 +1,2 @@ +ERROR: -(10): + Code generation before SECTION directive diff --git a/test/asm/pushs-outside-section.asm b/test/asm/pushs-outside-section.asm new file mode 100644 index 00000000..8226722c --- /dev/null +++ b/test/asm/pushs-outside-section.asm @@ -0,0 +1,2 @@ +PUSHS +POPS diff --git a/test/asm/pushs-outside-section.out b/test/asm/pushs-outside-section.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/pushs-outside-section.out.pipe b/test/asm/pushs-outside-section.out.pipe new file mode 100644 index 00000000..e69de29b