From fcc067e5154bedc92a2e8ab009718d97d1fc94e5 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Fri, 11 Oct 2024 18:50:26 +0100 Subject: [PATCH 1/3] [preproc] support C23 enum underlying type syntax (#2043) --- tools/preproc/asm_file.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index 4eda54a3aa..a82354cb5f 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -524,6 +524,17 @@ bool AsmFile::ParseEnum() long enumCounter = 0; long symbolCount = 0; + if (m_buffer[m_pos] == ':') // : + { + m_pos++; + std::string underlyingType; + do { + currentHeaderLine += SkipWhitespaceAndEol(); + underlyingType = ReadIdentifier(); + } while (!underlyingType.empty()); + currentHeaderLine += SkipWhitespaceAndEol(); + } + if (m_buffer[m_pos] != '{') // assume assembly macro, otherwise assume enum and report errors accordingly { m_pos = fallbackPosition - 4; From 2c7964dbc273b0bed4456cdbd31ed4ee9b0bc783 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Fri, 11 Oct 2024 18:33:32 +0000 Subject: [PATCH 2/3] Fix deleting files with dependency files (#2045) --- Makefile | 4 +--- tools/scaninc/scaninc.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5eaf4cf0bc..ee36562b13 100644 --- a/Makefile +++ b/Makefile @@ -315,10 +315,9 @@ else @echo -e ".text\n\t.align\t2, 0\n" >> $3.s $$(AS) $$(ASFLAGS) -o $$@ $3.s endif +ifneq ($(NODEP),1) $1.d: $2 $(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $2 -ifneq ($(NODEP),1) -$1.o: $1.d -include $1.d endif endef @@ -346,7 +345,6 @@ endef define ASM_SCANINC ifneq ($(NODEP),1) -$1.o: $1.d $1.d: $2 $(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I "" $2 -include $1.d diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index c1b7987a5a..d470a3f163 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -157,19 +157,29 @@ int main(int argc, char **argv) // Print a make rule for the object file size_t ext_pos = make_outfile.find_last_of("."); auto object_file = make_outfile.substr(0, ext_pos + 1) + "o"; - output << object_file.c_str() << ": "; + output << object_file.c_str() << ":"; for (const std::string &path : dependencies) { - output << path << " "; + output << " " << path; } + output << '\n'; // Dependency list rule. // Although these rules are identical, they need to be separate, else make will trigger the rule again after the file is created for the first time. - output << "\n" << make_outfile.c_str() << ": "; + output << make_outfile.c_str() << ":"; for (const std::string &path : dependencies_includes) { - output << path << " "; + output << " " << path; } + output << '\n'; + + // Dummy rules + // If a dependency is deleted, make will try to make it, instead of rescanning the dependencies before trying to do that. + for (const std::string &path : dependencies) + { + output << path << ":\n"; + } + output.flush(); output.close(); } From b6892f5b67782afe05fcd31eaa2d1850bc4e3bc1 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 11 Oct 2024 15:03:38 -0400 Subject: [PATCH 3/3] Let scaninc ignore empty C files --- tools/scaninc/c_file.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/scaninc/c_file.cpp b/tools/scaninc/c_file.cpp index 595f366cbe..c1fe10d374 100644 --- a/tools/scaninc/c_file.cpp +++ b/tools/scaninc/c_file.cpp @@ -33,6 +33,11 @@ CFile::CFile(std::string path) m_size = std::ftell(fp); + if (m_size < 0) + FATAL_ERROR("File size of \"%s\" is less than zero.\n", path.c_str()); + else if (m_size == 0) + return; // Empty file + m_buffer = new char[m_size + 1]; m_buffer[m_size] = 0; @@ -49,7 +54,7 @@ CFile::CFile(std::string path) CFile::~CFile() { - delete[] m_buffer; + if (m_size > 0) delete[] m_buffer; } void CFile::FindIncbins()