diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-03 20:09:11 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-03 20:09:11 -0800 |
commit | 556decb19a4bcb32daad1569402fcc385d49b1d4 (patch) | |
tree | 1fdea88574ffd481f4b68776db86bc3d0169ef22 | |
parent | 3d4a6d6d24fc5a220ba4b32d9bdae069389a084e (diff) |
fixes for using node as both compiler engine and code running engine. node is now default in settings.py
-rw-r--r-- | settings.py | 31 | ||||
-rw-r--r-- | src/compiler.js | 19 | ||||
-rw-r--r-- | src/library.js | 1 | ||||
-rw-r--r-- | src/shell.js | 104 | ||||
-rw-r--r-- | tests/cases/gepoverflow.ll | 1 | ||||
-rw-r--r-- | tests/runner.py | 15 | ||||
-rw-r--r-- | tools/shared.py | 7 |
7 files changed, 125 insertions, 53 deletions
diff --git a/settings.py b/settings.py index b294f8bd..82297db5 100644 --- a/settings.py +++ b/settings.py @@ -1,27 +1,28 @@ # This file will be copied to ~/.emscripten if that file doesn't exist. # IMPORTANT: Edit it with the right paths! -EMSCRIPTEN_ROOT=os.path.expanduser("~/Dev/emscripten") # TODO: Use this - -TEMP_DIR='/tmp' - LLVM_ROOT=os.path.expanduser('~/Dev/llvm-3.0/cbuild/bin') -COMPILER_OPTS = [] - -SPIDERMONKEY_ENGINE = [os.path.expanduser('~/Dev/mozilla-central/js/src/js'), '-m', '-n'] -V8_ENGINE = [os.path.expanduser('~/Dev/v8/d8')] NODE_JS = 'node' +SPIDERMONKEY_ENGINE = [os.path.expanduser('~/Dev/mozilla-central/js/src/js'), '-m', '-n'] # optional, but recommended +V8_ENGINE = os.path.expanduser('~/Dev/v8/d8') # optional (mostly unneeded if you have node) -#COMPILER_ENGINE=SPIDERMONKEY_ENGINE -COMPILER_ENGINE=V8_ENGINE -#COMPILER_ENGINE=[NODE_JS] +CLOSURE_COMPILER = os.path.expanduser('~/Dev/closure-compiler/compiler.jar') # optional (needed for the benchmarks) -JS_ENGINE=V8_ENGINE +TEMP_DIR='/tmp' + +######################################################################################################## -TIMEOUT = None +# Pick the JS engine to use for running the compiler. Any of the three will work. This engine +# must exist, or nothing can be compiled. + +COMPILER_ENGINE=NODE_JS +#COMPILER_ENGINE=SPIDERMONKEY_ENGINE +#COMPILER_ENGINE=V8_ENGINE -# Tools +# JS engines to use when running the automatic tests. Modify this to include all +# the JS engines you have installed. Not all these engines must exist, if they do not, +# they will be skipped in the test runner. -CLOSURE_COMPILER = os.path.expanduser('~/Dev/closure-compiler/compiler.jar') +JS_ENGINES=[NODE_JS, SPIDERMONKEY_ENGINE] diff --git a/src/compiler.js b/src/compiler.js index d2d14d9b..90f05cf0 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -7,6 +7,9 @@ try { gcparam('maxBytes', 1024*1024*1024); } catch(e) {} + +// The environment setup code appears both here and in shell.js, because it can't be shared. Keep them in sync! +// *** Environment setup code *** var arguments_ = []; var ENVIRONMENT_IS_NODE = typeof process === 'object'; @@ -16,20 +19,24 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE; if (ENVIRONMENT_IS_NODE) { // Expose functionality in the same simple way that the shells work print = function(x) { - process.stdout.write(x + '\n'); + process['stdout'].write(x + '\n'); }; printErr = function(x) { - process.stderr.write(x + '\n'); + process['stderr'].write(x + '\n'); }; var nodeFS = require('fs'); read = function(filename) { - if (filename[0] != '/') filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; - return nodeFS.readFileSync(filename).toString(); + var ret = nodeFS['readFileSync'](filename).toString(); + if (!ret && filename[0] != '/') { + filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + ret = nodeFS['readFileSync'](filename).toString(); + } + return ret; }; - arguments_ = process.argv.slice(2); + arguments_ = process['argv'].slice(2); } else if (ENVIRONMENT_IS_SHELL) { // Polyfill over SpiderMonkey/V8 differences @@ -71,6 +78,8 @@ if (!this['load']) { globalEval(read(f)); }; } +// *** Environment setup code *** + // Basic utilities diff --git a/src/library.js b/src/library.js index ce6152d1..1d296981 100644 --- a/src/library.js +++ b/src/library.js @@ -393,6 +393,7 @@ LibraryManager.library = { }, quit: function() { + if (!FS.init.initialized) return; // Flush any partially-printed lines in stdout and stderr if (FS.streams[2].object.output.buffer.length > 0) FS.streams[2].object.output('\n'.charCodeAt(0)); if (FS.streams[3].object.output.buffer.length > 0) FS.streams[3].object.output('\n'.charCodeAt(0)); diff --git a/src/shell.js b/src/shell.js index 7be76536..d52cd77d 100644 --- a/src/shell.js +++ b/src/shell.js @@ -1,36 +1,88 @@ // TODO: " u s e s t r i c t "; -/* -// Capture the output of this into a variable, if you want -(function(Module, args) { - Module = Module || {}; - Module.arguments = args || []; -*/ - -///* -// Runs much faster, for some reason -if (!this['Module']) { - this['Module'] = {}; -} -if (!Module.arguments) { - try { - Module.arguments = scriptArgs; - } catch(e) { - try { - Module.arguments = arguments; - } catch(e) { - Module.arguments = []; + +// *** Environment setup code *** +var arguments_ = []; + +var ENVIRONMENT_IS_NODE = typeof process === 'object'; +var ENVIRONMENT_IS_WEB = typeof window === 'object'; +var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE; + +if (ENVIRONMENT_IS_NODE) { + // Expose functionality in the same simple way that the shells work + print = function(x) { + process['stdout'].write(x + '\n'); + }; + printErr = function(x) { + process['stderr'].write(x + '\n'); + }; + + var nodeFS = require('fs'); + + read = function(filename) { + var ret = nodeFS['readFileSync'](filename).toString(); + if (!ret && filename[0] != '/') { + filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename; + ret = nodeFS['readFileSync'](filename).toString(); } + return ret; + }; + + arguments_ = process['argv'].slice(2); + +} else if (ENVIRONMENT_IS_SHELL) { + // Polyfill over SpiderMonkey/V8 differences + if (!this['read']) { + read = function(f) { snarf(f) }; + } + + if (!this['arguments']) { + arguments_ = scriptArgs; + } else { + arguments_ = arguments; } + +} else if (ENVIRONMENT_IS_WEB) { + printErr = function(x) { + console.log(x); + }; + + read = function(url) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, false); + xhr.send(null); + return xhr.responseText; + }; + + if (this['arguments']) { + arguments_ = arguments; + } +} else { + throw 'Unknown runtime environment. Where are we?'; +} + +function globalEval(x) { + eval.call(null, x); +} + +if (!this['load']) { + load = function(f) { + globalEval(read(f)); + }; +} +// *** Environment setup code *** + + +try { + this['Module'] = Module; +} catch(e) { + this['Module'] = Module = {}; +} +if (!Module.arguments) { + Module.arguments = arguments_; } -//*/ {{BODY}} // {{MODULE_ADDITIONS}} -/* - return Module; -}).call(this, {}, arguments); // Replace parameters as needed -*/ - diff --git a/tests/cases/gepoverflow.ll b/tests/cases/gepoverflow.ll index 11c3b6a0..315e9100 100644 --- a/tests/cases/gepoverflow.ll +++ b/tests/cases/gepoverflow.ll @@ -30,6 +30,7 @@ entry: br label %return return: ; preds = %entry + store i32 0, i32* %retval %retval1 = load i32* %retval ; [#uses=1] ret i32 %retval1 } diff --git a/tests/runner.py b/tests/runner.py index 5ffd01e8..1175f877 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -35,6 +35,7 @@ class RunnerCore(unittest.TestCase): save_JS = 0 def setUp(self): + self.banned_js_engines = [] if not self.save_dir: dirname = tempfile.mkdtemp(prefix="ems_" + self.__class__.__name__ + "_", dir=TEMP_DIR) else: @@ -238,11 +239,12 @@ if 'benchmark' not in str(sys.argv): # Run in both JavaScript engines, if optimizing - significant differences there (typed arrays) if js_engines is None: - js_engines = [SPIDERMONKEY_ENGINE, V8_ENGINE] + js_engines = JS_ENGINES if Settings.USE_TYPED_ARRAYS: - js_engines = [SPIDERMONKEY_ENGINE] # V8 issue 1822 - js_engines = filter(lambda engine: os.path.exists(engine[0]), js_engines) - assert len(js_engines) > 0, 'No JS engine present to run this test with. Check ~/.emscripten and the paths therein.' + js_engines = filter(lambda engine: engine != V8_ENGINE, js_engines) # V8 issue 1822 + js_engines = filter(lambda engine: os.path.exists(engine[0]) or os.path.sep not in engine, js_engines) + js_engines = filter(lambda engine: engine not in self.banned_js_engines, js_engines) + if len(js_engines) == 0: return self.skip('No JS engine present to run this test with. Check ~/.emscripten and settings.py and the paths therein.') for engine in js_engines: js_output = self.run_generated_code(engine, filename + '.o.js', args) if output_nicerizer is not None: @@ -3710,6 +3712,8 @@ if 'benchmark' not in str(sys.argv): # They are only valid enough for us to read for test purposes, not for llvm-as # to process. def test_cases(self): + self.banned_js_engines = [NODE_JS] # node issue 1669, exception causes stdout not to be flushed + Settings.CHECK_OVERFLOWS = 0 if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly") @@ -4072,7 +4076,7 @@ Block 0: ''', post_build=post1) def post2(filename): src = open(filename, 'r').read().replace( '// {{MODULE_ADDITIONS}', - '''load('bindingtest.js')''' + '\n\n' + script_src_2 + '\n\n' + + open(os.path.join(self.get_dir(), 'bindingtest.js')).read() + '\n\n' + script_src_2 + '\n\n' + '// {{MODULE_ADDITIONS}' ) open(filename, 'w').write(src) @@ -4277,7 +4281,6 @@ Child2:9 except Exception, e: # This test *should* fail, by throwing this exception assert 'Too many corrections' in str(e), str(e) - assert 'CHECK_OVERFLOW' in str(e), str(e) def test_debug(self): src = ''' diff --git a/tools/shared.py b/tools/shared.py index f6a03c6c..9750cb8a 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -36,6 +36,10 @@ JS_OPTIMIZER = path_from_root('tools', 'js-optimizer.js') # Additional compiler options +try: + COMPILER_OPTS # Can be set in ~/.emscripten, optionally +except: + COMPILER_OPTS = [] COMPILER_OPTS = COMPILER_OPTS + ['-m32', '-U__i386__', '-U__x86_64__', '-U__i386', '-U__x86_64', '-U__SSE__', '-U__SSE2__', '-U__MMX__', '-UX87_DOUBLE_ROUNDING', '-UHAVE_GCC_ASM_FOR_X87', '-DEMSCRIPTEN', '-U__STRICT_ANSI__'] @@ -76,6 +80,7 @@ def timeout_run(proc, timeout, note): return proc.communicate()[0] def run_js(engine, filename, args=[], check_timeout=False, stdout=PIPE, stderr=None, cwd=None): + if type(engine) is not list: engine = [engine] return timeout_run(Popen(engine + [filename] + (['--'] if 'd8' in engine[0] else []) + args, stdout=stdout, stderr=stderr, cwd=cwd), 15*60 if check_timeout else None, 'Execution') @@ -283,7 +288,7 @@ class Building: except: pass settings = ['-s %s=%s' % (k, json.dumps(v)) for k, v in exported_settings.items()] - compiler_output = timeout_run(Popen(['python', EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + settings + extra_args, stdout=PIPE), TIMEOUT, 'Compiling') + compiler_output = timeout_run(Popen(['python', EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + settings + extra_args, stdout=PIPE), None, 'Compiling') #print compiler_output # Detect compilation crashes and errors |