1 package org.simantics.scl.compiler.constants;
3 import org.objectweb.asm.Label;
4 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
5 import org.simantics.scl.compiler.internal.codegen.references.Val;
6 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
7 import org.simantics.scl.compiler.types.TVar;
8 import org.simantics.scl.compiler.types.Type;
9 import org.simantics.scl.compiler.types.Types;
11 public class JavaComparisonToZeroOperation extends FunctionValue implements ComparisonFunction {
12 public static final JavaComparisonToZeroOperation IEQUAL = new JavaComparisonToZeroOperation("==");
13 public static final JavaComparisonToZeroOperation INOT_EQUAL = new JavaComparisonToZeroOperation("!=");
14 public static final JavaComparisonToZeroOperation ILESS = new JavaComparisonToZeroOperation("<");
15 public static final JavaComparisonToZeroOperation ILESS_OR_EQUAL = new JavaComparisonToZeroOperation("<=");
16 public static final JavaComparisonToZeroOperation IGREATER = new JavaComparisonToZeroOperation(">");
17 public static final JavaComparisonToZeroOperation IGREATER_OR_EQUAL = new JavaComparisonToZeroOperation(">=");
21 public JavaComparisonToZeroOperation(String op) {
22 super(TVar.EMPTY_ARRAY, Types.NO_EFFECTS, Types.BOOLEAN, Types.INTEGER);
27 public Type applyExact(MethodBuilder mb, Val[] parameters) {
28 Label thenBranch = mb.createLabel();
29 Label joinPoint = mb.createLabel();
31 mb.push(parameters[0], Types.INTEGER);
32 mb.ifZeroComparisonBranch(thenBranch, op);
34 mb.loadConstant(false);
37 mb.setLocation(thenBranch);
38 mb.loadConstant(true);
39 mb.setLocation(joinPoint);
41 return getReturnType();
45 public void generateCondition(MethodBuilder mb, Val[] parameters, Cont then_, Cont else_) {
46 mb.push(parameters[0], Types.INTEGER);
47 mb.ifZeroComparisonBranch(mb.getLabel(then_), op);
49 mb.ensureExists(then_);
53 public String toString() {