Avoid creating programs with number of variables less than number of parameters

This commit is contained in:
Alexey Andreev 2016-11-29 22:32:22 +03:00
parent 2e20287f80
commit 86b78b8f5d
3 changed files with 10 additions and 1 deletions

View File

@ -326,6 +326,11 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
Program program = new Program();
method.setProgram(program);
for (int i = 0; i <= method.parameterCount(); ++i) {
program.createVariable();
}
BasicBlock block = program.createBasicBlock();
Variable exceptionVar = program.createVariable();
ConstructInstruction newExceptionInsn = new ConstructInstruction();

View File

@ -29,6 +29,10 @@ public class UnusedVariableElimination implements MethodOptimization {
boolean[] escaping = VariableEscapeAnalyzer.findEscapingVariables(program);
boolean[] used = new boolean[escaping.length];
for (int i = 0; i <= method.parameterCount(); ++i) {
used[i] = true;
}
int[] stack = new int[graph.size() * 2];
int top = 0;
for (int i = 0; i < used.length; ++i) {

View File

@ -28,7 +28,7 @@ public class TypeInferer {
GraphBuilder arrayElemBuilder;
public void inferTypes(ProgramReader program, MethodReference method) {
int sz = Math.max(method.parameterCount(), program.variableCount());
int sz = program.variableCount();
types = new VariableType[sz];
types[0] = VariableType.OBJECT;