summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog137
-rw-r--r--src/jsifier.js13
-rw-r--r--src/library.js6
-rw-r--r--src/parseTools.js10
-rw-r--r--src/settings.js2
-rwxr-xr-xtests/runner.py53
-rw-r--r--tests/time/src.c3
-rw-r--r--tools/find_bigfuncs.py23
8 files changed, 99 insertions, 148 deletions
diff --git a/ChangeLog b/ChangeLog
deleted file mode 100644
index b60921cd..00000000
--- a/ChangeLog
+++ /dev/null
@@ -1,137 +0,0 @@
-2011-??-??: Version 2.0
-
- * Bundled headers
- * TODO: try to not need all the -h in tests/runner.py, and for user scripts too
-
-2011-07-31: Version 1.5
-
- * eSpeak text-to-speech demo
- * Filesystem emulation API
- * Parse metadata type info for easier interaction with llvm structures
- * Bindings generator improvements
- * Many library improvements and fixes
- * Various bug fixes
-
-2011-07-10: Version 1.4
-
- * Compiling and loading of dynamic libraries
- * Automatic bindings generation using CppHeaderParser
- * Much improved emscripten.py
- * Many library improvements and fixes
- * Various bug fixes
-
-2011-06-22: Version 1.3
-
- * Optional typed arrays with single shared buffer (TA2)
- * Optional support for nonportable optimizations with TA2
- * Relooper optimizations
- * Reading from stdin on the web opens window.prompt
- * Various bug fixes
-
-2011-05-29: Version 1.2
-
- * Doom demo
- * Major SDL improvements: color palettes, input events, audio
- * Various improvements for CHECK_* and CORRECT_*, and new AUTO_OPTIMIZE
- * Experimental work towards supporting OpenGL in WebGL
- * Various bug fixes
-
-2011-05-01: Version 1.1
-
- * Much improved Bullet demo (llvm opts, quantum = 1, CubicVR.js)
- * QUANTUM == 1 a.k.a memory compression option
- * Dead function elimination tool
- * Various performance improvements in generated code
- * Various bug fixes
-
-2011-04-09: Version 1.0
-
- * Poppler test and web demo
- * Optimize compiler memory usage very significantly
- * Support for LLVM 2.9
- * Better interaction with closure compiler
- * Finish docs/paper.pdf
- * Many bug fixes
-
-2011-03-05: Version 0.9
-
- * OpenJPEG test and web demo
- * Line number debugging info and autodebugger tool
- * CORRECT_ROUNDINGS option
- * Line-specific CORRECT_* options
- * 20% faster compilation
- * Generate strict mode JavaScript
- * Many bug fixes, additional tests and library implementations
-
-2011-02-06: Version 0.8
-
- * Freetype web demo (2011-02-08, right after 0.8)
- * Freetype and zlib tests (including the entire build procedure)
- * File emulation
- * CHECK_OVERFLOWS & CORRECT_OVERFLOWS options to handle numerical size issues
- * CHECK_SIGNS option to find whether GUARD_SIGNS is necessary
- * Improvements to usage of llvm optimizations, and testing
- * Many bug fixes, additional tests and library implementations
-
-2010-12-18: Version 0.7
-
- * Python web demo
- * Support for essentially all LLVM optimizations
- * Proper support for C bitfields
- * Many bug fixes, additional tests and library implementations
-
-2010-11-25: Version 0.6
-
- * Web demos: Lua and Bullet/WebGL
- * SAFE_HEAP checks for invalid reads/writes, nonportable .ll
- * Basic C++ exceptions support (|catch(...)|)
- * Optimize compilation of very large projects (memory and speed)
- * Support for frontend-optimized .ll input, plus tests
- * Integration (combining scripts with compiled C++) tools and tests
- * Many bug fixes, additional tests and library implementations
-
-2010-11-02: Version 0.5
-
- * Much faster compilation, in particular of large projects
- * Bullet physics library test
- * GCC name demangling test
- * Module-ization of generated code (optional)
- * Name demangler and namespace generator tools
- * Many code cleanups, bug fixes, additional tests and library implementations
-
-2010-10-17: Version 0.4
-
- * Much faster optimized code, now 10X the speed of our unoptimized code
- * Support for the recently-released LLVM 2.8
- * Support for typed arrays
- * Integration with the Closure Compiler
- * Benchmarking framework in test runner
- * Many code cleanups, bug fixes, and additional tests
-
-2010-10-05: Version 0.3
-
- * Much faster compilation (but still slow with relooper)
- * Clang support
- * Optional memory alignment that precisely matches C/C++
- * Proper memory management, including stack and (optional) dlmalloc
- * Rewritten relooper; no emulated blocks in any test
- * Initial support for SDL
- * Raytracing test + web demo
- * Many code cleanups, bug fixes, additional tests and library implementations
-
-2010-09-11: Version 0.2
-
- * sauer (cubescript) test passes (without RELOOPing), + web demo
- * ES_SIZEOF - safe&portable sizeof replacement
- * emscripten.py tool for easy compiling
- * Better debugging support, using SAFE_HEAP and LABEL_DEBUG, using internal preprocessor
- * Compiler can now run all tests in both SpiderMonkey and V8
- * Various compiler optimizations (still barely scratched the surface though)
- * Many code cleanups, bug fixes, additional tests and library implementations
-
-2010-08-28: Version 0.1
-
- * All tests pass, including fannkuch and fasta, but constglobalstructs
- * Relooping of Fannkuch is complete, fasta has one left
- * Emscriptened Fannkuch is 19X slower than gcc -O0, 37X than gcc -O2
-
diff --git a/src/jsifier.js b/src/jsifier.js
index a01b2655..9678a56d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1370,7 +1370,7 @@ function JSify(data, functionsOnly, givenFunctions) {
args = args.map(function(arg, i) { return indexizeFunctions(arg, argsTypes[i]) });
if (ASM_JS) {
- if (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced) {
+ if (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced || funcData.setjmpTable) {
args = args.map(function(arg, i) { return asmCoercion(arg, argsTypes[i]) });
} else {
args = args.map(function(arg, i) { return asmEnsureFloat(arg, argsTypes[i]) });
@@ -1448,20 +1448,21 @@ function JSify(data, functionsOnly, givenFunctions) {
var sig = Functions.getSignature(returnType, argsTypes, hasVarArgs);
if (ASM_JS) {
assert(returnType.search(/\("'\[,/) == -1); // XXX need isFunctionType(type, out)
- if (!byPointerForced) {
+ if (!byPointerForced && !funcData.setjmpTable) {
+ // normal asm function pointer call
callIdent = '(' + callIdent + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py
} else {
- // This is a forced call, through an invoke_*.
+ // This is a call through an invoke_*, either a forced one, or a setjmp-required one
// note: no need to update argsTypes at this point
- Functions.unimplementedFunctions[callIdent] = sig;
- args.unshift(byPointerForced ? Functions.getIndex(callIdent) : callIdent);
+ if (byPointerForced) Functions.unimplementedFunctions[callIdent] = sig;
+ args.unshift(byPointerForced ? Functions.getIndex(callIdent) : asmCoercion(callIdent, 'i32'));
callIdent = 'invoke_' + sig;
}
} else if (SAFE_DYNCALLS) {
assert(!ASM_JS, 'cannot emit safe dyncalls in asm');
callIdent = '(tempInt=' + callIdent + ',tempInt < 0 || tempInt >= FUNCTION_TABLE.length-1 || !FUNCTION_TABLE[tempInt] ? abort("dyncall error: ' + sig + ' " + FUNCTION_TABLE_NAMES[tempInt]) : tempInt)';
}
- if (!byPointerForced) callIdent = Functions.getTable(sig) + '[' + callIdent + ']';
+ if (!ASM_JS || (!byPointerForced && !funcData.setjmpTable)) callIdent = Functions.getTable(sig) + '[' + callIdent + ']';
}
var ret = callIdent + '(' + args.join(', ') + ')';
diff --git a/src/library.js b/src/library.js
index 939da8b1..91270c38 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6220,6 +6220,7 @@ LibraryManager.library = {
saveSetjmp__asm: true,
saveSetjmp__sig: 'iii',
+ saveSetjmp__deps: ['putchar'],
saveSetjmp: function(env, label, table) {
// Not particularly fast: slow table lookup of setjmpId to label. But setjmp
// prevents relooping anyhow, so slowness is to be expected. And typical case
@@ -6233,7 +6234,7 @@ LibraryManager.library = {
#endif
setjmpId = (setjmpId+1)|0;
{{{ makeSetValueAsm('env', '0', 'setjmpId', 'i32') }}};
- while ((i|0) < {{{ MAX_SETJMPS }}}) {
+ while ((i|0) < {{{ 2*MAX_SETJMPS }}}) {
if ({{{ makeGetValueAsm('table', 'i*4', 'i32') }}} == 0) {
{{{ makeSetValueAsm('table', 'i*4', 'setjmpId', 'i32') }}};
{{{ makeSetValueAsm('table', 'i*4+4', 'label', 'i32') }}};
@@ -6243,7 +6244,8 @@ LibraryManager.library = {
}
i = (i+2)|0;
}
- abort(987); // if you hit this, adjust MAX_SETJMPS
+ {{{ makePrintChars('too many setjmps in a function call, build with a higher value for MAX_SETJMPS') }}};
+ abort(0);
return 0;
},
diff --git a/src/parseTools.js b/src/parseTools.js
index 2eb456f1..fe21dfd5 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -2363,3 +2363,13 @@ function getTypeFromHeap(suffix) {
}
}
+// Generates code that prints without printf(), but just putchar (so can be directly inline)
+function makePrintChars(s) {
+ var ret = '';
+ for (var i = 0; i < s.length; i++) {
+ ret += '_putchar(' + s.charCodeAt(i) + ');';
+ }
+ ret += '_putchar(10);';
+ return ret;
+}
+
diff --git a/src/settings.js b/src/settings.js
index 7cd0c02e..d30db173 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -55,7 +55,7 @@ var ALLOW_MEMORY_GROWTH = 0; // If false, we abort with an error if we try to al
// that case we must be careful about optimizations, in particular the
// eliminator). Note that memory growth is only supported with typed
// arrays.
-var MAX_SETJMPS = 10; // size of setjmp table allocated in each function invocation (that has setjmp)
+var MAX_SETJMPS = 20; // size of setjmp table allocated in each function invocation (that has setjmp)
// Code embetterments
var MICRO_OPTS = 1; // Various micro-optimizations, like nativizing variables
diff --git a/tests/runner.py b/tests/runner.py
index 99f24fc9..33a2ef67 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -138,7 +138,7 @@ class RunnerCore(unittest.TestCase):
# Hardcode in the arguments, so js is portable without manual commandlinearguments
if not args: return
js = open(filename).read()
- open(filename, 'w').write(js.replace('var ret = run();', 'var ret = run(%s);' % str(args)))
+ open(filename, 'w').write(js.replace('run();', 'run(%s);' % str(args)))
def prep_ll_run(self, filename, ll_file, force_recompile=False, build_ll_hook=None):
if ll_file.endswith(('.bc', '.o')):
@@ -2489,6 +2489,57 @@ Calling longjmp the second time!
Exception execution path of first function! 1
''')
+ def test_longjmp_funcptr(self):
+ src = r'''
+ #include <stdio.h>
+ #include <setjmp.h>
+
+ static jmp_buf buf;
+
+ void (*fp)() = NULL;
+
+ void second(void) {
+ printf("second\n"); // prints
+ longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
+ }
+
+ void first(void) {
+ fp();
+ printf("first\n"); // does not print
+ }
+
+ int main(int argc, char **argv) {
+ fp = argc == 200 ? NULL : second;
+
+ volatile int x = 0;
+ if ( ! setjmp(buf) ) {
+ x++;
+ first(); // when executed, setjmp returns 0
+ } else { // when longjmp jumps back, setjmp returns 1
+ printf("main: %d\n", x); // prints
+ }
+
+ return 0;
+ }
+ '''
+ self.do_run(src, 'second\nmain: 1\n')
+
+ def test_setjmp_many(self):
+ src = r'''
+ #include <stdio.h>
+ #include <setjmp.h>
+
+ int main(int argc) {
+ jmp_buf buf;
+ for (int i = 0; i < NUM; i++) printf("%d\n", setjmp(buf));
+ if (argc-- == 1131) longjmp(buf, 11);
+ return 0;
+ }
+ '''
+ for num in [Settings.MAX_SETJMPS, Settings.MAX_SETJMPS+1]:
+ print num
+ self.do_run(src.replace('NUM', str(num)), '0\n' * num if num <= Settings.MAX_SETJMPS or not Settings.ASM_JS else 'build with a higher value for MAX_SETJMPS')
+
def test_exceptions(self):
if Settings.QUANTUM_SIZE == 1: return self.skip("we don't support libcxx in q1")
if self.emcc_args is None: return self.skip('need emcc to add in libcxx properly')
diff --git a/tests/time/src.c b/tests/time/src.c
index aaf2878f..d33885fe 100644
--- a/tests/time/src.c
+++ b/tests/time/src.c
@@ -96,7 +96,8 @@ int main() {
clock_t start = clock();
printf("clock(start): %d\n", start >= 0);
while (clock() - start < 2 * CLOCKS_PER_SEC); // Poor man's sleep().
- printf("clock(end): %d\n", time(NULL) - start_t == 2);
+ clock_t diff = time(NULL) - start_t;
+ printf("clock(end): %d\n", diff >= 2 && diff < 30);
// Verify that ctime_r(x, buf) is equivalent to asctime_r(localtime(x), buf).
time_t t7 = time(0);
diff --git a/tools/find_bigfuncs.py b/tools/find_bigfuncs.py
new file mode 100644
index 00000000..ebff8b6e
--- /dev/null
+++ b/tools/find_bigfuncs.py
@@ -0,0 +1,23 @@
+'''
+Simple tool to find big functions in an .ll file. Anything over i64 is of interest.
+'''
+
+import os, sys, re
+
+filename = sys.argv[1]
+i = 0
+maxx = -1
+maxxest = '?'
+start = -1
+curr = '?'
+for line in open(filename):
+ i += 1
+ if line.startswith('function '):
+ start = i
+ curr = line
+ elif line.startswith('}'):
+ size = i - start
+ if size > maxx:
+ maxx = size
+ maxxest = curr
+print maxx, 'lines in', maxxest