diff --git a/Makefile b/Makefile index f84101ca..14a572a0 100644 --- a/Makefile +++ b/Makefile @@ -240,12 +240,12 @@ coverage: # Target used in development to format source code with clang-format. format: - $Qclang-format -i include/**/*.hpp src/**/*.cpp + $Qclang-format -i $$(git ls-files 'include/**/*.hpp' 'src/**/*.cpp') # Target used in development to check code with clang-tidy. # Requires Bison-generated header files to exist. tidy: src/asm/parser.hpp src/link/script.hpp - $Qclang-tidy -p . $$(find src -name '*.cpp') + $Qclang-tidy -p . $$(git ls-files 'include/**/*.hpp' 'src/**/*.cpp') # Target used in development to remove unused `#include` headers. iwyu: diff --git a/include/asm/actions.hpp b/include/asm/actions.hpp index 4e36ffa2..72d4173b 100644 --- a/include/asm/actions.hpp +++ b/include/asm/actions.hpp @@ -4,14 +4,16 @@ #define RGBDS_ASM_ACTIONS_HPP #include +#include #include #include #include #include #include -#include "asm/output.hpp" // AssertionType -#include "asm/rpn.hpp" // RPNCommand +#include "linkdefs.hpp" // AssertionType, RPNCommand + +#include "asm/rpn.hpp" // Expression struct AlignmentSpec { uint8_t alignment; diff --git a/include/asm/charmap.hpp b/include/asm/charmap.hpp index b1292ca5..18d851a3 100644 --- a/include/asm/charmap.hpp +++ b/include/asm/charmap.hpp @@ -4,6 +4,7 @@ #define RGBDS_ASM_CHARMAP_HPP #include +#include #include #include #include diff --git a/include/asm/lexer.hpp b/include/asm/lexer.hpp index c86762de..0b7288a7 100644 --- a/include/asm/lexer.hpp +++ b/include/asm/lexer.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/include/asm/main.hpp b/include/asm/main.hpp index 02775829..a1dbbfe8 100644 --- a/include/asm/main.hpp +++ b/include/asm/main.hpp @@ -7,8 +7,6 @@ #include #include -#include "verbosity.hpp" - enum MissingInclude { INC_ERROR, // A missing included file is an error that halts assembly GEN_EXIT, // A missing included file is assumed to be generated; exit normally diff --git a/include/asm/output.hpp b/include/asm/output.hpp index 310f78a0..ba457a60 100644 --- a/include/asm/output.hpp +++ b/include/asm/output.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "linkdefs.hpp" diff --git a/include/asm/section.hpp b/include/asm/section.hpp index 28ea1dad..0c5bcd53 100644 --- a/include/asm/section.hpp +++ b/include/asm/section.hpp @@ -6,9 +6,9 @@ #include #include #include +#include #include #include -#include #include #include "linkdefs.hpp" diff --git a/include/asm/symbol.hpp b/include/asm/symbol.hpp index 967994ae..779fe9fc 100644 --- a/include/asm/symbol.hpp +++ b/include/asm/symbol.hpp @@ -5,9 +5,7 @@ #include #include -#include #include -#include #include #include #include diff --git a/include/diagnostics.hpp b/include/diagnostics.hpp index 3a8dc7d8..796e58b9 100644 --- a/include/diagnostics.hpp +++ b/include/diagnostics.hpp @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include #include #include "helpers.hpp" diff --git a/include/file.hpp b/include/file.hpp index 4b73451c..b0c3489a 100644 --- a/include/file.hpp +++ b/include/file.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/include/fix/warning.hpp b/include/fix/warning.hpp index 44392344..d091e2a7 100644 --- a/include/fix/warning.hpp +++ b/include/fix/warning.hpp @@ -3,6 +3,8 @@ #ifndef RGBDS_FIX_WARNING_HPP #define RGBDS_FIX_WARNING_HPP +#include + #include "diagnostics.hpp" enum WarningLevel { diff --git a/include/gfx/main.hpp b/include/gfx/main.hpp index 83af6838..52001389 100644 --- a/include/gfx/main.hpp +++ b/include/gfx/main.hpp @@ -5,13 +5,12 @@ #include #include +#include #include #include -#include #include #include "helpers.hpp" -#include "verbosity.hpp" #include "gfx/rgba.hpp" diff --git a/include/gfx/pal_sorting.hpp b/include/gfx/pal_sorting.hpp index 19f2b268..adbe5a9c 100644 --- a/include/gfx/pal_sorting.hpp +++ b/include/gfx/pal_sorting.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include "gfx/rgba.hpp" diff --git a/include/gfx/png.hpp b/include/gfx/png.hpp index 18b43484..4869bdd8 100644 --- a/include/gfx/png.hpp +++ b/include/gfx/png.hpp @@ -3,8 +3,8 @@ #ifndef RGBDS_GFX_PNG_HPP #define RGBDS_GFX_PNG_HPP -#include #include +#include #include #include "gfx/rgba.hpp" diff --git a/include/link/section.hpp b/include/link/section.hpp index 4330a95e..a474f279 100644 --- a/include/link/section.hpp +++ b/include/link/section.hpp @@ -3,9 +3,6 @@ #ifndef RGBDS_LINK_SECTION_HPP #define RGBDS_LINK_SECTION_HPP -// GUIDELINE: external code MUST NOT BE AWARE of the data structure used! - -#include #include #include #include @@ -13,8 +10,6 @@ #include "linkdefs.hpp" -#include "link/main.hpp" - struct FileStackNode; struct Section; struct Symbol; diff --git a/include/linkdefs.hpp b/include/linkdefs.hpp index a12b1215..9ffc944a 100644 --- a/include/linkdefs.hpp +++ b/include/linkdefs.hpp @@ -101,18 +101,18 @@ extern struct SectionTypeInfo { // Tells whether a section has data in its object file definition, // depending on type. -static inline bool sect_HasData(SectionType type) { +static inline bool sectTypeHasData(SectionType type) { assume(type != SECTTYPE_INVALID); return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX; } // Returns a memory region's end address (last byte), e.g. 0x7FFF -static inline uint16_t endaddr(SectionType type) { +static inline uint16_t sectTypeEndAddr(SectionType type) { return sectionTypeInfo[type].startAddr + sectionTypeInfo[type].size - 1; } // Returns a memory region's number of banks, or 1 for regions without banking -static inline uint32_t nbbanks(SectionType type) { +static inline uint32_t sectTypeBanks(SectionType type) { return sectionTypeInfo[type].lastBank - sectionTypeInfo[type].firstBank + 1; } diff --git a/src/asm/actions.cpp b/src/asm/actions.cpp index 62de9fa2..804145e1 100644 --- a/src/asm/actions.cpp +++ b/src/asm/actions.cpp @@ -2,16 +2,30 @@ #include "asm/actions.hpp" +#include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include "extern/utf8decoder.hpp" #include "helpers.hpp" +#include "linkdefs.hpp" #include "asm/charmap.hpp" #include "asm/format.hpp" #include "asm/fstack.hpp" +#include "asm/lexer.hpp" +#include "asm/output.hpp" +#include "asm/rpn.hpp" // Expression +#include "asm/section.hpp" #include "asm/symbol.hpp" #include "asm/warning.hpp" diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index 6660f674..f2ab2778 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -4,12 +4,17 @@ #include #include +#include #include +#include #include #include #include +#include +#include #include #include +#include #include "extern/utf8decoder.hpp" #include "helpers.hpp" diff --git a/src/asm/fixpoint.cpp b/src/asm/fixpoint.cpp index 7b229c55..d8097bac 100644 --- a/src/asm/fixpoint.cpp +++ b/src/asm/fixpoint.cpp @@ -6,6 +6,7 @@ #include #include +#include static constexpr double tau = std::numbers::pi * 2; diff --git a/src/asm/format.cpp b/src/asm/format.cpp index 266032eb..ecea78f5 100644 --- a/src/asm/format.cpp +++ b/src/asm/format.cpp @@ -5,11 +5,12 @@ #include #include #include +#include #include #include #include +#include -#include "asm/fixpoint.hpp" #include "asm/main.hpp" // options #include "asm/warning.hpp" diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index da18714e..d32cf63f 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -7,15 +7,20 @@ #include #include #include +#include #include +#include #include #include +#include +#include +#include +#include +#include #include "backtrace.hpp" -#include "diagnostics.hpp" #include "helpers.hpp" #include "linkdefs.hpp" -#include "platform.hpp" // S_ISDIR (stat macro) #include "verbosity.hpp" #include "asm/lexer.hpp" diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index aa59f45b..322aeeef 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -2,27 +2,34 @@ #include "asm/lexer.hpp" #include -#include #include #include #include #include #include +#include #include #include +#include #include // nothrow +#include +#include #include #include #include +#include #include +#include +#include +#include #include "helpers.hpp" +#include "platform.hpp" #include "style.hpp" #include "util.hpp" #include "verbosity.hpp" -#include "asm/fixpoint.hpp" #include "asm/format.hpp" #include "asm/fstack.hpp" #include "asm/macro.hpp" diff --git a/src/asm/macro.cpp b/src/asm/macro.cpp index a8f597b6..cc314280 100644 --- a/src/asm/macro.cpp +++ b/src/asm/macro.cpp @@ -2,6 +2,8 @@ #include "asm/macro.hpp" +#include +#include #include #include #include diff --git a/src/asm/main.cpp b/src/asm/main.cpp index 590c513a..f678e2c6 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -4,18 +4,25 @@ #include #include -#include +#include #include #include +#include +#include #include #include +#include #include +#include +#include +#include #include "backtrace.hpp" #include "diagnostics.hpp" #include "extern/getopt.hpp" #include "helpers.hpp" #include "parser.hpp" // Generated from parser.y +#include "platform.hpp" #include "style.hpp" #include "usage.hpp" #include "util.hpp" // UpperMap @@ -26,6 +33,7 @@ #include "asm/fstack.hpp" #include "asm/opt.hpp" #include "asm/output.hpp" +#include "asm/section.hpp" #include "asm/symbol.hpp" #include "asm/warning.hpp" diff --git a/src/asm/opt.cpp b/src/asm/opt.cpp index 5201be3d..942019ad 100644 --- a/src/asm/opt.cpp +++ b/src/asm/opt.cpp @@ -1,19 +1,20 @@ // SPDX-License-Identifier: MIT #include +#include // std::size #include +#include #include #include #include +#include "diagnostics.hpp" #include "helpers.hpp" // assume #include "util.hpp" // isBlankSpace -#include "asm/fixpoint.hpp" #include "asm/fstack.hpp" #include "asm/lexer.hpp" #include "asm/main.hpp" // options -#include "asm/section.hpp" #include "asm/warning.hpp" struct OptStackEntry { diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 47706218..f0a73cec 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -6,13 +6,16 @@ #include #include #include +#include +#include #include #include #include #include +#include -#include "diagnostics.hpp" #include "helpers.hpp" // assume, Defer +#include "linkdefs.hpp" #include "platform.hpp" #include "asm/charmap.hpp" @@ -93,7 +96,7 @@ static void writeSection(Section const §, FILE *file) { putc(sect.align, file); putLong(sect.alignOfs, file); - if (sect_HasData(sect.type)) { + if (sectTypeHasData(sect.type)) { fwrite(sect.data.data(), 1, sect.size, file); putLong(sect.patches.size(), file); diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index f0f3e595..1ccf4e4a 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -5,12 +5,16 @@ #include #include #include +#include #include #include #include +#include #include +#include #include "helpers.hpp" // assume +#include "linkdefs.hpp" #include "opmath.hpp" #include "asm/output.hpp" diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 5c5eeccc..bf5d2f9e 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -3,15 +3,23 @@ #include "asm/section.hpp" #include +#include #include #include +#include +#include #include +#include #include #include #include +#include +#include #include +#include #include "helpers.hpp" +#include "linkdefs.hpp" #include "asm/fstack.hpp" #include "asm/lexer.hpp" @@ -67,7 +75,7 @@ static bool requireCodeSection() { return false; } - if (sect_HasData(currentSection->type)) { + if (sectTypeHasData(currentSection->type)) { return true; } @@ -128,7 +136,7 @@ static unsigned int mergeSectUnion( // Unionized sections only need "compatible" constraints, and they end up with the strictest // combination of both. - if (sect_HasData(type)) { + if (sectTypeHasData(type)) { sectError("Cannot declare ROM sections as `UNION`"); } @@ -333,7 +341,7 @@ static Section *createSection( out_RegisterNode(sect.src); // It is only needed to allocate memory for ROM sections. - if (sect_HasData(type)) { + if (sectTypeHasData(type)) { sect.data.resize(sectionTypeInfo[type].size); } @@ -359,7 +367,7 @@ static Section *createSectionFragmentLiteral(Section const &parent) { out_RegisterNode(sect.src); // Section fragment literals must be ROM sections. - assume(sect_HasData(sect.type)); + assume(sectTypeHasData(sect.type)); sect.data.resize(sectionTypeInfo[sect.type].size); return § @@ -396,7 +404,7 @@ static Section *getSection( sectionTypeInfo[type].lastBank ); } - } else if (nbbanks(type) == 1) { + } else if (sectTypeBanks(type) == 1) { // If the section type only has a single bank, implicitly force it bank = sectionTypeInfo[type].firstBank; } @@ -411,14 +419,14 @@ static Section *getSection( } if (org != UINT32_MAX) { - if (org < sectionTypeInfo[type].startAddr || org > endaddr(type)) { + if (org < sectionTypeInfo[type].startAddr || org > sectTypeEndAddr(type)) { error( "Section \"%s\"'s fixed address $%04" PRIx32 " is outside of range [$%04" PRIx16 "; $%04" PRIx16 "]", name.c_str(), org, sectionTypeInfo[type].startAddr, - endaddr(type) + sectTypeEndAddr(type) ); } } @@ -539,7 +547,7 @@ void sect_SetLoadSection( return; } - if (sect_HasData(type)) { + if (sectTypeHasData(type)) { error("`LOAD` blocks cannot create a ROM section"); return; } @@ -715,7 +723,7 @@ void sect_StartUnion() { error("`UNION`s must be inside a `SECTION`"); return; } - if (sect_HasData(currentSection->type)) { + if (sectTypeHasData(currentSection->type)) { error("Cannot use `UNION` inside of `ROM0` or `ROMX` sections"); return; } @@ -812,7 +820,7 @@ void sect_Skip(uint32_t skip, bool ds) { return; } - if (!sect_HasData(currentSection->type)) { + if (!sectTypeHasData(currentSection->type)) { growSection(skip); } else { if (!ds) { @@ -1110,7 +1118,7 @@ std::string sect_PushSectionFragmentLiteral() { if (!currentSection) { fatal("Cannot output fragment literals outside of a `SECTION`"); } - if (!sect_HasData(currentSection->type)) { + if (!sectTypeHasData(currentSection->type)) { fatal( "Section \"%s\" cannot contain fragment literals (not `ROM0` or `ROMX`)", currentSection->name.c_str() diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 537ee652..1211f09c 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -5,9 +5,16 @@ #include #include #include +#include +#include #include +#include +#include +#include #include #include +#include +#include #include "diagnostics.hpp" #include "helpers.hpp" // assume @@ -19,6 +26,7 @@ #include "asm/macro.hpp" #include "asm/main.hpp" #include "asm/output.hpp" +#include "asm/section.hpp" #include "asm/warning.hpp" using namespace std::literals; diff --git a/src/asm/warning.cpp b/src/asm/warning.cpp index fc0f3918..ae523bc6 100644 --- a/src/asm/warning.cpp +++ b/src/asm/warning.cpp @@ -2,20 +2,16 @@ #include "asm/warning.hpp" +#include #include #include -#include #include #include -#include #include "diagnostics.hpp" -#include "helpers.hpp" -#include "itertools.hpp" #include "style.hpp" #include "asm/fstack.hpp" -#include "asm/lexer.hpp" #include "asm/main.hpp" // clang-format off: nested initializers diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index d1ead143..d60a86a6 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -2,6 +2,14 @@ #include "diagnostics.hpp" +#include +#include +#include +#include +#include +#include + +#include "helpers.hpp" #include "style.hpp" #include "util.hpp" // isDigit diff --git a/src/extern/utf8decoder.cpp b/src/extern/utf8decoder.cpp index 480bd340..3f9505f0 100644 --- a/src/extern/utf8decoder.cpp +++ b/src/extern/utf8decoder.cpp @@ -6,6 +6,8 @@ #include "extern/utf8decoder.hpp" +#include + // clang-format off: vertically align values static uint8_t const utf8d[] = { // The first part of the table maps bytes to character classes that diff --git a/src/fix/main.cpp b/src/fix/main.cpp index e73c726d..11ad2dfe 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT #include -#include #include #include diff --git a/src/fix/mbc.cpp b/src/fix/mbc.cpp index 7419476b..3a211d6c 100644 --- a/src/fix/mbc.cpp +++ b/src/fix/mbc.cpp @@ -2,6 +2,8 @@ #include "fix/mbc.hpp" +#include +#include #include #include #include diff --git a/src/fix/warning.cpp b/src/fix/warning.cpp index b6a154fc..c356820c 100644 --- a/src/fix/warning.cpp +++ b/src/fix/warning.cpp @@ -2,6 +2,13 @@ #include "fix/warning.hpp" +#include +#include +#include +#include +#include + +#include "diagnostics.hpp" #include "style.hpp" // clang-format off: nested initializers diff --git a/src/gfx/color_set.cpp b/src/gfx/color_set.cpp index 6dc35ec9..2b61309b 100644 --- a/src/gfx/color_set.cpp +++ b/src/gfx/color_set.cpp @@ -3,6 +3,10 @@ #include "gfx/color_set.hpp" #include +#include +#include +#include +#include #include "helpers.hpp" diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index 998fa6af..c35c7d9f 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -4,10 +4,11 @@ #include #include +#include #include #include -#include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "diagnostics.hpp" #include "extern/getopt.hpp" #include "file.hpp" +#include "helpers.hpp" #include "platform.hpp" #include "style.hpp" #include "usage.hpp" @@ -27,6 +29,7 @@ #include "gfx/pal_spec.hpp" #include "gfx/process.hpp" #include "gfx/reverse.hpp" +#include "gfx/rgba.hpp" #include "gfx/warning.hpp" using namespace std::literals::string_view_literals; diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index b9c9f715..9a9c7233 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -5,15 +5,19 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include +#include #include "helpers.hpp" +#include "style.hpp" #include "verbosity.hpp" #include "gfx/color_set.hpp" diff --git a/src/gfx/pal_sorting.cpp b/src/gfx/pal_sorting.cpp index dadefcb4..a1cebcbe 100644 --- a/src/gfx/pal_sorting.cpp +++ b/src/gfx/pal_sorting.cpp @@ -3,11 +3,16 @@ #include "gfx/pal_sorting.hpp" #include +#include +#include +#include +#include #include "helpers.hpp" #include "verbosity.hpp" #include "gfx/main.hpp" +#include "gfx/rgba.hpp" void sortIndexed(std::vector &palettes, std::vector const &embPal) { verbosePrint(VERB_NOTICE, "Sorting palettes using embedded palette...\n"); diff --git a/src/gfx/pal_spec.cpp b/src/gfx/pal_spec.cpp index 3389c9c2..56c5eaec 100644 --- a/src/gfx/pal_spec.cpp +++ b/src/gfx/pal_spec.cpp @@ -3,19 +3,20 @@ #include "gfx/pal_spec.hpp" #include +#include #include #include #include #include -#include +#include #include #include #include -#include #include #include #include #include +#include #include "diagnostics.hpp" #include "helpers.hpp" @@ -24,6 +25,7 @@ #include "gfx/main.hpp" #include "gfx/png.hpp" +#include "gfx/rgba.hpp" #include "gfx/warning.hpp" using namespace std::string_view_literals; diff --git a/src/gfx/png.cpp b/src/gfx/png.cpp index 46866dea..8051fbd0 100644 --- a/src/gfx/png.cpp +++ b/src/gfx/png.cpp @@ -2,11 +2,23 @@ #include "gfx/png.hpp" +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include "diagnostics.hpp" +#include "helpers.hpp" +#include "style.hpp" #include "verbosity.hpp" -#include "gfx/main.hpp" #include "gfx/rgba.hpp" #include "gfx/warning.hpp" diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index ee524e95..29b94565 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -3,13 +3,17 @@ #include "gfx/process.hpp" #include +#include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include @@ -18,6 +22,7 @@ #include "file.hpp" #include "helpers.hpp" #include "itertools.hpp" +#include "style.hpp" #include "verbosity.hpp" #include "gfx/color_set.hpp" @@ -25,6 +30,7 @@ #include "gfx/pal_packing.hpp" #include "gfx/pal_sorting.hpp" #include "gfx/png.hpp" +#include "gfx/rgba.hpp" #include "gfx/warning.hpp" static bool isBgColorTransparent() { @@ -610,7 +616,7 @@ public: template<> struct std::hash { - std::size_t operator()(TileData const &tile) const { return tile.hash(); } + size_t operator()(TileData const &tile) const { return tile.hash(); } }; static void outputUnoptimizedTileData( diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index e095a67d..fed8d8fd 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -6,10 +6,16 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include +#include +#include #include #include "diagnostics.hpp" @@ -18,6 +24,7 @@ #include "verbosity.hpp" #include "gfx/main.hpp" +#include "gfx/rgba.hpp" #include "gfx/warning.hpp" static std::vector readInto(std::string const &path) { diff --git a/src/gfx/rgba.cpp b/src/gfx/rgba.cpp index aefe041d..ef37eace 100644 --- a/src/gfx/rgba.cpp +++ b/src/gfx/rgba.cpp @@ -3,6 +3,7 @@ #include "gfx/rgba.hpp" #include +#include #include #include diff --git a/src/gfx/warning.cpp b/src/gfx/warning.cpp index 5a631d68..6d54d494 100644 --- a/src/gfx/warning.cpp +++ b/src/gfx/warning.cpp @@ -2,11 +2,12 @@ #include "gfx/warning.hpp" +#include #include -#include #include #include +#include "diagnostics.hpp" #include "style.hpp" // clang-format off: nested initializers diff --git a/src/link/assign.cpp b/src/link/assign.cpp index ac2dbf1e..8b2d5733 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -4,16 +4,17 @@ #include #include +#include +#include #include #include #include +#include #include -#include "diagnostics.hpp" #include "helpers.hpp" #include "itertools.hpp" #include "linkdefs.hpp" -#include "platform.hpp" #include "verbosity.hpp" #include "link/main.hpp" @@ -38,7 +39,7 @@ static std::vector> memory[SECTTYPE_INVALID]; // Init the free space-modelling structs static void initFreeSpace() { for (SectionType type : EnumSeq(SECTTYPE_INVALID)) { - memory[type].resize(nbbanks(type)); + memory[type].resize(sectTypeBanks(type)); for (std::deque &bankMem : memory[type]) { bankMem.push_back({ .address = sectionTypeInfo[type].startAddr, @@ -114,8 +115,8 @@ static MemoryLocation getStartLocation(Section const §ion) { } // Returns a suitable free space index into `memory[section->type]` at which to place the given -// section, or -1 if none was found. -static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { +// section, or `std::nullopt` if none was found. +static std::optional getPlacement(Section const §ion, MemoryLocation &location) { SectionTypeInfo const &typeInfo = sectionTypeInfo[section.type]; // Switch to the beginning of the next bank @@ -169,7 +170,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { // Try scrambled banks in descending order until no bank in the scrambled range is // available. Otherwise, try in ascending order. if (section.isBankFixed) { - return -1; + return std::nullopt; } else if (options.scrambleROMX && section.type == SECTTYPE_ROMX && location.bank <= options.scrambleROMX) { if (location.bank > typeInfo.firstBank) { @@ -177,7 +178,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { } else if (options.scrambleROMX < typeInfo.lastBank) { location.bank = options.scrambleROMX + 1; } else { - return -1; + return std::nullopt; } } else if (options.scrambleWRAMX && section.type == SECTTYPE_WRAMX && location.bank <= options.scrambleWRAMX) { @@ -186,7 +187,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { } else if (options.scrambleWRAMX < typeInfo.lastBank) { location.bank = options.scrambleWRAMX + 1; } else { - return -1; + return std::nullopt; } } else if (options.scrambleSRAM && section.type == SECTTYPE_SRAM && location.bank <= options.scrambleSRAM) { @@ -195,12 +196,12 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { } else if (options.scrambleSRAM < typeInfo.lastBank) { location.bank = options.scrambleSRAM + 1; } else { - return -1; + return std::nullopt; } } else if (location.bank < typeInfo.lastBank) { ++location.bank; } else { - return -1; + return std::nullopt; } return getPlacement(section, location); // Tail recursion @@ -210,7 +211,7 @@ static std::string getSectionDescription(Section const §ion) { std::string where; char bank[8], addr[8], mask[8], offset[8]; - if (section.isBankFixed && nbbanks(section.type) != 1) { + if (section.isBankFixed && sectTypeBanks(section.type) != 1) { snprintf(bank, sizeof(bank), "%02" PRIx32, section.bank); } if (section.isAddressFixed) { @@ -221,7 +222,7 @@ static std::string getSectionDescription(Section const §ion) { snprintf(offset, sizeof(offset), "%" PRIx16, section.alignOfs); } - if (section.isBankFixed && nbbanks(section.type) != 1) { + if (section.isBankFixed && sectTypeBanks(section.type) != 1) { if (section.isAddressFixed) { where = "at $"; where += bank; @@ -272,10 +273,10 @@ static void placeSection(Section §ion) { // Place section using first-fit decreasing algorithm // https://en.wikipedia.org/wiki/Bin_packing_problem#First-fit_algorithm MemoryLocation location = getStartLocation(section); - if (ssize_t spaceIdx = getPlacement(section, location); spaceIdx != -1) { + if (std::optional spaceIdx = getPlacement(section, location); spaceIdx) { std::deque &bankMem = memory[section.type][location.bank - sectionTypeInfo[section.type].firstBank]; - FreeSpace &freeSpace = bankMem[spaceIdx]; + FreeSpace &freeSpace = bankMem[*spaceIdx]; assignSection(section, location); @@ -285,17 +286,17 @@ static void placeSection(Section §ion) { bool noRightSpace = freeSpace.address + freeSpace.size == sectionEnd; if (noLeftSpace && noRightSpace) { // The free space is entirely deleted - bankMem.erase(bankMem.begin() + spaceIdx); + bankMem.erase(bankMem.begin() + *spaceIdx); } else if (!noLeftSpace && !noRightSpace) { // The free space is split in two // Append the new space after the original one uint16_t size = static_cast(freeSpace.address + freeSpace.size - sectionEnd); - bankMem.insert(bankMem.begin() + spaceIdx + 1, {.address = sectionEnd, .size = size}); + bankMem.insert(bankMem.begin() + *spaceIdx + 1, {.address = sectionEnd, .size = size}); // **`freeSpace` cannot be reused from this point on, because `bankMem.insert` // invalidates all references to itself!** // Resize the original space (address is unmodified) - bankMem[spaceIdx].size = section.org - bankMem[spaceIdx].address; + bankMem[*spaceIdx].size = section.org - bankMem[*spaceIdx].address; } else { // The amount of free spaces doesn't change: resize! freeSpace.size -= section.size; @@ -315,7 +316,7 @@ static void placeSection(Section §ion) { sectionTypeInfo[section.type].name.c_str(), getSectionDescription(section).c_str() ); - } else if (section.org + section.size > endaddr(section.type) + 1) { + } else if (section.org + section.size > sectTypeEndAddr(section.type) + 1) { // If the section just can't fit the bank, report that fatal( "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > " @@ -324,7 +325,7 @@ static void placeSection(Section §ion) { sectionTypeInfo[section.type].name.c_str(), getSectionDescription(section).c_str(), section.org + section.size, - endaddr(section.type) + 1 + sectTypeEndAddr(section.type) + 1 ); } else { // Otherwise there is overlap with another section diff --git a/src/link/fstack.cpp b/src/link/fstack.cpp index c36471c5..5fdd5638 100644 --- a/src/link/fstack.cpp +++ b/src/link/fstack.cpp @@ -1,8 +1,14 @@ #include "link/fstack.hpp" -#include +#include +#include +#include +#include +#include #include "backtrace.hpp" +#include "helpers.hpp" +#include "linkdefs.hpp" #include "link/warning.hpp" diff --git a/src/link/layout.cpp b/src/link/layout.cpp index 816eace0..ab4a925f 100644 --- a/src/link/layout.cpp +++ b/src/link/layout.cpp @@ -5,10 +5,11 @@ #include #include #include +#include #include #include "helpers.hpp" -#include "util.hpp" +#include "linkdefs.hpp" #include "link/section.hpp" #include "link/warning.hpp" @@ -30,7 +31,7 @@ static void setActiveTypeAndIdx(SectionType type, uint32_t idx) { } void layout_SetFloatingSectionType(SectionType type) { - if (nbbanks(type) == 1) { + if (sectTypeBanks(type) == 1) { // There is only a single bank anyway, so just set the index to 0. setActiveTypeAndIdx(type, 0); } else { @@ -45,7 +46,7 @@ void layout_SetFloatingSectionType(SectionType type) { } void layout_SetSectionType(SectionType type) { - if (nbbanks(type) != 1) { + if (sectTypeBanks(type) != 1) { scriptError("A bank number must be specified for %s", sectionTypeInfo[type].name.c_str()); // Keep going with a default value for the bank index. } @@ -91,14 +92,14 @@ void layout_SetAddr(uint32_t addr) { if (addr < pc) { scriptError("Cannot decrease the current address (from $%04x to $%04x)", pc, addr); - } else if (addr > endaddr(activeType)) { // Allow "one past the end" sections. + } else if (addr > sectTypeEndAddr(activeType)) { // Allow "one past the end" sections. scriptError( "Cannot set the current address to $%04" PRIx32 ": %s ends at $%04" PRIx16, addr, typeInfo.name.c_str(), - endaddr(activeType) + sectTypeEndAddr(activeType) ); - pc = endaddr(activeType); + pc = sectTypeEndAddr(activeType); } else { pc = addr; } @@ -178,7 +179,7 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) { ", past $%04" PRIx16, pc, static_cast(pc + length), - static_cast(endaddr(activeType) + 1) + static_cast(sectTypeEndAddr(activeType) + 1) ); return; } @@ -206,7 +207,7 @@ void layout_Pad(uint32_t length) { "Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16, length, typeInfo.size - offset, - static_cast(endaddr(activeType) + 1) + static_cast(sectTypeEndAddr(activeType) + 1) ); } else { pc += length; @@ -232,13 +233,13 @@ void layout_PlaceSection(std::string const &name, bool isOptional) { // Check that the linker script doesn't contradict what the code says. if (section->type == SECTTYPE_INVALID) { // A section that has data must get assigned a type that requires data. - if (!sect_HasData(activeType) && !section->data.empty()) { + if (!sectTypeHasData(activeType) && !section->data.empty()) { scriptError( "\"%s\" is specified to be a %s section, but it contains data", name.c_str(), typeInfo.name.c_str() ); - } else if (sect_HasData(activeType) && section->data.empty() && section->size != 0) { + } else if (sectTypeHasData(activeType) && section->data.empty() && section->size != 0) { // A section that lacks data can only be assigned to a type that requires data // if it's empty. scriptError( diff --git a/src/link/lexer.cpp b/src/link/lexer.cpp index cd7a137d..ec602231 100644 --- a/src/link/lexer.cpp +++ b/src/link/lexer.cpp @@ -2,16 +2,19 @@ #include "link/lexer.hpp" -#include #include #include -#include +#include +#include #include +#include +#include +#include #include #include "backtrace.hpp" #include "helpers.hpp" -#include "itertools.hpp" +#include "linkdefs.hpp" #include "util.hpp" #include "link/warning.hpp" diff --git a/src/link/main.cpp b/src/link/main.cpp index e0327559..c7cb0b75 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -1,11 +1,12 @@ // SPDX-License-Identifier: MIT -#include -#include +#include "link/main.hpp" #include #include #include +#include +#include #include #include #include @@ -13,9 +14,7 @@ #include "backtrace.hpp" #include "diagnostics.hpp" #include "extern/getopt.hpp" -#include "helpers.hpp" // assume -#include "itertools.hpp" -#include "platform.hpp" +#include "linkdefs.hpp" #include "script.hpp" // Generated from script.y #include "style.hpp" #include "usage.hpp" @@ -29,7 +28,6 @@ #include "link/output.hpp" #include "link/patch.hpp" #include "link/section.hpp" -#include "link/symbol.hpp" #include "link/warning.hpp" Options options; diff --git a/src/link/object.cpp b/src/link/object.cpp index 2bf18eb6..527b4f55 100644 --- a/src/link/object.cpp +++ b/src/link/object.cpp @@ -11,18 +11,18 @@ #include #include #include +#include +#include +#include #include -#include "diagnostics.hpp" #include "helpers.hpp" #include "linkdefs.hpp" #include "platform.hpp" #include "verbosity.hpp" #include "version.hpp" -#include "link/assign.hpp" #include "link/fstack.hpp" -#include "link/main.hpp" #include "link/patch.hpp" #include "link/sdas_obj.hpp" #include "link/section.hpp" @@ -360,7 +360,7 @@ static void readSection( } section.alignOfs = tmp; - if (sect_HasData(section.type)) { + if (sectTypeHasData(section.type)) { if (section.size) { section.data.resize(section.size); if (fread(section.data.data(), 1, section.size, file) != section.size) { @@ -549,7 +549,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) { // Give patches' PC section pointers to their sections for (uint32_t i = 0; i < nbSections; ++i) { - if (sect_HasData(fileSections[i]->type)) { + if (sectTypeHasData(fileSections[i]->type)) { for (Patch &patch : fileSections[i]->patches) { linkPatchToPCSect(patch, fileSections); } diff --git a/src/link/output.cpp b/src/link/output.cpp index 05c21ca3..adbeeeba 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -6,9 +6,12 @@ #include #include #include +#include #include #include #include +#include +#include #include #include "diagnostics.hpp" diff --git a/src/link/patch.cpp b/src/link/patch.cpp index 824a8a29..f551e3a2 100644 --- a/src/link/patch.cpp +++ b/src/link/patch.cpp @@ -5,14 +5,15 @@ #include #include #include +#include #include +#include "diagnostics.hpp" #include "helpers.hpp" // assume #include "linkdefs.hpp" #include "opmath.hpp" #include "verbosity.hpp" -#include "link/main.hpp" #include "link/section.hpp" #include "link/symbol.hpp" #include "link/warning.hpp" @@ -566,7 +567,7 @@ static void applyFilePatches(Section §ion, Section &dataSection) { // Applies all of a section's patches, iterating over "components" of unionized sections static void applyPatches(Section §ion) { - if (!sect_HasData(section.type)) { + if (!sectTypeHasData(section.type)) { return; } diff --git a/src/link/sdas_obj.cpp b/src/link/sdas_obj.cpp index 1c434317..c115dc6c 100644 --- a/src/link/sdas_obj.cpp +++ b/src/link/sdas_obj.cpp @@ -6,16 +6,17 @@ #include #include #include +#include #include #include +#include +#include #include "helpers.hpp" // assume, literal_strlen #include "linkdefs.hpp" #include "platform.hpp" -#include "link/assign.hpp" #include "link/fstack.hpp" -#include "link/main.hpp" #include "link/section.hpp" #include "link/symbol.hpp" #include "link/warning.hpp" @@ -865,7 +866,7 @@ void sdobj_ReadFile(FileStackNode const &src, FILE *file, std::vector &f // Otherwise, how would the type already be known at this point? assume(section->isAddressFixed); - if (!sect_HasData(section->type)) { + if (!sectTypeHasData(section->type)) { if (!section->data.empty()) { fatalAt( where, diff --git a/src/link/section.cpp b/src/link/section.cpp index d943361e..04368bfe 100644 --- a/src/link/section.cpp +++ b/src/link/section.cpp @@ -3,13 +3,19 @@ #include "link/section.hpp" #include +#include +#include #include #include +#include #include +#include +#include -#include "diagnostics.hpp" #include "helpers.hpp" +#include "linkdefs.hpp" +#include "link/main.hpp" #include "link/warning.hpp" static std::vector> sectionList; @@ -167,7 +173,7 @@ static void mergeSections(Section &target, std::unique_ptr
&&other) { // Append `other` to `target` other->offset = target.size; target.size += other->size; - // Normally we'd check that `sect_HasData`, but SDCC areas may be `_INVALID` here + // Normally we'd check that `sectTypeHasData`, but SDCC areas may be `_INVALID` here if (!other->data.empty()) { target.data.insert(target.data.end(), RANGE(other->data)); // Adjust patches' PC offsets @@ -195,7 +201,7 @@ void sect_AddSection(std::unique_ptr
&§ion) { // Check if the section already exists if (Section *target = sect_GetSection(section->name); target) { mergeSections(*target, std::move(section)); - } else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) { + } else if (section->modifier == SECTION_UNION && sectTypeHasData(section->type)) { fatal( "Section \"%s\" is of type `%s`, which cannot be `UNION`ized", section->name.c_str(), @@ -315,23 +321,23 @@ static void doSanityChecks(Section §ion) { // Ensure the target address is valid if (section.org < sectionTypeInfo[section.type].startAddr - || section.org > endaddr(section.type)) { + || section.org > sectTypeEndAddr(section.type)) { error( "Section \"%s\"'s fixed address $%04" PRIx16 " is outside of range [$%04" PRIx16 "; $%04" PRIx16 "]", section.name.c_str(), section.org, sectionTypeInfo[section.type].startAddr, - endaddr(section.type) + sectTypeEndAddr(section.type) ); } - if (section.org + section.size > endaddr(section.type) + 1) { + if (section.org + section.size > sectTypeEndAddr(section.type) + 1) { error( "Section \"%s\"'s end address $%04x is greater than last address $%04x", section.name.c_str(), section.org + section.size, - endaddr(section.type) + 1 + sectTypeEndAddr(section.type) + 1 ); } } diff --git a/src/link/symbol.cpp b/src/link/symbol.cpp index 1fce50a0..5fc02b36 100644 --- a/src/link/symbol.cpp +++ b/src/link/symbol.cpp @@ -2,12 +2,17 @@ #include "link/symbol.hpp" -#include +#include +#include #include +#include #include +#include +#include #include #include "helpers.hpp" // assume +#include "linkdefs.hpp" #include "link/fstack.hpp" #include "link/section.hpp" diff --git a/src/link/warning.cpp b/src/link/warning.cpp index f3c2380b..3bcd4c87 100644 --- a/src/link/warning.cpp +++ b/src/link/warning.cpp @@ -4,7 +4,11 @@ #include #include +#include +#include +#include +#include "diagnostics.hpp" #include "style.hpp" #include "link/fstack.hpp" diff --git a/src/linkdefs.cpp b/src/linkdefs.cpp index d1b14804..e3374f84 100644 --- a/src/linkdefs.cpp +++ b/src/linkdefs.cpp @@ -2,6 +2,8 @@ #include "linkdefs.hpp" +#include + using namespace std::literals; // The default values are the most lax, as they are used as-is by RGBASM; only RGBLINK has the full diff --git a/src/style.cpp b/src/style.cpp index e8c4ede1..55d15a98 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -5,6 +5,7 @@ #include "style.hpp" +#include #include // getenv #include diff --git a/src/usage.cpp b/src/usage.cpp index cab34a86..cddfd7aa 100644 --- a/src/usage.cpp +++ b/src/usage.cpp @@ -2,7 +2,7 @@ #include "usage.hpp" -#include +#include #include #include diff --git a/src/verbosity.cpp b/src/verbosity.cpp index 6e7645aa..4204527b 100644 --- a/src/verbosity.cpp +++ b/src/verbosity.cpp @@ -8,6 +8,8 @@ #include #include +#include "style.hpp" + static Verbosity verbosity = VERB_NONE; bool checkVerbosity(Verbosity level) { diff --git a/src/version.cpp b/src/version.cpp index 8f69e6a5..8dac003f 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -2,8 +2,6 @@ #include "version.hpp" -#include - #include "helpers.hpp" // We do not build `make develop` with `-fsanitize=leak` because macOS clang++ does not support it. diff --git a/test/gfx/rgbgfx_test.cpp b/test/gfx/rgbgfx_test.cpp index 45f52d7e..0b88ca23 100644 --- a/test/gfx/rgbgfx_test.cpp +++ b/test/gfx/rgbgfx_test.cpp @@ -2,10 +2,10 @@ #include #include -#include -#include +#include #include #include +#include #include #include #include