Fix bugs in textual IR parser and stringifier

This commit is contained in:
Alexey Andreev 2017-05-08 18:17:33 +03:00
parent 1139c2bd6c
commit 812aa5a682
2 changed files with 24 additions and 1 deletions

View File

@ -220,6 +220,7 @@ class InstructionStringifier implements InstructionReader {
break;
}
append(" ").appendLocalVar(second);
append(" as ").append(type.name().toLowerCase());
}
@Override
@ -242,7 +243,8 @@ class InstructionStringifier implements InstructionReader {
public void cast(VariableReader receiver, VariableReader value, NumericOperandType sourceType,
NumericOperandType targetType) {
appendLocalVar(receiver).append(" := cast ").appendLocalVar(value)
.append(" from ").append(sourceType.toString()).append(" to ").append(targetType.toString());
.append(" from ").append(sourceType.toString().toLowerCase(Locale.ROOT)).append(" to ")
.append(targetType.toString().toLowerCase(Locale.ROOT));
}
@Override

View File

@ -58,6 +58,7 @@ import org.teavm.model.instructions.DoubleConstantInstruction;
import org.teavm.model.instructions.EmptyInstruction;
import org.teavm.model.instructions.ExitInstruction;
import org.teavm.model.instructions.FloatConstantInstruction;
import org.teavm.model.instructions.GetElementInstruction;
import org.teavm.model.instructions.GetFieldInstruction;
import org.teavm.model.instructions.InitClassInstruction;
import org.teavm.model.instructions.IntegerConstantInstruction;
@ -509,6 +510,9 @@ public class ListingParser {
case SHIFT_RIGHT_UNSIGNED:
parseBinary(receiver, variable, BinaryOperation.SHIFT_RIGHT_UNSIGNED);
break;
case LEFT_SQUARE_BRACKET:
parseSubscript(receiver, variable);
break;
case IDENTIFIER:
switch ((String) lexer.getTokenValue()) {
case "compareTo":
@ -549,6 +553,23 @@ public class ListingParser {
addInstruction(insn);
}
private void parseSubscript(Variable receiver, Variable array) throws IOException, ListingParseException {
lexer.nextToken();
Variable index = expectVariable();
expect(ListingToken.RIGHT_SQUARE_BRACKET);
lexer.nextToken();
expectKeyword("as");
ArrayElementType type = expectArrayType();
GetElementInstruction insn = new GetElementInstruction(type);
insn.setReceiver(receiver);
insn.setArray(array);
insn.setIndex(index);
addInstruction(insn);
}
private void parseArrayAssignment(Variable array) throws IOException, ListingParseException {
Variable index = expectVariable();
expect(ListingToken.RIGHT_SQUARE_BRACKET);