Created
June 2, 2010 20:05
-
-
Save enebo/422906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Interp | |
public Iterator<LocalVariable> getLiveLocalVariables() { | |
Map<LocalVariable, Integer> ends = new HashMap<LocalVariable, Integer>(); | |
Map<LocalVariable, Integer> starts = new HashMap<LocalVariable, Integer>(); | |
Set<LocalVariable> variables = new TreeSet<LocalVariable>(); | |
for (int i = instructions.size() - 1; i >= 0; i--) { | |
Instr instr = instructions.get(i); | |
Variable variable = instr.result; | |
if (variable != null && variable instanceof LocalVariable) { | |
variables.add((LocalVariable) variable); | |
starts.put((LocalVariable) variable, i); | |
} | |
for (Operand operand : instr.getOperands()) { | |
if (!(operand instanceof LocalVariable)) continue; | |
variable = (LocalVariable) operand; | |
if (ends.get((LocalVariable) variable) == null) { | |
ends.put((LocalVariable) variable, i); | |
variables.add((LocalVariable) variable); | |
} | |
} | |
} | |
return variables.iterator(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment