Emit neg and not

This commit is contained in:
Alexey Andreev 2015-07-31 17:20:21 +03:00
parent e95b537687
commit 57a39a156a
2 changed files with 26 additions and 0 deletions

View File

@ -45,4 +45,8 @@ public class ConditionEmitter {
ForkEmitter newFork = fork.or(block, otherEmitter.fork);
return new ConditionEmitter(pe, newFork);
}
public ConditionEmitter not() {
return new ConditionEmitter(pe, fork.not());
}
}

View File

@ -45,6 +45,7 @@ import org.teavm.model.instructions.IntegerSubtype;
import org.teavm.model.instructions.InvocationType;
import org.teavm.model.instructions.InvokeInstruction;
import org.teavm.model.instructions.IsInstanceInstruction;
import org.teavm.model.instructions.NegateInstruction;
import org.teavm.model.instructions.NumericOperandType;
import org.teavm.model.instructions.PutElementInstruction;
import org.teavm.model.instructions.PutFieldInstruction;
@ -119,6 +120,27 @@ public class ValueEmitter {
return pe;
}
public ValueEmitter neg() {
if (!(type instanceof ValueType.Primitive)) {
throw new EmitException("Can't negate non-primitive: " + type);
}
ValueEmitter value = this;
PrimitiveType type = ((ValueType.Primitive) this.type).getKind();
IntegerSubtype subtype = convertToIntegerSubtype(type);
if (subtype != null) {
value = value.castToInteger(subtype);
type = PrimitiveType.INTEGER;
}
ValueEmitter result = pe.newVar(ValueType.primitive(type));
NegateInstruction insn = new NegateInstruction(convertToNumeric(type));
insn.setOperand(value.variable);
insn.setReceiver(result.variable);
pe.addInstruction(insn);
return result;
}
static class Pair {
ValueEmitter first;
ValueEmitter second;