mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Instructions, that have separate class name and field/method name now
use FieldReference and MethodReference instead
This commit is contained in:
parent
91a50605bc
commit
6efbb75783
|
@ -17,10 +17,7 @@ package org.teavm.dependency;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import org.teavm.codegen.ConcurrentCachedMapper;
|
import org.teavm.codegen.ConcurrentCachedMapper;
|
||||||
import org.teavm.codegen.ConcurrentCachedMapper.KeyListener;
|
import org.teavm.codegen.ConcurrentCachedMapper.KeyListener;
|
||||||
import org.teavm.codegen.Mapper;
|
import org.teavm.codegen.Mapper;
|
||||||
|
@ -48,6 +45,13 @@ public class DependencyChecker {
|
||||||
public DependencyChecker(ClassHolderSource classSource, int numThreads) {
|
public DependencyChecker(ClassHolderSource classSource, int numThreads) {
|
||||||
this.classSource = classSource;
|
this.classSource = classSource;
|
||||||
executor = new ScheduledThreadPoolExecutor(numThreads);
|
executor = new ScheduledThreadPoolExecutor(numThreads);
|
||||||
|
executor.setThreadFactory(new ThreadFactory() {
|
||||||
|
@Override public Thread newThread(Runnable r) {
|
||||||
|
Thread thread = new Thread(r);
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
});
|
||||||
methodCache = new ConcurrentCachedMapper<>(new Mapper<MethodReference, MethodGraph>() {
|
methodCache = new ConcurrentCachedMapper<>(new Mapper<MethodReference, MethodGraph>() {
|
||||||
@Override public MethodGraph map(MethodReference preimage) {
|
@Override public MethodGraph map(MethodReference preimage) {
|
||||||
return createMethodGraph(preimage);
|
return createMethodGraph(preimage);
|
||||||
|
|
|
@ -129,8 +129,7 @@ class DependencyGraphBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeSpecial(InvokeInstruction insn) {
|
private void invokeSpecial(InvokeInstruction insn) {
|
||||||
MethodReference method = new MethodReference(insn.getClassName(), insn.getMethod());
|
MethodGraph targetGraph = dependencyChecker.attachMethodGraph(insn.getMethod());
|
||||||
MethodGraph targetGraph = dependencyChecker.attachMethodGraph(method);
|
|
||||||
DependencyNode[] targetParams = targetGraph.getVariableNodes();
|
DependencyNode[] targetParams = targetGraph.getVariableNodes();
|
||||||
List<Variable> arguments = insn.getArguments();
|
List<Variable> arguments = insn.getArguments();
|
||||||
for (int i = 0; i < arguments.size(); ++i) {
|
for (int i = 0; i < arguments.size(); ++i) {
|
||||||
|
@ -152,7 +151,7 @@ class DependencyGraphBuilder {
|
||||||
}
|
}
|
||||||
actualArgs[0] = nodes[insn.getInstance().getIndex()];
|
actualArgs[0] = nodes[insn.getInstance().getIndex()];
|
||||||
DependencyConsumer listener = new VirtualCallPropagationListener(nodes[insn.getInstance().getIndex()],
|
DependencyConsumer listener = new VirtualCallPropagationListener(nodes[insn.getInstance().getIndex()],
|
||||||
insn.getMethod(), dependencyChecker, actualArgs,
|
insn.getMethod().getDescriptor(), dependencyChecker, actualArgs,
|
||||||
insn.getReceiver() != null ? nodes[insn.getReceiver().getIndex()] : null);
|
insn.getReceiver() != null ? nodes[insn.getReceiver().getIndex()] : null);
|
||||||
nodes[insn.getInstance().getIndex()].addConsumer(listener);
|
nodes[insn.getInstance().getIndex()].addConsumer(listener);
|
||||||
}
|
}
|
||||||
|
@ -190,16 +189,14 @@ class DependencyGraphBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PutFieldInstruction insn) {
|
public void visit(PutFieldInstruction insn) {
|
||||||
DependencyNode fieldNode = dependencyChecker.getFieldNode(new FieldReference(insn.getClassName(),
|
DependencyNode fieldNode = dependencyChecker.getFieldNode(insn.getField());
|
||||||
insn.getField()));
|
|
||||||
DependencyNode valueNode = nodes[insn.getValue().getIndex()];
|
DependencyNode valueNode = nodes[insn.getValue().getIndex()];
|
||||||
valueNode.connect(fieldNode);
|
valueNode.connect(fieldNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(GetFieldInstruction insn) {
|
public void visit(GetFieldInstruction insn) {
|
||||||
DependencyNode fieldNode = dependencyChecker.getFieldNode(new FieldReference(insn.getClassName(),
|
DependencyNode fieldNode = dependencyChecker.getFieldNode(insn.getField());
|
||||||
insn.getField()));
|
|
||||||
DependencyNode receiverNode = nodes[insn.getReceiver().getIndex()];
|
DependencyNode receiverNode = nodes[insn.getReceiver().getIndex()];
|
||||||
fieldNode.connect(receiverNode);
|
fieldNode.connect(receiverNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,18 +156,16 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor {
|
||||||
}
|
}
|
||||||
switch (expr.getType()) {
|
switch (expr.getType()) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
resultExpr = Expr.invokeStatic(expr.getClassName(), expr.getMethod(), args);
|
resultExpr = Expr.invokeStatic(expr.getMethod(), args);
|
||||||
break;
|
break;
|
||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
resultExpr = Expr.invoke(expr.getClassName(), expr.getMethod(), args[0], Arrays.copyOfRange(
|
resultExpr = Expr.invoke(expr.getMethod(), args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||||
args, 1, args.length));
|
|
||||||
break;
|
break;
|
||||||
case SPECIAL:
|
case SPECIAL:
|
||||||
resultExpr = Expr.invokeSpecial(expr.getClassName(), expr.getMethod(), args[0], Arrays.copyOfRange(
|
resultExpr = Expr.invokeSpecial(expr.getMethod(), args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||||
args, 1, args.length));
|
|
||||||
break;
|
break;
|
||||||
case CONSTRUCTOR:
|
case CONSTRUCTOR:
|
||||||
resultExpr = Expr.constructObject(expr.getClassName(), expr.getMethod(), args);
|
resultExpr = Expr.constructObject(expr.getMethod(), args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,12 +197,12 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
NewExpr constructed = (NewExpr)assignment.getRightValue();
|
NewExpr constructed = (NewExpr)assignment.getRightValue();
|
||||||
if (!constructed.getConstructedClass().equals(expr.getClassName())) {
|
if (!constructed.getConstructedClass().equals(expr.getMethod().getClassName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Expr[] args = expr.getArguments().toArray(new Expr[0]);
|
Expr[] args = expr.getArguments().toArray(new Expr[0]);
|
||||||
args = Arrays.copyOfRange(args, 1, args.length);
|
args = Arrays.copyOfRange(args, 1, args.length);
|
||||||
assignment.setRightValue(Expr.constructObject(expr.getClassName(), expr.getMethod(), args));
|
assignment.setRightValue(Expr.constructObject(expr.getMethod(), args));
|
||||||
stats.reads[var.getIndex()]--;
|
stats.reads[var.getIndex()]--;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +211,7 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor {
|
||||||
public void visit(QualificationExpr expr) {
|
public void visit(QualificationExpr expr) {
|
||||||
expr.getQualified().acceptVisitor(this);
|
expr.getQualified().acceptVisitor(this);
|
||||||
Expr qualified = resultExpr;
|
Expr qualified = resultExpr;
|
||||||
resultExpr = Expr.qualify(qualified, expr.getClassName(), expr.getField());
|
resultExpr = Expr.qualify(qualified, expr.getField());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -689,8 +689,8 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(InvocationExpr expr) {
|
public void visit(InvocationExpr expr) {
|
||||||
String className = naming.getNameFor(expr.getClassName());
|
String className = naming.getNameFor(expr.getMethod().getClassName());
|
||||||
String name = naming.getNameFor(new MethodReference(expr.getClassName(), expr.getMethod()));
|
String name = naming.getNameFor(expr.getMethod());
|
||||||
switch (expr.getType()) {
|
switch (expr.getType()) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
writer.append(className).append("_").append(name).append("(");
|
writer.append(className).append("_").append(name).append("(");
|
||||||
|
@ -738,7 +738,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(QualificationExpr expr) {
|
public void visit(QualificationExpr expr) {
|
||||||
expr.getQualified().acceptVisitor(this);
|
expr.getQualified().acceptVisitor(this);
|
||||||
writer.append('.').appendField(new FieldReference(expr.getClassName(), expr.getField()));
|
writer.append('.').appendField(expr.getField());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -412,10 +412,10 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
public void visit(GetFieldInstruction insn) {
|
public void visit(GetFieldInstruction insn) {
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
statements.add(Statement.assign(Expr.var(insn.getReceiver().getIndex()),
|
statements.add(Statement.assign(Expr.var(insn.getReceiver().getIndex()),
|
||||||
Expr.qualify(Expr.var(insn.getInstance().getIndex()), insn.getClassName(), insn.getField())));
|
Expr.qualify(Expr.var(insn.getInstance().getIndex()), insn.getField())));
|
||||||
} else {
|
} else {
|
||||||
Expr fieldExpr = Expr.qualify(Expr.staticClass(ValueType.object(insn.getClassName())),
|
Expr fieldExpr = Expr.qualify(Expr.staticClass(ValueType.object(insn.getField().getClassName())),
|
||||||
insn.getClassName(), insn.getField());
|
insn.getField());
|
||||||
statements.add(Statement.assign(Expr.var(insn.getReceiver().getIndex()), fieldExpr));
|
statements.add(Statement.assign(Expr.var(insn.getReceiver().getIndex()), fieldExpr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,11 +423,11 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(PutFieldInstruction insn) {
|
public void visit(PutFieldInstruction insn) {
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
statements.add(Statement.assign(Expr.qualify(Expr.var(insn.getInstance().getIndex()),
|
statements.add(Statement.assign(Expr.qualify(Expr.var(insn.getInstance().getIndex()), insn.getField()),
|
||||||
insn.getClassName(), insn.getField()), Expr.var(insn.getValue().getIndex())));
|
Expr.var(insn.getValue().getIndex())));
|
||||||
} else {
|
} else {
|
||||||
Expr fieldExpr = Expr.qualify(Expr.staticClass(ValueType.object(insn.getClassName())),
|
Expr fieldExpr = Expr.qualify(Expr.staticClass(ValueType.object(insn.getField().getClassName())),
|
||||||
insn.getClassName(), insn.getField());
|
insn.getField());
|
||||||
statements.add(Statement.assign(fieldExpr, Expr.var(insn.getValue().getIndex())));
|
statements.add(Statement.assign(fieldExpr, Expr.var(insn.getValue().getIndex())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,8 +439,9 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CloneArrayInstruction insn) {
|
public void visit(CloneArrayInstruction insn) {
|
||||||
MethodDescriptor cloneMethod = new MethodDescriptor("clone", ValueType.object("java.lang.Object"));
|
MethodDescriptor cloneMethodDesc = new MethodDescriptor("clone", ValueType.object("java.lang.Object"));
|
||||||
assign(Expr.invoke("java.lang.Object", cloneMethod, Expr.var(insn.getArray().getIndex()), new Expr[0]),
|
MethodReference cloneMethod = new MethodReference("java.lang.Object", cloneMethodDesc);
|
||||||
|
assign(Expr.invoke(cloneMethod, Expr.var(insn.getArray().getIndex()), new Expr[0]),
|
||||||
insn.getReceiver().getIndex());
|
insn.getReceiver().getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,10 +459,9 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(InvokeInstruction insn) {
|
public void visit(InvokeInstruction insn) {
|
||||||
String declaringClass = findDeclaringClass(insn.getClassName(), insn.getMethod());
|
MethodReference method = findDeclaringClass(insn.getMethod());
|
||||||
if (declaringClass == null) {
|
if (method == null) {
|
||||||
throw new IllegalArgumentException("Method not found: " + insn.getClassName() + "." +
|
throw new IllegalArgumentException("Method not found: " + insn.getMethod());
|
||||||
insn.getMethod());
|
|
||||||
}
|
}
|
||||||
Expr[] exprArgs = new Expr[insn.getMethod().getParameterTypes().length];
|
Expr[] exprArgs = new Expr[insn.getMethod().getParameterTypes().length];
|
||||||
for (int i = 0; i < insn.getArguments().size(); ++i) {
|
for (int i = 0; i < insn.getArguments().size(); ++i) {
|
||||||
|
@ -470,14 +470,12 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
Expr invocationExpr;
|
Expr invocationExpr;
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
if (insn.getType() == InvocationType.VIRTUAL) {
|
if (insn.getType() == InvocationType.VIRTUAL) {
|
||||||
invocationExpr = Expr.invoke(declaringClass, insn.getMethod(),
|
invocationExpr = Expr.invoke(insn.getMethod(), Expr.var(insn.getInstance().getIndex()), exprArgs);
|
||||||
Expr.var(insn.getInstance().getIndex()), exprArgs);
|
|
||||||
} else {
|
} else {
|
||||||
invocationExpr = Expr.invokeSpecial(declaringClass, insn.getMethod(),
|
invocationExpr = Expr.invokeSpecial(method, Expr.var(insn.getInstance().getIndex()), exprArgs);
|
||||||
Expr.var(insn.getInstance().getIndex()), exprArgs);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invocationExpr = Expr.invokeStatic(declaringClass, insn.getMethod(), exprArgs);
|
invocationExpr = Expr.invokeStatic(method, exprArgs);
|
||||||
}
|
}
|
||||||
if (insn.getReceiver() != null) {
|
if (insn.getReceiver() != null) {
|
||||||
assign(invocationExpr, insn.getReceiver().getIndex());
|
assign(invocationExpr, insn.getReceiver().getIndex());
|
||||||
|
@ -486,12 +484,12 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findDeclaringClass(String className, MethodDescriptor method) {
|
public MethodReference findDeclaringClass(MethodReference method) {
|
||||||
ClassHolder cls = classSource.getClassHolder(className);
|
ClassHolder cls = classSource.getClassHolder(method.getClassName());
|
||||||
while (cls != null && cls.getMethod(method) == null) {
|
while (cls != null && cls.getMethod(method.getDescriptor()) == null) {
|
||||||
cls = cls.getParent() != null ? classSource.getClassHolder(cls.getParent()) : null;
|
cls = cls.getParent() != null ? classSource.getClassHolder(cls.getParent()) : null;
|
||||||
}
|
}
|
||||||
return cls != null ? cls.getName() : null;
|
return cls != null ? new MethodReference(cls.getName(), method.getDescriptor()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -95,26 +95,23 @@ public abstract class Expr implements Cloneable {
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expr constructObject(String cls, MethodDescriptor method, Expr[] arguments) {
|
public static Expr constructObject(MethodReference method, Expr[] arguments) {
|
||||||
InvocationExpr expr = new InvocationExpr();
|
InvocationExpr expr = new InvocationExpr();
|
||||||
expr.setClassName(cls);
|
|
||||||
expr.setMethod(method);
|
expr.setMethod(method);
|
||||||
expr.setType(InvocationType.CONSTRUCTOR);
|
expr.setType(InvocationType.CONSTRUCTOR);
|
||||||
expr.getArguments().addAll(Arrays.asList(arguments));
|
expr.getArguments().addAll(Arrays.asList(arguments));
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expr qualify(Expr target, String className, String field) {
|
public static Expr qualify(Expr target, FieldReference field) {
|
||||||
QualificationExpr expr = new QualificationExpr();
|
QualificationExpr expr = new QualificationExpr();
|
||||||
expr.setQualified(target);
|
expr.setQualified(target);
|
||||||
expr.setClassName(className);
|
|
||||||
expr.setField(field);
|
expr.setField(field);
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expr invoke(String cls, MethodDescriptor method, Expr target, Expr[] arguments) {
|
public static Expr invoke(MethodReference method, Expr target, Expr[] arguments) {
|
||||||
InvocationExpr expr = new InvocationExpr();
|
InvocationExpr expr = new InvocationExpr();
|
||||||
expr.setClassName(cls);
|
|
||||||
expr.setMethod(method);
|
expr.setMethod(method);
|
||||||
expr.setType(InvocationType.DYNAMIC);
|
expr.setType(InvocationType.DYNAMIC);
|
||||||
expr.getArguments().add(target);
|
expr.getArguments().add(target);
|
||||||
|
@ -122,10 +119,8 @@ public abstract class Expr implements Cloneable {
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expr invokeSpecial(String cls, MethodDescriptor method,
|
public static Expr invokeSpecial(MethodReference method, Expr target, Expr[] arguments) {
|
||||||
Expr target, Expr[] arguments) {
|
|
||||||
InvocationExpr expr = new InvocationExpr();
|
InvocationExpr expr = new InvocationExpr();
|
||||||
expr.setClassName(cls);
|
|
||||||
expr.setMethod(method);
|
expr.setMethod(method);
|
||||||
expr.setType(InvocationType.SPECIAL);
|
expr.setType(InvocationType.SPECIAL);
|
||||||
expr.getArguments().add(target);
|
expr.getArguments().add(target);
|
||||||
|
@ -133,9 +128,8 @@ public abstract class Expr implements Cloneable {
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expr invokeStatic(String cls, MethodDescriptor method, Expr[] arguments) {
|
public static Expr invokeStatic(MethodReference method, Expr[] arguments) {
|
||||||
InvocationExpr expr = new InvocationExpr();
|
InvocationExpr expr = new InvocationExpr();
|
||||||
expr.setClassName(cls);
|
|
||||||
expr.setMethod(method);
|
expr.setMethod(method);
|
||||||
expr.setType(InvocationType.STATIC);
|
expr.setType(InvocationType.STATIC);
|
||||||
expr.getArguments().addAll(Arrays.asList(arguments));
|
expr.getArguments().addAll(Arrays.asList(arguments));
|
||||||
|
|
|
@ -18,31 +18,22 @@ package org.teavm.javascript.ast;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class InvocationExpr extends Expr {
|
public class InvocationExpr extends Expr {
|
||||||
private String className;
|
private MethodReference method;
|
||||||
private MethodDescriptor method;
|
|
||||||
private InvocationType type;
|
private InvocationType type;
|
||||||
private List<Expr> arguments = new ArrayList<>();
|
private List<Expr> arguments = new ArrayList<>();
|
||||||
|
|
||||||
public String getClassName() {
|
public MethodReference getMethod() {
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassName(String className) {
|
|
||||||
this.className = className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodDescriptor getMethod() {
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMethod(MethodDescriptor method) {
|
public void setMethod(MethodReference method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +63,6 @@ public class InvocationExpr extends Expr {
|
||||||
InvocationExpr copy = new InvocationExpr();
|
InvocationExpr copy = new InvocationExpr();
|
||||||
cache.put(this, copy);
|
cache.put(this, copy);
|
||||||
copy.setMethod(method);
|
copy.setMethod(method);
|
||||||
copy.setClassName(className);
|
|
||||||
for (Expr arg : arguments) {
|
for (Expr arg : arguments) {
|
||||||
copy.getArguments().add(arg.clone(cache));
|
copy.getArguments().add(arg.clone(cache));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package org.teavm.javascript.ast;
|
package org.teavm.javascript.ast;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.teavm.model.FieldReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -23,8 +24,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class QualificationExpr extends Expr {
|
public class QualificationExpr extends Expr {
|
||||||
private Expr qualified;
|
private Expr qualified;
|
||||||
private String className;
|
private FieldReference field;
|
||||||
private String field;
|
|
||||||
|
|
||||||
public Expr getQualified() {
|
public Expr getQualified() {
|
||||||
return qualified;
|
return qualified;
|
||||||
|
@ -34,19 +34,11 @@ public class QualificationExpr extends Expr {
|
||||||
this.qualified = qualified;
|
this.qualified = qualified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public FieldReference getField() {
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassName(String className) {
|
|
||||||
this.className = className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setField(String field) {
|
public void setField(FieldReference field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +55,6 @@ public class QualificationExpr extends Expr {
|
||||||
}
|
}
|
||||||
QualificationExpr copy = new QualificationExpr();
|
QualificationExpr copy = new QualificationExpr();
|
||||||
cache.put(this, copy);
|
cache.put(this, copy);
|
||||||
copy.setClassName(className);
|
|
||||||
copy.setField(field);
|
copy.setField(field);
|
||||||
copy.setQualified(qualified != null ? qualified.clone(cache) : null);
|
copy.setQualified(qualified != null ? qualified.clone(cache) : null);
|
||||||
return copy;
|
return copy;
|
||||||
|
|
|
@ -22,7 +22,19 @@ public class MethodReference {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int parameterCount() {
|
public int parameterCount() {
|
||||||
return descriptor.getParameterTypes().length;
|
return descriptor.parameterCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueType[] getParameterTypes() {
|
||||||
|
return descriptor.getParameterTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueType[] getSignature() {
|
||||||
|
return descriptor.getSignature();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return descriptor.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.teavm.model.instructions;
|
package org.teavm.model.instructions;
|
||||||
|
|
||||||
|
import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.Instruction;
|
import org.teavm.model.Instruction;
|
||||||
import org.teavm.model.ValueType;
|
import org.teavm.model.ValueType;
|
||||||
import org.teavm.model.Variable;
|
import org.teavm.model.Variable;
|
||||||
|
@ -10,8 +11,7 @@ import org.teavm.model.Variable;
|
||||||
*/
|
*/
|
||||||
public class GetFieldInstruction extends Instruction {
|
public class GetFieldInstruction extends Instruction {
|
||||||
private Variable instance;
|
private Variable instance;
|
||||||
private String className;
|
private FieldReference field;
|
||||||
private String field;
|
|
||||||
private ValueType fieldType;
|
private ValueType fieldType;
|
||||||
private Variable receiver;
|
private Variable receiver;
|
||||||
|
|
||||||
|
@ -23,19 +23,11 @@ public class GetFieldInstruction extends Instruction {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public FieldReference getField() {
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassName(String className) {
|
|
||||||
this.className = className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setField(String field) {
|
public void setField(FieldReference field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,7 @@ import org.teavm.model.*;
|
||||||
*/
|
*/
|
||||||
public class InvokeInstruction extends Instruction {
|
public class InvokeInstruction extends Instruction {
|
||||||
private InvocationType type;
|
private InvocationType type;
|
||||||
private String className;
|
private MethodReference method;
|
||||||
private MethodDescriptor method;
|
|
||||||
private Variable instance;
|
private Variable instance;
|
||||||
private List<Variable> arguments = new ArrayList<>();
|
private List<Variable> arguments = new ArrayList<>();
|
||||||
private Variable receiver;
|
private Variable receiver;
|
||||||
|
@ -36,19 +35,11 @@ public class InvokeInstruction extends Instruction {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public MethodReference getMethod() {
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassName(String className) {
|
|
||||||
this.className = className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodDescriptor getMethod() {
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMethod(MethodDescriptor method) {
|
public void setMethod(MethodReference method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.teavm.model.instructions;
|
package org.teavm.model.instructions;
|
||||||
|
|
||||||
|
import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.Instruction;
|
import org.teavm.model.Instruction;
|
||||||
import org.teavm.model.Variable;
|
import org.teavm.model.Variable;
|
||||||
|
|
||||||
|
@ -9,8 +10,7 @@ import org.teavm.model.Variable;
|
||||||
*/
|
*/
|
||||||
public class PutFieldInstruction extends Instruction {
|
public class PutFieldInstruction extends Instruction {
|
||||||
private Variable instance;
|
private Variable instance;
|
||||||
private String className;
|
private FieldReference field;
|
||||||
private String field;
|
|
||||||
private Variable value;
|
private Variable value;
|
||||||
|
|
||||||
public Variable getInstance() {
|
public Variable getInstance() {
|
||||||
|
@ -21,19 +21,11 @@ public class PutFieldInstruction extends Instruction {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public FieldReference getField() {
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassName(String className) {
|
|
||||||
this.className = className;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setField(String field) {
|
public void setField(FieldReference field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,12 +197,14 @@ class ClassRefsRenamer implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(GetFieldInstruction insn) {
|
public void visit(GetFieldInstruction insn) {
|
||||||
insn.setClassName(classNameMapper.map(insn.getClassName()));
|
String className = classNameMapper.map(insn.getField().getClassName());
|
||||||
|
insn.setField(new FieldReference(className, insn.getField().getFieldName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PutFieldInstruction insn) {
|
public void visit(PutFieldInstruction insn) {
|
||||||
insn.setClassName(classNameMapper.map(insn.getClassName()));
|
String className = classNameMapper.map(insn.getField().getClassName());
|
||||||
|
insn.setField(new FieldReference(className, insn.getField().getFieldName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -223,12 +225,12 @@ class ClassRefsRenamer implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(InvokeInstruction insn) {
|
public void visit(InvokeInstruction insn) {
|
||||||
insn.setClassName(classNameMapper.map(insn.getClassName()));
|
String className = classNameMapper.map(insn.getMethod().getClassName());
|
||||||
ValueType[] signature = insn.getMethod().getSignature();
|
ValueType[] signature = insn.getMethod().getSignature();
|
||||||
for (int i = 0; i < signature.length; ++i) {
|
for (int i = 0; i < signature.length; ++i) {
|
||||||
signature[i] = rename(signature[i]);
|
signature[i] = rename(signature[i]);
|
||||||
}
|
}
|
||||||
insn.setMethod(new MethodDescriptor(insn.getMethod().getName(), signature));
|
insn.setMethod(new MethodReference(className, new MethodDescriptor(insn.getMethod().getName(), signature)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class InstructionStringifier implements InstructionVisitor {
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
sb.append("@").append(insn.getInstance().getIndex());
|
sb.append("@").append(insn.getInstance().getIndex());
|
||||||
} else {
|
} else {
|
||||||
sb.append(insn.getClassName());
|
sb.append(insn.getField().getClassName());
|
||||||
}
|
}
|
||||||
sb.append(".").append(insn.getField());
|
sb.append(".").append(insn.getField());
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ public class InstructionStringifier implements InstructionVisitor {
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
sb.append("@").append(insn.getInstance().getIndex());
|
sb.append("@").append(insn.getInstance().getIndex());
|
||||||
} else {
|
} else {
|
||||||
sb.append(insn.getClassName());
|
sb.append(insn.getField().getClassName());
|
||||||
}
|
}
|
||||||
sb.append(".").append(insn.getField()).append(" := @").append(insn.getValue().getIndex());
|
sb.append(".").append(insn.getField()).append(" := @").append(insn.getValue().getIndex());
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ public class InstructionStringifier implements InstructionVisitor {
|
||||||
if (insn.getInstance() != null) {
|
if (insn.getInstance() != null) {
|
||||||
sb.append("@").append(insn.getInstance().getIndex());
|
sb.append("@").append(insn.getInstance().getIndex());
|
||||||
} else {
|
} else {
|
||||||
sb.append(insn.getClassName());
|
sb.append(insn.getMethod().getClassName());
|
||||||
}
|
}
|
||||||
sb.append(".").append(insn.getMethod().getName()).append("(");
|
sb.append(".").append(insn.getMethod().getName()).append("(");
|
||||||
List<Variable> arguments = insn.getArguments();
|
List<Variable> arguments = insn.getArguments();
|
||||||
|
|
|
@ -357,8 +357,7 @@ public class ProgramParser {
|
||||||
}
|
}
|
||||||
args[--j] = getVariable(--currentDepth);
|
args[--j] = getVariable(--currentDepth);
|
||||||
}
|
}
|
||||||
MethodDescriptor method = new MethodDescriptor(name,
|
MethodDescriptor method = new MethodDescriptor(name, MethodDescriptor.parseSignature(desc));
|
||||||
MethodDescriptor.parseSignature(desc));
|
|
||||||
int instance = -1;
|
int instance = -1;
|
||||||
if (opcode != Opcodes.INVOKESTATIC) {
|
if (opcode != Opcodes.INVOKESTATIC) {
|
||||||
instance = --currentDepth;
|
instance = --currentDepth;
|
||||||
|
@ -374,8 +373,7 @@ public class ProgramParser {
|
||||||
}
|
}
|
||||||
if (instance == -1) {
|
if (instance == -1) {
|
||||||
InvokeInstruction insn = new InvokeInstruction();
|
InvokeInstruction insn = new InvokeInstruction();
|
||||||
insn.setClassName(ownerCls);
|
insn.setMethod(new MethodReference(ownerCls, method));
|
||||||
insn.setMethod(method);
|
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
insn.setReceiver(getVariable(result));
|
insn.setReceiver(getVariable(result));
|
||||||
}
|
}
|
||||||
|
@ -388,8 +386,7 @@ public class ProgramParser {
|
||||||
} else {
|
} else {
|
||||||
insn.setType(InvocationType.VIRTUAL);
|
insn.setType(InvocationType.VIRTUAL);
|
||||||
}
|
}
|
||||||
insn.setClassName(ownerCls);
|
insn.setMethod(new MethodReference(ownerCls, method));
|
||||||
insn.setMethod(method);
|
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
insn.setReceiver(getVariable(result));
|
insn.setReceiver(getVariable(result));
|
||||||
}
|
}
|
||||||
|
@ -1292,8 +1289,7 @@ public class ProgramParser {
|
||||||
}
|
}
|
||||||
GetFieldInstruction insn = new GetFieldInstruction();
|
GetFieldInstruction insn = new GetFieldInstruction();
|
||||||
insn.setInstance(getVariable(instance));
|
insn.setInstance(getVariable(instance));
|
||||||
insn.setClassName(ownerCls);
|
insn.setField(new FieldReference(ownerCls, name));
|
||||||
insn.setField(name);
|
|
||||||
insn.setFieldType(type);
|
insn.setFieldType(type);
|
||||||
insn.setReceiver(getVariable(value));
|
insn.setReceiver(getVariable(value));
|
||||||
builder.add(insn);
|
builder.add(insn);
|
||||||
|
@ -1309,8 +1305,7 @@ public class ProgramParser {
|
||||||
int instance = --currentDepth;
|
int instance = --currentDepth;
|
||||||
PutFieldInstruction insn = new PutFieldInstruction();
|
PutFieldInstruction insn = new PutFieldInstruction();
|
||||||
insn.setInstance(getVariable(instance));
|
insn.setInstance(getVariable(instance));
|
||||||
insn.setClassName(ownerCls);
|
insn.setField(new FieldReference(ownerCls, name));
|
||||||
insn.setField(name);
|
|
||||||
insn.setValue(getVariable(value));
|
insn.setValue(getVariable(value));
|
||||||
builder.add(insn);
|
builder.add(insn);
|
||||||
break;
|
break;
|
||||||
|
@ -1322,8 +1317,7 @@ public class ProgramParser {
|
||||||
currentDepth++;
|
currentDepth++;
|
||||||
}
|
}
|
||||||
GetFieldInstruction insn = new GetFieldInstruction();
|
GetFieldInstruction insn = new GetFieldInstruction();
|
||||||
insn.setClassName(ownerCls);
|
insn.setField(new FieldReference(ownerCls, name));
|
||||||
insn.setField(name);
|
|
||||||
insn.setFieldType(type);
|
insn.setFieldType(type);
|
||||||
insn.setReceiver(getVariable(value));
|
insn.setReceiver(getVariable(value));
|
||||||
builder.add(insn);
|
builder.add(insn);
|
||||||
|
@ -1335,8 +1329,7 @@ public class ProgramParser {
|
||||||
}
|
}
|
||||||
int value = --currentDepth;
|
int value = --currentDepth;
|
||||||
PutFieldInstruction insn = new PutFieldInstruction();
|
PutFieldInstruction insn = new PutFieldInstruction();
|
||||||
insn.setClassName(ownerCls);
|
insn.setField(new FieldReference(ownerCls, name));
|
||||||
insn.setField(name);
|
|
||||||
insn.setValue(getVariable(value));
|
insn.setValue(getVariable(value));
|
||||||
builder.add(insn);
|
builder.add(insn);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user