mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-28 22:07:49 +00:00
Run clang-format on everything (#1332)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#ifndef RGBDS_FORMAT_SPEC_H
|
||||
#define RGBDS_FORMAT_SPEC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum FormatState {
|
||||
@@ -30,7 +31,7 @@ class FormatSpec {
|
||||
public:
|
||||
bool isEmpty() const { return !state; }
|
||||
bool isValid() const { return valid || state == FORMAT_DONE; }
|
||||
bool isFinished() const { return state >= FORMAT_DONE;}
|
||||
bool isFinished() const { return state >= FORMAT_DONE; }
|
||||
|
||||
void useCharacter(int c);
|
||||
void finishCharacters();
|
||||
|
||||
@@ -11,24 +11,25 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "asm/lexer.hpp"
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
#include "asm/lexer.hpp"
|
||||
|
||||
struct FileStackNode {
|
||||
FileStackNode *parent; // Pointer to parent node, for error reporting
|
||||
// Line at which the parent context was exited; meaningless for the root level
|
||||
uint32_t lineNo;
|
||||
|
||||
bool referenced; // If referenced by a Symbol, Section, or Patch's `src`, don't `delete`!
|
||||
uint32_t ID; // Set only if referenced: ID within the object file, -1 if not output yet
|
||||
uint32_t ID; // Set only if referenced: ID within the object file, -1 if not output yet
|
||||
|
||||
enum FileStackNodeType type;
|
||||
std::variant<
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
> data;
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
>
|
||||
data;
|
||||
|
||||
// REPT iteration counts since last named node, in reverse depth order
|
||||
std::vector<uint32_t> &iters();
|
||||
@@ -62,8 +63,15 @@ bool yywrap();
|
||||
void fstk_RunInclude(char const *path);
|
||||
void fstk_RunMacro(char const *macroName, MacroArgs &args);
|
||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char const *body, size_t size);
|
||||
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||
int32_t reptLineNo, char const *body, size_t size);
|
||||
void fstk_RunFor(
|
||||
char const *symName,
|
||||
int32_t start,
|
||||
int32_t stop,
|
||||
int32_t step,
|
||||
int32_t reptLineNo,
|
||||
char const *body,
|
||||
size_t size
|
||||
);
|
||||
void fstk_StopRept();
|
||||
bool fstk_Break();
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ struct Expansion {
|
||||
char const *unowned;
|
||||
char *owned; // Non-`const` only so it can be `delete []`d
|
||||
} contents;
|
||||
size_t size; // Length of the contents
|
||||
size_t size; // Length of the contents
|
||||
size_t offset; // Cursor into the contents
|
||||
bool owned; // Whether or not to free contents when this expansion is freed
|
||||
bool owned; // Whether or not to free contents when this expansion is freed
|
||||
};
|
||||
|
||||
struct IfStackEntry {
|
||||
bool ranIfBlock; // Whether an IF/ELIF/ELSE block ran already
|
||||
bool ranIfBlock; // Whether an IF/ELIF/ELSE block ran already
|
||||
bool reachedElseBlock; // Whether an ELSE block ran already
|
||||
};
|
||||
|
||||
@@ -59,9 +59,9 @@ struct ViewedLexerState {
|
||||
|
||||
struct BufferedLexerState {
|
||||
int fd;
|
||||
size_t index; // Read index into the buffer
|
||||
size_t index; // Read index into the buffer
|
||||
char buf[LEXER_BUF_SIZE]; // Circular buffer
|
||||
size_t nbChars; // Number of "fresh" chars in the buffer
|
||||
size_t nbChars; // Number of "fresh" chars in the buffer
|
||||
};
|
||||
|
||||
struct LexerState {
|
||||
@@ -75,8 +75,8 @@ struct LexerState {
|
||||
|
||||
std::deque<IfStackEntry> ifStack;
|
||||
|
||||
bool capturing; // Whether the text being lexed should be captured
|
||||
size_t captureSize; // Amount of text captured
|
||||
bool capturing; // Whether the text being lexed should be captured
|
||||
size_t captureSize; // Amount of text captured
|
||||
std::vector<char> *captureBuf; // Buffer to send the captured text to if non-null
|
||||
|
||||
bool disableMacroArgs;
|
||||
@@ -85,38 +85,29 @@ struct LexerState {
|
||||
bool expandStrings;
|
||||
std::deque<Expansion> expansions; // Front is the innermost current expansion
|
||||
|
||||
std::variant<
|
||||
std::monostate,
|
||||
MmappedLexerState,
|
||||
ViewedLexerState,
|
||||
BufferedLexerState
|
||||
> content;
|
||||
std::variant<std::monostate, MmappedLexerState, ViewedLexerState, BufferedLexerState> content;
|
||||
};
|
||||
|
||||
extern LexerState *lexerState;
|
||||
extern LexerState *lexerStateEOL;
|
||||
|
||||
static inline void lexer_SetState(LexerState *state)
|
||||
{
|
||||
static inline void lexer_SetState(LexerState *state) {
|
||||
lexerState = state;
|
||||
}
|
||||
|
||||
static inline void lexer_SetStateAtEOL(LexerState *state)
|
||||
{
|
||||
static inline void lexer_SetStateAtEOL(LexerState *state) {
|
||||
lexerStateEOL = state;
|
||||
}
|
||||
|
||||
extern char binDigits[2];
|
||||
extern char gfxDigits[4];
|
||||
|
||||
static inline void lexer_SetBinDigits(char const digits[2])
|
||||
{
|
||||
static inline void lexer_SetBinDigits(char const digits[2]) {
|
||||
binDigits[0] = digits[0];
|
||||
binDigits[1] = digits[1];
|
||||
}
|
||||
|
||||
static inline void lexer_SetGfxDigits(char const digits[4])
|
||||
{
|
||||
static inline void lexer_SetGfxDigits(char const digits[4]) {
|
||||
gfxDigits[0] = digits[0];
|
||||
gfxDigits[1] = digits[1];
|
||||
gfxDigits[2] = digits[2];
|
||||
@@ -125,8 +116,9 @@ static inline void lexer_SetGfxDigits(char const digits[4])
|
||||
|
||||
// `path` is referenced, but not held onto..!
|
||||
bool lexer_OpenFile(LexerState &state, char const *path);
|
||||
void lexer_OpenFileView(LexerState &state, char const *path, char const *buf, size_t size,
|
||||
uint32_t lineNo);
|
||||
void lexer_OpenFileView(
|
||||
LexerState &state, char const *path, char const *buf, size_t size, uint32_t lineNo
|
||||
);
|
||||
void lexer_RestartRept(uint32_t lineNo);
|
||||
void lexer_CleanupState(LexerState &state);
|
||||
void lexer_Init();
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
struct MacroArgs {
|
||||
unsigned int shift;
|
||||
std::vector<std::string> args;
|
||||
|
||||
@@ -16,7 +16,9 @@ void out_RegisterNode(FileStackNode *node);
|
||||
void out_ReplaceNode(FileStackNode *node);
|
||||
void out_SetFileName(char *s);
|
||||
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift);
|
||||
void out_CreateAssert(enum AssertionType type, Expression const &expr, char const *message, uint32_t ofs);
|
||||
void out_CreateAssert(
|
||||
enum AssertionType type, Expression const &expr, char const *message, uint32_t ofs
|
||||
);
|
||||
void out_WriteObject();
|
||||
|
||||
#endif // RGBDS_ASM_OUTPUT_H
|
||||
|
||||
@@ -5,18 +5,19 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
struct Symbol;
|
||||
|
||||
struct Expression {
|
||||
int32_t val; // If the expression's value is known, it's here
|
||||
int32_t val; // If the expression's value is known, it's here
|
||||
std::string *reason; // Why the expression is not known, if it isn't
|
||||
bool isKnown; // Whether the expression's value is known at assembly time
|
||||
bool isSymbol; // Whether the expression represents a symbol suitable for const diffing
|
||||
bool isKnown; // Whether the expression's value is known at assembly time
|
||||
bool isSymbol; // Whether the expression represents a symbol suitable for const diffing
|
||||
std::vector<uint8_t> *rpn; // Bytes serializing the RPN expression
|
||||
uint32_t rpnPatchSize; // Size the expression will take in the object file
|
||||
uint32_t rpnPatchSize; // Size the expression will take in the object file
|
||||
|
||||
int32_t getConstVal() const;
|
||||
Symbol const *symbolOf() const;
|
||||
@@ -26,7 +27,9 @@ struct Expression {
|
||||
void rpn_Number(Expression &expr, uint32_t val);
|
||||
void rpn_Symbol(Expression &expr, char const *symName);
|
||||
void rpn_LOGNOT(Expression &expr, const Expression &src);
|
||||
void rpn_BinaryOp(enum RPNCommand op, Expression &expr, const Expression &src1, const Expression &src2);
|
||||
void rpn_BinaryOp(
|
||||
enum RPNCommand op, Expression &expr, const Expression &src1, const Expression &src2
|
||||
);
|
||||
void rpn_HIGH(Expression &expr, const Expression &src);
|
||||
void rpn_LOW(Expression &expr, const Expression &src);
|
||||
void rpn_ISCONST(Expression &expr, const Expression &src);
|
||||
|
||||
@@ -30,7 +30,7 @@ struct Section {
|
||||
enum SectionType type;
|
||||
enum SectionModifier modifier;
|
||||
FileStackNode const *src; // Where the section was defined
|
||||
uint32_t fileLine; // Line where the section was defined
|
||||
uint32_t fileLine; // Line where the section was defined
|
||||
uint32_t size;
|
||||
uint32_t org;
|
||||
uint32_t bank;
|
||||
@@ -52,10 +52,20 @@ extern std::deque<Section> sectionList;
|
||||
extern Section *currentSection;
|
||||
|
||||
Section *sect_FindSectionByName(char const *name);
|
||||
void sect_NewSection(char const *name, enum SectionType type, uint32_t org,
|
||||
SectionSpec const &attrs, enum SectionModifier mod);
|
||||
void sect_SetLoadSection(char const *name, enum SectionType type, uint32_t org,
|
||||
SectionSpec const &attrs, enum SectionModifier mod);
|
||||
void sect_NewSection(
|
||||
char const *name,
|
||||
enum SectionType type,
|
||||
uint32_t org,
|
||||
SectionSpec const &attrs,
|
||||
enum SectionModifier mod
|
||||
);
|
||||
void sect_SetLoadSection(
|
||||
char const *name,
|
||||
enum SectionType type,
|
||||
uint32_t org,
|
||||
SectionSpec const &attrs,
|
||||
enum SectionModifier mod
|
||||
);
|
||||
void sect_EndLoadSection();
|
||||
|
||||
Section *sect_GetSymbolSection();
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#define RGBDS_SYMBOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <time.h>
|
||||
#include <variant>
|
||||
@@ -23,7 +23,7 @@ enum SymbolType {
|
||||
SYM_REF // Forward reference to a label
|
||||
};
|
||||
|
||||
struct Symbol; // For the `sym_IsPC` forward declaration
|
||||
struct Symbol; // For the `sym_IsPC` forward declaration
|
||||
bool sym_IsPC(Symbol const *sym); // For the inline `getSection` method
|
||||
|
||||
struct Symbol {
|
||||
@@ -33,14 +33,15 @@ struct Symbol {
|
||||
bool isBuiltin; // Whether the symbol is a built-in
|
||||
Section *section;
|
||||
FileStackNode *src; // Where the symbol was defined
|
||||
uint32_t fileLine; // Line where the symbol was defined
|
||||
uint32_t fileLine; // Line where the symbol was defined
|
||||
|
||||
std::variant<
|
||||
int32_t, // If isNumeric()
|
||||
int32_t (*)(), // If isNumeric() and has a callback
|
||||
std::string_view *, // For SYM_MACRO
|
||||
std::string * // For SYM_EQUS
|
||||
> data;
|
||||
int32_t, // If isNumeric()
|
||||
int32_t (*)(), // If isNumeric() and has a callback
|
||||
std::string_view *, // For SYM_MACRO
|
||||
std::string * // For SYM_EQUS
|
||||
>
|
||||
data;
|
||||
|
||||
uint32_t ID; // ID of the symbol in the object file (-1 if none)
|
||||
|
||||
|
||||
@@ -7,34 +7,29 @@
|
||||
|
||||
extern unsigned int nbErrors, maxErrors;
|
||||
|
||||
enum WarningState {
|
||||
WARNING_DEFAULT,
|
||||
WARNING_DISABLED,
|
||||
WARNING_ENABLED,
|
||||
WARNING_ERROR
|
||||
};
|
||||
enum WarningState { WARNING_DEFAULT, WARNING_DISABLED, WARNING_ENABLED, WARNING_ERROR };
|
||||
|
||||
enum WarningID {
|
||||
WARNING_ASSERT, // Assertions
|
||||
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
|
||||
WARNING_BUILTIN_ARG, // Invalid args to builtins
|
||||
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
|
||||
WARNING_DIV, // Division undefined behavior
|
||||
WARNING_ASSERT, // Assertions
|
||||
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
|
||||
WARNING_BUILTIN_ARG, // Invalid args to builtins
|
||||
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
|
||||
WARNING_DIV, // Division undefined behavior
|
||||
WARNING_EMPTY_DATA_DIRECTIVE, // `db`, `dw` or `dl` directive without data in ROM
|
||||
WARNING_EMPTY_MACRO_ARG, // Empty macro argument
|
||||
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
|
||||
WARNING_LARGE_CONSTANT, // Constants too large
|
||||
WARNING_LONG_STR, // String too long for internal buffers
|
||||
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
|
||||
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
|
||||
WARNING_OBSOLETE, // Obsolete things
|
||||
WARNING_SHIFT, // Shifting undefined behavior
|
||||
WARNING_SHIFT_AMOUNT, // Strange shift amount
|
||||
WARNING_USER, // User warnings
|
||||
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
|
||||
WARNING_LARGE_CONSTANT, // Constants too large
|
||||
WARNING_LONG_STR, // String too long for internal buffers
|
||||
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
|
||||
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
|
||||
WARNING_OBSOLETE, // Obsolete things
|
||||
WARNING_SHIFT, // Shifting undefined behavior
|
||||
WARNING_SHIFT_AMOUNT, // Strange shift amount
|
||||
WARNING_USER, // User warnings
|
||||
|
||||
NB_PLAIN_WARNINGS,
|
||||
|
||||
// Warnings past this point are "parametric" warnings, only mapping to a single flag
|
||||
// Warnings past this point are "parametric" warnings, only mapping to a single flag
|
||||
#define PARAM_WARNINGS_START NB_PLAIN_WARNINGS
|
||||
// Treating string as number may lose some bits
|
||||
WARNING_NUMERIC_STRING_1 = PARAM_WARNINGS_START,
|
||||
@@ -49,7 +44,7 @@ enum WarningID {
|
||||
NB_PLAIN_AND_PARAM_WARNINGS,
|
||||
#define NB_PARAM_WARNINGS (NB_PLAIN_AND_PARAM_WARNINGS - PARAM_WARNINGS_START)
|
||||
|
||||
// Warnings past this point are "meta" warnings
|
||||
// Warnings past this point are "meta" warnings
|
||||
#define META_WARNINGS_START NB_PLAIN_AND_PARAM_WARNINGS
|
||||
WARNING_ALL = META_WARNINGS_START,
|
||||
WARNING_EXTRA,
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
void warn(char const *fmt ...) format_(printf, 1, 2);
|
||||
void warn(char const *fmt...) format_(printf, 1, 2);
|
||||
void warnx(char const *fmt, ...) format_(printf, 1, 2);
|
||||
|
||||
[[noreturn]] void err(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[noreturn]] void errx(char const *fmt, ...) format_(printf, 1, 2);
|
||||
|
||||
}
|
||||
|
||||
#endif // RGBDS_ERROR_H
|
||||
|
||||
11
include/extern/getopt.hpp
vendored
11
include/extern/getopt.hpp
vendored
@@ -17,12 +17,13 @@ struct option {
|
||||
int val;
|
||||
};
|
||||
|
||||
int musl_getopt_long_only(int argc, char **argv, char const *optstring,
|
||||
const option *longopts, int *idx);
|
||||
int musl_getopt_long_only(
|
||||
int argc, char **argv, char const *optstring, const option *longopts, int *idx
|
||||
);
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
|
||||
@@ -40,8 +40,11 @@ public:
|
||||
assert(!(mode & std::ios_base::out));
|
||||
_file.emplace<std::streambuf *>(std::cin.rdbuf());
|
||||
if (setmode(STDIN_FILENO, (mode & std::ios_base::binary) ? O_BINARY : O_TEXT) == -1) {
|
||||
fatal("Failed to set stdin to %s mode: %s",
|
||||
mode & std::ios_base::binary ? "binary" : "text", strerror(errno));
|
||||
fatal(
|
||||
"Failed to set stdin to %s mode: %s",
|
||||
mode & std::ios_base::binary ? "binary" : "text",
|
||||
strerror(errno)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
assert(mode & std::ios_base::out);
|
||||
@@ -50,9 +53,12 @@ public:
|
||||
return this;
|
||||
}
|
||||
std::streambuf &operator*() {
|
||||
return std::visit(Visitor{[](std::filebuf &file) -> std::streambuf & { return file; },
|
||||
[](std::streambuf *buf) -> std::streambuf & { return *buf; }},
|
||||
_file);
|
||||
return std::visit(
|
||||
Visitor{
|
||||
[](std::filebuf &file) -> std::streambuf & { return file; },
|
||||
[](std::streambuf *buf) -> std::streambuf & { return *buf; }},
|
||||
_file
|
||||
);
|
||||
}
|
||||
std::streambuf const &operator*() const {
|
||||
// The non-`const` version does not perform any modifications, so it's okay.
|
||||
@@ -65,25 +71,32 @@ public:
|
||||
}
|
||||
|
||||
File *close() {
|
||||
return std::visit(Visitor{[this](std::filebuf &file) {
|
||||
// This is called by the destructor, and an explicit `close`
|
||||
// shouldn't close twice.
|
||||
_file.emplace<std::streambuf *>(nullptr);
|
||||
return file.close() != nullptr;
|
||||
},
|
||||
[](std::streambuf *buf) { return buf != nullptr; }},
|
||||
_file)
|
||||
return std::visit(
|
||||
Visitor{
|
||||
[this](std::filebuf &file) {
|
||||
// This is called by the destructor, and an explicit `close`
|
||||
// shouldn't close twice.
|
||||
_file.emplace<std::streambuf *>(nullptr);
|
||||
return file.close() != nullptr;
|
||||
},
|
||||
[](std::streambuf *buf) { return buf != nullptr; },
|
||||
},
|
||||
_file
|
||||
)
|
||||
? this
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
char const *c_str(std::string const &path) const {
|
||||
return std::visit(Visitor{[&path](std::filebuf const &) { return path.c_str(); },
|
||||
[](std::streambuf const *buf) {
|
||||
return buf == std::cin.rdbuf()
|
||||
? "<stdin>" : "<stdout>";
|
||||
}},
|
||||
_file);
|
||||
return std::visit(
|
||||
Visitor{
|
||||
[&path](std::filebuf const &) { return path.c_str(); },
|
||||
[](std::streambuf const *buf) {
|
||||
return buf == std::cin.rdbuf() ? "<stdin>" : "<stdout>";
|
||||
},
|
||||
},
|
||||
_file
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ struct Options {
|
||||
uint16_t reversedWidth = 0; // -r, in tiles
|
||||
bool reverse() const { return reversedWidth != 0; }
|
||||
|
||||
bool useColorCurve = false; // -C
|
||||
bool useColorCurve = false; // -C
|
||||
bool allowMirroring = false; // -m
|
||||
bool allowDedup = false; // -u
|
||||
bool columnMajor = false; // -Z, previously -h
|
||||
uint8_t verbosity = 0; // -v
|
||||
bool allowDedup = false; // -u
|
||||
bool columnMajor = false; // -Z, previously -h
|
||||
uint8_t verbosity = 0; // -v
|
||||
|
||||
std::string attrmap{}; // -a, -A
|
||||
std::string attrmap{}; // -a, -A
|
||||
std::array<uint8_t, 2> baseTileIDs{0, 0}; // -b
|
||||
enum {
|
||||
NO_SPEC,
|
||||
@@ -39,25 +39,25 @@ struct Options {
|
||||
uint16_t top;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
} inputSlice{0, 0, 0, 0}; // -L (margins in clockwise order, like CSS)
|
||||
} inputSlice{0, 0, 0, 0}; // -L (margins in clockwise order, like CSS)
|
||||
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N
|
||||
uint8_t nbPalettes = 8; // -n
|
||||
std::string output{}; // -o
|
||||
std::string palettes{}; // -p, -P
|
||||
std::string palmap{}; // -q, -Q
|
||||
uint8_t nbColorsPerPal = 0; // -s; 0 means "auto" = 1 << bitDepth;
|
||||
std::string tilemap{}; // -t, -T
|
||||
uint64_t trim = 0; // -x
|
||||
uint8_t nbPalettes = 8; // -n
|
||||
std::string output{}; // -o
|
||||
std::string palettes{}; // -p, -P
|
||||
std::string palmap{}; // -q, -Q
|
||||
uint8_t nbColorsPerPal = 0; // -s; 0 means "auto" = 1 << bitDepth;
|
||||
std::string tilemap{}; // -t, -T
|
||||
uint64_t trim = 0; // -x
|
||||
|
||||
std::string input{}; // positional arg
|
||||
|
||||
static constexpr uint8_t VERB_NONE = 0; // Normal, no extra output
|
||||
static constexpr uint8_t VERB_CFG = 1; // Print configuration after parsing options
|
||||
static constexpr uint8_t VERB_LOG_ACT = 2; // Log actions before doing them
|
||||
static constexpr uint8_t VERB_INTERM = 3; // Print some intermediate results
|
||||
static constexpr uint8_t VERB_DEBUG = 4; // Internals are logged
|
||||
static constexpr uint8_t VERB_NONE = 0; // Normal, no extra output
|
||||
static constexpr uint8_t VERB_CFG = 1; // Print configuration after parsing options
|
||||
static constexpr uint8_t VERB_LOG_ACT = 2; // Log actions before doing them
|
||||
static constexpr uint8_t VERB_INTERM = 3; // Print some intermediate results
|
||||
static constexpr uint8_t VERB_DEBUG = 4; // Internals are logged
|
||||
static constexpr uint8_t VERB_UNMAPPED = 5; // Unused so far
|
||||
static constexpr uint8_t VERB_VVVVVV = 6; // What, can't I have a little fun?
|
||||
static constexpr uint8_t VERB_VVVVVV = 6; // What, can't I have a little fun?
|
||||
format_(printf, 3, 4) void verbosePrint(uint8_t level, char const *fmt, ...) const;
|
||||
|
||||
mutable bool hasTransparentPixels = false;
|
||||
|
||||
@@ -15,10 +15,16 @@ struct Palette;
|
||||
|
||||
namespace sorting {
|
||||
|
||||
void indexed(std::vector<Palette> &palettes, int palSize, png_color const *palRGB,
|
||||
int palAlphaSize, png_byte *palAlpha);
|
||||
void grayscale(std::vector<Palette> &palettes,
|
||||
std::array<std::optional<Rgba>, 0x8001> const &colors);
|
||||
void indexed(
|
||||
std::vector<Palette> &palettes,
|
||||
int palSize,
|
||||
png_color const *palRGB,
|
||||
int palAlphaSize,
|
||||
png_byte *palAlpha
|
||||
);
|
||||
void grayscale(
|
||||
std::vector<Palette> &palettes, std::array<std::optional<Rgba>, 0x8001> const &colors
|
||||
);
|
||||
void rgb(std::vector<Palette> &palettes);
|
||||
|
||||
} // namespace sorting
|
||||
|
||||
@@ -25,8 +25,12 @@ struct Rgba {
|
||||
fiveBpp &= 0b11111; // For caller's convenience
|
||||
return fiveBpp << 3 | fiveBpp >> 2;
|
||||
};
|
||||
return {_5to8(cgbColor), _5to8(cgbColor >> 5), _5to8(cgbColor >> 10),
|
||||
(uint8_t)(cgbColor & 0x8000 ? 0x00 : 0xFF)};
|
||||
return {
|
||||
_5to8(cgbColor),
|
||||
_5to8(cgbColor >> 5),
|
||||
_5to8(cgbColor >> 10),
|
||||
(uint8_t)(cgbColor & 0x8000 ? 0x00 : 0xFF),
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
// Ideally, we'd use `__has_attribute` and `__has_builtin`, but these were only introduced in GCC 9
|
||||
#ifdef __GNUC__ // GCC or compatible
|
||||
#define format_(archetype, str_index, first_arg) \
|
||||
__attribute__ ((format (archetype, str_index, first_arg)))
|
||||
#define attr_(...) __attribute__ ((__VA_ARGS__))
|
||||
__attribute__((format(archetype, str_index, first_arg)))
|
||||
#define attr_(...) __attribute__((__VA_ARGS__))
|
||||
// In release builds, define "unreachable" as such, but trap in debug builds
|
||||
#ifdef NDEBUG
|
||||
#define unreachable_ __builtin_unreachable
|
||||
@@ -18,9 +18,10 @@
|
||||
// Unsupported, but no need to throw a fit
|
||||
#define format_(archetype, str_index, first_arg)
|
||||
#define attr_(...)
|
||||
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
|
||||
[[noreturn]] static inline void unreachable_() {}
|
||||
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
|
||||
[[noreturn]] static inline void unreachable_() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use builtins whenever possible, and shim them otherwise
|
||||
@@ -32,50 +33,46 @@
|
||||
#include <assert.h>
|
||||
#include <intrin.h>
|
||||
#pragma intrinsic(_BitScanReverse, _BitScanForward)
|
||||
static inline int ctz(unsigned int x)
|
||||
{
|
||||
unsigned long cnt;
|
||||
static inline int ctz(unsigned int x) {
|
||||
unsigned long cnt;
|
||||
|
||||
assert(x != 0);
|
||||
_BitScanForward(&cnt, x);
|
||||
return cnt;
|
||||
}
|
||||
static inline int clz(unsigned int x)
|
||||
{
|
||||
unsigned long cnt;
|
||||
assert(x != 0);
|
||||
_BitScanForward(&cnt, x);
|
||||
return cnt;
|
||||
}
|
||||
static inline int clz(unsigned int x) {
|
||||
unsigned long cnt;
|
||||
|
||||
assert(x != 0);
|
||||
_BitScanReverse(&cnt, x);
|
||||
return 31 - cnt;
|
||||
}
|
||||
assert(x != 0);
|
||||
_BitScanReverse(&cnt, x);
|
||||
return 31 - cnt;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <limits.h>
|
||||
static inline int ctz(unsigned int x)
|
||||
{
|
||||
int cnt = 0;
|
||||
static inline int ctz(unsigned int x) {
|
||||
int cnt = 0;
|
||||
|
||||
while (!(x & 1)) {
|
||||
x >>= 1;
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
while (!(x & 1)) {
|
||||
x >>= 1;
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static inline int clz(unsigned int x)
|
||||
{
|
||||
int cnt = 0;
|
||||
static inline int clz(unsigned int x) {
|
||||
int cnt = 0;
|
||||
|
||||
while (x <= UINT_MAX / 2) {
|
||||
x <<= 1;
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
while (x <= UINT_MAX / 2) {
|
||||
x <<= 1;
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Macros for stringification
|
||||
#define STR(x) #x
|
||||
#define STR(x) #x
|
||||
#define EXPAND_AND_STR(x) STR(x)
|
||||
|
||||
// Obtaining the size of an array; `arr` must be an expression, not a type!
|
||||
|
||||
@@ -64,8 +64,9 @@ public:
|
||||
}
|
||||
|
||||
auto operator*() const {
|
||||
return std::apply([](auto &&...it) { return std::tuple<decltype(*it)...>(*it...); },
|
||||
_iters);
|
||||
return std::apply(
|
||||
[](auto &&...it) { return std::tuple<decltype(*it)...>(*it...); }, _iters
|
||||
);
|
||||
}
|
||||
|
||||
friend auto operator==(Zip const &lhs, Zip const &rhs) {
|
||||
@@ -92,7 +93,8 @@ public:
|
||||
using std::begin;
|
||||
return std::make_tuple(begin(containers)...);
|
||||
},
|
||||
_containers));
|
||||
_containers
|
||||
));
|
||||
}
|
||||
|
||||
auto end() {
|
||||
@@ -101,14 +103,15 @@ public:
|
||||
using std::end;
|
||||
return std::make_tuple(end(containers)...);
|
||||
},
|
||||
_containers));
|
||||
_containers
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// Take ownership of objects and rvalue refs passed to us, but not lvalue refs
|
||||
template<typename T>
|
||||
using Holder = std::conditional_t<std::is_lvalue_reference_v<T>, T,
|
||||
std::remove_cv_t<std::remove_reference_t<T>>>;
|
||||
using Holder = std::
|
||||
conditional_t<std::is_lvalue_reference_v<T>, T, std::remove_cv_t<std::remove_reference_t<T>>>;
|
||||
} // namespace detail
|
||||
|
||||
// Does the same number of iterations as the first container's iterator!
|
||||
|
||||
@@ -31,10 +31,11 @@ extern bool isWRAM0Mode;
|
||||
extern bool disablePadding;
|
||||
|
||||
// Helper macro for printing verbose-mode messages
|
||||
#define verbosePrint(...) do { \
|
||||
if (beVerbose) \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define verbosePrint(...) \
|
||||
do { \
|
||||
if (beVerbose) \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
struct FileStackNode {
|
||||
FileStackNode *parent;
|
||||
@@ -43,10 +44,11 @@ struct FileStackNode {
|
||||
|
||||
enum FileStackNodeType type;
|
||||
std::variant<
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
> data;
|
||||
std::monostate, // Default constructed; `.type` and `.data` must be set manually
|
||||
std::vector<uint32_t>, // NODE_REPT
|
||||
std::string // NODE_FILE, NODE_MACRO
|
||||
>
|
||||
data;
|
||||
|
||||
// REPT iteration counts since last named node, in reverse depth order
|
||||
std::vector<uint32_t> &iters();
|
||||
@@ -58,8 +60,10 @@ struct FileStackNode {
|
||||
std::string const *dumpFileStack() const;
|
||||
};
|
||||
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) format_(printf, 3, 4);
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
format_(printf, 3, 4);
|
||||
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) format_(printf, 3, 4);
|
||||
[[noreturn]] void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) format_(printf, 3, 4);
|
||||
[[noreturn]] void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
format_(printf, 3, 4);
|
||||
|
||||
#endif // RGBDS_LINK_MAIN_H
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "link/section.hpp"
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
#include "link/section.hpp"
|
||||
|
||||
struct Assertion {
|
||||
Patch patch; // Also used for its `.type`
|
||||
std::string message;
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "link/main.hpp"
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
#include "link/main.hpp"
|
||||
|
||||
struct FileStackNode;
|
||||
struct Section;
|
||||
struct Symbol;
|
||||
|
||||
@@ -30,9 +30,10 @@ struct Symbol {
|
||||
FileStackNode const *src;
|
||||
int32_t lineNo;
|
||||
std::variant<
|
||||
int32_t, // Constants just have a numeric value
|
||||
Label // Label values refer to an offset within a specific section
|
||||
> data;
|
||||
int32_t, // Constants just have a numeric value
|
||||
Label // Label values refer to an offset within a specific section
|
||||
>
|
||||
data;
|
||||
|
||||
Label &label();
|
||||
Label const &label() const;
|
||||
|
||||
@@ -8,56 +8,52 @@
|
||||
#include <string>
|
||||
|
||||
#define RGBDS_OBJECT_VERSION_STRING "RGBA"
|
||||
#define RGBDS_OBJECT_REV 10U
|
||||
#define RGBDS_OBJECT_REV 10U
|
||||
|
||||
enum AssertionType {
|
||||
ASSERT_WARN,
|
||||
ASSERT_ERROR,
|
||||
ASSERT_FATAL
|
||||
};
|
||||
enum AssertionType { ASSERT_WARN, ASSERT_ERROR, ASSERT_FATAL };
|
||||
|
||||
enum RPNCommand {
|
||||
RPN_ADD = 0x00,
|
||||
RPN_SUB = 0x01,
|
||||
RPN_MUL = 0x02,
|
||||
RPN_DIV = 0x03,
|
||||
RPN_MOD = 0x04,
|
||||
RPN_NEG = 0x05,
|
||||
RPN_EXP = 0x06,
|
||||
RPN_ADD = 0x00,
|
||||
RPN_SUB = 0x01,
|
||||
RPN_MUL = 0x02,
|
||||
RPN_DIV = 0x03,
|
||||
RPN_MOD = 0x04,
|
||||
RPN_NEG = 0x05,
|
||||
RPN_EXP = 0x06,
|
||||
|
||||
RPN_OR = 0x10,
|
||||
RPN_AND = 0x11,
|
||||
RPN_XOR = 0x12,
|
||||
RPN_NOT = 0x13,
|
||||
RPN_OR = 0x10,
|
||||
RPN_AND = 0x11,
|
||||
RPN_XOR = 0x12,
|
||||
RPN_NOT = 0x13,
|
||||
|
||||
RPN_LOGAND = 0x21,
|
||||
RPN_LOGOR = 0x22,
|
||||
RPN_LOGNOT = 0x23,
|
||||
RPN_LOGAND = 0x21,
|
||||
RPN_LOGOR = 0x22,
|
||||
RPN_LOGNOT = 0x23,
|
||||
|
||||
RPN_LOGEQ = 0x30,
|
||||
RPN_LOGNE = 0x31,
|
||||
RPN_LOGGT = 0x32,
|
||||
RPN_LOGLT = 0x33,
|
||||
RPN_LOGGE = 0x34,
|
||||
RPN_LOGLE = 0x35,
|
||||
RPN_LOGEQ = 0x30,
|
||||
RPN_LOGNE = 0x31,
|
||||
RPN_LOGGT = 0x32,
|
||||
RPN_LOGLT = 0x33,
|
||||
RPN_LOGGE = 0x34,
|
||||
RPN_LOGLE = 0x35,
|
||||
|
||||
RPN_SHL = 0x40,
|
||||
RPN_SHR = 0x41,
|
||||
RPN_USHR = 0x42,
|
||||
RPN_SHL = 0x40,
|
||||
RPN_SHR = 0x41,
|
||||
RPN_USHR = 0x42,
|
||||
|
||||
RPN_BANK_SYM = 0x50,
|
||||
RPN_BANK_SECT = 0x51,
|
||||
RPN_BANK_SELF = 0x52,
|
||||
RPN_SIZEOF_SECT = 0x53,
|
||||
RPN_STARTOF_SECT = 0x54,
|
||||
RPN_SIZEOF_SECTTYPE = 0x55,
|
||||
RPN_STARTOF_SECTTYPE = 0x56,
|
||||
RPN_BANK_SYM = 0x50,
|
||||
RPN_BANK_SECT = 0x51,
|
||||
RPN_BANK_SELF = 0x52,
|
||||
RPN_SIZEOF_SECT = 0x53,
|
||||
RPN_STARTOF_SECT = 0x54,
|
||||
RPN_SIZEOF_SECTTYPE = 0x55,
|
||||
RPN_STARTOF_SECTTYPE = 0x56,
|
||||
|
||||
RPN_HRAM = 0x60,
|
||||
RPN_RST = 0x61,
|
||||
RPN_HRAM = 0x60,
|
||||
RPN_RST = 0x61,
|
||||
|
||||
RPN_CONST = 0x80,
|
||||
RPN_SYM = 0x81
|
||||
RPN_CONST = 0x80,
|
||||
RPN_SYM = 0x81
|
||||
};
|
||||
|
||||
enum SectionType {
|
||||
@@ -96,8 +92,7 @@ extern struct SectionTypeInfo {
|
||||
* @param type The section's type
|
||||
* @return `true` if the section's definition includes data
|
||||
*/
|
||||
static inline bool sect_HasData(enum SectionType type)
|
||||
{
|
||||
static inline bool sect_HasData(enum SectionType type) {
|
||||
assert(type != SECTTYPE_INVALID);
|
||||
return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX;
|
||||
}
|
||||
@@ -106,8 +101,7 @@ static inline bool sect_HasData(enum SectionType type)
|
||||
* Computes a memory region's end address (last byte), eg. 0x7FFF
|
||||
* @return The address of the last byte in that memory region
|
||||
*/
|
||||
static inline uint16_t endaddr(enum SectionType type)
|
||||
{
|
||||
static inline uint16_t endaddr(enum SectionType type) {
|
||||
return sectionTypeInfo[type].startAddr + sectionTypeInfo[type].size - 1;
|
||||
}
|
||||
|
||||
@@ -115,24 +109,15 @@ static inline uint16_t endaddr(enum SectionType type)
|
||||
* Computes a memory region's number of banks
|
||||
* @return The number of banks, 1 for regions without banking
|
||||
*/
|
||||
static inline uint32_t nbbanks(enum SectionType type)
|
||||
{
|
||||
static inline uint32_t nbbanks(enum SectionType type) {
|
||||
return sectionTypeInfo[type].lastBank - sectionTypeInfo[type].firstBank + 1;
|
||||
}
|
||||
|
||||
enum SectionModifier {
|
||||
SECTION_NORMAL,
|
||||
SECTION_UNION,
|
||||
SECTION_FRAGMENT
|
||||
};
|
||||
enum SectionModifier { SECTION_NORMAL, SECTION_UNION, SECTION_FRAGMENT };
|
||||
|
||||
extern char const * const sectionModNames[];
|
||||
|
||||
enum ExportLevel {
|
||||
SYMTYPE_LOCAL,
|
||||
SYMTYPE_IMPORT,
|
||||
SYMTYPE_EXPORT
|
||||
};
|
||||
enum ExportLevel { SYMTYPE_LOCAL, SYMTYPE_IMPORT, SYMTYPE_EXPORT };
|
||||
|
||||
enum PatchType {
|
||||
PATCHTYPE_BYTE,
|
||||
|
||||
@@ -7,62 +7,62 @@
|
||||
|
||||
// MSVC doesn't have str(n)casecmp, use a suitable replacement
|
||||
#ifdef _MSC_VER
|
||||
# include <string.h>
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#include <string.h>
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
// MSVC prefixes the names of S_* macros with underscores,
|
||||
// and doesn't define any S_IS* macros; define them ourselves
|
||||
#ifdef _MSC_VER
|
||||
# define S_IFMT _S_IFMT
|
||||
# define S_IFDIR _S_IFDIR
|
||||
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_IFMT _S_IFMT
|
||||
#define S_IFDIR _S_IFDIR
|
||||
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
// gcc has __PRETTY_FUNCTION__, MSVC has __FUNCSIG__, __func__ is standard
|
||||
#ifndef __PRETTY_FUNCTION__
|
||||
# ifdef __FUNCSIG__
|
||||
# define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||
# else
|
||||
# define __PRETTY_FUNCTION__ __func__
|
||||
# endif
|
||||
#ifdef __FUNCSIG__
|
||||
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||
#else
|
||||
#define __PRETTY_FUNCTION__ __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// MSVC doesn't use POSIX types or defines for `read`
|
||||
#ifdef _MSC_VER
|
||||
# include <io.h>
|
||||
# define STDIN_FILENO 0
|
||||
# define STDOUT_FILENO 1
|
||||
# define STDERR_FILENO 2
|
||||
# define ssize_t int
|
||||
# define SSIZE_MAX INT_MAX
|
||||
#include <io.h>
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
#define STDERR_FILENO 2
|
||||
#define ssize_t int
|
||||
#define SSIZE_MAX INT_MAX
|
||||
#else
|
||||
# include <fcntl.h>
|
||||
# include <limits.h>
|
||||
# include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
// MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag
|
||||
#ifdef _MSC_VER
|
||||
# include <fcntl.h>
|
||||
# define O_RDWR _O_RDWR
|
||||
# define S_ISREG(field) ((field) & _S_IFREG)
|
||||
# define O_BINARY _O_BINARY
|
||||
# define O_TEXT _O_TEXT
|
||||
#include <fcntl.h>
|
||||
#define O_RDWR _O_RDWR
|
||||
#define S_ISREG(field) ((field)&_S_IFREG)
|
||||
#define O_BINARY _O_BINARY
|
||||
#define O_TEXT _O_TEXT
|
||||
#elif !defined(O_BINARY) // Cross-compilers define O_BINARY
|
||||
# define O_BINARY 0 // POSIX says we shouldn't care!
|
||||
# define O_TEXT 0 // Assume that it's not defined either
|
||||
#endif // _MSC_VER
|
||||
#define O_BINARY 0 // POSIX says we shouldn't care!
|
||||
#define O_TEXT 0 // Assume that it's not defined either
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Windows has stdin and stdout open as text by default, which we may not want
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
# include <io.h>
|
||||
# define setmode(fd, mode) _setmode(fd, mode)
|
||||
#include <io.h>
|
||||
#define setmode(fd, mode) _setmode(fd, mode)
|
||||
#else
|
||||
# define setmode(fd, mode) (0)
|
||||
#define setmode(fd, mode) (0)
|
||||
#endif
|
||||
|
||||
#endif // RGBDS_PLATFORM_H
|
||||
|
||||
@@ -10,7 +10,6 @@ extern "C" {
|
||||
#define PACKAGE_VERSION_PATCH 0
|
||||
|
||||
char const *get_package_version_string();
|
||||
|
||||
}
|
||||
|
||||
#endif // EXTERN_VERSION_H
|
||||
|
||||
Reference in New Issue
Block a user