diff options
Diffstat (limited to 'codegen.hs')
-rw-r--r-- | codegen.hs | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -139,7 +139,7 @@ setGlobalFunction name label t = do state $ \s -> ((), s {globalFunctions = Map.insert name (t, label) $ globalFunctions s}) lookupVar :: Name -> CGMonad (Type, LLName) -lookupVar name | trace ("Looking up var " ++ name) False = undefined +lookupVar name | trace ("Looking up local var " ++ name) False = undefined lookupVar name = do obj <- get let locfound = Map.lookup name $ variables obj @@ -198,13 +198,13 @@ codegen :: Program -- Program to compile -> String -- File name of source -> Error A.Module codegen prog name fname = do - (defs, st) <- runCGMonad $ do + (defs, _) <- runCGMonad $ do defs <- generateDefs prog -- traceShow defs $ return () -- liftM stringLiterals get >>= flip traceShow (return ()) return defs - traceShow st $ return () + -- traceShow st $ return () return $ A.defaultModule { A.moduleName = name, @@ -429,6 +429,7 @@ genExpression (ExCast t e) = do (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 [] + (TypePtr _, t2@(TypePtr _)) -> makeLocRef t2 $ addInstr $ A.BitCast eop (toLLVMType t2) [] _ -> undefined genExpression (ExBinOp bo e1 e2 (Just t)) = do case bo of @@ -623,6 +624,8 @@ genExpression (ExBinOp bo e1 e2 (Just t)) = do reslabel <- addInstr $ A.Phi A.i1 [(A.ConstantOperand (A.C.Int 1 1), A.Name firstbb), (A.LocalReference A.i1 (A.Name label2), A.Name bb2)] [] return $ A.LocalReference A.i1 (A.Name reslabel) + Index -> do + genExpression $ ExUnOp Dereference (ExBinOp Plus e1 e2 (Just $ TypePtr t)) (Just t) genExpression (ExUnOp uo e1 (Just t)) = do e1op <- genExprArgument e1 case uo of @@ -664,6 +667,7 @@ genExprArgument expr = case expr of literalToOperand :: Literal -> Type -> CGMonad A.Operand literalToOperand (LitInt i) (TypeInt sz) = return $ A.ConstantOperand (A.C.Int (fromIntegral sz) i) +literalToOperand (LitUInt i) (TypeUInt sz) = return $ A.ConstantOperand (A.C.Int (fromIntegral sz) i) literalToOperand (LitFloat f) TypeFloat = return $ A.ConstantOperand (A.C.Float (A.F.Single (realToFrac f))) literalToOperand (LitFloat f) TypeDouble = return $ A.ConstantOperand (A.C.Float (A.F.Double f)) literalToOperand (LitVar n) t = do @@ -702,6 +706,10 @@ castOperand orig@(A.ConstantOperand (A.C.Int s1 val)) t2@(TypeInt s2) | fromIntegral s1 == s2 = return orig | fromIntegral s1 < s2 = return $ A.ConstantOperand (A.C.Int (fromIntegral s2) val) | fromIntegral s1 > s2 = throwError $ "Integer " ++ show val ++ " too large for type '" ++ pshow t2 ++ "'" +castOperand orig@(A.ConstantOperand (A.C.Int s1 val)) t2@(TypeUInt s2) + | fromIntegral s1 == s2 = return orig + | fromIntegral s1 < s2 = return $ A.ConstantOperand (A.C.Int (fromIntegral s2) val) + | fromIntegral s1 > s2 = throwError $ "Integer " ++ show val ++ " too large for type '" ++ pshow t2 ++ "'" castOperand (A.ConstantOperand (A.C.Int _ val)) TypeFloat = do return $ A.ConstantOperand (A.C.Float (A.F.Single (fromIntegral val))) castOperand (A.ConstantOperand (A.C.Int _ val)) TypeDouble = do |