mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
Replace ArrayList with array to store arguments of InvokeInstruction
This commit is contained in:
parent
f589b0035a
commit
9305a532bb
|
@ -531,7 +531,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
|||
initExceptionInsn.setInstance(exceptionVar);
|
||||
initExceptionInsn.setMethod(new MethodReference(NoSuchMethodError.class, "<init>", String.class, void.class));
|
||||
initExceptionInsn.setType(InvocationType.SPECIAL);
|
||||
initExceptionInsn.getArguments().add(constVar);
|
||||
initExceptionInsn.setArguments(constVar);
|
||||
block.add(initExceptionInsn);
|
||||
|
||||
RaiseInstruction raiseInsn = new RaiseInstruction();
|
||||
|
|
|
@ -1039,9 +1039,11 @@ public class ProgramIO {
|
|||
MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt()));
|
||||
insn.setMethod(createMethodReference(className, methodDesc));
|
||||
int paramCount = insn.getMethod().getDescriptor().parameterCount();
|
||||
Variable[] arguments = new Variable[paramCount];
|
||||
for (int i = 0; i < paramCount; ++i) {
|
||||
insn.getArguments().add(program.variableAt(input.readShort()));
|
||||
arguments[i] = program.variableAt(input.readShort());
|
||||
}
|
||||
insn.setArguments(arguments);
|
||||
return insn;
|
||||
}
|
||||
case 34: {
|
||||
|
@ -1054,9 +1056,11 @@ public class ProgramIO {
|
|||
MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt()));
|
||||
insn.setMethod(createMethodReference(className, methodDesc));
|
||||
int paramCount = insn.getMethod().getDescriptor().parameterCount();
|
||||
Variable[] arguments = new Variable[paramCount];
|
||||
for (int i = 0; i < paramCount; ++i) {
|
||||
insn.getArguments().add(program.variableAt(input.readShort()));
|
||||
arguments[i] = program.variableAt(input.readShort());
|
||||
}
|
||||
insn.setArguments(arguments);
|
||||
return insn;
|
||||
}
|
||||
case 35: {
|
||||
|
@ -1069,9 +1073,11 @@ public class ProgramIO {
|
|||
MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt()));
|
||||
insn.setMethod(createMethodReference(className, methodDesc));
|
||||
int paramCount = insn.getMethod().getDescriptor().parameterCount();
|
||||
Variable[] arguments = new Variable[paramCount];
|
||||
for (int i = 0; i < paramCount; ++i) {
|
||||
insn.getArguments().add(program.variableAt(input.readShort()));
|
||||
arguments[i] = program.variableAt(input.readShort());
|
||||
}
|
||||
insn.setArguments(arguments);
|
||||
return insn;
|
||||
}
|
||||
case 36: {
|
||||
|
|
|
@ -179,8 +179,7 @@ public class InstructionReadVisitor implements InstructionVisitor {
|
|||
|
||||
@Override
|
||||
public void visit(InvokeInstruction insn) {
|
||||
reader.invoke(insn.getReceiver(), insn.getInstance(), insn.getMethod(),
|
||||
Collections.unmodifiableList(insn.getArguments()), insn.getType());
|
||||
reader.invoke(insn.getReceiver(), insn.getInstance(), insn.getMethod(), insn.getArguments(), insn.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -236,9 +236,12 @@ public final class ProgramEmitter {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(method);
|
||||
insn.setReceiver(result);
|
||||
for (ValueEmitter arg : arguments) {
|
||||
insn.getArguments().add(arg.variable);
|
||||
Variable[] insnArguments = new Variable[arguments.length];
|
||||
for (int i = 0; i < insnArguments.length; ++i) {
|
||||
insnArguments[i] = arguments[i].variable;
|
||||
}
|
||||
insn.setArguments(insnArguments);
|
||||
|
||||
addInstruction(insn);
|
||||
return result != null ? var(result, method.getReturnType()) : null;
|
||||
}
|
||||
|
@ -260,9 +263,11 @@ public final class ProgramEmitter {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(method);
|
||||
insn.setReceiver(result);
|
||||
for (ValueEmitter arg : arguments) {
|
||||
insn.getArguments().add(arg.variable);
|
||||
Variable[] insnArguments = new Variable[arguments.length];
|
||||
for (int i = 0; i < insnArguments.length; ++i) {
|
||||
insnArguments[i] = arguments[i].variable;
|
||||
}
|
||||
insn.setArguments(insnArguments);
|
||||
addInstruction(insn);
|
||||
return result != null ? var(result, resultType) : null;
|
||||
}
|
||||
|
|
|
@ -445,9 +445,11 @@ public class ValueEmitter {
|
|||
insn.setMethod(method);
|
||||
insn.setInstance(variable);
|
||||
insn.setReceiver(result);
|
||||
for (ValueEmitter arg : arguments) {
|
||||
insn.getArguments().add(arg.variable);
|
||||
Variable[] insnArguments = new Variable[arguments.length];
|
||||
for (int i = 0; i < insnArguments.length; ++i) {
|
||||
insnArguments[i] = arguments[i].variable;
|
||||
}
|
||||
insn.setArguments(insnArguments);
|
||||
pe.addInstruction(insn);
|
||||
return result != null ? pe.var(result, method.getReturnType()) : null;
|
||||
}
|
||||
|
@ -474,9 +476,11 @@ public class ValueEmitter {
|
|||
insn.setMethod(method);
|
||||
insn.setInstance(variable);
|
||||
insn.setReceiver(result);
|
||||
for (ValueEmitter arg : arguments) {
|
||||
insn.getArguments().add(arg.variable);
|
||||
Variable[] insnArguments = new Variable[arguments.length];
|
||||
for (int i = 0; i < insnArguments.length; ++i) {
|
||||
insnArguments[i] = arguments[i].variable;
|
||||
}
|
||||
insn.setArguments(insnArguments);
|
||||
pe.addInstruction(insn);
|
||||
return result != null ? pe.var(result, resultType) : null;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
*/
|
||||
package org.teavm.model.instructions;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
import org.teavm.model.Instruction;
|
||||
import org.teavm.model.MethodReference;
|
||||
import org.teavm.model.Variable;
|
||||
|
@ -25,7 +27,7 @@ public class InvokeInstruction extends Instruction {
|
|||
private InvocationType type;
|
||||
private MethodReference method;
|
||||
private Variable instance;
|
||||
private List<Variable> arguments = new ArrayList<>(1);
|
||||
private Variable[] arguments;
|
||||
private Variable receiver;
|
||||
|
||||
public InvocationType getType() {
|
||||
|
@ -44,8 +46,20 @@ public class InvokeInstruction extends Instruction {
|
|||
this.instance = instance;
|
||||
}
|
||||
|
||||
public List<Variable> getArguments() {
|
||||
return arguments;
|
||||
public List<? extends Variable> getArguments() {
|
||||
return argumentList;
|
||||
}
|
||||
|
||||
public void replaceArguments(UnaryOperator<Variable> f) {
|
||||
if (arguments != null) {
|
||||
for (int i = 0; i < arguments.length; ++i) {
|
||||
arguments[i] = f.apply(arguments[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setArguments(Variable... arguments) {
|
||||
this.arguments = arguments.length > 0 ? arguments.clone() : null;
|
||||
}
|
||||
|
||||
public MethodReference getMethod() {
|
||||
|
@ -68,4 +82,19 @@ public class InvokeInstruction extends Instruction {
|
|||
public void acceptVisitor(InstructionVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
private List<? extends Variable> argumentList = new AbstractList<Variable>() {
|
||||
@Override
|
||||
public Variable get(int index) {
|
||||
if (arguments == null) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
return arguments[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return arguments != null ? arguments.length : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class ClassInitializerTransformer {
|
|||
InvokeInstruction checkInitialized = new InvokeInstruction();
|
||||
checkInitialized.setType(InvocationType.SPECIAL);
|
||||
checkInitialized.setMethod(new MethodReference(Allocator.class, "isInitialized", Class.class, boolean.class));
|
||||
checkInitialized.getArguments().add(clsVariable);
|
||||
checkInitialized.setArguments(clsVariable);
|
||||
checkInitialized.setReceiver(initializedVariable);
|
||||
block.add(checkInitialized);
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ public class ExceptionHandlingShadowStackContributor {
|
|||
raise.setMethod(new MethodReference(ExceptionHandling.class, "throwException", Throwable.class,
|
||||
void.class));
|
||||
raise.setType(InvocationType.SPECIAL);
|
||||
raise.getArguments().add(((RaiseInstruction) insn).getException());
|
||||
raise.setArguments(((RaiseInstruction) insn).getException());
|
||||
raise.setLocation(insn.getLocation());
|
||||
insn.replace(raise);
|
||||
insn = raise;
|
||||
|
@ -300,7 +300,7 @@ public class ExceptionHandlingShadowStackContributor {
|
|||
InvokeInstruction registerInsn = new InvokeInstruction();
|
||||
registerInsn.setMethod(new MethodReference(ShadowStack.class, "registerCallSite", int.class, void.class));
|
||||
registerInsn.setType(InvocationType.SPECIAL);
|
||||
registerInsn.getArguments().add(idVariable);
|
||||
registerInsn.setArguments(idVariable);
|
||||
instructions.add(registerInsn);
|
||||
|
||||
return instructions;
|
||||
|
|
|
@ -374,18 +374,20 @@ public class GCShadowStackContributor {
|
|||
slotConstant.setLocation(callInstruction.getLocation());
|
||||
instructionsToAdd.add(slotConstant);
|
||||
|
||||
List<Variable> arguments = new ArrayList<>();
|
||||
InvokeInstruction registerInvocation = new InvokeInstruction();
|
||||
registerInvocation.setLocation(callInstruction.getLocation());
|
||||
registerInvocation.setType(InvocationType.SPECIAL);
|
||||
registerInvocation.getArguments().add(slotVar);
|
||||
arguments.add(slotVar);
|
||||
if (var >= 0) {
|
||||
registerInvocation.setMethod(new MethodReference(ShadowStack.class, "registerGCRoot", int.class,
|
||||
Object.class, void.class));
|
||||
registerInvocation.getArguments().add(program.variableAt(var));
|
||||
arguments.add(program.variableAt(var));
|
||||
} else {
|
||||
registerInvocation.setMethod(new MethodReference(ShadowStack.class, "removeGCRoot", int.class,
|
||||
void.class));
|
||||
}
|
||||
registerInvocation.setArguments(arguments.toArray(new Variable[0]));
|
||||
instructionsToAdd.add(registerInvocation);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ShadowStackTransformer {
|
|||
InvokeInstruction invocation = new InvokeInstruction();
|
||||
invocation.setType(InvocationType.SPECIAL);
|
||||
invocation.setMethod(new MethodReference(ShadowStack.class, "allocStack", int.class, void.class));
|
||||
invocation.getArguments().add(sizeVariable);
|
||||
invocation.setArguments(sizeVariable);
|
||||
instructionsToAdd.add(invocation);
|
||||
|
||||
block.addFirstAll(instructionsToAdd);
|
||||
|
@ -139,7 +139,7 @@ public class ShadowStackTransformer {
|
|||
InvokeInstruction invocation = new InvokeInstruction();
|
||||
invocation.setType(InvocationType.SPECIAL);
|
||||
invocation.setMethod(new MethodReference(ShadowStack.class, "releaseStack", int.class, void.class));
|
||||
invocation.getArguments().add(sizeVariable);
|
||||
invocation.setArguments(sizeVariable);
|
||||
instructionsToAdd.add(invocation);
|
||||
|
||||
exitBlock.getLastInstruction().insertPreviousAll(instructionsToAdd);
|
||||
|
|
|
@ -727,7 +727,7 @@ public class GlobalValueNumbering implements MethodOptimization {
|
|||
int instance = map[insn.getInstance().getIndex()];
|
||||
insn.setInstance(program.variableAt(instance));
|
||||
}
|
||||
insn.getArguments().replaceAll(mapper);
|
||||
insn.replaceArguments(mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -713,9 +713,9 @@ public class ListingParser {
|
|||
lexer.getIndex());
|
||||
}
|
||||
insn.setInstance(arguments.get(0));
|
||||
insn.getArguments().addAll(arguments.subList(1, arguments.size()));
|
||||
insn.setArguments(arguments.subList(1, arguments.size()).toArray(new Variable[0]));
|
||||
} else {
|
||||
insn.getArguments().addAll(arguments);
|
||||
insn.setArguments(arguments.toArray(new Variable[0]));
|
||||
}
|
||||
|
||||
addInstruction(insn);
|
||||
|
|
|
@ -411,9 +411,11 @@ public class InstructionCopyReader implements InstructionReader {
|
|||
insnCopy.setType(type);
|
||||
insnCopy.setInstance(instance != null ? copyVar(instance) : null);
|
||||
insnCopy.setReceiver(receiver != null ? copyVar(receiver) : null);
|
||||
for (VariableReader arg : arguments) {
|
||||
insnCopy.getArguments().add(copyVar(arg));
|
||||
Variable[] argsCopy = new Variable[arguments.size()];
|
||||
for (int i = 0; i < argsCopy.length; ++i) {
|
||||
argsCopy[i] = copyVar(arguments.get(i));
|
||||
}
|
||||
insnCopy.setArguments(argsCopy);
|
||||
copy = insnCopy;
|
||||
copy.setLocation(location);
|
||||
}
|
||||
|
|
|
@ -267,9 +267,7 @@ public class InstructionVariableMapper extends AbstractInstructionVisitor {
|
|||
if (insn.getInstance() != null) {
|
||||
insn.setInstance(map(insn.getInstance()));
|
||||
}
|
||||
for (int i = 0; i < insn.getArguments().size(); ++i) {
|
||||
insn.getArguments().set(i, map(insn.getArguments().get(i)));
|
||||
}
|
||||
insn.replaceArguments(this::map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -117,7 +117,7 @@ public class MissingItemsProcessor {
|
|||
initExceptionInsn.setMethod(new MethodReference(exceptionName, "<init>", ValueType.object("java.lang.String"),
|
||||
ValueType.VOID));
|
||||
initExceptionInsn.setType(InvocationType.SPECIAL);
|
||||
initExceptionInsn.getArguments().add(constVar);
|
||||
initExceptionInsn.setArguments(constVar);
|
||||
initExceptionInsn.setLocation(location);
|
||||
instructionsToAdd.add(initExceptionInsn);
|
||||
|
||||
|
|
|
@ -686,10 +686,7 @@ public class PhiUpdater {
|
|||
|
||||
@Override
|
||||
public void visit(InvokeInstruction insn) {
|
||||
List<Variable> args = insn.getArguments();
|
||||
for (int i = 0; i < args.size(); ++i) {
|
||||
args.set(i, use(args.get(i)));
|
||||
}
|
||||
insn.replaceArguments(v -> use(v));
|
||||
if (insn.getInstance() != null) {
|
||||
insn.setInstance(use(insn.getInstance()));
|
||||
}
|
||||
|
|
|
@ -657,7 +657,7 @@ public class ProgramParser {
|
|||
if (result >= 0) {
|
||||
insn.setReceiver(getVariable(result));
|
||||
}
|
||||
insn.getArguments().addAll(Arrays.asList(args));
|
||||
insn.setArguments(args);
|
||||
addInstruction(insn);
|
||||
} else {
|
||||
InvokeInstruction insn = new InvokeInstruction();
|
||||
|
@ -671,7 +671,7 @@ public class ProgramParser {
|
|||
insn.setReceiver(getVariable(result));
|
||||
}
|
||||
insn.setInstance(getVariable(instance));
|
||||
insn.getArguments().addAll(Arrays.asList(args));
|
||||
insn.setArguments(args);
|
||||
addInstruction(insn);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -329,7 +329,12 @@ class JSClassProcessor {
|
|||
if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) {
|
||||
invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static",
|
||||
getStaticSignature(method.getReference())));
|
||||
invoke.getArguments().add(0, invoke.getInstance());
|
||||
Variable[] newArguments = new Variable[invoke.getArguments().size() + 1];
|
||||
newArguments[0] = invoke.getInstance();
|
||||
for (int i = 0; i < invoke.getArguments().size(); ++i) {
|
||||
newArguments[i + 1] = invoke.getArguments().get(i);
|
||||
}
|
||||
invoke.setArguments(newArguments);
|
||||
invoke.setInstance(null);
|
||||
}
|
||||
invoke.setType(InvocationType.SPECIAL);
|
||||
|
@ -369,16 +374,18 @@ class JSClassProcessor {
|
|||
newInvoke.setType(InvocationType.SPECIAL);
|
||||
newInvoke.setReceiver(result);
|
||||
newInvoke.setLocation(invoke.getLocation());
|
||||
List<Variable> newArgs = new ArrayList<>();
|
||||
if (invoke.getInstance() != null) {
|
||||
Variable arg = marshaller.wrapArgument(callLocation, invoke.getInstance(),
|
||||
ValueType.object(method.getOwnerName()), false);
|
||||
newInvoke.getArguments().add(arg);
|
||||
newArgs.add(arg);
|
||||
}
|
||||
for (int i = 0; i < invoke.getArguments().size(); ++i) {
|
||||
Variable arg = marshaller.wrapArgument(callLocation, invoke.getArguments().get(i),
|
||||
method.parameterType(i), byRefParams[i]);
|
||||
newInvoke.getArguments().add(arg);
|
||||
newArgs.add(arg);
|
||||
}
|
||||
newInvoke.setArguments(newArgs.toArray(new Variable[0]));
|
||||
replacement.add(newInvoke);
|
||||
if (result != null) {
|
||||
result = marshaller.unwrapReturnValue(callLocation, result, method.getResultType());
|
||||
|
@ -501,15 +508,17 @@ class JSClassProcessor {
|
|||
newInvoke.setMethod(JSMethods.invoke(method.parameterCount()));
|
||||
newInvoke.setType(InvocationType.SPECIAL);
|
||||
newInvoke.setReceiver(result);
|
||||
newInvoke.getArguments().add(invoke.getInstance());
|
||||
newInvoke.getArguments().add(marshaller.addStringWrap(marshaller.addString(name, invoke.getLocation()),
|
||||
List<Variable> newArguments = new ArrayList<>();
|
||||
newArguments.add(invoke.getInstance());
|
||||
newArguments.add(marshaller.addStringWrap(marshaller.addString(name, invoke.getLocation()),
|
||||
invoke.getLocation()));
|
||||
newInvoke.setLocation(invoke.getLocation());
|
||||
for (int i = 0; i < invoke.getArguments().size(); ++i) {
|
||||
Variable arg = marshaller.wrapArgument(callLocation, invoke.getArguments().get(i),
|
||||
method.parameterType(i), byRefParams[i]);
|
||||
newInvoke.getArguments().add(arg);
|
||||
newArguments.add(arg);
|
||||
}
|
||||
newInvoke.setArguments(newArguments.toArray(new Variable[0]));
|
||||
replacement.add(newInvoke);
|
||||
if (result != null) {
|
||||
result = marshaller.unwrapReturnValue(callLocation, result, method.getResultType());
|
||||
|
@ -661,10 +670,12 @@ class JSClassProcessor {
|
|||
insn.setInstance(marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++),
|
||||
ValueType.object(calleeRef.getClassName())));
|
||||
}
|
||||
Variable[] args = new Variable[callee.parameterCount()];
|
||||
for (int i = 0; i < callee.parameterCount(); ++i) {
|
||||
insn.getArguments().add(marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++),
|
||||
callee.parameterType(i)));
|
||||
args[i] = marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++),
|
||||
callee.parameterType(i));
|
||||
}
|
||||
insn.setArguments(args);
|
||||
if (callee.getResultType() != ValueType.VOID) {
|
||||
insn.setReceiver(program.createVariable());
|
||||
}
|
||||
|
@ -691,8 +702,7 @@ class JSClassProcessor {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.GET);
|
||||
insn.setReceiver(receiver);
|
||||
insn.getArguments().add(instance);
|
||||
insn.getArguments().add(nameVar);
|
||||
insn.setArguments(instance, nameVar);
|
||||
insn.setLocation(location);
|
||||
replacement.add(insn);
|
||||
}
|
||||
|
@ -702,9 +712,7 @@ class JSClassProcessor {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.SET);
|
||||
insn.getArguments().add(instance);
|
||||
insn.getArguments().add(nameVar);
|
||||
insn.getArguments().add(value);
|
||||
insn.setArguments(instance, nameVar, value);
|
||||
insn.setLocation(location);
|
||||
replacement.add(insn);
|
||||
}
|
||||
|
@ -714,8 +722,7 @@ class JSClassProcessor {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.GET);
|
||||
insn.setReceiver(receiver);
|
||||
insn.getArguments().add(array);
|
||||
insn.getArguments().add(index);
|
||||
insn.setArguments(array, index);
|
||||
insn.setLocation(location);
|
||||
replacement.add(insn);
|
||||
}
|
||||
|
@ -724,9 +731,7 @@ class JSClassProcessor {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.SET);
|
||||
insn.getArguments().add(array);
|
||||
insn.getArguments().add(index);
|
||||
insn.getArguments().add(value);
|
||||
insn.setArguments(array, index, value);
|
||||
insn.setLocation(location);
|
||||
replacement.add(insn);
|
||||
}
|
||||
|
|
|
@ -125,15 +125,14 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
|
|||
JSValueMarshaller marshaller = new JSValueMarshaller(diagnostics, typeHelper, hierarchy.getClassSource(),
|
||||
program, marshallInstructions);
|
||||
|
||||
List<Variable> variablesToPass = new ArrayList<>();
|
||||
Variable[] variablesToPass = new Variable[method.parameterCount()];
|
||||
for (int i = 0; i < method.parameterCount(); ++i) {
|
||||
variablesToPass.add(program.createVariable());
|
||||
variablesToPass[i] = program.createVariable();
|
||||
}
|
||||
|
||||
for (int i = 0; i < method.parameterCount(); ++i) {
|
||||
Variable var = marshaller.unwrapReturnValue(callLocation, variablesToPass.get(i),
|
||||
variablesToPass[i] = marshaller.unwrapReturnValue(callLocation, variablesToPass[i],
|
||||
method.parameterType(i));
|
||||
variablesToPass.set(i, var);
|
||||
}
|
||||
|
||||
basicBlock.addAll(marshallInstructions);
|
||||
|
@ -143,7 +142,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
|
|||
invocation.setType(InvocationType.VIRTUAL);
|
||||
invocation.setInstance(program.variableAt(0));
|
||||
invocation.setMethod(methodRef);
|
||||
invocation.getArguments().addAll(variablesToPass);
|
||||
invocation.setArguments(variablesToPass);
|
||||
basicBlock.add(invocation);
|
||||
|
||||
ExitInstruction exit = new ExitInstruction();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.teavm.jso.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import org.teavm.diagnostics.Diagnostics;
|
||||
|
@ -90,8 +91,7 @@ class JSValueMarshaller {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.FUNCTION);
|
||||
insn.setReceiver(functor);
|
||||
insn.getArguments().add(var);
|
||||
insn.getArguments().add(nameVar);
|
||||
insn.setArguments(var, nameVar);
|
||||
insn.setLocation(location.getSourceLocation());
|
||||
replacement.add(insn);
|
||||
return functor;
|
||||
|
@ -103,7 +103,7 @@ class JSValueMarshaller {
|
|||
insn.setMethod(JSMethods.ARRAY_DATA);
|
||||
insn.setReceiver(program.createVariable());
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.getArguments().add(var);
|
||||
insn.setArguments(var);
|
||||
replacement.add(insn);
|
||||
return insn.getReceiver();
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ class JSValueMarshaller {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setMethod(referenceCache.getCached(new MethodReference(JS.class.getName(), "wrap",
|
||||
getWrappedType(type), getWrapperType(type))));
|
||||
insn.getArguments().add(var);
|
||||
insn.setArguments(var);
|
||||
insn.setReceiver(result);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setLocation(location);
|
||||
|
@ -145,7 +145,7 @@ class JSValueMarshaller {
|
|||
while (--degree > 1) {
|
||||
insn = new InvokeInstruction();
|
||||
insn.setMethod(JSMethods.ARRAY_MAPPER);
|
||||
insn.getArguments().add(function);
|
||||
insn.setArguments(function);
|
||||
function = program.createVariable();
|
||||
insn.setReceiver(function);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
|
@ -156,8 +156,7 @@ class JSValueMarshaller {
|
|||
insn = new InvokeInstruction();
|
||||
insn.setMethod(referenceCache.getCached(new MethodReference(JS.class.getName(), "map",
|
||||
getWrappedType(type), ValueType.parse(Function.class), getWrapperType(type))));
|
||||
insn.getArguments().add(var);
|
||||
insn.getArguments().add(function);
|
||||
insn.setArguments(var, function);
|
||||
insn.setReceiver(result);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setLocation(location);
|
||||
|
@ -309,6 +308,7 @@ class JSValueMarshaller {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setMethod(singleDimensionArrayUnwrapper(type));
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
List<Variable> args = new ArrayList<>();
|
||||
|
||||
if (insn.getMethod().parameterCount() == 2) {
|
||||
Variable cls = program.createVariable();
|
||||
|
@ -317,10 +317,11 @@ class JSValueMarshaller {
|
|||
clsInsn.setLocation(location.getSourceLocation());
|
||||
clsInsn.setReceiver(cls);
|
||||
replacement.add(clsInsn);
|
||||
insn.getArguments().add(cls);
|
||||
args.add(cls);
|
||||
}
|
||||
|
||||
insn.getArguments().add(var);
|
||||
args.add(var);
|
||||
insn.setArguments(args.toArray(new Variable[0]));
|
||||
insn.setReceiver(result);
|
||||
replacement.add(insn);
|
||||
return result;
|
||||
|
@ -340,7 +341,7 @@ class JSValueMarshaller {
|
|||
clsInsn.setLocation(location.getSourceLocation());
|
||||
clsInsn.setReceiver(cls);
|
||||
replacement.add(clsInsn);
|
||||
insn.getArguments().add(cls);
|
||||
insn.setArguments(cls);
|
||||
}
|
||||
|
||||
insn.setReceiver(function);
|
||||
|
@ -359,8 +360,7 @@ class JSValueMarshaller {
|
|||
insn = new InvokeInstruction();
|
||||
insn.setMethod(JSMethods.ARRAY_UNMAPPER);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.getArguments().add(cls);
|
||||
insn.getArguments().add(function);
|
||||
insn.setArguments(cls, function);
|
||||
function = program.createVariable();
|
||||
insn.setReceiver(function);
|
||||
replacement.add(insn);
|
||||
|
@ -375,9 +375,7 @@ class JSValueMarshaller {
|
|||
|
||||
insn = new InvokeInstruction();
|
||||
insn.setMethod(JSMethods.UNMAP_ARRAY);
|
||||
insn.getArguments().add(cls);
|
||||
insn.getArguments().add(var);
|
||||
insn.getArguments().add(function);
|
||||
insn.setArguments(cls, var, function);
|
||||
insn.setReceiver(var);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setLocation(location.getSourceLocation());
|
||||
|
@ -454,7 +452,7 @@ class JSValueMarshaller {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setMethod(referenceCache.getCached(referenceCache.getCached(new MethodReference(
|
||||
JS.class.getName(), methodName, argType, resultType))));
|
||||
insn.getArguments().add(var);
|
||||
insn.setArguments(var);
|
||||
insn.setReceiver(result);
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setLocation(location);
|
||||
|
@ -476,8 +474,7 @@ class JSValueMarshaller {
|
|||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(JSMethods.FUNCTION_AS_OBJECT);
|
||||
insn.setReceiver(functor);
|
||||
insn.getArguments().add(var);
|
||||
insn.getArguments().add(nameVar);
|
||||
insn.setArguments(var, nameVar);
|
||||
insn.setLocation(location.getSourceLocation());
|
||||
replacement.add(insn);
|
||||
return functor;
|
||||
|
|
|
@ -406,7 +406,7 @@ public class CompositeMethodGenerator {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setMethod(new MethodReference(wrapper, "valueOf", primitive, wrapper));
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.getArguments().add(var);
|
||||
insn.setArguments(var);
|
||||
var = program.createVariable();
|
||||
insn.setReceiver(var);
|
||||
add(insn);
|
||||
|
@ -851,7 +851,7 @@ public class CompositeMethodGenerator {
|
|||
insn.setReceiver(var(receiver));
|
||||
insn.setMethod(method);
|
||||
insn.setType(type);
|
||||
insn.getArguments().addAll(arguments.stream().map(this::var).collect(Collectors.toList()));
|
||||
insn.setArguments(arguments.stream().map(this::var).toArray(Variable[]::new));
|
||||
add(insn);
|
||||
}
|
||||
|
||||
|
@ -932,7 +932,7 @@ public class CompositeMethodGenerator {
|
|||
insn.setType(Modifier.isStatic(reflectMethod.getModifiers()) ? InvocationType.SPECIAL
|
||||
: InvocationType.VIRTUAL);
|
||||
insn.setMethod(reflectMethod.method.getReference());
|
||||
emitArguments(var(arguments.get(1)), reflectMethod, insn.getArguments());
|
||||
insn.setArguments(emitArguments(var(arguments.get(1)), reflectMethod));
|
||||
add(insn);
|
||||
|
||||
if (receiver != null) {
|
||||
|
@ -964,7 +964,7 @@ public class CompositeMethodGenerator {
|
|||
insn.setInstance(constructInsn.getReceiver());
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(reflectMethod.method.getReference());
|
||||
emitArguments(var(arguments.get(0)), reflectMethod, insn.getArguments());
|
||||
insn.setArguments(emitArguments(var(arguments.get(0)), reflectMethod));
|
||||
add(insn);
|
||||
|
||||
return true;
|
||||
|
@ -1054,14 +1054,14 @@ public class CompositeMethodGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private void emitArguments(Variable argumentsVar, ReflectMethodImpl reflectMethod,
|
||||
List<Variable> arguments) {
|
||||
private Variable[] emitArguments(Variable argumentsVar, ReflectMethodImpl reflectMethod) {
|
||||
UnwrapArrayInstruction unwrapInsn = new UnwrapArrayInstruction(ArrayElementType.OBJECT);
|
||||
unwrapInsn.setArray(argumentsVar);
|
||||
unwrapInsn.setReceiver(program.createVariable());
|
||||
add(unwrapInsn);
|
||||
argumentsVar = unwrapInsn.getReceiver();
|
||||
|
||||
Variable[] arguments = new Variable[reflectMethod.getParameterCount()];
|
||||
for (int i = 0; i < reflectMethod.getParameterCount(); ++i) {
|
||||
IntegerConstantInstruction indexInsn = new IntegerConstantInstruction();
|
||||
indexInsn.setConstant(i);
|
||||
|
@ -1074,9 +1074,10 @@ public class CompositeMethodGenerator {
|
|||
extractArgInsn.setReceiver(program.createVariable());
|
||||
add(extractArgInsn);
|
||||
|
||||
arguments.add(unbox(extractArgInsn.getReceiver(),
|
||||
reflectMethod.method.parameterType(i)));
|
||||
arguments[i] = unbox(extractArgInsn.getReceiver(), reflectMethod.method.parameterType(i));
|
||||
}
|
||||
|
||||
return arguments;
|
||||
}
|
||||
|
||||
private Variable unwrapArray(ValueType type, Variable array) {
|
||||
|
|
|
@ -130,9 +130,11 @@ public class ProxyVariableContext extends VariableContext {
|
|||
initInsn.setInstance(constructInsn.getReceiver());
|
||||
initInsn.setMethod(ctor.getReference());
|
||||
initInsn.setType(InvocationType.SPECIAL);
|
||||
Variable[] initArgs = new Variable[capturedValues.size()];
|
||||
for (int i = 0; i < capturedValues.size(); ++i) {
|
||||
initInsn.getArguments().add(capturedValues.get(i).value);
|
||||
initArgs[i] = capturedValues.get(i).value;
|
||||
}
|
||||
initInsn.setArguments(initArgs);
|
||||
generator.add(initInsn);
|
||||
|
||||
return constructInsn.getReceiver();
|
||||
|
|
|
@ -333,7 +333,7 @@ class UsageGenerator {
|
|||
InvokeInstruction insn = new InvokeInstruction();
|
||||
insn.setType(InvocationType.SPECIAL);
|
||||
insn.setMethod(new MethodReference(boxed, "valueOf", primitive, boxed));
|
||||
insn.getArguments().add(var);
|
||||
insn.setArguments(var);
|
||||
var = program.createVariable();
|
||||
insn.setReceiver(var);
|
||||
|
||||
|
|
|
@ -80,8 +80,12 @@ class ResourceProgramTransformer {
|
|||
System.arraycopy(method.getDescriptor().getSignature(), 0, types, 1,
|
||||
method.getDescriptor().parameterCount() + 1);
|
||||
accessInsn.setMethod(new MethodReference(ResourceAccessor.class.getName(), method.getName(), types));
|
||||
accessInsn.getArguments().add(insn.getInstance());
|
||||
accessInsn.getArguments().addAll(insn.getArguments());
|
||||
Variable[] accessArgs = new Variable[insn.getArguments().size() + 1];
|
||||
accessArgs[0] = insn.getInstance();
|
||||
for (int i = 0; i < insn.getArguments().size(); ++i) {
|
||||
accessArgs[i + 1] = insn.getArguments().get(i);
|
||||
}
|
||||
accessInsn.setArguments(accessArgs);
|
||||
accessInsn.setReceiver(insn.getReceiver());
|
||||
return Arrays.asList(accessInsn);
|
||||
}
|
||||
|
@ -111,13 +115,13 @@ class ResourceProgramTransformer {
|
|||
InvokeInstruction keysInsn = new InvokeInstruction();
|
||||
keysInsn.setType(InvocationType.SPECIAL);
|
||||
keysInsn.setMethod(KEYS);
|
||||
keysInsn.getArguments().add(insn.getInstance());
|
||||
keysInsn.setArguments(insn.getInstance());
|
||||
keysInsn.setReceiver(tmp);
|
||||
|
||||
InvokeInstruction transformInsn = new InvokeInstruction();
|
||||
transformInsn.setType(InvocationType.SPECIAL);
|
||||
transformInsn.setMethod(KEYS_TO_STRINGS);
|
||||
transformInsn.getArguments().add(tmp);
|
||||
transformInsn.setArguments(tmp);
|
||||
transformInsn.setReceiver(insn.getReceiver());
|
||||
|
||||
return Arrays.asList(keysInsn, transformInsn);
|
||||
|
@ -161,7 +165,7 @@ class ResourceProgramTransformer {
|
|||
InvokeInstruction castInvoke = new InvokeInstruction();
|
||||
castInvoke.setType(InvocationType.SPECIAL);
|
||||
castInvoke.setMethod(CAST_TO_STRING);
|
||||
castInvoke.getArguments().add(resultVar);
|
||||
castInvoke.setArguments(resultVar);
|
||||
castInvoke.setReceiver(insn.getReceiver());
|
||||
instructions.add(castInvoke);
|
||||
return instructions;
|
||||
|
@ -191,8 +195,7 @@ class ResourceProgramTransformer {
|
|||
InvokeInstruction accessorInvoke = new InvokeInstruction();
|
||||
accessorInvoke.setType(InvocationType.SPECIAL);
|
||||
accessorInvoke.setMethod(GET_PROPERTY);
|
||||
accessorInvoke.getArguments().add(insn.getInstance());
|
||||
accessorInvoke.getArguments().add(nameVar);
|
||||
accessorInvoke.setArguments(insn.getInstance(), nameVar);
|
||||
accessorInvoke.setReceiver(resultVar);
|
||||
instructions.add(accessorInvoke);
|
||||
}
|
||||
|
@ -208,7 +211,7 @@ class ResourceProgramTransformer {
|
|||
+ primitiveCapitalized.substring(1);
|
||||
castInvoke.setMethod(new MethodReference(ResourceAccessor.class, "castTo" + primitiveCapitalized,
|
||||
Object.class, primitive));
|
||||
castInvoke.getArguments().add(resultVar);
|
||||
castInvoke.setArguments(resultVar);
|
||||
castInvoke.setReceiver(insn.getReceiver());
|
||||
instructions.add(castInvoke);
|
||||
}
|
||||
|
@ -247,7 +250,7 @@ class ResourceProgramTransformer {
|
|||
InvokeInstruction castInvoke = new InvokeInstruction();
|
||||
castInvoke.setType(InvocationType.SPECIAL);
|
||||
castInvoke.setMethod(CAST_FROM_STRING);
|
||||
castInvoke.getArguments().add(insn.getArguments().get(0));
|
||||
castInvoke.setArguments(insn.getArguments().get(0));
|
||||
castInvoke.setReceiver(castVar);
|
||||
instructions.add(castInvoke);
|
||||
setProperty(insn, property, instructions, castVar);
|
||||
|
@ -272,9 +275,7 @@ class ResourceProgramTransformer {
|
|||
InvokeInstruction accessorInvoke = new InvokeInstruction();
|
||||
accessorInvoke.setType(InvocationType.SPECIAL);
|
||||
accessorInvoke.setMethod(PUT);
|
||||
accessorInvoke.getArguments().add(insn.getInstance());
|
||||
accessorInvoke.getArguments().add(nameVar);
|
||||
accessorInvoke.getArguments().add(valueVar);
|
||||
accessorInvoke.setArguments(insn.getInstance(), nameVar, valueVar);
|
||||
instructions.add(accessorInvoke);
|
||||
}
|
||||
|
||||
|
@ -288,7 +289,7 @@ class ResourceProgramTransformer {
|
|||
+ primitiveCapitalized.substring(1);
|
||||
castInvoke.setMethod(new MethodReference(ResourceAccessor.class, "castFrom" + primitiveCapitalized,
|
||||
primitive, Object.class));
|
||||
castInvoke.getArguments().add(insn.getArguments().get(0));
|
||||
castInvoke.setArguments(insn.getArguments().get(0));
|
||||
castInvoke.setReceiver(castVar);
|
||||
instructions.add(castInvoke);
|
||||
setProperty(insn, property, instructions, castVar);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class StringAmplifierTransformer implements ClassHolderTransformer {
|
|||
amplifyInstruction.setMethod(new MethodReference(StringAmplifier.class, "amplify",
|
||||
String.class, String.class));
|
||||
amplifyInstruction.setType(InvocationType.SPECIAL);
|
||||
amplifyInstruction.getArguments().add(var);
|
||||
amplifyInstruction.setArguments(var);
|
||||
amplifyInstruction.setReceiver(invoke.getReceiver());
|
||||
amplifyInstruction.setLocation(invoke.getLocation());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user