X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FllvmGen%2FLlvm%2FPpLlvm.hs;h=1a419544f07fe0c55431f603f9af344eada1bdc5;hb=e553a60151dc282c8b8c201871212cba0c3bf2a0;hp=9afb76e59608435a9952b831e500603303809c93;hpb=6bae9f3ff5422c8ebe8a53d0981f51b3ced26777;p=ghc-hetmet.git diff --git a/compiler/llvmGen/Llvm/PpLlvm.hs b/compiler/llvmGen/Llvm/PpLlvm.hs index 9afb76e..1a41954 100644 --- a/compiler/llvmGen/Llvm/PpLlvm.hs +++ b/compiler/llvmGen/Llvm/PpLlvm.hs @@ -10,8 +10,8 @@ module Llvm.PpLlvm ( ppLlvmComment, ppLlvmGlobals, ppLlvmGlobal, - ppLlvmType, - ppLlvmTypes, + ppLlvmAlias, + ppLlvmAliases, ppLlvmFunctionDecls, ppLlvmFunctionDecl, ppLlvmFunctions, @@ -38,9 +38,11 @@ import Unique -- | Print out a whole LLVM module. ppLlvmModule :: LlvmModule -> Doc -ppLlvmModule (LlvmModule comments globals decls funcs) +ppLlvmModule (LlvmModule comments aliases globals decls funcs) = ppLlvmComments comments $+$ empty + $+$ ppLlvmAliases aliases + $+$ empty $+$ ppLlvmGlobals globals $+$ empty $+$ ppLlvmFunctionDecls decls @@ -83,19 +85,12 @@ ppLlvmGlobal oth = error $ "Non Global var ppr as global! " ++ show oth -- | Print out a list of LLVM type aliases. -ppLlvmTypes :: [LlvmType] -> Doc -ppLlvmTypes tys = vcat $ map ppLlvmType tys +ppLlvmAliases :: [LlvmAlias] -> Doc +ppLlvmAliases tys = vcat $ map ppLlvmAlias tys -- | Print out an LLVM type alias. -ppLlvmType :: LlvmType -> Doc - -ppLlvmType al@(LMAlias _ t) - = texts al <+> equals <+> text "type" <+> texts t - -ppLlvmType (LMFunction t) - = ppLlvmFunctionDecl t - -ppLlvmType _ = empty +ppLlvmAlias :: LlvmAlias -> Doc +ppLlvmAlias (name, ty) = text "%" <> ftext name <+> equals <+> text "type" <+> texts ty -- | Print out a list of function definitions. @@ -177,7 +172,7 @@ ppLlvmExpression expr Call tp fp args attrs -> ppCall tp fp args attrs Cast op from to -> ppCast op from to Compare op left right -> ppCmpOp op left right - GetElemPtr ptr indexes -> ppGetElementPtr ptr indexes + GetElemPtr inb ptr indexes -> ppGetElementPtr inb ptr indexes Load ptr -> ppLoad ptr Malloc tp amount -> ppMalloc tp amount Phi tp precessors -> ppPhi tp precessors @@ -230,9 +225,12 @@ ppCmpOp op left right = let cmpOp | isInt (getVarType left) && isInt (getVarType right) = text "icmp" | isFloat (getVarType left) && isFloat (getVarType right) = text "fcmp" + | otherwise = text "icmp" -- Just continue as its much easier to debug + {- | otherwise = error ("can't compare different types, left = " ++ (show $ getVarType left) ++ ", right = " ++ (show $ getVarType right)) + -} in cmpOp <+> texts op <+> texts (getVarType left) <+> (text $ getName left) <> comma <+> (text $ getName right) @@ -265,10 +263,11 @@ ppAlloca tp amount = in text "alloca" <+> texts tp <> comma <+> texts amount' -ppGetElementPtr :: LlvmVar -> [Int] -> Doc -ppGetElementPtr ptr idx = +ppGetElementPtr :: Bool -> LlvmVar -> [Int] -> Doc +ppGetElementPtr inb ptr idx = let indexes = hcat $ map ((comma <+> texts i32 <+>) . texts) idx - in text "getelementptr" <+> texts ptr <> indexes + inbound = if inb then text "inbounds" else empty + in text "getelementptr" <+> inbound <+> texts ptr <> indexes ppReturn :: Maybe LlvmVar -> Doc