summaryrefslogtreecommitdiff
path: root/codegen.hs
diff options
context:
space:
mode:
Diffstat (limited to 'codegen.hs')
-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