When unexpected exception occurs during optimization, dump IR to stderr.

This commit is contained in:
Alexey Andreev 2016-10-22 15:56:49 +03:00
parent a30ac3cd83
commit 3dbca7959b
2 changed files with 12 additions and 7 deletions

View File

@ -354,11 +354,7 @@ public class PhiUpdater {
continue;
}
Map<Variable, TryCatchJoint> joints = jointMap.get(tryCatch);
if (joints == null) {
joints = new HashMap<>();
jointMap.put(tryCatch, joints);
}
Map<Variable, TryCatchJoint> joints = jointMap.computeIfAbsent(tryCatch, k -> new HashMap<>());
TryCatchJoint joint = joints.get(original);
if (joint == null) {
joint = new TryCatchJoint();
@ -398,7 +394,7 @@ public class PhiUpdater {
private Variable use(Variable var) {
Variable mappedVar = variableMap[var.getIndex()];
if (mappedVar == null) {
throw new AssertionError();
throw new AssertionError("Variable used before definition: " + var.getIndex());
}
return mappedVar;
}

View File

@ -61,6 +61,7 @@ import org.teavm.model.optimization.MethodOptimization;
import org.teavm.model.optimization.RedundantJumpElimination;
import org.teavm.model.optimization.UnreachableBasicBlockElimination;
import org.teavm.model.optimization.UnusedVariableElimination;
import org.teavm.model.util.ListingBuilder;
import org.teavm.model.util.MissingItemsProcessor;
import org.teavm.model.util.ModelUtils;
import org.teavm.model.util.ProgramUtils;
@ -478,7 +479,15 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
do {
changed = false;
for (MethodOptimization optimization : getOptimizations()) {
try {
changed |= optimization.optimize(method, optimizedProgram);
} catch (Exception e) {
ListingBuilder listingBuilder = new ListingBuilder();
String listing = listingBuilder.buildListing(optimizedProgram, "");
System.err.println("Error optimizing program for method" + method.getReference()
+ ":\n" + listing);
throw new RuntimeException(e);
}
}
} while (changed);