This commit is contained in:
Jindra Petřík
2021-02-08 20:15:19 +01:00
parent 7725258ceb
commit ddab9c4ac9
2 changed files with 43 additions and 0 deletions
@@ -501,6 +501,14 @@ public class AVM2Graph extends Graph {
finCatchName = AVM2Item.localRegName(new HashMap<>(), sl.regIndex);
}
}
} else {
//No kill ins
if (!ncatchedCommands.isEmpty() && (ncatchedCommands.get(0) instanceof SetLocalAVM2Item)) {
SetLocalAVM2Item sl = (SetLocalAVM2Item) ncatchedCommands.get(0);
if (sl.value.getThroughDuplicate().getNotCoerced() instanceof ExceptionAVM2Item) {
ncatchedCommands.remove(0);
}
}
}
}
}
@@ -1176,4 +1184,29 @@ public class AVM2Graph extends Graph {
protected List<GraphTargetItem> filter(List<GraphTargetItem> list) {
return avm2code.clearTemporaryRegisters(list);
}
@Override
protected void checkSwitch(BaseLocalData localData, SwitchItem switchItem, Map<Integer, GraphTargetItem> otherSides, List<GraphTargetItem> output) {
if (output.isEmpty()) {
return;
}
if (!(output.get(output.size() - 1) instanceof SetLocalAVM2Item)) {
return;
}
AVM2LocalData avm2LocalData = (AVM2LocalData) localData;
SetLocalAVM2Item setLocal = (SetLocalAVM2Item) output.get(output.size() - 1);
int setLocalIp = avm2LocalData.code.code.indexOf(setLocal.getSrc());
Set<Integer> allUsages = new HashSet<>(avm2LocalData.setLocalPosToGetLocalPos.get(setLocalIp));
for (GraphTargetItem otherSide : otherSides.values()) {
if (otherSide instanceof LocalRegAVM2Item) {
LocalRegAVM2Item otherLog = (LocalRegAVM2Item) otherSide;
int getLocalIp = avm2LocalData.code.code.indexOf(otherLog.getSrc());
allUsages.remove((Integer) getLocalIp);
}
}
if (allUsages.isEmpty()) {
output.remove(output.size() - 1);
switchItem.switchedObject = setLocal.value;
}
}
}