frontend: fix support of Integer.TYPE, Long.TYPE, etc.

This commit is contained in:
Alexey Andreev 2016-09-16 22:56:50 +03:00
parent ed7e8ff7f4
commit 8bfcb5f086
4 changed files with 43 additions and 16 deletions

View File

@ -263,6 +263,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
renderer.renderRuntime();
renderer.render(clsNodes);
renderer.renderStringPool();
renderer.renderStringConstants();
for (Map.Entry<String, TeaVMEntryPoint> entry : controller.getEntryPoints().entrySet()) {
sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws();
MethodReference ref = entry.getValue().getReference();

View File

@ -147,7 +147,7 @@ public class Renderer implements RenderingManager {
try {
for (PostponedFieldInitializer initializer : postponedFieldInitializers) {
writer.appendStaticField(initializer.field).ws().append("=").ws()
.append(constantToString(initializer.value)).append(";").softNewLine();
.append(context.constantToString(initializer.value)).append(";").softNewLine();
}
} catch (IOException e) {
throw new RenderingException("IO error", e);
@ -331,7 +331,7 @@ public class Renderer implements RenderingManager {
}
FieldReference fieldRef = new FieldReference(cls.getName(), field.getName());
if (value instanceof String) {
constantToString(value);
context.constantToString(value);
postponedFieldInitializers.add(new PostponedFieldInitializer(fieldRef, (String) value));
value = null;
}

View File

@ -49,7 +49,6 @@ import org.teavm.model.Phi;
import org.teavm.model.PrimitiveType;
import org.teavm.model.Program;
import org.teavm.model.ReferenceCache;
import org.teavm.model.TryCatchJoint;
import org.teavm.model.ValueType;
import org.teavm.model.Variable;
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
@ -122,12 +121,10 @@ public class Parser {
debugNames = newDebugNames;
}
for (Variable definedVar : defExtractor.getDefinedVariables()) {
/*
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
if (sourceVar >= 0) {
varMap.put(sourceVar, definedVar.getIndex());
}
*/
}
for (Map.Entry<Integer, String> debugName : debugNames.entrySet()) {
int receiver = varMap.getOrDefault(debugName.getKey(), -1);
@ -175,12 +172,10 @@ public class Parser {
for (Phi phi : block.getPhis()) {
int receiver = phi.getReceiver().getIndex();
/*
int sourceVar = phiUpdater.getSourceVariable(receiver);
if (sourceVar >= 0) {
varMap.put(sourceVar, receiver);
}
*/
}
result[node] = new IntIntOpenHashMap(varMap);
@ -188,12 +183,10 @@ public class Parser {
for (Instruction insn : block.getInstructions()) {
insn.acceptVisitor(defExtractor);
for (Variable definedVar : defExtractor.getDefinedVariables()) {
/*
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
if (sourceVar >= 0) {
varMap.put(sourceVar, definedVar.getIndex());
}
*/
}
}

View File

@ -1682,13 +1682,21 @@ public class ProgramParser {
break;
}
case Opcodes.GETSTATIC: {
ValueType type = referenceCache.parseValueTypeCached(desc);
int value = desc.equals("D") || desc.equals("J") ? pushDouble() : pushSingle();
GetFieldInstruction insn = new GetFieldInstruction();
insn.setField(referenceCache.getCached(new FieldReference(ownerCls, name)));
insn.setFieldType(type);
insn.setReceiver(getVariable(value));
addInstruction(insn);
ValueType primitiveClassLiteral = getPrimitiveTypeField(owner + "." + name);
if (primitiveClassLiteral != null) {
ClassConstantInstruction insn = new ClassConstantInstruction();
insn.setConstant(primitiveClassLiteral);
insn.setReceiver(getVariable(pushSingle()));
addInstruction(insn);
} else {
ValueType type = referenceCache.parseValueTypeCached(desc);
int value = desc.equals("D") || desc.equals("J") ? pushDouble() : pushSingle();
GetFieldInstruction insn = new GetFieldInstruction();
insn.setField(referenceCache.getCached(new FieldReference(ownerCls, name)));
insn.setFieldType(type);
insn.setReceiver(getVariable(value));
addInstruction(insn);
}
break;
}
case Opcodes.PUTSTATIC: {
@ -1763,4 +1771,29 @@ public class ProgramParser {
throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag());
}
}
private static ValueType getPrimitiveTypeField(String fieldName) {
switch (fieldName) {
case "java/lang/Boolean.TYPE":
return ValueType.BOOLEAN;
case "java/lang/Byte.TYPE":
return ValueType.BYTE;
case "java/lang/Short.TYPE":
return ValueType.SHORT;
case "java/lang/Character.TYPE":
return ValueType.CHARACTER;
case "java/lang/Integer.TYPE":
return ValueType.INTEGER;
case "java/lang/Long.TYPE":
return ValueType.LONG;
case "java/lang/Float.TYPE":
return ValueType.FLOAT;
case "java/lang/Double.TYPE":
return ValueType.DOUBLE;
case "java/lang/Void.TYPE":
return ValueType.VOID;
default:
return null;
}
}
}