summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-02-02 22:58:46 +0100
committertomsmeding <tom.smeding@gmail.com>2017-02-02 22:58:46 +0100
commit8eb3171845497a1d6025a3f59c09048d1975cd12 (patch)
tree09074f43df50c72acaf7fa81cca40b1e421d7ad7
parenteb141a89887bb2994ea626c1aa31766d67292f08 (diff)
Codegen some casts; makes mandel.nl JUST work
-rw-r--r--codegen.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/codegen.hs b/codegen.hs
index bee7c49..ae02506 100644
--- a/codegen.hs
+++ b/codegen.hs
@@ -411,6 +411,25 @@ makeLocRef t = liftM $ A.LocalReference (toLLVMType t) . A.Name
genExpression :: Expression -> CGMonad A.Operand
genExpression (ExLit lit (Just t)) = literalToOperand lit t
+genExpression (ExCast t e) = do
+ eop <- genExpression e
+ let extype = fromJust (exTypeOf e)
+ dstllvm = toLLVMType t
+
+ isSomeInt (TypeInt _) = True
+ isSomeInt (TypeUInt _) = True
+ isSomeInt _ = False
+
+ intSize (TypeInt s) = s
+ intSize (TypeUInt s) = s
+ intSize _ = undefined
+
+ case (extype, t) of
+ (t1, t2) | t1 == t2 -> return eop
+ (t1, t2) | isSomeInt t1 && isSomeInt t2 -> case intSize t1 < intSize t2 of
+ True -> makeLocRef t $ addInstr $ A.SExt eop dstllvm []
+ False -> makeLocRef t $ addInstr $ A.Trunc eop dstllvm []
+ _ -> undefined
genExpression (ExBinOp bo e1 e2 (Just t)) = do
case bo of
Plus -> case (fromJust (exTypeOf e1), fromJust (exTypeOf e2)) of