packages feed

llvm-hs-pretty 0.2.0.0 → 0.2.1.0

raw patch · 4 files changed

+38/−20 lines, 4 filesdep −pretty-showPVP ok

version bump matches the API change (PVP)

Dependencies removed: pretty-show

API changes (from Hackage documentation)

+ LLVM.Pretty: class PP p
+ LLVM.Pretty: pp :: PP p => p -> Doc

Files

README.md view
@@ -11,7 +11,7 @@ Usage ----- -There is a single function ``ppllvm`` that maps a LLVM.AST.Module to a String.+There is a single function ``ppllvm`` that maps a LLVM.AST.Module to a Text.  ```haskell import LLVM.AST@@ -37,7 +37,7 @@ Using stack:  ```bash-$ stac build+$ stack build $ stack test ``` 
llvm-hs-pretty.cabal view
@@ -1,5 +1,5 @@ name:                llvm-hs-pretty-version:             0.2.0.0+version:             0.2.1.0 license:             MIT synopsis:            A pretty printer for LLVM IR.  description:         A pretty printer for the LLVM AST types provided by llvm-hs.@@ -12,10 +12,6 @@ homepage:            https://github.com/llvm-hs/llvm-hs-pretty extra-source-files:  README.md ChangeLog.md -Synopsis: Pretty printer for LLVM IR.-Description:-  Pretty printer for LLVM IR.- Source-Repository head     Type: git     Location: git@github.com:llvm-hs/llvm-hs-pretty.git@@ -49,7 +45,6 @@     transformers         >= 0.3 && < 0.6,     directory            >= 1.2,     filepath             >= 1.3,-    pretty-show          >= 1.6 && < 1.7,     tasty                >= 0.11,     tasty-hspec          >= 1.1,     tasty-hunit          -any,
src/LLVM/Pretty.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleContexts #-}@@ -8,6 +9,7 @@ {-# OPTIONS_GHC -fwarn-incomplete-uni-patterns #-}  module LLVM.Pretty (+  PP(..),   ppllvm,   ppll, ) where@@ -199,21 +201,24 @@         [] ->           ("declare" <+> pp linkage <+> pp callingConvention             <+> pp returnAttributes <+> pp returnType <+> global (pp name)-            <> ppParams (pp . typeOf) parameters <+> pp functionAttributes <+> align <+> gcName)+            <> ppParams (pp . typeOf) parameters <+> pp functionAttributes <+> align <+> gcName <+> pre)          -- single unnamed block is special cased, and won't parse otherwise... yeah good times         [b@(BasicBlock (UnName _) _ _)] ->             ("define" <+> pp linkage <+> pp callingConvention               <+> pp returnAttributes <+> pp returnType <+> global (pp name)-              <> ppParams pp parameters <+> pp functionAttributes <+> align <+> gcName)+              <> ppParams pp parameters <+> pp functionAttributes <+> align <+> gcName <+> pre)             `wrapbraces` (indent 2 $ ppSingleBlock b)          bs ->           ("define" <+> pp linkage <+> pp callingConvention             <+> pp returnAttributes <+> pp returnType <+> global (pp name)-            <> ppParams pp parameters <+> pp functionAttributes <+> align <+> gcName)+            <> ppParams pp parameters <+> pp functionAttributes <+> align <+> gcName <+> pre)           `wrapbraces` (vcat $ fmap pp bs)     where+      pre = case prefix of+              Nothing  -> empty+              Just con -> "prefix" <+> ppTyped con       align | alignment == 0    = empty             | otherwise = "align" <+> pp alignment       gcName = maybe empty (\n -> "gc" <+> dquotes (text $ pack n)) (fmap unShort garbageCollectorName)@@ -611,7 +616,13 @@     in if packed          then angleBrackets struct          else struct-  pp (C.Null {}) = "zeroinitializer"++  pp (C.Null constantType) = ppNullInitializer constantType++#if MIN_VERSION_llvm_hs_pure(5,1,3)+  pp (C.AggregateZero constantType) = "zeroinitializer"+#endif+   pp (C.Undef {}) = "undef"   pp (C.TokenNone {}) = "none"   pp (C.BlockAddress fn blk) = "blockaddress" <> parens (commas (fmap pp [fn, blk]))@@ -684,7 +695,7 @@  instance PP SynchronizationScope where   pp = \case-    SingleThread -> "syncscope(\"singlethreaded\")"+    SingleThread -> "syncscope(\"singlethread\")"     System -> mempty  instance PP MemoryOrdering where@@ -761,6 +772,13 @@ ppFunctionArgumentTypes FunctionType {..} = ppParams pp (argumentTypes, isVarArg) ppFunctionArgumentTypes _ = error "Non-function argument. (Malformed AST)" +ppNullInitializer :: Type -> Doc+ppNullInitializer PointerType {..} = "zeroinitializer"+ppNullInitializer StructureType {..} = "zeroinitializer"+ppNullInitializer FunctionType {..} = "zeroinitializer"+ppNullInitializer ArrayType {..} = "zeroinitializer"+ppNullInitializer _ = error "Non-pointer argument. (Malformed AST)"+ ppCall :: Instruction -> Doc ppCall Call { function = Right f,..}   = tail <+> "call" <+> pp callingConvention <+> pp returnAttributes <+> pp resultType <+> ftype@@ -798,12 +816,6 @@ ppSingleBlock :: BasicBlock -> Doc ppSingleBlock (BasicBlock nm instrs term) = (vcat $ (fmap pp instrs) ++ [pp term]) -ppllvm :: Module -> Text-ppllvm = displayT . renderPretty 0.4 100 . pp--ppll :: PP a => a -> Text-ppll = displayT . renderPretty 0.4 100 . pp- -- According to <https://stackoverflow.com/a/7002812/3877993> this is -- the best way to cast floats to words. @@ -823,3 +835,15 @@ ppInstrMeta :: InstructionMetadata -> Doc ppInstrMeta [] = mempty ppInstrMeta xs = "," <> pp xs++-------------------------------------------------------------------------------+-- Toplevel+-------------------------------------------------------------------------------++-- | Pretty print a LLVM module+ppllvm :: Module -> Text+ppllvm = displayT . renderPretty 0.4 100 . pp++-- | Pretty print a printable LLVM expression+ppll :: PP a => a -> Text+ppll = displayT . renderPretty 0.4 100 . pp
tests/Main.hs view
@@ -10,7 +10,6 @@ import Data.Functor import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.IO as T-import Text.Show.Pretty (ppShow)  import System.IO import System.Exit