diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-24 09:14:54 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-24 09:14:54 -0700 |
commit | 087231e369f5fc44b26be5db1b86af378a67028d (patch) | |
tree | fa782c1bd852cdb6bc267b71149a024ca1b6078c /src | |
parent | 9971952dd5199c0b202397ae7d45d7c686c477ef (diff) |
auto-generate library stubs that abort for missing library functions, and implement DEAD_FUNCTIONS that way
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.js | 4 | ||||
-rw-r--r-- | src/jsifier.js | 24 | ||||
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | src/settings.js | 7 |
4 files changed, 9 insertions, 28 deletions
diff --git a/src/compiler.js b/src/compiler.js index d74ff7cb..313fd5f7 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -169,7 +169,9 @@ EXPORTED_FUNCTIONS = set(EXPORTED_FUNCTIONS); EXPORTED_GLOBALS = set(EXPORTED_GLOBALS); EXCEPTION_CATCHING_WHITELIST = set(EXCEPTION_CATCHING_WHITELIST); -if (DEAD_FUNCTIONS.length && ASSERTIONS) DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('putchar'); // for debug output +DEAD_FUNCTIONS.forEach(function(dead) { + DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push(dead.substr(1)); +}); DEAD_FUNCTIONS = numberedSet(DEAD_FUNCTIONS); RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG; diff --git a/src/jsifier.js b/src/jsifier.js index 30a06d76..f08be1c9 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -484,17 +484,11 @@ function JSify(data, functionsOnly, givenFunctions) { if (BUILD_AS_SHARED_LIB) { // Shared libraries reuse the runtime of their parents. item.JS = ''; - } else if (LibraryManager.library.hasOwnProperty(shortident)) { - item.JS = addFromLibrary(shortident); - } else if (!LibraryManager.library.hasOwnProperty(shortident + '__inline')) { - if (!(item.ident in DEAD_FUNCTIONS)) { - item.JS = 'var ' + item.ident + '; // stub for ' + item.ident; - if (ASM_JS) { - error('Unresolved symbol: ' + item.ident + ', this must be corrected for asm.js validation to succeed. Consider adding it to DEAD_FUNCTIONS.'); - } else if (WARN_ON_UNDEFINED_SYMBOLS) { - warn('Unresolved symbol: ' + item.ident); - } + } else { + if (!LibraryManager.library.hasOwnProperty(shortident)) { + LibraryManager.library[shortident] = new Function("Module['printErr']('missing library function: " + shortident + "'); abort(-1);"); } + item.JS = addFromLibrary(shortident); } return ret; } @@ -1439,16 +1433,6 @@ function JSify(data, functionsOnly, givenFunctions) { returnType = getReturnType(type); } - if (callIdent in DEAD_FUNCTIONS) { - var ret = 'abort(' + DEAD_FUNCTIONS[callIdent] + ')'; - if (ASM_JS) ret = asmCoercion(ret, returnType); - if (ASSERTIONS) { - assert(DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.indexOf('putchar') >= 0, 'need putchar for DEAD_FUNCTIONS + ASSERTIONS output'); - ret = '(' + makePrintChars('dead:' + callIdent, ',') + ',' + ret + ')'; - } - return ret; - } - if (byPointer) { var sig = Functions.getSignature(returnType, argsTypes, hasVarArgs); if (ASM_JS) { diff --git a/src/modules.js b/src/modules.js index 7a769846..ce162ac1 100644 --- a/src/modules.js +++ b/src/modules.js @@ -291,7 +291,7 @@ var Functions = { var sig = ASM_JS ? Functions.implementedFunctions[ident] || Functions.unimplementedFunctions[ident] || LibraryManager.library[ident.substr(1) + '__sig'] : 'x'; assert(sig, ident); if (!tables[sig]) tables[sig] = emptyTable(sig); // TODO: make them compact - tables[sig][this.indexedFunctions[ident]] = ident in DEAD_FUNCTIONS ? '0' : ident; + tables[sig][this.indexedFunctions[ident]] = ident; } var generated = false; var wrapped = {}; diff --git a/src/settings.js b/src/settings.js index 8c7d1f83..c878be92 100644 --- a/src/settings.js +++ b/src/settings.js @@ -342,12 +342,7 @@ var PGO = 0; // Enables profile-guided optimization in the form of runtime check // calling PGOMonitor.dump()); var DEAD_FUNCTIONS = []; // Functions on this list are not converted to JS, and calls to // them are turned into abort()s. This is potentially useful for - // (1) reducing code size, if you know some function will never - // be called (see PGO), and also (2) ASM.js requires all declared - // functions to have a corresponding implementation (even if the - // function is never called) and will emit an error during linking if no - // implementation can be found; with this option, asm.js validation will - // succeed for that function and calls to it. + // reducing code size. // If a dead function is actually called, you will get a runtime // error. // TODO: options to lazily load such functions |