tests/LLVMIRBuilderTests.st
changeset 66 0125c050d0f1
parent 63 923ad3de94f3
--- a/tests/LLVMIRBuilderTests.st	Sat Jun 18 16:00:36 2016 +0100
+++ b/tests/LLVMIRBuilderTests.st	Sat Jun 18 16:54:17 2016 +0100
@@ -116,6 +116,60 @@
     self assert: ((jit externalOfFunction: f) callWith: -100) == -1.
 
     "Created: / 25-04-2016 / 23:27:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_if_then_else_02c
+    | f fTy asm jit |
+
+    fTy := LLVMType function: { LLVMType intptr }  returning: LLVMType intptr.
+    f := module addFunctionNamed: testSelector type: fTy.
+    asm := f builder.
+
+    asm if: (asm icmp: (LLVMConstant sintptr: 0) _: (f parameterAt:1) cond: LLVMIntEQ) then:[ 
+        asm ret: (LLVMConstant sintptr: 0)
+    ] else:[ 
+        asm if: (asm icmp: (f parameterAt:1) _: (LLVMConstant sintptr: 0) cond: LLVMIntSGT) then:[ 
+            asm ret: (LLVMConstant sintptr: 1)
+        ] else:[ 
+            asm ret: (LLVMConstant sintptr: -1).
+        ].
+    ].
+    jit := LLVMExecutionEngine newForModule: module.
+    self assert: ((jit externalOfFunction: f) callWith: 0) == 0.
+    self assert: ((jit externalOfFunction: f) callWith: 100) == 1.
+    self assert: ((jit externalOfFunction: f) callWith: -100) == -1.
+
+    "Created: / 18-06-2016 / 11:35:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_if_then_else_02d
+    | f fTy asm retval jit  |
+
+    fTy := LLVMType function: { LLVMType intptr }  returning: LLVMType intptr.
+    f := module addFunctionNamed: testSelector type: fTy.
+    asm := f builder.
+    retval := asm alloca: LLVMType intptr.
+
+    asm if: (asm icmp: (LLVMConstant sintptr: 0) _: (f parameterAt:1) cond: LLVMIntEQ) then:[ 
+        asm store: (LLVMConstant sintptr: 0) at: retval.
+    ] else:[ 
+        asm if: (asm icmp: (f parameterAt:1) _: (LLVMConstant sintptr: 0) cond: LLVMIntSGT) then:[ 
+            asm store: (LLVMConstant sintptr: 1) at: retval.
+        ] else:[ 
+            asm store: (LLVMConstant sintptr: -1) at: retval.
+        ].
+    ].
+    asm ret: (asm load: retval).
+
+    module verify.
+
+    jit := LLVMExecutionEngine newForModule: module.
+    self assert: ((jit externalOfFunction: f) callWith: 0) == 0.
+    self assert: ((jit externalOfFunction: f) callWith: 100) == 1.
+    self assert: ((jit externalOfFunction: f) callWith: -100) == -1.
+
+    "Created: / 18-06-2016 / 11:38:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-06-2016 / 16:51:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !LLVMIRBuilderTests class methodsFor:'documentation'!