Split up the linkerscript lexer and layout actions

This commit is contained in:
Rangi42
2025-07-27 13:03:28 -04:00
parent a353637a90
commit 16e16cdf51
15 changed files with 448 additions and 433 deletions

View File

@@ -3,37 +3,20 @@
#ifndef RGBDS_LINK_LAYOUT_HPP
#define RGBDS_LINK_LAYOUT_HPP
#include <fstream>
#include <stdint.h>
#include <string>
#include "linkdefs.hpp"
struct LexerStackEntry {
std::filebuf file;
std::string path;
uint32_t lineNo;
explicit LexerStackEntry(std::string &&path_) : file(), path(path_), lineNo(1) {}
};
#define scriptError(context, fmt, ...) \
::error( \
"%s(%" PRIu32 "): " fmt, context.path.c_str(), context.lineNo __VA_OPT__(, ) __VA_ARGS__ \
)
LexerStackEntry &lexer_Context();
void lexer_IncludeFile(std::string &&path);
void lexer_IncLineNo();
bool lexer_Init(char const *linkerScriptName);
void layout_SetFloatingSectionType(SectionType type);
void layout_SetSectionType(SectionType type);
void layout_SetSectionType(SectionType type, uint32_t bank);
void layout_SetAddr(uint32_t addr);
void layout_MakeAddrFloating();
void layout_AlignTo(uint32_t alignment, uint32_t offset);
void layout_Pad(uint32_t length);
void layout_PlaceSection(std::string const &name, bool isOptional);
#endif // RGBDS_LINK_LAYOUT_HPP

17
include/link/lexer.hpp Normal file
View File

@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
#ifndef RGBDS_LINK_LEXER_HPP
#define RGBDS_LINK_LEXER_HPP
#include <stdarg.h>
#include <string>
[[gnu::format(printf, 1, 2)]]
void lexer_Error(char const *fmt, ...);
void lexer_IncludeFile(std::string &&path);
void lexer_IncLineNo();
bool lexer_Init(char const *linkerScriptName);
#endif // RGBDS_LINK_LEXER_HPP

View File

@@ -12,13 +12,13 @@
#include "linkdefs.hpp"
struct Options {
bool isDmgMode; // -d
char const *mapFileName; // -m
bool noSymInMap; // -M
char const *symFileName; // -n
char const *overlayFileName; // -O
char const *outputFileName; // -o
uint8_t padValue; // -p
bool isDmgMode; // -d
char const *mapFileName; // -m
bool noSymInMap; // -M
char const *symFileName; // -n
char const *overlayFileName; // -O
char const *outputFileName; // -o
uint8_t padValue; // -p
bool hasPadValue = false;
// Setting these three to 0 disables the functionality
uint16_t scrambleROMX; // -S

View File

@@ -3,6 +3,7 @@
#ifndef RGBDS_LINK_WARNING_HPP
#define RGBDS_LINK_WARNING_HPP
#include <stdarg.h>
#include <stdint.h>
#include "diagnostics.hpp"
@@ -48,7 +49,9 @@ void error(char const *fmt, ...);
[[gnu::format(printf, 1, 2)]]
void errorNoDump(char const *fmt, ...);
[[gnu::format(printf, 2, 3)]]
void argErr(char flag, char const *fmt, ...);
void argError(char flag, char const *fmt, ...);
void scriptError(char const *name, uint32_t lineNo, char const *fmt, va_list args);
[[gnu::format(printf, 3, 4), noreturn]]
void fatal(FileStackNode const *src, uint32_t lineNo, char const *fmt, ...);