mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Use // line comments not /* block comments
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/assign.hpp"
|
||||
|
||||
@@ -48,11 +48,9 @@ static void initFreeSpace() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Assigns a section to a given memory location
|
||||
* @param section The section to assign
|
||||
* @param location The location to assign the section to
|
||||
*/
|
||||
// Assigns a section to a given memory location
|
||||
// @param section The section to assign
|
||||
// @param location The location to assign the section to
|
||||
static void assignSection(Section §ion, MemoryLocation const &location) {
|
||||
// Propagate the assigned location to all UNIONs/FRAGMENTs
|
||||
// so `jr` patches in them will have the correct offset
|
||||
@@ -66,15 +64,13 @@ static void assignSection(Section §ion, MemoryLocation const &location) {
|
||||
out_AddSection(section);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks whether a given location is suitable for placing a given section
|
||||
* This checks not only that the location has enough room for the section, but
|
||||
* also that the constraints (alignment...) are respected.
|
||||
* @param section The section to be placed
|
||||
* @param freeSpace The candidate free space to place the section into
|
||||
* @param location The location to attempt placing the section at
|
||||
* @return True if the location is suitable, false otherwise.
|
||||
*/
|
||||
// Checks whether a given location is suitable for placing a given section
|
||||
// This checks not only that the location has enough room for the section, but
|
||||
// also that the constraints (alignment...) are respected.
|
||||
// @param section The section to be placed
|
||||
// @param freeSpace The candidate free space to place the section into
|
||||
// @param location The location to attempt placing the section at
|
||||
// @return True if the location is suitable, false otherwise.
|
||||
static bool isLocationSuitable(
|
||||
Section const §ion, FreeSpace const &freeSpace, MemoryLocation const &location
|
||||
) {
|
||||
@@ -90,13 +86,11 @@ static bool isLocationSuitable(
|
||||
return location.address + section.size <= freeSpace.address + freeSpace.size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds a suitable location to place a section at.
|
||||
* @param section The section to be placed
|
||||
* @param location A pointer to a memory location that will be filled
|
||||
* @return The index into `memory[section->type]` of the free space encompassing the location,
|
||||
* or -1 if none was found
|
||||
*/
|
||||
// Finds a suitable location to place a section at.
|
||||
// @param section The section to be placed
|
||||
// @param location A pointer to a memory location that will be filled
|
||||
// @return The index into `memory[section->type]` of the free space encompassing the location,
|
||||
// or -1 if none was found
|
||||
static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
||||
SectionTypeInfo const &typeInfo = sectionTypeInfo[section.type];
|
||||
|
||||
@@ -206,12 +200,10 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Places a section in a suitable location, or error out if it fails to.
|
||||
* @warning Due to the implemented algorithm, this should be called with
|
||||
* sections of decreasing size.
|
||||
* @param section The section to place
|
||||
*/
|
||||
// Places a section in a suitable location, or error out if it fails to.
|
||||
// @warning Due to the implemented algorithm, this should be called with
|
||||
// sections of decreasing size.
|
||||
// @param section The section to place
|
||||
static void placeSection(Section §ion) {
|
||||
MemoryLocation location;
|
||||
|
||||
@@ -336,11 +328,9 @@ static constexpr uint8_t ALIGN_CONSTRAINED = 1 << 0;
|
||||
// clang-format on
|
||||
static std::deque<Section *> unassignedSections[1 << 3];
|
||||
|
||||
/*
|
||||
* Categorize a section depending on how constrained it is
|
||||
* This is so the most-constrained sections are placed first
|
||||
* @param section The section to categorize
|
||||
*/
|
||||
// Categorize a section depending on how constrained it is
|
||||
// This is so the most-constrained sections are placed first
|
||||
// @param section The section to categorize
|
||||
static void categorizeSection(Section §ion) {
|
||||
uint8_t constraints = 0;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -132,16 +132,13 @@ void argErr(char flag, char const *fmt, ...) {
|
||||
// Short options
|
||||
static char const *optstring = "dhl:m:Mn:O:o:p:S:tVvWwx";
|
||||
|
||||
/*
|
||||
* Equivalent long options
|
||||
* Please keep in the same order as short opts
|
||||
*
|
||||
* Also, make sure long opts don't create ambiguity:
|
||||
* A long opt's name should start with the same letter as its short opt,
|
||||
* except if it doesn't create any ambiguity (`verbose` versus `version`).
|
||||
* This is because long opt matching, even to a single char, is prioritized
|
||||
* over short opt matching
|
||||
*/
|
||||
// Equivalent long options
|
||||
// Please keep in the same order as short opts.
|
||||
// Also, make sure long opts don't create ambiguity:
|
||||
// A long opt's name should start with the same letter as its short opt,
|
||||
// except if it doesn't create any ambiguity (`verbose` versus `version`).
|
||||
// This is because long opt matching, even to a single char, is prioritized
|
||||
// over short opt matching.
|
||||
static option const longopts[] = {
|
||||
{"dmg", no_argument, nullptr, 'd'},
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/object.hpp"
|
||||
|
||||
@@ -41,11 +41,9 @@ static std::vector<std::vector<FileStackNode>> nodes;
|
||||
var = static_cast<vartype>(tmpVal); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Reads an unsigned long (32-bit) value from a file.
|
||||
* @param file The file to read from. This will read 4 bytes from the file.
|
||||
* @return The value read, cast to a int64_t, or `INT64_MAX` on failure.
|
||||
*/
|
||||
// Reads an unsigned long (32-bit) value from a file.
|
||||
// @param file The file to read from. This will read 4 bytes from the file.
|
||||
// @return The value read, cast to a int64_t, or `INT64_MAX` on failure.
|
||||
static int64_t readLong(FILE *file) {
|
||||
uint32_t value = 0;
|
||||
|
||||
@@ -66,37 +64,31 @@ static int64_t readLong(FILE *file) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper macro for reading longs from a file, and errors out if it fails to.
|
||||
* Not as a function to avoid overhead in the general case.
|
||||
* @param var The variable to stash the number into
|
||||
* @param file The file to read from. Its position will be advanced
|
||||
* @param ... A format string and related arguments; note that an extra string
|
||||
* argument is provided, the reason for failure
|
||||
*/
|
||||
// Helper macro for reading longs from a file, and errors out if it fails to.
|
||||
// Not as a function to avoid overhead in the general case.
|
||||
// @param var The variable to stash the number into
|
||||
// @param file The file to read from. Its position will be advanced
|
||||
// @param ... A format string and related arguments; note that an extra string
|
||||
// argument is provided, the reason for failure
|
||||
#define tryReadLong(var, file, ...) \
|
||||
tryRead(readLong, int64_t, INT64_MAX, long, var, file, __VA_ARGS__)
|
||||
|
||||
// There is no `readbyte`, just use `fgetc` or `getc`.
|
||||
// There is no `readByte`, just use `fgetc` or `getc`.
|
||||
|
||||
/*
|
||||
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
||||
* Not as a function to avoid overhead in the general case.
|
||||
* @param var The variable to stash the number into
|
||||
* @param file The file to read from. Its position will be advanced
|
||||
* @param ... A format string and related arguments; note that an extra string
|
||||
* argument is provided, the reason for failure
|
||||
*/
|
||||
// Helper macro for reading bytes from a file, and errors out if it fails to.
|
||||
// Not as a function to avoid overhead in the general case.
|
||||
// @param var The variable to stash the number into
|
||||
// @param file The file to read from. Its position will be advanced
|
||||
// @param ... A format string and related arguments; note that an extra string
|
||||
// argument is provided, the reason for failure
|
||||
#define tryGetc(type, var, file, ...) tryRead(getc, int, EOF, type, var, file, __VA_ARGS__)
|
||||
|
||||
/*
|
||||
* Helper macro for readings '\0'-terminated strings from a file, and errors out if it fails to.
|
||||
* Not as a function to avoid overhead in the general case.
|
||||
* @param var The variable to stash the string into
|
||||
* @param file The file to read from. Its position will be advanced
|
||||
* @param ... A format string and related arguments; note that an extra string
|
||||
* argument is provided, the reason for failure
|
||||
*/
|
||||
// Helper macro for readings '\0'-terminated strings from a file, and errors out if it fails to.
|
||||
// Not as a function to avoid overhead in the general case.
|
||||
// @param var The variable to stash the string into
|
||||
// @param file The file to read from. Its position will be advanced
|
||||
// @param ... A format string and related arguments; note that an extra string
|
||||
// argument is provided, the reason for failure
|
||||
#define tryReadString(var, file, ...) \
|
||||
do { \
|
||||
FILE *tmpFile = file; \
|
||||
@@ -112,13 +104,11 @@ static int64_t readLong(FILE *file) {
|
||||
|
||||
// Functions to parse object files
|
||||
|
||||
/*
|
||||
* Reads a file stack node form a file.
|
||||
* @param file The file to read from
|
||||
* @param nodes The file's array of nodes
|
||||
* @param i The ID of the node in the array
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
// Reads a file stack node form a file.
|
||||
// @param file The file to read from
|
||||
// @param nodes The file's array of nodes
|
||||
// @param i The ID of the node in the array
|
||||
// @param fileName The filename to report in errors
|
||||
static void readFileStackNode(
|
||||
FILE *file, std::vector<FileStackNode> &fileNodes, uint32_t i, char const *fileName
|
||||
) {
|
||||
@@ -171,12 +161,10 @@ static void readFileStackNode(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a symbol from a file.
|
||||
* @param file The file to read from
|
||||
* @param symbol The symbol to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
// Reads a symbol from a file.
|
||||
// @param file The file to read from
|
||||
// @param symbol The symbol to fill
|
||||
// @param fileName The filename to report in errors
|
||||
static void readSymbol(
|
||||
FILE *file, Symbol &symbol, char const *fileName, std::vector<FileStackNode> const &fileNodes
|
||||
) {
|
||||
@@ -229,13 +217,11 @@ static void readSymbol(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a patch from a file.
|
||||
* @param file The file to read from
|
||||
* @param patch The patch to fill
|
||||
* @param fileName The filename to report in errors
|
||||
* @param i The number of the patch to report in errors
|
||||
*/
|
||||
// Reads a patch from a file.
|
||||
// @param file The file to read from
|
||||
// @param patch The patch to fill
|
||||
// @param fileName The filename to report in errors
|
||||
// @param i The number of the patch to report in errors
|
||||
static void readPatch(
|
||||
FILE *file,
|
||||
Patch &patch,
|
||||
@@ -320,22 +306,18 @@ static void readPatch(
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets a patch's pcSection from its pcSectionID.
|
||||
* @param patch The patch to fix
|
||||
*/
|
||||
// Sets a patch's pcSection from its pcSectionID.
|
||||
// @param patch The patch to fix
|
||||
static void
|
||||
linkPatchToPCSect(Patch &patch, std::vector<std::unique_ptr<Section>> const &fileSections) {
|
||||
patch.pcSection =
|
||||
patch.pcSectionID != UINT32_MAX ? fileSections[patch.pcSectionID].get() : nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a section from a file.
|
||||
* @param file The file to read from
|
||||
* @param section The section to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
// Reads a section from a file.
|
||||
// @param file The file to read from
|
||||
// @param section The section to fill
|
||||
// @param fileName The filename to report in errors
|
||||
static void readSection(
|
||||
FILE *file, Section §ion, char const *fileName, std::vector<FileStackNode> const &fileNodes
|
||||
) {
|
||||
@@ -440,11 +422,9 @@ static void readSection(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Links a symbol to a section, keeping the section's symbol list sorted.
|
||||
* @param symbol The symbol to link
|
||||
* @param section The section to link
|
||||
*/
|
||||
// Links a symbol to a section, keeping the section's symbol list sorted.
|
||||
// @param symbol The symbol to link
|
||||
// @param section The section to link
|
||||
static void linkSymToSect(Symbol &symbol, Section §ion) {
|
||||
uint32_t a = 0, b = section.symbols.size();
|
||||
int32_t symbolOffset = symbol.label().offset;
|
||||
@@ -462,12 +442,10 @@ static void linkSymToSect(Symbol &symbol, Section §ion) {
|
||||
section.symbols.insert(section.symbols.begin() + a, &symbol);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads an assertion from a file
|
||||
* @param file The file to read from
|
||||
* @param assert The assertion to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
// Reads an assertion from a file
|
||||
// @param file The file to read from
|
||||
// @param assert The assertion to fill
|
||||
// @param fileName The filename to report in errors
|
||||
static void readAssertion(
|
||||
FILE *file,
|
||||
Assertion &assert,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/output.hpp"
|
||||
|
||||
@@ -98,10 +98,8 @@ Section const *out_OverlappingSection(Section const §ion) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Performs sanity checks on the overlay file.
|
||||
* @return The number of ROM banks in the overlay file
|
||||
*/
|
||||
// Performs sanity checks on the overlay file.
|
||||
// @return The number of ROM banks in the overlay file
|
||||
static uint32_t checkOverlaySize() {
|
||||
if (!overlayFile)
|
||||
return 0;
|
||||
@@ -126,12 +124,10 @@ static uint32_t checkOverlaySize() {
|
||||
return (overlaySize + BANK_SIZE - 1) / BANK_SIZE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand `sections[SECTTYPE_ROMX]` to cover all the overlay banks.
|
||||
* This ensures that `writeROM` will output each bank, even if some are not
|
||||
* covered by any sections.
|
||||
* @param nbOverlayBanks The number of banks in the overlay file
|
||||
*/
|
||||
// Expand `sections[SECTTYPE_ROMX]` to cover all the overlay banks.
|
||||
// This ensures that `writeROM` will output each bank, even if some are not
|
||||
// covered by any sections.
|
||||
// @param nbOverlayBanks The number of banks in the overlay file
|
||||
static void coverOverlayBanks(uint32_t nbOverlayBanks) {
|
||||
// 2 if is32kMode, 1 otherwise
|
||||
uint32_t nbRom0Banks = sectionTypeInfo[SECTTYPE_ROM0].size / BANK_SIZE;
|
||||
@@ -162,12 +158,10 @@ static uint8_t getNextFillByte() {
|
||||
return padValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a ROM bank's sections to the output file.
|
||||
* @param bankSections The bank's sections, ordered by increasing address
|
||||
* @param baseOffset The address of the bank's first byte in GB address space
|
||||
* @param size The size of the bank
|
||||
*/
|
||||
// Write a ROM bank's sections to the output file.
|
||||
// @param bankSections The bank's sections, ordered by increasing address
|
||||
// @param baseOffset The address of the bank's first byte in GB address space
|
||||
// @param size The size of the bank
|
||||
static void
|
||||
writeBank(std::deque<Section const *> *bankSections, uint16_t baseOffset, uint16_t size) {
|
||||
uint16_t offset = 0;
|
||||
@@ -327,10 +321,8 @@ static bool compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a bank's contents to the sym file
|
||||
* @param bankSections The bank's sections
|
||||
*/
|
||||
// Write a bank's contents to the sym file
|
||||
// @param bankSections The bank's sections
|
||||
static void writeSymBank(SortedSections const &bankSections, SectionType type, uint32_t bank) {
|
||||
#define forEachSortedSection(sect, ...) \
|
||||
do { \
|
||||
@@ -421,9 +413,7 @@ static void printSectionName(std::string const &name, FILE *file) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a bank's contents to the map file
|
||||
*/
|
||||
// Write a bank's contents to the map file
|
||||
static void writeMapBank(SortedSections const §List, SectionType type, uint32_t bank) {
|
||||
fprintf(
|
||||
mapFile,
|
||||
@@ -495,9 +485,7 @@ static void writeMapBank(SortedSections const §List, SectionType type, uint3
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the total used and free space by section type to the map file
|
||||
*/
|
||||
// Write the total used and free space by section type to the map file
|
||||
static void writeMapSummary() {
|
||||
fputs("SUMMARY:\n", mapFile);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/patch.hpp"
|
||||
|
||||
@@ -63,14 +63,12 @@ static Symbol const *getSymbol(std::vector<Symbol> const &symbolList, uint32_t i
|
||||
return &symbol;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute a patch's value from its RPN string.
|
||||
* @param patch The patch to compute the value of
|
||||
* @param section The section the patch is contained in
|
||||
* @return The patch's value
|
||||
* @return isError Set if an error occurred during evaluation, and further
|
||||
* errors caused by the value should be suppressed.
|
||||
*/
|
||||
// Compute a patch's value from its RPN string.
|
||||
// @param patch The patch to compute the value of
|
||||
// @param section The section the patch is contained in
|
||||
// @return The patch's value
|
||||
// @return isError Set if an error occurred during evaluation, and further
|
||||
// errors caused by the value should be suppressed.
|
||||
static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fileSymbols) {
|
||||
uint8_t const *expression = patch.rpnExpression.data();
|
||||
int32_t size = static_cast<int32_t>(patch.rpnExpression.size());
|
||||
@@ -471,11 +469,9 @@ void patch_CheckAssertions() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Applies all of a section's patches
|
||||
* @param section The section component to patch
|
||||
* @param dataSection The section to patch
|
||||
*/
|
||||
// Applies all of a section's patches
|
||||
// @param section The section component to patch
|
||||
// @param dataSection The section to patch
|
||||
static void applyFilePatches(Section §ion, Section &dataSection) {
|
||||
verbosePrint("Patching section \"%s\"...\n", section.name.c_str());
|
||||
for (Patch &patch : section.patches) {
|
||||
@@ -537,10 +533,8 @@ static void applyFilePatches(Section §ion, Section &dataSection) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Applies all of a section's patches, iterating over "components" of unionized sections
|
||||
* @param section The section to patch
|
||||
*/
|
||||
// Applies all of a section's patches, iterating over "components" of unionized sections
|
||||
// @param section The section to patch
|
||||
static void applyPatches(Section §ion) {
|
||||
if (!sect_HasData(section.type))
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
%language "c++"
|
||||
%define api.value.type variant
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/sdas_obj.hpp"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/section.hpp"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/symbol.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user