mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 00:14:10 -08:00
WASM: fix exception handling
This commit is contained in:
parent
f6103ec00b
commit
055f39c1c8
|
@ -200,11 +200,11 @@ public class WasmTarget implements TeaVMTarget {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contributeDependencies(DependencyChecker dependencyChecker) {
|
public void contributeDependencies(DependencyChecker dependencyChecker) {
|
||||||
for (Class type : Arrays.asList(int.class, long.class, float.class, double.class)) {
|
for (Class<?> type : Arrays.asList(int.class, long.class, float.class, double.class)) {
|
||||||
MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class);
|
MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class);
|
||||||
dependencyChecker.linkMethod(method, null).use();
|
dependencyChecker.linkMethod(method, null).use();
|
||||||
}
|
}
|
||||||
for (Class type : Arrays.asList(float.class, double.class)) {
|
for (Class<?> type : Arrays.asList(float.class, double.class)) {
|
||||||
MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type);
|
MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type);
|
||||||
dependencyChecker.linkMethod(method, null).use();
|
dependencyChecker.linkMethod(method, null).use();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@ package org.teavm.model.lowlevel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.teavm.common.DominatorTree;
|
import org.teavm.common.DominatorTree;
|
||||||
import org.teavm.common.Graph;
|
import org.teavm.common.Graph;
|
||||||
|
@ -90,8 +92,12 @@ public class ExceptionHandlingShadowStackContributor {
|
||||||
allPhis.addAll(program.basicBlockAt(i).getPhis());
|
allPhis.addAll(program.basicBlockAt(i).getPhis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<BasicBlock> exceptionHandlers = new HashSet<>();
|
||||||
for (int i = 0; i < blockCount; ++i) {
|
for (int i = 0; i < blockCount; ++i) {
|
||||||
BasicBlock block = program.basicBlockAt(i);
|
BasicBlock block = program.basicBlockAt(i);
|
||||||
|
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||||
|
exceptionHandlers.add(tryCatch.getHandler());
|
||||||
|
}
|
||||||
|
|
||||||
if (block.getExceptionVariable() != null) {
|
if (block.getExceptionVariable() != null) {
|
||||||
InvokeInstruction catchCall = new InvokeInstruction();
|
InvokeInstruction catchCall = new InvokeInstruction();
|
||||||
|
@ -111,9 +117,11 @@ public class ExceptionHandlingShadowStackContributor {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Phi phi : allPhis) {
|
for (Phi phi : allPhis) {
|
||||||
for (Incoming incoming : phi.getIncomings()) {
|
if (!exceptionHandlers.contains(phi.getBasicBlock())) {
|
||||||
int mappedSource = blockMapping[incoming.getSource().getIndex()];
|
for (Incoming incoming : phi.getIncomings()) {
|
||||||
incoming.setSource(program.basicBlockAt(mappedSource));
|
int mappedSource = blockMapping[incoming.getSource().getIndex()];
|
||||||
|
incoming.setSource(program.basicBlockAt(mappedSource));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,8 +195,8 @@ public class ExceptionHandlingShadowStackContributor {
|
||||||
List<Instruction> pre = setLocation(getInstructionsBeforeCallSite(callSite), insn.getLocation());
|
List<Instruction> pre = setLocation(getInstructionsBeforeCallSite(callSite), insn.getLocation());
|
||||||
List<Instruction> post = getInstructionsAfterCallSite(block, next, callSite, currentJointSources);
|
List<Instruction> post = getInstructionsAfterCallSite(block, next, callSite, currentJointSources);
|
||||||
post = setLocation(post, insn.getLocation());
|
post = setLocation(post, insn.getLocation());
|
||||||
insn.insertPreviousAll(pre);
|
block.getLastInstruction().insertPreviousAll(pre);
|
||||||
insn.insertNextAll(post);
|
block.addAll(post);
|
||||||
hasExceptionHandlers = true;
|
hasExceptionHandlers = true;
|
||||||
|
|
||||||
if (next == null || last) {
|
if (next == null || last) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user