projects
/
kaleidoscope-hs-old.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
93653d4
)
Check the type of if condition
author
Luke Lau
<luke_lau@icloud.com>
Sun, 10 Mar 2019 16:11:02 +0000
(16:11 +0000)
committer
Luke Lau
<luke_lau@icloud.com>
Wed, 17 Apr 2019 22:38:30 +0000
(23:38 +0100)
Main.hs
patch
|
blob
|
history
diff --git
a/Main.hs
b/Main.hs
index 89fd91a39cf663048b77497b879e9d01903e5751..328aaf3c72c56d9b1d13f4f1de4376cf07b5681d 100644
(file)
--- a/
Main.hs
+++ b/
Main.hs
@@
-23,6
+23,7
@@
import LLVM.AST.Float
import LLVM.AST.FloatingPointPredicate hiding (False, True)
import LLVM.AST.Operand
import LLVM.AST.Type as Type
import LLVM.AST.FloatingPointPredicate hiding (False, True)
import LLVM.AST.Operand
import LLVM.AST.Type as Type
+import LLVM.AST.Typed
import LLVM.Pretty
import Debug.Trace
import LLVM.Pretty
import Debug.Trace
@@
-90,7
+91,9
@@
buildExpr binds (AST.BinOp op a b) = do
buildExpr binds (AST.If cond thenE elseE) = mdo
_ifB <- block `named` "if"
buildExpr binds (AST.If cond thenE elseE) = mdo
_ifB <- block `named` "if"
+
condV <- buildExpr binds cond
condV <- buildExpr binds cond
+ when (typeOf condV /= i1) $ lift $ lift $ Left "Not a boolean"
condBr condV thenB elseB
thenB <- block `named` "then"
condBr condV thenB elseB
thenB <- block `named` "then"