Skip to content

Commit

Permalink
Remove magic handling of FS_xxx symbols in exportRuntime. NFC (#21878)
Browse files Browse the repository at this point in the history
This helps with my work towards #8380
  • Loading branch information
sbc100 authored May 2, 2024
1 parent b385e89 commit 33881ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,4 +1863,7 @@ FS.staticInit();` +
*/`,
$FS_mkdirTree__deps: ['$FS'],
$FS_mkdirTree: (path, mode) => FS.mkdirTree(path, mode),

$FS_createLazyFile__deps: ['$FS'],
$FS_createLazyFile: 'FS.createLazyFile',
});
12 changes: 12 additions & 0 deletions src/library_fs_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ addToLibrary({
}
return FS_stdin_getChar_buffer.shift();
},

$FS_unlink__deps: ['$FS'],
$FS_unlink: 'FS.unlink',

$FS_createPath__deps: ['$FS'],
$FS_createPath: 'FS.createPath',

$FS_createDevice__deps: ['$FS'],
$FS_createDevice: 'FS.createDevice',

$FS_readFile__deps: ['$FS'],
$FS_readFile: 'FS.readFile',
});

// Normally only the FS things that the compiler sees are needed are included.
Expand Down
28 changes: 6 additions & 22 deletions src/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,11 @@ function exportRuntime() {
const EXPORTED_RUNTIME_METHODS_SET = new Set(EXPORTED_RUNTIME_METHODS);

// optionally export something.
// in ASSERTIONS mode we show a useful error if it is used without
// being exported. how we show the message depends on whether it's
// a function (almost all of them) or a number.
function maybeExport(name) {
// HEAP objects are exported separately in updateMemoryViews
if (name.startsWith('HEAP')) {
return;
}
// if requested to be exported, export it
if (EXPORTED_RUNTIME_METHODS_SET.has(name)) {
let exported = name;
// the exported name may differ from the internal name
if (exported.startsWith('FS_')) {
// this is a filesystem value, FS.x exported as FS_x
exported = 'FS.' + exported.substr(3);
}
return `Module['${name}'] = ${exported};`;
// If requested to be exported, export it. HEAP objects are exported
// separately in updateMemoryViews
if (EXPORTED_RUNTIME_METHODS_SET.has(name) && !name.startsWith('HEAP')) {
return `Module['${name}'] = ${name};`;
}
}

Expand All @@ -401,12 +389,6 @@ function exportRuntime() {
'addOnPostRun',
'addRunDependency',
'removeRunDependency',
'FS_createFolder',
'FS_createPath',
'FS_createLazyFile',
'FS_createLink',
'FS_createDevice',
'FS_readFile',
'out',
'err',
'callMain',
Expand Down Expand Up @@ -500,6 +482,8 @@ function exportRuntime() {
const results = exports.filter((name) => name);

if (ASSERTIONS && !EXPORT_ALL) {
// in ASSERTIONS mode we show a useful error if it is used without being
// exported. See `unexportedRuntimeSymbol` in runtime_debug.js.
const unusedLibSymbols = getUnusedLibrarySymbols();
if (unusedLibSymbols.size) {
results.push(addMissingLibraryStubs(unusedLibSymbols));
Expand Down

0 comments on commit 33881ed

Please sign in to comment.