]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaComparisonToZeroOperation.java
Merge "AbstractCompileStructuralValueRequest uses wrong RuntimeEnvironment"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / JavaComparisonToZeroOperation.java
1 package org.simantics.scl.compiler.constants;
2
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;
10
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(">=");
18     
19     String op;
20     
21     public JavaComparisonToZeroOperation(String op) {
22         super(TVar.EMPTY_ARRAY, Types.NO_EFFECTS, Types.BOOLEAN, Types.INTEGER);
23         this.op = op;
24     }
25
26     @Override
27     public Type applyExact(MethodBuilder mb, Val[] parameters) {
28         Label thenBranch = mb.createLabel();
29         Label joinPoint = mb.createLabel();
30         
31         mb.push(parameters[0], Types.INTEGER);        
32         mb.ifZeroComparisonBranch(thenBranch, op);
33         
34         mb.loadConstant(false);
35         mb.branch(joinPoint);
36         
37         mb.setLocation(thenBranch);
38         mb.loadConstant(true);
39         mb.setLocation(joinPoint);
40         
41         return getReturnType();
42     }
43     
44     @Override
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);
48         mb.jump(else_);
49         mb.ensureExists(then_);
50     }
51     
52     @Override
53     public String toString() {
54         return op;
55     }
56
57 }