]> gerrit.simantics Code Review - simantics/platform.git/blob
e5a58bb77cb44d5b9bfd1cd2fd52a7d43a0351ba
[simantics/platform.git] /
1 package org.simantics.scl.compiler.constants;
2
3 import org.objectweb.asm.Label;
4 import org.simantics.scl.compiler.internal.codegen.references.Val;
5 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
6 import org.simantics.scl.compiler.types.TVar;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.Types;
9
10 public class JavaComparisonToZeroOperation extends FunctionValue {
11     
12     String op;
13     
14     public JavaComparisonToZeroOperation(String op) {
15         super(TVar.EMPTY_ARRAY, Types.NO_EFFECTS, Types.BOOLEAN, Types.INTEGER);
16         this.op = op;
17     }
18
19     @Override
20     public Type applyExact(MethodBuilder mb, Val[] parameters) {
21         Label thenBranch = mb.createLabel();
22         Label joinPoint = mb.createLabel();
23         
24         mb.push(parameters[0], Types.INTEGER);        
25         mb.ifZeroComparisonBranch(thenBranch, op);
26         
27         mb.loadConstant(false);
28         mb.branch(joinPoint);
29         
30         mb.setLocation(thenBranch);
31         mb.loadConstant(true);
32         mb.setLocation(joinPoint);
33         
34         return getReturnType();
35     }
36     
37     @Override
38     public String toString() {
39         return op;
40     }
41
42 }