diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-12-25 16:03:43 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-12-25 16:03:43 -0800 |
commit | b2fd961d06812c0bfcecc19521a040b8c0a06d24 (patch) | |
tree | a4f6b4da99ceae126b800a5c1b36e29daeb2a345 /src | |
parent | 8e5c52df194f951187e897e5213849828e41b490 (diff) |
refactor and fix global variables, should they be needed for analysis
Diffstat (limited to 'src')
-rw-r--r-- | src/analyzer.js | 11 | ||||
-rw-r--r-- | src/jsifier.js | 21 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 8f4ba95e..0cb89eda 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -217,6 +217,17 @@ function analyzer(data, givenTypes) { // Variable analyzer substrate.addActor('VariableAnalyzer', { processItem: function(item) { + // Globals + + var old = item.globalVariables; + item.globalVariables = {}; + old.forEach(function(variable) { + variable.impl = 'emulated'; // All global variables are emulated, for now. Consider optimizing later if useful + item.globalVariables[variable.ident] = variable; + }); + + // Function locals + item.functions.forEach(function(func) { dprint('vars', 'Analyzing variables in ' + func.ident); diff --git a/src/jsifier.js b/src/jsifier.js index 85108b7d..e3fbf3e4 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1,12 +1,13 @@ // Convert analyzed data to javascript -function JSify(data, functionsOnly, givenTypes, givenFunctions) { +function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVariables) { substrate = new Substrate('JSifyer'); var TYPES = functionsOnly ? givenTypes : data.types; - var FUNCTIONS = functionsOnly ? givenFunctions : {}; + var GLOBAL_VARIABLES = functionsOnly ? givenGlobalVariables : data.globalVariables; + var FUNCTIONS = functionsOnly ? givenFunctions : {}; // Now that analysis has completed, we can get around to handling unparsedFunctions (functionsOnly ? data.functions : data.unparsedFunctions.concat(data.functions)).forEach(function(func) { // Save just what we need, to save memory - whether there are varargs, and the # of parameters @@ -19,7 +20,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { for (var i = 0; i < data.unparsedFunctions.length; i++) { var func = data.unparsedFunctions[i]; dprint('unparsedFunctions', 'processing |' + func.ident + '|, ' + i + '/' + data.unparsedFunctions.length); - func.JS = JSify(analyzer(intertyper(func.lines, true, func.lineNum-1), TYPES), true, TYPES, FUNCTIONS); + func.JS = JSify(analyzer(intertyper(func.lines, true, func.lineNum-1), TYPES), true, TYPES, FUNCTIONS, GLOBAL_VARIABLES); delete func.lines; // clean up memory as much as possible } @@ -441,17 +442,14 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { } }); - function getVarData(funcData, ident) { // XXX - need to check globals as well! - return funcData.variables[ident]; + function getVarData(funcData, ident) { + return funcData.variables[ident] || GLOBAL_VARIABLES[ident]; } function getVarImpl(funcData, ident) { var data = getVarData(funcData, ident); - if (data) { - return data.impl; - } else { - return 'emulated'; // All global are emulated - } + assert(data, 'What variable is this? |' + ident + '|'); + return data.impl; } substrate.addActor('FuncLineTriager', { @@ -484,7 +482,6 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { var type = item.value.type; var value = parseNumerical(item.value.JS); - //print("zz var: " + item.JS); var impl = getVarImpl(item.funcData, item.ident); switch (impl) { case VAR_NATIVE: { @@ -990,7 +987,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { // Data substrate.addItems(values(data.types).filter(function(type) { return type.lineNum != '?' }), 'Type'); - substrate.addItems(data.globalVariables, 'GlobalVariable'); + substrate.addItems(values(data.globalVariables), 'GlobalVariable'); substrate.addItems(data.functions, 'FunctionSplitter'); substrate.addItems(data.functionStubs, 'FunctionStub'); |