aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js14
-rw-r--r--src/library.js45
-rw-r--r--src/modules.js3
-rw-r--r--src/settings.js7
4 files changed, 68 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 91cfbe6a..d8ed589e 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -300,6 +300,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
substrate.addActor('FunctionStub', {
processItem: function(item) {
var ret = [item];
+ if (IGNORED_FUNCTIONS.indexOf(item.ident) >= 0) return null;
var shortident = item.ident.substr(1);
if (BUILD_AS_SHARED_LIB) {
// Shared libraries reuse the runtime of their parents.
@@ -433,6 +434,8 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
// We have this function all reconstructed, go and finalize it's JS!
+ if (IGNORED_FUNCTIONS.indexOf(func.ident) >= 0) return null;
+
func.JS = '\nfunction ' + func.ident + '(' + func.paramIdents.join(', ') + ') {\n';
if (PROFILE) {
@@ -929,7 +932,14 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
generated = generated.concat(itemsDict.function).concat(data.unparsedFunctions);
- if (!mainPass) return generated.map(function(item) { return item.JS }).join('\n');
+ if (!mainPass) {
+ Functions.allIdents = Functions.allIdents.concat(itemsDict.function.map(function(func) {
+ return func.ident;
+ }).filter(function(func) {
+ return IGNORED_FUNCTIONS.indexOf(func.ident) < 0;
+ }));
+ return generated.map(function(item) { return item.JS }).join('\n');
+ }
// We are ready to print out the data, but must do so carefully - we are
// dealing with potentially *huge* strings. Convenient replacements and
@@ -965,6 +975,8 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
print(Functions.generateIndexing()); // done last, as it may rely on aliases set in postsets
print(postParts[1]);
print(shellParts[1]);
+ // Print out some useful metadata (for additional optimizations later, like the eliminator)
+ print('// EMSCRIPTEN_GENERATED_FUNCTIONS: ' + JSON.stringify(Functions.allIdents) + '\n');
return null;
}
diff --git a/src/library.js b/src/library.js
index faa86c68..75010afb 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5372,6 +5372,21 @@ LibraryManager.library = {
},
__01getrlimit64_: 'getrlimit',
+ // TODO: Implement for real. We just do time used, and no useful data
+ __rusage_struct_layout: Runtime.generateStructInfo(null, '%struct.rusage'),
+ getrusage__deps: ['__rusage_struct_layout'],
+ getrusage: function(resource, rlp) {
+ // %struct.timeval = type { i32, i32 }
+ var timeval = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] });
+
+ // int getrusage(int resource, struct rusage *rlp);
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_utime+timeval[0]', '1', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_utime+timeval[1]', '2', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_stime+timeval[0]', '3', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_stime+timeval[1]', '4', 'i32') }}}
+ return 0;
+ },
+
// ==========================================================================
// pthread.h (stubs for mutexes only - no thread support yet!)
// ==========================================================================
@@ -5417,6 +5432,36 @@ LibraryManager.library = {
EMSCRIPTEN_COMMENT__inline: function(param) {
param = stripCorrections(param);
return '// ' + Variables.globals[param].value.text.replace('\\00', '') + ' ';
+ },
+
+ $Profiling: {
+ max_: 0,
+ times: null,
+ invalid: 0,
+ dump: function() {
+ if (Profiling.invalid) {
+ print('Invalid # of calls to Profiling begin and end!');
+ return;
+ }
+ print('Profiling data:')
+ for (var i = 0; i < Profiling.max_; i++) {
+ print('Block ' + i + ': ' + Profiling.times[i]);
+ }
+ }
+ },
+ EMSCRIPTEN_PROFILE_INIT__deps: ['$Profiling'],
+ EMSCRIPTEN_PROFILE_INIT: function(max_) {
+ Profiling.max_ = max_;
+ Profiling.times = new Array(max_);
+ for (var i = 0; i < max_; i++) Profiling.times[i] = 0;
+ },
+ EMSCRIPTEN_PROFILE_BEGIN__inline: function(id) {
+ return 'Profiling.times[' + id + '] -= Date.now();'
+ + 'Profiling.invalid++;'
+ },
+ EMSCRIPTEN_PROFILE_END__inline: function(id) {
+ return 'Profiling.times[' + id + '] += Date.now();'
+ + 'Profiling.invalid--;'
}
};
diff --git a/src/modules.js b/src/modules.js
index 3b370878..f04731f8 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -228,6 +228,9 @@ var Functions = {
// All functions that will be implemented in this file
implementedFunctions: null,
+ // All the function idents seen so far
+ allIdents: [],
+
indexedFunctions: [0, 0], // Start at a non-0 (even, see below) value
// Mark a function as needing indexing, and returns the index
diff --git a/src/settings.js b/src/settings.js
index 0fdc445d..0e70316f 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -116,6 +116,13 @@ PROFILE = 0; // Enables runtime profiling. See test_profiling for a usage exampl
EXPORTED_FUNCTIONS = ['_main']; // Functions that are explicitly exported, so they are guaranteed to
// be accessible outside of the generated code.
+IGNORED_FUNCTIONS = []; // Functions that we should not generate, neither a stub nor a complete function.
+ // This is useful if your project code includes a function, and you want to replace
+ // that in the compiled code with your own handwritten JS. (Of course even without
+ // this option, you could just override the generated function at runtime. However,
+ // JS engines might optimize better if the function is defined once in a single
+ // place in your code.)
+
EXPORTED_GLOBALS = []; // Global non-function variables that are explicitly
// exported, so they are guaranteed to be
// accessible outside of the generated code.