From 2b77f6ae60cfaf3f3cbdcc4121e82a619b9372c3 Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Sat, 8 Feb 2020 00:52:15 +0100 Subject: Add C-/JS-APIs for lowMemoryUnused and pass arguments (#2639) Allows a user to enable/disable the `lowMemoryUnused` option and to get/set/clear arbitrary pass arguments when using the C- or JS-APIs. * binaryen.**getLowMemoryUnused**(): `boolean` * binaryen.**setLowMemoryUnused**(on: `boolean`): `void` * binaryen.**getPassArgument**(key: `string`): `string | null` * binaryen.**setPassArgument**(key: `string`, value: `string | null`): `void` * binaryen.**clearPassArguments**(): `void` --- src/js/binaryen.js-post.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 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 fd2832bf2..d41e9575b 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -2873,7 +2873,7 @@ Module['getOptimizeLevel'] = function() { // Sets the optimization level to use. 0, 1, 2 correspond to -O0, -O1, -O2, etc. Module['setOptimizeLevel'] = function(level) { - return Module['_BinaryenSetOptimizeLevel'](level); + Module['_BinaryenSetOptimizeLevel'](level); }; // Gets the currently set shrink level. 0, 1, 2 correspond to -O0, -Os, -Oz. @@ -2883,7 +2883,7 @@ Module['getShrinkLevel'] = function() { // Sets the shrink level to use. 0, 1, 2 correspond to -O0, -Os, -Oz. Module['setShrinkLevel'] = function(level) { - return Module['_BinaryenSetShrinkLevel'](level); + Module['_BinaryenSetShrinkLevel'](level); }; // Gets whether generating debug information is currently enabled or not. @@ -2893,7 +2893,39 @@ Module['getDebugInfo'] = function() { // Enables or disables debug information in emitted binaries. Module['setDebugInfo'] = function(on) { - return Module['_BinaryenSetDebugInfo'](on); + Module['_BinaryenSetDebugInfo'](on); +}; + +// Gets whether the low 1K of memory can be considered unused when optimizing. +Module['getLowMemoryUnused'] = function() { + return Boolean(Module['_BinaryenGetLowMemoryUnused']()); +}; + +// Enables or disables whether the low 1K of memory can be considered unused +// when optimizing. +Module['setLowMemoryUnused'] = function(on) { + Module['_BinaryenSetLowMemoryUnused'](on); +}; + +// Gets the value of the specified arbitrary pass argument. +Module['getPassArgument'] = function(key) { + return preserveStack(function() { + var ret = Module['_BinaryenGetPassArgument'](strToStack(key)); + return ret !== 0 ? UTF8ToString(ret) : null; + }); +}; + +// Sets the value of the specified arbitrary pass argument. Removes the +// respective argument if `value` is NULL. +Module['setPassArgument'] = function (key, value) { + preserveStack(function () { + Module['_BinaryenSetPassArgument'](strToStack(key), strToStack(value)); + }); +}; + +// Clears all arbitrary pass arguments. +Module['clearPassArguments'] = function() { + Module['_BinaryenClearPassArguments'](); }; // Enables or disables C-API tracing -- cgit v1.2.3