From 8eb3171845497a1d6025a3f59c09048d1975cd12 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 2 Feb 2017 22:58:46 +0100 Subject: Codegen some casts; makes mandel.nl JUST work --- codegen.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- cgit v1.2.3