Merge branch 'async' of https://github.com/konsoletyper/teavm into threads

This commit is contained in:
Steve Hannah 2015-02-03 07:07:46 -08:00
commit 8fa50a0504
2 changed files with 8 additions and 3 deletions

View File

@ -202,17 +202,19 @@ public class Decompiler {
AsyncMethodNode node = new AsyncMethodNode(method.getReference()); AsyncMethodNode node = new AsyncMethodNode(method.getReference());
AsyncProgramSplitter splitter = new AsyncProgramSplitter(asyncMethods); AsyncProgramSplitter splitter = new AsyncProgramSplitter(asyncMethods);
splitter.split(method.getProgram()); splitter.split(method.getProgram());
List<Program> partPrograms = new ArrayList<>();
for (int i = 0; i < splitter.size(); ++i) { for (int i = 0; i < splitter.size(); ++i) {
AsyncMethodPart part = getRegularMethodStatement(splitter.getProgram(i), splitter.getBlockSuccessors(i)); AsyncMethodPart part = getRegularMethodStatement(splitter.getProgram(i), splitter.getBlockSuccessors(i));
part.setInputVariable(splitter.getInput(i)); part.setInputVariable(splitter.getInput(i));
node.getBody().add(part); node.getBody().add(part);
partPrograms.add(splitter.getProgram(i));
} }
Program program = method.getProgram(); Program program = method.getProgram();
for (int i = 0; i < program.variableCount(); ++i) { for (int i = 0; i < program.variableCount(); ++i) {
node.getVariables().add(program.variableAt(i).getRegister()); node.getVariables().add(program.variableAt(i).getRegister());
} }
Optimizer optimizer = new Optimizer(); Optimizer optimizer = new Optimizer();
optimizer.optimize(node, method.getProgram()); optimizer.optimize(node, partPrograms);
node.getModifiers().addAll(mapModifiers(method.getModifiers())); node.getModifiers().addAll(mapModifiers(method.getModifiers()));
int paramCount = Math.min(method.getSignature().length, program.variableCount()); int paramCount = Math.min(method.getSignature().length, program.variableCount());
for (int i = 0; i < paramCount; ++i) { for (int i = 0; i < paramCount; ++i) {

View File

@ -15,6 +15,7 @@
*/ */
package org.teavm.javascript; package org.teavm.javascript;
import java.util.List;
import org.teavm.javascript.ast.AsyncMethodNode; import org.teavm.javascript.ast.AsyncMethodNode;
import org.teavm.javascript.ast.AsyncMethodPart; import org.teavm.javascript.ast.AsyncMethodPart;
import org.teavm.javascript.ast.RegularMethodNode; import org.teavm.javascript.ast.RegularMethodNode;
@ -43,9 +44,11 @@ public class Optimizer {
} }
} }
public void optimize(AsyncMethodNode method, Program program) { public void optimize(AsyncMethodNode method, List<Program> programs) {
ReadWriteStatsBuilder stats = new ReadWriteStatsBuilder(method.getVariables().size()); ReadWriteStatsBuilder stats = new ReadWriteStatsBuilder(method.getVariables().size());
stats.analyze(program); for (Program program : programs) {
stats.analyze(program);
}
OptimizingVisitor optimizer = new OptimizingVisitor(stats); OptimizingVisitor optimizer = new OptimizingVisitor(stats);
for (AsyncMethodPart part : method.getBody()) { for (AsyncMethodPart part : method.getBody()) {
part.getStatement().acceptVisitor(optimizer); part.getStatement().acceptVisitor(optimizer);