sdcc now parses #symbol directives

This commit is contained in:
Steven Hugg committed 2026-09-24 14:48:58 +02:00
1 parent 8161ae1fa3
commit d21d112fa2
3 files changed
+22 -2

No files matched your search

+12 -1
View File
@@ -591,7 +591,7 @@ function applySymbolConfigs(params, entries: string[]) {
/**
* Record a linker symbol. If the platform already passes `NAME=...` in
* libargs, the entry is replaced in place -- appending instead would define the
* libargs (or `-g NAME=...` in extra_link_args), the entry is replaced in place -- appending instead would define the
* symbol twice ("Redefinition of symbol", "Definition of public symbol ...").
*/
function setLinkSymbol(params, symbols: PhaseLists, entry: string) {
@@ -606,6 +606,17 @@ function setLinkSymbol(params, symbols: PhaseLists, entry: string) {
}
}
}
// sdldz80 platforms pass `-g NAME=...` pairs in extra_link_args
let xa = params.extra_link_args;
if (xa) {
for (let i = 1; i < xa.length; i++) {
if (xa[i - 1] === '-g' && xa[i].split('=')[0] === name) {
xa[i] = entry;
applySymbolConfigs(params, [entry]);
return;
}
}
}
symbols.linker = mergeByName(symbols.linker, entry);
applySymbolConfigs(params, [entry]);
}
+2 -1
View File
@@ -1,7 +1,7 @@
import { Worker } from "node:worker_threads";
import { defineArgs, extraArgsFor, linkSymbolArgs } from "../../common/toolmeta";
import { CodeListingMap, WorkerError } from "../../common/workertypes";
import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, putWorkFile, populateExtraFiles, anyTargetChanged, getWorkFileAsString } from "../builder";
import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, putWorkFile, populateExtraFiles, anyTargetChanged, getWorkFileAsString, fixParamsWithDefines } from "../builder";
import { parseListing, parseSourceLines, msvcErrorMatcher } from "../listingutils";
import { EmscriptenModule, emglobal, execMain, loadNative, moduleInstFn, print_fn, setupFS, setupStdin } from "../wasmutils";
import { preprocessMCPP } from "./mcpp";
@@ -266,6 +266,7 @@ export function compileSDCC(step: BuildStep): BuildStepResult {
var params = step.params;
var isGBZ80 = params.arch === 'gbz80';
var outpath = step.prefix + ".asm";
fixParamsWithDefines(step.path, params); // //#symbol, //#flag, //#tooldef
if (staleFiles(step, [outpath])) {
var errors = [];
loadNative('sdcc');
+8
View File
@@ -214,6 +214,14 @@ describe("explicit build directives (//#symbol, //#flag, //#tooldef)", function
assert.deepStrictEqual(params.symbols.linker, []);
});
it("#symbol ld replaces a matching -g entry in extra_link_args (sdldz80)", function () {
const params: any = { extra_link_args: ['-l', 'gb', '-g', 'GB_MAPPER=0x0', '-g', 'GB_RAM_SIZE=0x0'] };
applyDirectives("//#symbol ld GB_MAPPER=0x03\n//#symbol ld GB_RAM_SIZE=0x02\n", params);
assert.deepStrictEqual(params.extra_link_args, ['-l', 'gb', '-g', 'GB_MAPPER=0x03', '-g', 'GB_RAM_SIZE=0x02']);
// merged into extra_link_args, not queued again -> no duplicate -g on the link line
assert.deepStrictEqual(params.symbols.linker, []);
});
it("#symbol ld queues a symbol that is not a platform libarg", function () {
const params = nesParams();
applyDirectives("//#symbol ld NEWSYM=0x10\n", params);