Skip to content

Instantly share code, notes, and snippets.

@enebo
Created June 2, 2010 20:05
Show Gist options
  • Save enebo/422906 to your computer and use it in GitHub Desktop.
Save enebo/422906 to your computer and use it in GitHub Desktop.
@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