diff options
author | Daniel Wirtz <dcode@dcode.io> | 2018-01-17 18:25:49 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-01-17 09:25:49 -0800 |
commit | 01b23987405d8d7b2f13e40ef906169163ac2a5f (patch) | |
tree | 7b76946e0392eb65ad773cbb6524ad0fdbddde38 /src/js/binaryen.js-post.js | |
parent | 3d8358f8e10a01869ef59189539ab1d17d52cb10 (diff) | |
download | binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.gz binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.bz2 binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.zip |
Add optimize, shrink level and debug info options to C/JS (#1357)
* Add optimize, shrink level and debug info options to C/JS
* Add instantiate functionality for creating additional unique instances of the API
* Use a workaround when running tests in node
Tests misuse a module as a script by concatenating, so instead of catching this case in the library, catch it there
* Update sieve test
Seems optimized output changed due to running with optimize levels 2/1 now
* Use the options with all pass runners
* Update relooper-fuzz C-API test
* Share defaults between tools and the C-API
* Add a test for optimize levels
* Unify node test support in check.by and auto_update_tests.py
* Also add getters for optimize levels and test them
* Also test debugInfo
* Add debug info to C tests that used it as well
* Fix missing NODEJS import in auto_update_tests
* Detect node.js version (WASM support)
* Update hello-world JS test (now also runs with node)
* feature-test WebAssembly in node instead
* Document that these options apply globally, and where
* Make sure hello-world.js output doesn't differ between mozjs/node
Diffstat (limited to 'src/js/binaryen.js-post.js')
-rw-r--r-- | src/js/binaryen.js-post.js | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 76b038d8d..c4e0d62d8 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -1256,7 +1256,7 @@ Module['getExpressionInfo'] = function(expr) { 'type': type, 'condition': Module['_BinaryenIfGetCondition'](expr), 'ifTrue': Module['_BinaryenIfGetIfTrue'](expr), - 'ifFalse': Module['_BinaryenIfGetIfFalse'](expr) + 'ifFalse': Module['_BinaryenIfGetIfFalse'](expr) }; case Module['LoopId']: return { @@ -1460,7 +1460,7 @@ Module['getExpressionInfo'] = function(expr) { // Obtains information about a 'FunctionType' Module['getFunctionTypeInfo'] = function(func) { return { - 'name': Module['_BinaryenFunctionTypeGetName'](func), + 'name': Pointer_stringify(Module['_BinaryenFunctionTypeGetName'](func)), 'params': getAllNested(func, Module['_BinaryenFunctionTypeGetNumParams'], Module['_BinaryenFunctionTypeGetParam']), 'result': Module['_BinaryenFunctionTypeGetResult'](func) }; @@ -1469,8 +1469,8 @@ Module['getFunctionTypeInfo'] = function(func) { // Obtains information about a 'Function' Module['getFunctionInfo'] = function(func) { return { - 'name': Module['_BinaryenFunctionGetName'](func), - 'type': Module['_BinaryenFunctionGetType'](func), + 'name': Pointer_stringify(Module['_BinaryenFunctionGetName'](func)), + 'type': Pointer_stringify(Module['_BinaryenFunctionGetType'](func)), 'params': getAllNested(func, Module['_BinaryenFunctionGetNumParams'], Module['_BinaryenFunctionGetParam']), 'result': Module['_BinaryenFunctionGetResult'](func), 'vars': getAllNested(func, Module['_BinaryenFunctionGetNumVars'], Module['_BinaryenFunctionGetVar']), @@ -1529,8 +1529,53 @@ Module['parseText'] = function(text) { return new Module['Module'](ptr); }; +// Gets the currently set optimize level. 0, 1, 2 correspond to -O0, -O1, -O2, etc. +Module['getOptimizeLevel'] = function() { + return Module['_BinaryenGetOptimizeLevel'](); +}; + +// Sets the optimization level to use. 0, 1, 2 correspond to -O0, -O1, -O2, etc. +Module['setOptimizeLevel'] = function(level) { + return Module['_BinaryenSetOptimizeLevel'](level); +}; + +// Gets the currently set shrink level. 0, 1, 2 correspond to -O0, -Os, -Oz. +Module['getShrinkLevel'] = function() { + return Module['_BinaryenGetShrinkLevel'](); +}; + +// Sets the shrink level to use. 0, 1, 2 correspond to -O0, -Os, -Oz. +Module['setShrinkLevel'] = function(level) { + return Module['_BinaryenSetShrinkLevel'](level); +}; + +// Gets whether generating debug information is currently enabled or not. +Module['getDebugInfo'] = function() { + return Boolean(Module['_BinaryenGetDebugInfo']()); +}; + +// Enables or disables debug information in emitted binaries. +Module['setDebugInfo'] = function(on) { + return Module['_BinaryenSetDebugInfo'](on); +}; + // Enables or disables C-API tracing Module['setAPITracing'] = function(on) { return Module['_BinaryenSetAPITracing'](on); }; +// Instantiates a new unique instance of the API with its own memory etc. +Module['instantiate'] = instantiate; +return Module; + +} // end of instantiate + +// Module loader code borrowed from webpack +if (typeof exports === 'object' && typeof module === 'object') + module.exports = instantiate(); +else if (typeof define === 'function' && define['amd']) + define([], instantiate); +else if (typeof exports === 'object') + exports['Binaryen'] = instantiate(); +else + (typeof self !== "undefined" ? self : this)['Binaryen'] = instantiate(); |