Skip to content

Commit 9cc746f

Browse files
committed
Automatically generate __sig properties for JS library symbols
1 parent 9a40912 commit 9cc746f

28 files changed

+373
-108
lines changed

src/compiler.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ global.printErr = (x) => {
2121
};
2222

2323
function find(filename) {
24+
assert(filename);
2425
const prefixes = [__dirname, process.cwd()];
2526
for (let i = 0; i < prefixes.length; ++i) {
2627
const combined = nodePath.join(prefixes[i], filename);
@@ -32,6 +33,7 @@ function find(filename) {
3233
}
3334

3435
global.read = (filename) => {
36+
assert(filename);
3537
const absolute = find(filename);
3638
return fs.readFileSync(absolute).toString();
3739
};
@@ -43,22 +45,25 @@ function load(f) {
4345
// Basic utilities
4446
load('utility.js');
4547

48+
// Load default settings
49+
load('./settings.js');
50+
load('./settings_internal.js');
4651

4752
const argv = process.argv.slice(2);
4853
const symbolsOnlyArg = argv.indexOf('--symbols-only');
4954
if (symbolsOnlyArg != -1) {
5055
argv.splice(symbolsOnlyArg, 1);
5156
}
5257

53-
const symbolsOnly = symbolsOnlyArg != -1;
54-
5558
// Load settings from JSON passed on the command line
5659
const settingsFile = argv[0];
5760
assert(settingsFile);
5861

5962
const settings = JSON.parse(read(settingsFile));
6063
Object.assign(global, settings);
6164

65+
global.symbolsOnly = symbolsOnlyArg != -1;
66+
6267
EXPORTED_FUNCTIONS = new Set(EXPORTED_FUNCTIONS);
6368
WASM_EXPORTS = new Set(WASM_EXPORTS);
6469
SIDE_MODULE_EXPORTS = new Set(SIDE_MODULE_EXPORTS);
@@ -94,7 +99,7 @@ if (!STRICT) {
9499
B = new Benchmarker();
95100

96101
try {
97-
runJSify(symbolsOnly);
102+
runJSify();
98103

99104
B.print('glue');
100105
} catch (err) {

src/jsifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function isDefined(symName) {
6666
return false;
6767
}
6868

69-
function runJSify(symbolsOnly = false) {
69+
function runJSify() {
7070
const libraryItems = [];
7171
const symbolDeps = {};
7272
let postSets = [];

src/library.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,9 +1225,9 @@ mergeInto(LibraryManager.library, {
12251225

12261226
return 0;
12271227
},
1228-
strptime_l__sig: 'pppp',
1228+
strptime_l__sig: 'ppppp',
12291229
strptime_l__deps: ['strptime'],
1230-
strptime_l: function(buf, format, tm) {
1230+
strptime_l: function(buf, format, tm, locale) {
12311231
return _strptime(buf, format, tm); // no locale support yet
12321232
},
12331233

@@ -3029,16 +3029,11 @@ mergeInto(LibraryManager.library, {
30293029
return runEmAsmFunction(code, sigPtr, argbuf);
30303030
},
30313031

3032-
#if MEMORY64
3033-
// We can't use the alias in wasm64 mode becuase the function signature differs
30343032
emscripten_asm_const_ptr__sig: 'pppp',
30353033
emscripten_asm_const_ptr__deps: ['$runEmAsmFunction'],
30363034
emscripten_asm_const_ptr: function(code, sigPtr, argbuf) {
30373035
return runEmAsmFunction(code, sigPtr, argbuf);
30383036
},
3039-
#else
3040-
emscripten_asm_const_ptr: 'emscripten_asm_const_int',
3041-
#endif
30423037

30433038
$runMainThreadEmAsm__deps: ['$readEmAsmArgs'],
30443039
$runMainThreadEmAsm__sig: 'iippi',

src/library_sdl.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ var LibrarySDL = {
13981398

13991399
SDL_WasInit__deps: ['SDL_Init'],
14001400
SDL_WasInit__proxy: 'sync',
1401-
SDL_WasInit__sig: 'i',
1402-
SDL_WasInit: function() {
1401+
SDL_WasInit__sig: 'ii',
1402+
SDL_WasInit: function(flags) {
14031403
if (SDL.startTime === null) {
14041404
_SDL_Init();
14051405
}
@@ -1937,7 +1937,7 @@ var LibrarySDL = {
19371937
},
19381938

19391939
SDL_SetClipRect__proxy: 'sync',
1940-
SDL_SetClipRect__sig: 'vii',
1940+
SDL_SetClipRect__sig: 'iii',
19411941
SDL_SetClipRect: function(surf, rect) {
19421942
var surfData = SDL.surfaces[surf];
19431943

@@ -1946,6 +1946,7 @@ var LibrarySDL = {
19461946
} else {
19471947
delete surfData.clipRect;
19481948
}
1949+
return 1;
19491950
},
19501951

19511952
SDL_FillRect__proxy: 'sync',
@@ -2228,7 +2229,7 @@ var LibrarySDL = {
22282229

22292230
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', 'malloc'],
22302231
IMG_Load_RW__proxy: 'sync',
2231-
IMG_Load_RW__sig: 'iii',
2232+
IMG_Load_RW__sig: 'ipi',
22322233
IMG_Load_RW: function(rwopsID, freeSrc) {
22332234
try {
22342235
// stb_image integration support
@@ -2380,7 +2381,7 @@ var LibrarySDL = {
23802381

23812382
IMG_Load__deps: ['IMG_Load_RW', 'SDL_RWFromFile'],
23822383
IMG_Load__proxy: 'sync',
2383-
IMG_Load__sig: 'ii',
2384+
IMG_Load__sig: 'ip',
23842385
IMG_Load: function(filename){
23852386
var rwops = _SDL_RWFromFile(filename);
23862387
var result = _IMG_Load_RW(rwops, 1);
@@ -2905,9 +2906,10 @@ var LibrarySDL = {
29052906
SDL.channelMinimumNumber = num;
29062907
},
29072908
Mix_PlayChannelTimed__proxy: 'sync',
2908-
Mix_PlayChannelTimed__sig: 'iiii',
2909-
Mix_PlayChannelTimed: function(channel, id, loops) {
2909+
Mix_PlayChannelTimed__sig: 'iiiii',
2910+
Mix_PlayChannelTimed: function(channel, id, loops, ticks) {
29102911
// TODO: handle fixed amount of N loops. Currently loops either 0 or infinite times.
2912+
assert(ticks == -1);
29112913

29122914
// Get the audio element associated with the ID
29132915
var info = SDL.audios[id];
@@ -3459,8 +3461,8 @@ var LibrarySDL = {
34593461
SDL_DestroyRenderer: function(renderer) {},
34603462

34613463
SDL_GetWindowFlags__proxy: 'sync',
3462-
SDL_GetWindowFlags__sig: 'iii',
3463-
SDL_GetWindowFlags: function(x, y) {
3464+
SDL_GetWindowFlags__sig: 'ii',
3465+
SDL_GetWindowFlags: function(window) {
34643466
if (Browser.isFullscreen) {
34653467
return 1;
34663468
}
@@ -3475,8 +3477,8 @@ var LibrarySDL = {
34753477
SDL_GL_DeleteContext: function(context) {},
34763478

34773479
SDL_GL_GetSwapInterval__proxy: 'sync',
3478-
SDL_GL_GetSwapInterval__sig: 'ii',
3479-
SDL_GL_GetSwapInterval: function(state) {
3480+
SDL_GL_GetSwapInterval__sig: 'i',
3481+
SDL_GL_GetSwapInterval: function() {
34803482
if (Browser.mainLoop.timingMode == 1/*EM_TIMING_RAF*/) return Browser.mainLoop.timingValue;
34813483
else return 0;
34823484
},

src/library_syscall.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ var SyscallsLibrary = {
175175
FS.chmod(path, mode);
176176
return 0;
177177
},
178-
__syscall_rename__sig: 'ipp',
179-
__syscall_rename: function(old_path, new_path) {
180-
old_path = SYSCALLS.getStr(old_path);
181-
new_path = SYSCALLS.getStr(new_path);
182-
FS.rename(old_path, new_path);
183-
return 0;
184-
},
185178
__syscall_rmdir__sig: 'ip',
186179
__syscall_rmdir: function(path) {
187180
path = SYSCALLS.getStr(path);

src/library_uuid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**Z
22
* @license
33
* Copyright 2013 The Emscripten Authors
44
* SPDX-License-Identifier: MIT

src/modules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ global.LibraryManager = {
247247

248248
if (!BOOTSTRAPPING_STRUCT_INFO) {
249249
// Load struct and define information.
250+
assert(STRUCT_INFO);
250251
const temp = JSON.parse(read(STRUCT_INFO));
251252
C_STRUCTS = temp.structs;
252253
C_DEFINES = temp.defines;

src/utility.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ function mergeInto(obj, other, options = null) {
119119
}
120120
}
121121

122+
for (const key of Object.keys(other)) {
123+
if (key.endsWith('__sig')) {
124+
if (obj.hasOwnProperty(key)) {
125+
const oldsig = obj[key];
126+
const newsig = other[key];
127+
if (oldsig != newsig) {
128+
console.warn(`Signature redefinition mismatch for : ${key}. (old=${oldsig} vs new=${newsig})`);
129+
}
130+
}
131+
}
132+
}
133+
122134
return Object.assign(obj, other);
123135
}
124136

system/include/SDL/SDL_cpuinfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,25 @@ extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
105105
* This function returns true if the CPU has MMX features.
106106
*/
107107
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
108+
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt(void);
108109

109110
/**
110111
* This function returns true if the CPU has 3DNow! features.
111112
*/
112113
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
114+
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt(void);
113115

114116
/**
115117
* This function returns true if the CPU has SSE features.
116118
*/
117119
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
120+
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSEExt(void);
118121

119122
/**
120123
* This function returns true if the CPU has SSE2 features.
121124
*/
122125
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
126+
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2Ext(void);
123127

124128
/**
125129
* This function returns true if the CPU has SSE3 features.

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_emscripten.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@
2626
#include <emscripten/stack.h>
2727
#include <sys/types.h>
2828

29-
namespace __sanitizer {
29+
#include "emscripten_internal.h"
3030

31-
extern "C" {
32-
char* emscripten_get_module_name(char *buf, size_t length);
33-
void* emscripten_builtin_mmap(void *addr, size_t length, int prot, int flags,
34-
int fd, off_t offset);
35-
int emscripten_builtin_munmap(void *addr, size_t length);
36-
}
31+
namespace __sanitizer {
3732

3833
void ListOfModules::init() {
3934
modules_.Initialize(2);

0 commit comments

Comments
 (0)