diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-19 11:25:57 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-19 11:25:57 -0800 |
commit | 1327ff5cbb6f0c433b64f713dd95acb0f09a669f (patch) | |
tree | 07119f129d5aafd3d28d17d9027a214856510d02 | |
parent | f7dd2645ee157a60cce28cb7db9327728699d544 (diff) | |
parent | 3732b13dce850dd6dc43ab390a7caf363d9d8edd (diff) |
Merge pull request #746 from xxuejie/function-name-filter
Add function name filter for LABEL_DEBUG
-rw-r--r-- | src/jsifier.js | 21 | ||||
-rw-r--r-- | src/settings.js | 6 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 50703b90..4192cd3f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -486,6 +486,19 @@ function JSify(data, functionsOnly, givenFunctions) { } }); + // function for filtering functions for label debugging + if (LABEL_FUNCTION_FILTERS.length > 0) { + var LABEL_FUNCTION_FILTER_SET = set(LABEL_FUNCTION_FILTERS); + var functionNameFilterTest = function(ident) { + return (ident in LABEL_FUNCTION_FILTER_SET); + }; + } else { + // no filters are specified, all function names are printed + var functionNameFilterTest = function(ident) { + return true; + } + } + // function reconstructor & post-JS optimizer substrate.addActor('FunctionReconstructor', { funcs: {}, @@ -566,7 +579,7 @@ function JSify(data, functionsOnly, givenFunctions) { } }); - if (LABEL_DEBUG) func.JS += " Module.print(INDENT + ' Entering: " + func.ident + ": ' + Array.prototype.slice.call(arguments)); INDENT += ' ';\n"; + if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " Module.print(INDENT + ' Entering: " + func.ident + ": ' + Array.prototype.slice.call(arguments)); INDENT += ' ';\n"; if (true) { // TODO: optimize away when not needed if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */'; @@ -580,7 +593,7 @@ function JSify(data, functionsOnly, givenFunctions) { function getLabelLines(label, indent, relooping) { if (!label) return ''; var ret = ''; - if (LABEL_DEBUG >= 2) { + if ((LABEL_DEBUG >= 2) && functionNameFilterTest(func.ident)) { ret += indent + "Module.print(INDENT + '" + func.ident + ":" + label.ident + "');\n"; } if (EXECUTION_TIMEOUT > 0) { @@ -692,7 +705,7 @@ function JSify(data, functionsOnly, givenFunctions) { } func.JS += walkBlock(func.block, ' '); // Finalize function - if (LABEL_DEBUG) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n"; + if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n"; // Add an unneeded return, needed for strict mode to not throw warnings in some cases. // If we are not relooping, then switches make it unimportant to have this (and, we lack hasReturn anyhow) if (RELOOP && func.lines.length > 0 && func.labels.filter(function(label) { return label.hasReturn }).length > 0) { @@ -1025,7 +1038,7 @@ function JSify(data, functionsOnly, givenFunctions) { + 'PROFILING_NODE = __parentProfilingNode__ ' + '}\n'; } - if (LABEL_DEBUG) { + if (LABEL_DEBUG && functionNameFilterTest(item.funcData.ident)) { ret += "Module.print(INDENT + 'Exiting: " + item.funcData.ident + "');\n" + "INDENT = INDENT.substr(0, INDENT.length-2);\n"; } diff --git a/src/settings.js b/src/settings.js index 1d8805a8..77111ed5 100644 --- a/src/settings.js +++ b/src/settings.js @@ -132,6 +132,12 @@ var SAFE_HEAP_LOG = 0; // Log out all SAFE_HEAP operations var LABEL_DEBUG = 0; // 1: Print out functions as we enter them // 2: Also print out each label as we enter it +var LABEL_FUNCTION_FILTERS = []; // Filters for function label debug. + // The items for this array will be used + // as filters for function names. Only the + // labels of functions that is equaled to + // one of the filters are printed out + // When the array is empty, the filter is disabled. var EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code var LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js). You can also unset |