mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 03:02:06 +00:00
Port linkerscript parser to Bison (#1266)
Notable side effects: * Use the standard-conformant MSVC preproc * Add test for linker script INCLUDE * Improve wording of placement conflict errors * Fix errors from not newline-terminated files * Teach checkdiff about the linker script doc * Call linker script "commands" "directives" instead --------- Co-authored-by: Rangi42 <remy.oukaour+rangi42@gmail.com>
This commit is contained in:
@@ -10,10 +10,10 @@
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "hashmap.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
// Charmaps are stored using a structure known as "trie".
|
||||
// Essentially a tree, where each nodes stores a single character's worth of info:
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#endif
|
||||
|
||||
#include "platform.hpp" // For `ssize_t` and `AT`
|
||||
#include "util.hpp"
|
||||
|
||||
#include "asm/lexer.hpp"
|
||||
#include "asm/fixpoint.hpp"
|
||||
@@ -28,7 +29,6 @@
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
// Include this last so it gets all type & constant definitions
|
||||
#include "parser.hpp" // For token definitions, generated from parser.y
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "asm/rpn.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "extern/utf8decoder.hpp"
|
||||
|
||||
@@ -222,7 +222,7 @@ static void mergeSections(struct Section *sect, enum SectionType type, uint32_t
|
||||
unsigned int nbSectErrors = 0;
|
||||
|
||||
if (type != sect->type)
|
||||
fail("Section already exists but with type %s\n", sectionTypeInfo[sect->type].name);
|
||||
fail("Section already exists but with type %s\n", sectionTypeInfo[sect->type].name.c_str());
|
||||
|
||||
if (sect->modifier != mod) {
|
||||
fail("Section already declared as %s section\n", sectionModNames[sect->modifier]);
|
||||
@@ -314,7 +314,7 @@ static struct Section *getSection(char const *name, enum SectionType type, uint3
|
||||
error("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections\n");
|
||||
else if (bank < sectionTypeInfo[type].firstBank || bank > sectionTypeInfo[type].lastBank)
|
||||
error("%s bank value $%04" PRIx32 " out of range ($%04" PRIx32 " to $%04"
|
||||
PRIx32 ")\n", sectionTypeInfo[type].name, bank,
|
||||
PRIx32 ")\n", sectionTypeInfo[type].name.c_str(), bank,
|
||||
sectionTypeInfo[type].firstBank, sectionTypeInfo[type].lastBank);
|
||||
} else if (nbbanks(type) == 1) {
|
||||
// If the section type only has a single bank, implicitly force it
|
||||
@@ -349,7 +349,7 @@ static struct Section *getSection(char const *name, enum SectionType type, uint3
|
||||
alignment = 0; // Ignore it if it's satisfied
|
||||
} else if (sectionTypeInfo[type].startAddr & mask) {
|
||||
error("Section \"%s\"'s alignment cannot be attained in %s\n",
|
||||
name, sectionTypeInfo[type].name);
|
||||
name, sectionTypeInfo[type].name.c_str());
|
||||
alignment = 0; // Ignore it if it's unattainable
|
||||
org = 0;
|
||||
} else if (alignment == 16) {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "asm/output.hpp"
|
||||
#include "asm/section.hpp"
|
||||
#include "asm/symbol.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "asm/main.hpp"
|
||||
#include "asm/util.hpp"
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
#include "extern/utf8decoder.hpp"
|
||||
|
||||
char const *printChar(int c)
|
||||
{
|
||||
// "'A'" + '\0': 4 bytes
|
||||
// "'\\n'" + '\0': 5 bytes
|
||||
// "0xFF" + '\0': 5 bytes
|
||||
static char buf[5];
|
||||
|
||||
if (c == EOF)
|
||||
return "EOF";
|
||||
|
||||
if (isprint(c)) {
|
||||
buf[0] = '\'';
|
||||
buf[1] = c;
|
||||
buf[2] = '\'';
|
||||
buf[3] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
buf[2] = 'n';
|
||||
break;
|
||||
case '\r':
|
||||
buf[2] = 'r';
|
||||
break;
|
||||
case '\t':
|
||||
buf[2] = 't';
|
||||
break;
|
||||
|
||||
default: // Print as hex
|
||||
buf[0] = '0';
|
||||
buf[1] = 'x';
|
||||
snprintf(&buf[2], 3, "%02hhX", (uint8_t)c); // includes the '\0'
|
||||
return buf;
|
||||
}
|
||||
buf[0] = '\'';
|
||||
buf[1] = '\\';
|
||||
buf[3] = '\'';
|
||||
buf[4] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
size_t readUTF8Char(uint8_t *dest, char const *src)
|
||||
{
|
||||
uint32_t state = 0;
|
||||
uint32_t codep;
|
||||
size_t i = 0;
|
||||
|
||||
for (;;) {
|
||||
if (decode(&state, &codep, src[i]) == 1)
|
||||
return 0;
|
||||
|
||||
if (dest)
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
|
||||
if (state == 0)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user