From 01b23987405d8d7b2f13e40ef906169163ac2a5f Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Wed, 17 Jan 2018 18:25:49 +0100 Subject: 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 --- src/js/binaryen.js-post.js | 53 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'src/js/binaryen.js-post.js') 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(); -- cgit v1.2.3