diff options
-rw-r--r-- | src/postamble.js | 11 | ||||
-rw-r--r-- | src/preamble.js | 10 | ||||
-rw-r--r-- | tests/runner.py | 33 | ||||
-rw-r--r-- | tests/settings.py | 11 | ||||
-rw-r--r-- | third_party/demangler.py | 7 | ||||
-rw-r--r-- | tools/namespacer.py | 3 |
6 files changed, 62 insertions, 13 deletions
diff --git a/src/postamble.js b/src/postamble.js index fb552606..066b83e3 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -37,14 +37,9 @@ function run(args) { __globalConstructor__(); - _main(argc, argv); - - while( __ATEXIT__.length > 0) { - var func = __ATEXIT__.pop(); - if (typeof func === 'number') { - func = FUNCTION_TABLE[func]; - } - func(); + if (Module['_main']) { + _main(argc, argv); + __shutdownRuntime__(); } } diff --git a/src/preamble.js b/src/preamble.js index 07ddf7ea..8a42243a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -168,6 +168,16 @@ function __initializeRuntime__() { STATICTOP = alignMemoryPage(STACK_MAX); } +function __shutdownRuntime__() { + while( __ATEXIT__.length > 0) { + var func = __ATEXIT__.pop(); + if (typeof func === 'number') { + func = FUNCTION_TABLE[func]; + } + func(); + } +} + // stdio.h // C-style: we work on ints on the HEAP. diff --git a/tests/runner.py b/tests/runner.py index ea13326b..407a9c57 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -99,7 +99,7 @@ class RunnerCore(unittest.TestCase): if 'benchmark' not in sys.argv: class T(RunnerCore): # Short name, to make it more fun to use manually on the commandline ## Does a complete test - builds, runs, checks output, etc. - def do_test(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, js_engines=None): + def do_test(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, js_engines=None, post_build=None): if not no_build: print 'Running test:', inspect.stack()[1][3].replace('test_', ''), '[%s%s]' % (COMPILER.split(os.sep)[-1], ',reloop&optimize' if RELOOP else '') dirname = self.get_dir() @@ -107,6 +107,9 @@ if 'benchmark' not in sys.argv: if not no_build: self.build(src, dirname, filename, main_file=main_file) + if post_build is not None: + post_build(filename + '.o.js') + # Run in both JavaScript engines, if optimizing - significant differences there (typed arrays) if js_engines is None: js_engines = [V8_ENGINE] if not OPTIMIZE else [V8_ENGINE, SPIDERMONKEY_ENGINE] @@ -943,6 +946,8 @@ if 'benchmark' not in sys.argv: # Bloated memory; same layout as C/C++ self.do_test(src, '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|24,0,20,0,4,4,8,12,12,16*\n*0,0,0,1,2,64,68,69,72*\n*2*') + ### 'Big' tests + def test_fannkuch(self): results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ] for i, j in results: @@ -988,6 +993,32 @@ if 'benchmark' not in sys.argv: no_build=True, js_engines=[V8_ENGINE]) # mozilla bug XXX + ### Integration tests + + def test_scriptaclass(self): + src = ''' + struct ScriptMe { + int value; + ScriptMe(int val); + int getVal(); // XXX Sadly, inlining these will result in LLVM not + // producing any code for them (when just building + // as a library) + int mulVal(int mul); + }; + ScriptMe::ScriptMe(int val) : value(val) { } + int ScriptMe::getVal() { return value; } + int ScriptMe::mulVal(int mul) { value *= mul; } + ''' + script_src = ''' + // TODO + ''' + def post(filename): + Popen(['python', DEMANGLER, filename, '.'], stdout=open(filename + '.tmp', 'w')).communicate() + Popen(['python', NAMESPACER, filename + '.tmp'], stdout=open(filename + '.tmp2', 'w')).communicate() + src = open(filename, 'r').read() + 'var Scriptable = ' + open(filename + '.tmp2', 'r').read().rstrip() + ';\n\n' + script_src + open(filename, 'w').write(src) + self.do_test(src, '', post_build=post) + # Generate tests for all our compilers def make_test(compiler, embetter): class TT(T): diff --git a/tests/settings.py b/tests/settings.py index e2d99e32..16c71400 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,3 +1,10 @@ +# XXX: Aside from these settings, you should create ~/.emscripten, and fill it with +# something like this: +# +# JS_ENGINE=[os.path.expanduser('~/Dev/tracemonkey/js/src/js'), '-m'] +# JS_ENGINE_PARAMS=[] +# + TEMP_DIR='/dev/shm' LLVM_ROOT=os.path.expanduser('~/Dev/llvm-2.8/cbuild/Release/bin') # Might not need 'Release' @@ -37,5 +44,9 @@ OUTPUT_TO_SCREEN = 0 # useful for debugging specific tests, or for subjectively TIMEOUT = None +# Tools + CLOSURE_COMPILER = os.path.expanduser('~/Dev/closure-compiler/compiler.jar') +DEMANGLER = path_from_root(['third_party', 'demangler.py']) +NAMESPACER = path_from_root(['tools', 'namespacer.py']) diff --git a/third_party/demangler.py b/third_party/demangler.py index bdb58cbd..b9b4b1ef 100644 --- a/third_party/demangler.py +++ b/third_party/demangler.py @@ -29,9 +29,10 @@ splitter = sys.argv[2] SEEN = {} for line in data: - if line[0] == ' ': continue - if line[0] != '_': continue - func = line.split(splitter)[0] + if len(line) < 4: continue + if line[:2] != ' ': continue + if line[2] != '_': continue + func = line.lstrip().split(splitter)[0] if func in SEEN: continue SEEN[func] = True args = JS_ENGINE + [os.path.join(os.path.dirname(__file__), 'gcc_demangler.js')] + JS_ENGINE_PARAMS + [func[1:]] diff --git a/tools/namespacer.py b/tools/namespacer.py index 966e917c..2fae222d 100644 --- a/tools/namespacer.py +++ b/tools/namespacer.py @@ -45,7 +45,8 @@ for line in data: if '<' not in ret and '[' not in ret and '(' not in ret: func = func[i+1:] - funcparts = ['Namespace'] + func.split('::') + #funcparts = ['Namespace'] + func.split('::') + funcparts = func.split('::') currspace = space for part in funcparts[:-1]: |