More refactoring around extern variables

This commit is contained in:
Rangi42
2025-07-21 19:22:10 -04:00
parent d1493a9f96
commit 5f333d9753
8 changed files with 22 additions and 34 deletions

View File

@@ -17,7 +17,6 @@ struct FileStackNode;
enum StateFeature { STATE_EQU, STATE_VAR, STATE_EQUS, STATE_CHAR, STATE_MACRO, NB_STATE_FEATURES }; enum StateFeature { STATE_EQU, STATE_VAR, STATE_EQUS, STATE_CHAR, STATE_MACRO, NB_STATE_FEATURES };
void out_RegisterNode(std::shared_ptr<FileStackNode> node); void out_RegisterNode(std::shared_ptr<FileStackNode> node);
void out_SetFileName(std::string const &name);
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift); void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift);
void out_CreateAssert( void out_CreateAssert(
AssertionType type, Expression const &expr, std::string const &message, uint32_t ofs AssertionType type, Expression const &expr, std::string const &message, uint32_t ofs

View File

@@ -44,9 +44,8 @@ struct Context {
static std::stack<Context> contextStack; static std::stack<Context> contextStack;
// The first include path for `fstk_FindFile` to try is none at all // The first include path for `fstk_FindFile` to try is none at all
static std::vector<std::string> includePaths = {""}; static std::vector<std::string> includePaths = {""}; // -I
static std::deque<std::string> preIncludeNames; // -P
static std::deque<std::string> preIncludeNames;
std::string FileStackNode::reptChain() const { std::string FileStackNode::reptChain() const {
std::string chain; std::string chain;

View File

@@ -501,8 +501,7 @@ LexerState::~LexerState() {
bool Expansion::advance() { bool Expansion::advance() {
assume(offset <= size()); assume(offset <= size());
++offset; return ++offset > size();
return offset > size();
} }
BufferedContent::~BufferedContent() { BufferedContent::~BufferedContent() {

View File

@@ -182,7 +182,6 @@ int main(int argc, char *argv[]) {
uint32_t maxDepth = 64; uint32_t maxDepth = 64;
char const *dependFileName = nullptr; char const *dependFileName = nullptr;
std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs; std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs;
std::string newTarget;
// Maximum of 100 errors only applies if rgbasm is printing errors to a terminal. // Maximum of 100 errors only applies if rgbasm is printing errors to a terminal.
if (isatty(STDERR_FILENO)) { if (isatty(STDERR_FILENO)) {
options.maxErrors = 100; options.maxErrors = 100;
@@ -252,7 +251,11 @@ int main(int argc, char *argv[]) {
break; break;
case 'o': case 'o':
out_SetFileName(musl_optarg); if (!options.objectFileName.empty()) {
warnx("Overriding output filename %s", options.objectFileName.c_str());
}
options.objectFileName = musl_optarg;
verbosePrint("Output filename %s\n", options.objectFileName.c_str()); // LCOV_EXCL_LINE
break; break;
case 'P': case 'P':
@@ -274,14 +277,12 @@ int main(int argc, char *argv[]) {
opt_P(padByte); opt_P(padByte);
break; break;
unsigned long precision; case 'Q': {
char const *precisionArg; char const *precisionArg = musl_optarg;
case 'Q':
precisionArg = musl_optarg;
if (precisionArg[0] == '.') { if (precisionArg[0] == '.') {
++precisionArg; ++precisionArg;
} }
precision = strtoul(precisionArg, &endptr, 0); unsigned long precision = strtoul(precisionArg, &endptr, 0);
if (musl_optarg[0] == '\0' || *endptr != '\0') { if (musl_optarg[0] == '\0' || *endptr != '\0') {
fatal("Invalid argument for option 'Q'"); fatal("Invalid argument for option 'Q'");
@@ -293,6 +294,7 @@ int main(int argc, char *argv[]) {
opt_Q(precision); opt_Q(precision);
break; break;
}
case 'r': case 'r':
maxDepth = strtoul(musl_optarg, &endptr, 0); maxDepth = strtoul(musl_optarg, &endptr, 0);
@@ -338,9 +340,8 @@ int main(int argc, char *argv[]) {
warnings.state.warningsEnabled = false; warnings.state.warningsEnabled = false;
break; break;
unsigned long maxErrors; case 'X': {
case 'X': unsigned long maxErrors = strtoul(musl_optarg, &endptr, 0);
maxErrors = strtoul(musl_optarg, &endptr, 0);
if (musl_optarg[0] == '\0' || *endptr != '\0') { if (musl_optarg[0] == '\0' || *endptr != '\0') {
fatal("Invalid argument for option 'X'"); fatal("Invalid argument for option 'X'");
@@ -352,6 +353,7 @@ int main(int argc, char *argv[]) {
options.maxErrors = maxErrors; options.maxErrors = maxErrors;
break; break;
}
// Long-only options // Long-only options
case 0: case 0:
@@ -369,8 +371,8 @@ int main(int argc, char *argv[]) {
break; break;
case 'Q': case 'Q':
case 'T': case 'T': {
newTarget = musl_optarg; std::string newTarget = musl_optarg;
if (depType == 'Q') { if (depType == 'Q') {
newTarget = make_escape(newTarget); newTarget = make_escape(newTarget);
} }
@@ -380,6 +382,7 @@ int main(int argc, char *argv[]) {
options.targetFileName += newTarget; options.targetFileName += newTarget;
break; break;
} }
}
break; break;
// Unrecognized options // Unrecognized options

View File

@@ -369,14 +369,6 @@ void out_WriteObject() {
} }
} }
void out_SetFileName(std::string const &name) {
if (!options.objectFileName.empty()) {
warnx("Overriding output filename %s", options.objectFileName.c_str());
}
options.objectFileName = name;
verbosePrint("Output filename %s\n", options.objectFileName.c_str()); // LCOV_EXCL_LINE
}
static void dumpString(std::string const &escape, FILE *file) { static void dumpString(std::string const &escape, FILE *file) {
for (char c : escape) { for (char c : escape) {
// Escape characters that need escaping // Escape characters that need escaping

View File

@@ -36,7 +36,7 @@ static char savedTIME[256];
static char savedDATE[256]; static char savedDATE[256];
static char savedTIMESTAMP_ISO8601_LOCAL[256]; static char savedTIMESTAMP_ISO8601_LOCAL[256];
static char savedTIMESTAMP_ISO8601_UTC[256]; static char savedTIMESTAMP_ISO8601_UTC[256];
static bool exportAll; static bool exportAll; // -E
bool sym_IsPC(Symbol const *sym) { bool sym_IsPC(Symbol const *sym) {
return sym == PCSymbol; return sym == PCSymbol;

View File

@@ -330,9 +330,8 @@ static void decant(
members.push_back(iter - processed.begin()); members.push_back(iter - processed.begin());
*iter = true; // Mark that proto-pal as processed *iter = true; // Mark that proto-pal as processed
} }
++iter;
++attrs; ++attrs;
} while (iter != processed.end()); } while (++iter != processed.end());
if (to.combinedVolume(RANGE(colors)) <= options.maxOpaqueColors()) { if (to.combinedVolume(RANGE(colors)) <= options.maxOpaqueColors()) {
// Iterate through the component's proto-palettes, and transfer them // Iterate through the component's proto-palettes, and transfer them

View File

@@ -149,12 +149,9 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
location.address &= ~section.alignMask; location.address &= ~section.alignMask;
// Go to next align boundary and add offset // Go to next align boundary and add offset
location.address += section.alignMask + 1 + section.alignOfs; location.address += section.alignMask + 1 + section.alignOfs;
} else { } else if (++spaceIdx < bankMem.size()) {
// Any location is fine, so, next free block // Any location is fine, so, next free block
++spaceIdx; location.address = bankMem[spaceIdx].address;
if (spaceIdx < bankMem.size()) {
location.address = bankMem[spaceIdx].address;
}
} }
// If that location is past the current block's end, // If that location is past the current block's end,