mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Fixes bugs in try/catch
This commit is contained in:
parent
ea3e6adb64
commit
a4f477329d
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.classlib.java.lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public class TSecurityException extends TRuntimeException {
|
||||||
|
private static final long serialVersionUID = 720572643357872552L;
|
||||||
|
|
||||||
|
public TSecurityException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TSecurityException(TString message, TThrowable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TSecurityException(TString message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TSecurityException(TThrowable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,6 +60,16 @@ class DependencyGraphBuilder {
|
||||||
nodes[incoming.getValue().getIndex()].connect(nodes[phi.getReceiver().getIndex()]);
|
nodes[incoming.getValue().getIndex()].connect(nodes[phi.getReceiver().getIndex()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (final TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) {
|
||||||
|
useRunners.add(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (tryCatch.getExceptionType() != null) {
|
||||||
|
dependencyChecker.initClass(tryCatch.getExceptionType(), callerStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dep.setUseRunner(new MultipleRunner(useRunners));
|
dep.setUseRunner(new MultipleRunner(useRunners));
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,9 @@ public class Decompiler {
|
||||||
if (node >= 0) {
|
if (node >= 0) {
|
||||||
generator.currentBlock = program.basicBlockAt(node);
|
generator.currentBlock = program.basicBlockAt(node);
|
||||||
int tmp = indexer.nodeAt(next);
|
int tmp = indexer.nodeAt(next);
|
||||||
|
if (tmp < 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
generator.nextBlock = next < indexer.size() ? program.basicBlockAt(tmp) : null;
|
generator.nextBlock = next < indexer.size() ? program.basicBlockAt(tmp) : null;
|
||||||
generator.statements.clear();
|
generator.statements.clear();
|
||||||
for (Instruction insn : generator.currentBlock.getInstructions()) {
|
for (Instruction insn : generator.currentBlock.getInstructions()) {
|
||||||
|
|
|
@ -1268,8 +1268,12 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
.ws().append("{").indent().softNewLine();
|
.ws().append("{").indent().softNewLine();
|
||||||
writer.append("$je").ws().append("=").ws().append("$e.$javaException;").softNewLine();
|
writer.append("$je").ws().append("=").ws().append("$e.$javaException;").softNewLine();
|
||||||
for (TryCatchStatement catchClause : sequence) {
|
for (TryCatchStatement catchClause : sequence) {
|
||||||
writer.append("if").ws().append("($je && $je instanceof ").appendClass(catchClause.getExceptionType())
|
writer.append("if").ws().append("($je");
|
||||||
.append(")").ws().append("{").indent().softNewLine();
|
if (catchClause.getExceptionType() != null) {
|
||||||
|
writer.ws().append("&&").ws().append("$je instanceof ")
|
||||||
|
.appendClass(catchClause.getExceptionType());
|
||||||
|
}
|
||||||
|
writer.append(")").ws().append("{").indent().softNewLine();
|
||||||
if (statement.getExceptionVariable() != catchClause.getExceptionVariable()) {
|
if (statement.getExceptionVariable() != catchClause.getExceptionVariable()) {
|
||||||
if (catchClause.getExceptionVariable() != null) {
|
if (catchClause.getExceptionVariable() != null) {
|
||||||
writer.append(variableName(catchClause.getExceptionVariable())).ws().append("=").ws()
|
writer.append(variableName(catchClause.getExceptionVariable())).ws().append("=").ws()
|
||||||
|
|
|
@ -25,6 +25,24 @@ import org.teavm.model.instructions.*;
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class ProgramUtils {
|
public class ProgramUtils {
|
||||||
|
public static Graph buildControlFlowGraphWithoutTryCatch(Program program) {
|
||||||
|
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
|
||||||
|
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
||||||
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
|
BasicBlock block = program.basicBlockAt(i);
|
||||||
|
Instruction insn = block.getLastInstruction();
|
||||||
|
if (insn != null) {
|
||||||
|
insn.acceptVisitor(transitionExtractor);
|
||||||
|
if (transitionExtractor.getTargets() != null) {
|
||||||
|
for (BasicBlock successor : transitionExtractor.getTargets()) {
|
||||||
|
graphBuilder.addEdge(i, successor.getIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return graphBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
public static Graph buildControlFlowGraph(Program program) {
|
public static Graph buildControlFlowGraph(Program program) {
|
||||||
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
|
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
|
||||||
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class SSATransformer {
|
||||||
private Program program;
|
private Program program;
|
||||||
private Graph cfg;
|
private Graph cfg;
|
||||||
private DominatorTree domTree;
|
private DominatorTree domTree;
|
||||||
private Graph domGraph;
|
|
||||||
private int[][] domFrontiers;
|
private int[][] domFrontiers;
|
||||||
private Variable[] variableMap;
|
private Variable[] variableMap;
|
||||||
private BasicBlock currentBlock;
|
private BasicBlock currentBlock;
|
||||||
|
@ -46,7 +45,7 @@ public class SSATransformer {
|
||||||
}
|
}
|
||||||
this.program = program;
|
this.program = program;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
cfg = ProgramUtils.buildControlFlowGraph(program);
|
cfg = ProgramUtils.buildControlFlowGraphWithoutTryCatch(program);
|
||||||
domTree = GraphUtils.buildDominatorTree(cfg);
|
domTree = GraphUtils.buildDominatorTree(cfg);
|
||||||
domFrontiers = new int[cfg.size()][];
|
domFrontiers = new int[cfg.size()][];
|
||||||
variableMap = new Variable[program.variableCount()];
|
variableMap = new Variable[program.variableCount()];
|
||||||
|
@ -103,11 +102,12 @@ public class SSATransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameVariables() {
|
private void renameVariables() {
|
||||||
domGraph = GraphUtils.buildDominatorGraph(domTree, program.basicBlockCount());
|
DominatorTree domTree = GraphUtils.buildDominatorTree(ProgramUtils.buildControlFlowGraph(program));
|
||||||
|
Graph domGraph = GraphUtils.buildDominatorGraph(domTree, program.basicBlockCount());
|
||||||
Task[] stack = new Task[cfg.size() * 2];
|
Task[] stack = new Task[cfg.size() * 2];
|
||||||
int head = 0;
|
int head = 0;
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
if (domTree.immediateDominatorOf(i) < 0) {
|
if (domGraph.incomingEdgesCount(i) == 0) {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.block = program.basicBlockAt(i);
|
task.block = program.basicBlockAt(i);
|
||||||
task.variables = Arrays.copyOf(variableMap, variableMap.length);
|
task.variables = Arrays.copyOf(variableMap, variableMap.length);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user