diff --git a/base/macaw-base.cabal b/base/macaw-base.cabal index fb7dc7b1..8b7388d1 100644 --- a/base/macaw-base.cabal +++ b/base/macaw-base.cabal @@ -29,7 +29,6 @@ description: library build-depends: base >= 4, - ansi-wl-pprint, binary, binary-symbols >= 0.1.3, bytestring, @@ -40,6 +39,7 @@ library lens >= 4.7, mtl, parameterized-utils >= 2.1.0 && < 2.2, + prettyprinter >= 1.7.0, template-haskell, text, vector, diff --git a/base/src/Data/Macaw/AbsDomain/AbsState.hs b/base/src/Data/Macaw/AbsDomain/AbsState.hs index 4d1a8d4c..e3eec255 100644 --- a/base/src/Data/Macaw/AbsDomain/AbsState.hs +++ b/base/src/Data/Macaw/AbsDomain/AbsState.hs @@ -4,6 +4,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -78,7 +79,7 @@ import Data.Set (Set) import qualified Data.Set as Set import GHC.Stack import Numeric (showHex) -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter import Data.Macaw.AbsDomain.CallParams import qualified Data.Macaw.AbsDomain.StridedInterval as SI @@ -256,31 +257,31 @@ instance EqF (AbsValue w) where instance MemWidth w => Show (AbsValue w tp) where show = show . pretty -ppSet :: [Doc] -> Doc +ppSet :: [Doc ann] -> Doc ann ppSet = encloseSep lbrace rbrace comma instance MemWidth w => Pretty (AbsValue w tp) where - pretty (BoolConst b) = text (show b) - pretty (FinSet s) = text "finset" <+> ppIntegerSet s - pretty (CodePointers s b) = text "code" <+> ppSet (s0 ++ sd) - where s0 = if b then [text "0"] else [] + pretty (BoolConst b) = viaShow b + pretty (FinSet s) = "finset" <+> ppIntegerSet s + pretty (CodePointers s b) = "code" <+> ppSet (s0 ++ sd) + where s0 = if b then ["0"] else [] sd = f <$> Set.toList s - f segAddr = text (show segAddr) + f segAddr = viaShow segAddr pretty (StridedInterval s) = - text "strided" <> parens (pretty s) + "strided" <> parens (pretty s) pretty (SubValue n av) = - text "sub" <> parens (integer (intValue n) <> comma <+> pretty av) + "sub" <> parens (pretty (intValue n) <> comma <+> pretty av) pretty (StackOffsetAbsVal a v') - | v' >= 0 = text $ "rsp_" ++ show a ++ " + " ++ showHex v' "" - | otherwise = text $ "rsp_" ++ show a ++ " - " ++ showHex (negate (toInteger v')) "" - pretty (SomeStackOffset a) = text $ "rsp_" ++ show a ++ " + ?" - pretty TopV = text "top" - pretty ReturnAddr = text "return_addr" + | v' >= 0 = pretty $ "rsp_" ++ show a ++ " + " ++ showHex v' "" + | otherwise = pretty $ "rsp_" ++ show a ++ " - " ++ showHex (negate (toInteger v')) "" + pretty (SomeStackOffset a) = pretty $ "rsp_" ++ show a ++ " + ?" + pretty TopV = "top" + pretty ReturnAddr = "return_addr" -ppIntegerSet :: (Integral w, Show w) => Set w -> Doc +ppIntegerSet :: (Integral w, Show w) => Set w -> Doc ann ppIntegerSet s = ppSet (ppv <$> Set.toList s) - where ppv v' | v' >= 0 = text (showHex v' "") + where ppv v' | v' >= 0 = pretty (showHex v' "") | otherwise = error "ppIntegerSet given negative value" -- | Returns a set of concrete integers that this value may be. @@ -366,7 +367,7 @@ joinAbsValue x y | Set.null s = r | otherwise = debug DAbsInt ("dropping " ++ show dropped ++ "\n" ++ show x ++ "\n" ++ show y ++ "\n") r where (r,s) = runState (joinAbsValue' x y) Set.empty - dropped = ppSet (text . show <$> Set.toList s) + dropped = ppSet (viaShow <$> Set.toList s) addWords :: Set (MemSegmentOff w) -> State (Set (MemSegmentOff w)) () addWords s = modify $ Set.union s @@ -855,14 +856,14 @@ bitop doOp _w (asConcreteSingleton -> Just v) (asFinSet "bitop" -> IsFin s) = FinSet (Set.map (doOp v) s) bitop _ _ _ _ = TopV -ppAbsValue :: MemWidth w => AbsValue w tp -> Maybe Doc +ppAbsValue :: MemWidth w => AbsValue w tp -> Maybe (Doc ann) ppAbsValue TopV = Nothing ppAbsValue v = Just (pretty v) -- | Print a list of Docs vertically separated. instance (MemWidth w, ShowF r) => PrettyRegValue r (AbsValue w) where ppValueEq _ TopV = Nothing - ppValueEq r v = Just (text (showF r) <+> text "=" <+> pretty v) + ppValueEq r v = Just (pretty (showF r) <+> "=" <+> pretty v) absTrue :: AbsValue w BoolType @@ -1030,9 +1031,9 @@ showSignedHex :: Integer -> ShowS showSignedHex x | x < 0 = showString "-0x" . showHex (negate x) | otherwise = showString "0x" . showHex x -ppAbsStack :: MemWidth w => AbsBlockStack w -> Doc +ppAbsStack :: MemWidth w => AbsBlockStack w -> Doc ann ppAbsStack m = vcat (pp <$> Map.toDescList m) - where pp (o,StackEntry _ v) = text (showSignedHex (toInteger o) " :=") <+> pretty v + where pp (o,StackEntry _ v) = pretty (showSignedHex (toInteger o) " :=") <+> pretty v ------------------------------------------------------------------------ -- AbsBlockState @@ -1108,13 +1109,18 @@ instance ( ShowF r , MemWidth (RegAddrWidth r) ) => Pretty (AbsBlockState r) where pretty s = - text "registers:" <$$> - indent 2 (pretty (s^.absRegState)) <$$> - stack_d + vcat + [ "registers:" + , indent 2 (pretty (s^.absRegState)) + , stack_d + ] where stack = startAbsStack s - stack_d | Map.null stack = empty - | otherwise = text "stack:" <$$> - indent 2 (ppAbsStack stack) + stack_d | Map.null stack = emptyDoc + | otherwise = + vcat + [ "stack:" + , indent 2 (ppAbsStack stack) + ] instance (ShowF r, MemWidth (RegAddrWidth r)) => Show (AbsBlockState r) where show = show . pretty @@ -1171,13 +1177,18 @@ curAbsStack = lens _curAbsStack (\s v -> s { _curAbsStack = v }) instance (ShowF r, MemWidth (RegAddrWidth r)) => Pretty (AbsProcessorState r ids) where pretty s = - text "registers:" <$$> - indent 2 (pretty (s^.absInitialRegs)) <$$> - stack_d + vcat + [ "registers:" + , indent 2 (pretty (s^.absInitialRegs)) + , stack_d + ] where stack = s^.curAbsStack - stack_d | Map.null stack = empty - | otherwise = text "stack:" <$$> - indent 2 (ppAbsStack stack) + stack_d | Map.null stack = emptyDoc + | otherwise = + vcat + [ "stack:" + , indent 2 (ppAbsStack stack) + ] instance (ShowF r, MemWidth (RegAddrWidth r)) => Show (AbsProcessorState r ids) where diff --git a/base/src/Data/Macaw/AbsDomain/JumpBounds.hs b/base/src/Data/Macaw/AbsDomain/JumpBounds.hs index 725e7510..91a3fdc8 100644 --- a/base/src/Data/Macaw/AbsDomain/JumpBounds.hs +++ b/base/src/Data/Macaw/AbsDomain/JumpBounds.hs @@ -11,6 +11,7 @@ known equivalent values. {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE StandaloneDeriving #-} @@ -45,7 +46,7 @@ import qualified Data.Parameterized.Map as MapF import Data.Parameterized.NatRepr import Data.Parameterized.Pair import Numeric.Natural -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter import Data.Macaw.AbsDomain.CallParams import Data.Macaw.AbsDomain.StackAnalysis @@ -119,7 +120,7 @@ data InitJumpBounds arch } -- | Pretty print jump bounds. -ppInitJumpBounds :: forall arch . ShowF (ArchReg arch) => InitJumpBounds arch -> [Doc] +ppInitJumpBounds :: forall arch ann . ShowF (ArchReg arch) => InitJumpBounds arch -> [Doc ann] ppInitJumpBounds cns = ppBlockStartStackConstraints (initBndsMap cns) <> ppLocMap ppSubRange (initRngPredMap cns) @@ -420,8 +421,8 @@ data SubRange tp where instance Pretty (SubRange tp) where pretty (SubRange p) = pretty p -ppSubRange :: Doc -> SubRange tp -> Doc -ppSubRange d (SubRange r) = d <+> text "in" <+> pretty r +ppSubRange :: Doc ann -> SubRange tp -> Doc ann +ppSubRange d (SubRange r) = d <+> "in" <+> pretty r -- | Take the union of two subranges, and return `Nothing` if this is -- a maximum range bound. @@ -467,10 +468,10 @@ instance ShowF (ArchReg arch) => Pretty (BranchConstraints arch ids) where pretty x = let cl = MapF.toList (newClassRepConstraints x) al = MapF.toList (newUninterpAssignConstraints x) - ppLoc :: Pair (BoundLoc (ArchReg arch)) SubRange -> Doc - ppLoc (Pair l r) = prettyF l <+> text ":=" <+> pretty r - ppAssign :: Pair (AssignId ids) SubRange -> Doc - ppAssign (Pair l r) = ppAssignId l <+> text ":=" <+> pretty r + ppLoc :: Pair (BoundLoc (ArchReg arch)) SubRange -> Doc ann + ppLoc (Pair l r) = prettyF l <+> ":=" <+> pretty r + ppAssign :: Pair (AssignId ids) SubRange -> Doc ann + ppAssign (Pair l r) = ppAssignId l <+> ":=" <+> pretty r in vcat (fmap ppLoc cl ++ fmap ppAssign al) instance ShowF (ArchReg arch) => Show (BranchConstraints arch ids) where diff --git a/base/src/Data/Macaw/AbsDomain/StackAnalysis.hs b/base/src/Data/Macaw/AbsDomain/StackAnalysis.hs index b6488221..987ae93f 100644 --- a/base/src/Data/Macaw/AbsDomain/StackAnalysis.hs +++ b/base/src/Data/Macaw/AbsDomain/StackAnalysis.hs @@ -39,6 +39,7 @@ proof rules: {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE StandaloneDeriving #-} @@ -118,7 +119,7 @@ import Data.Parameterized.TraversableFC import Data.Proxy import Data.STRef import GHC.Natural -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter import Text.Printf import Data.Macaw.AbsDomain.CallParams @@ -132,14 +133,14 @@ import Data.Macaw.Utils.Changed addrTypeRepr :: MemWidth w => TypeRepr (BVType w) addrTypeRepr = BVTypeRepr memWidthNatRepr -ppAddend :: MemInt w -> Doc +ppAddend :: MemInt w -> Doc ann ppAddend o | memIntValue o < 0 = - text "-" <+> pretty (negate (toInteger (memIntValue o))) - | otherwise = text "+" <+> pretty o + "-" <+> pretty (negate (toInteger (memIntValue o))) + | otherwise = "+" <+> pretty o -ppStackOff :: MemInt w -> MemRepr tp -> Doc +ppStackOff :: MemInt w -> MemRepr tp -> Doc ann ppStackOff o repr = - text "*(stack_frame" <+> ppAddend o <> text ", " <> pretty repr <> text ")" + "*(stack_frame" <+> ppAddend o <> ", " <> pretty repr <> ")" ------------------------------------------------------------------------ -- JoinClassPair @@ -211,7 +212,7 @@ instance OrdF r => OrdF (BoundLoc r) where EQ -> compareF xr yr instance ShowF r => Pretty (BoundLoc r tp) where - pretty (RegLoc r) = text (showF r) + pretty (RegLoc r) = pretty (showF r) pretty (StackOffLoc i tp) = ppStackOff i tp instance ShowF r => PrettyF (BoundLoc r) where @@ -434,7 +435,7 @@ locMapTraverseWithKey_ f m0 = do *> memMapTraverseWithKey_ stackFn (locMapStack m0) -- | Pretty print a location map. -ppLocMap :: ShowF r => (forall tp . Doc -> p tp -> Doc) -> LocMap r p -> [Doc] +ppLocMap :: ShowF r => (forall tp . Doc ann -> p tp -> Doc ann) -> LocMap r p -> [Doc ann] ppLocMap f m = let ppPair (Pair l v) = f (pretty l) v in ppPair <$> locMapToList m @@ -500,11 +501,11 @@ data StackEqConstraint r tp where -> StackEqConstraint r (BVType w) -ppStackEqConstraint :: ShowF r => Doc -> StackEqConstraint r tp -> Doc +ppStackEqConstraint :: ShowF r => Doc ann -> StackEqConstraint r tp -> Doc ann ppStackEqConstraint d (IsStackOff i) = - d <+> text "= stack_frame" <+> ppAddend i -ppStackEqConstraint d (EqualLoc l) = d <> text " = " <> pretty l -ppStackEqConstraint d (IsUExt l w) = d <> text " = (uext " <> pretty l <+> text (show w) <> text ")" + d <+> "= stack_frame" <+> ppAddend i +ppStackEqConstraint d (EqualLoc l) = d <> " = " <> pretty l +ppStackEqConstraint d (IsUExt l w) = d <> " = (uext " <> pretty l <+> viaShow w <> ")" ------------------------------------------------------------------------ -- BlockStartStackConstraints @@ -521,7 +522,7 @@ newtype BlockStartStackConstraints arch = -- | Pretty print the lines in stack constraints. ppBlockStartStackConstraints :: ShowF (ArchReg arch) => BlockStartStackConstraints arch - -> [Doc] + -> [Doc ann] ppBlockStartStackConstraints = ppLocMap ppStackEqConstraint . unBSSC fnEntryBlockStartStackConstraints :: RegisterInfo (ArchReg arch) @@ -875,13 +876,13 @@ instance ShowF (ArchReg arch) => Pretty (StackExpr arch id tp) where pretty e = case e of ClassRepExpr l -> pretty l - UninterpAssignExpr n _ -> parens (text "uninterp" <+> ppAssignId n) + UninterpAssignExpr n _ -> parens ("uninterp" <+> ppAssignId n) StackOffsetExpr o - | memIntValue o > 0 -> parens (text "+ stack_off" <+> pretty o) - | memIntValue o < 0 -> parens (text "- stack_off" <+> pretty (negate (toInteger (memIntValue o)))) - | otherwise -> text "stack_off" + | memIntValue o > 0 -> parens ("+ stack_off" <+> pretty o) + | memIntValue o < 0 -> parens ("- stack_off" <+> pretty (negate (toInteger (memIntValue o)))) + | otherwise -> "stack_off" CExpr v -> pretty v - UExtExpr l w -> parens (text "uext " <> pretty l <+> text (show w)) + UExtExpr l w -> parens ("uext " <> pretty l <+> viaShow w) AppExpr n _ -> ppAssignId n instance ShowF (ArchReg arch) => PrettyF (StackExpr arch id) where @@ -918,21 +919,21 @@ data BlockIntraStackConstraints arch ids instance ShowF (ArchReg arch) => Pretty (BlockIntraStackConstraints arch ids) where pretty cns = - let ppStk :: MemInt (ArchAddrWidth arch) -> MemRepr tp -> StackExpr arch ids tp -> Doc - ppStk o r v = text (show o) <> text ", " <> pretty r <> text " := " <> pretty v - sm :: Doc - sm = memMapFoldrWithKey (\o r v d -> ppStk o r v <$$> d) empty (stackExprMap cns) - ppAssign :: AssignId ids tp -> StackExpr arch ids tp -> Doc -> Doc + let ppStk :: MemInt (ArchAddrWidth arch) -> MemRepr tp -> StackExpr arch ids tp -> Doc ann + ppStk o r v = viaShow o <> ", " <> pretty r <> " := " <> pretty v + sm :: Doc ann + sm = memMapFoldrWithKey (\o r v d -> vcat [ppStk o r v, d]) emptyDoc (stackExprMap cns) + ppAssign :: AssignId ids tp -> StackExpr arch ids tp -> Doc ann -> Doc ann ppAssign a (AppExpr u app) d = case testEquality a u of - Nothing -> ppAssignId a <> text " := " <> ppAssignId u <$$> d - Just Refl -> ppAssignId a <> text " := " <> ppApp pretty app <$$> d - ppAssign a e d = ppAssignId a <> text " := " <> pretty e <$$> d - am :: Doc - am = MapF.foldrWithKey ppAssign empty (assignExprMap cns) - in vcat [ text "stackExprMap:" + Nothing -> vcat [ppAssignId a <> " := " <> ppAssignId u, d] + Just Refl -> vcat [ppAssignId a <> " := " <> ppApp pretty app, d] + ppAssign a e d = vcat [ppAssignId a <> " := " <> pretty e, d] + am :: Doc ann + am = MapF.foldrWithKey ppAssign emptyDoc (assignExprMap cns) + in vcat [ "stackExprMap:" , indent 2 sm - , text "assignExprMap:" + , "assignExprMap:" , indent 2 am ] diff --git a/base/src/Data/Macaw/AbsDomain/StridedInterval.hs b/base/src/Data/Macaw/AbsDomain/StridedInterval.hs index dac7ec94..dfcedc3a 100644 --- a/base/src/Data/Macaw/AbsDomain/StridedInterval.hs +++ b/base/src/Data/Macaw/AbsDomain/StridedInterval.hs @@ -6,6 +6,7 @@ A strided interval domain x + [a .. b] * c -} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} @@ -33,8 +34,8 @@ import Control.Exception (assert) import qualified Data.Foldable as Fold import Data.Parameterized.NatRepr import GHC.TypeLits (Nat) +import Prettyprinter import Test.QuickCheck -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), empty) -- import Data.Macaw.DebugLogging @@ -488,12 +489,12 @@ toList :: StridedInterval w -> [Integer] toList si@StridedInterval{} = map (\v -> base si + stride si * v) [0 .. range si] instance Pretty (StridedInterval w) where - pretty si | isEmpty si = text "[]" - pretty si | Just s <- isSingleton si = brackets (integer s) - pretty si@StridedInterval{} = brackets (integer (base si) <> comma - <+> integer (base si + stride si) - <+> text ".." - <+> integer (base si + range si * stride si)) + pretty si | isEmpty si = "[]" + pretty si | Just s <- isSingleton si = brackets (pretty s) + pretty si@StridedInterval{} = brackets (pretty (base si) <> comma + <+> pretty (base si + stride si) + <+> ".." + <+> pretty (base si + range si * stride si)) instance Arbitrary (StridedInterval 64) where arbitrary = frequency [ (1, return (empty knownNat)) diff --git a/base/src/Data/Macaw/Analysis/RegisterUse.hs b/base/src/Data/Macaw/Analysis/RegisterUse.hs index 2ea3dcc6..61ddf205 100644 --- a/base/src/Data/Macaw/Analysis/RegisterUse.hs +++ b/base/src/Data/Macaw/Analysis/RegisterUse.hs @@ -5,6 +5,7 @@ task needed before deleting unused code. {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE KindSignatures #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} @@ -70,7 +71,7 @@ import qualified Data.Parameterized.Map as MapF import Data.Set (Set) import qualified Data.Set as Set import GHC.Stack -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter import Data.Macaw.AbsDomain.StackAnalysis import Data.Macaw.CFG @@ -704,10 +705,10 @@ pvmFind l (PVM m) = MapF.findWithDefault (IVDomain (RegEqualLoc l)) l m instance ShowF (ArchReg arch) => Show (PostValueMap arch ids) where show (PVM m) = show m -ppPVM :: forall arch ids . ShowF (ArchReg arch) => PostValueMap arch ids -> Doc +ppPVM :: forall arch ids ann . ShowF (ArchReg arch) => PostValueMap arch ids -> Doc ann ppPVM (PVM m) = vcat $ ppVal <$> MapF.toList m - where ppVal :: Pair (BoundLoc (ArchReg arch)) (InferValue arch ids) -> Doc - ppVal (Pair l v) = pretty l <+> text ":=" <+> text (show v) + where ppVal :: Pair (BoundLoc (ArchReg arch)) (InferValue arch ids) -> Doc ann + ppVal (Pair l v) = pretty l <+> ":=" <+> viaShow v type StartInferInfo arch ids = ( ParsedBlock arch ids @@ -893,20 +894,20 @@ data DependencySet (r :: M.Type -> Type) ids = -- writes a value to the stack that is read later. } -ppSet :: (a -> Doc) -> Set a -> Doc +ppSet :: (a -> Doc ann) -> Set a -> Doc ann ppSet f s = encloseSep lbrace rbrace comma (f <$> Set.toList s) -ppSomeAssignId :: Some (AssignId ids) -> Doc -ppSomeAssignId (Some aid) = text (show aid) +ppSomeAssignId :: Some (AssignId ids) -> Doc ann +ppSomeAssignId (Some aid) = viaShow aid -ppSomeBoundLoc :: MapF.ShowF r => Some (BoundLoc r) -> Doc +ppSomeBoundLoc :: MapF.ShowF r => Some (BoundLoc r) -> Doc ann ppSomeBoundLoc (Some loc) = pretty loc instance MapF.ShowF r => Pretty (DependencySet r ids) where pretty ds = - vcat [ text "Assignments:" <+> ppSet ppSomeAssignId (dsAssignSet ds) - , text "Locations: " <+> ppSet ppSomeBoundLoc (dsLocSet ds) - , text "Write Stmts:" <+> ppSet pretty (dsWriteStmtIndexSet ds) + vcat [ "Assignments:" <+> ppSet ppSomeAssignId (dsAssignSet ds) + , "Locations: " <+> ppSet ppSomeBoundLoc (dsLocSet ds) + , "Write Stmts:" <+> ppSet pretty (dsWriteStmtIndexSet ds) ] -- | Empty dependency set. @@ -1257,25 +1258,26 @@ inferStartConstraints rctx blockMap addr = do propStartConstraints rctx blockMap Map.empty (Map.singleton addr cns) -- | Pretty print start constraints for debugging purposes. -ppStartConstraints :: forall arch ids +ppStartConstraints :: forall arch ids ann . (MemWidth (ArchAddrWidth arch), ShowF (ArchReg arch)) => Map (ArchSegmentOff arch) (StartInferInfo arch ids) - -> Doc + -> Doc ann ppStartConstraints m = vcat (pp <$> Map.toList m) - where pp :: (ArchSegmentOff arch, StartInferInfo arch ids) -> Doc + where pp :: (ArchSegmentOff arch, StartInferInfo arch ids) -> Doc ann pp (addr, (_,_,_,pvm)) = let pvmEntries = vcat (ppPVMPair <$> Map.toList pvm) - in pretty addr <$$> - indent 2 (text "post-values:" <$$> indent 2 pvmEntries) - ppPVMPair :: (ArchSegmentOff arch, PostValueMap arch ids) -> Doc + in vcat [ pretty addr + , indent 2 $ vcat ["post-values:", indent 2 pvmEntries] ] + ppPVMPair :: (ArchSegmentOff arch, PostValueMap arch ids) -> Doc ann ppPVMPair (preaddr, pvm) = - text "to" <+> pretty preaddr <> text ":" <$$> - indent 2 (ppPVM pvm) + vcat + [ "to" <+> pretty preaddr <> ":" + , indent 2 (ppPVM pvm) ] -_ppStartConstraints :: forall arch ids +_ppStartConstraints :: forall arch ids ann . (MemWidth (ArchAddrWidth arch), ShowF (ArchReg arch)) => Map (ArchSegmentOff arch) (StartInferInfo arch ids) - -> Doc + -> Doc ann _ppStartConstraints = ppStartConstraints ------------------------------------------------------------------------ diff --git a/base/src/Data/Macaw/CFG/App.hs b/base/src/Data/Macaw/CFG/App.hs index 5d84753c..7838ca4d 100644 --- a/base/src/Data/Macaw/CFG/App.hs +++ b/base/src/Data/Macaw/CFG/App.hs @@ -36,7 +36,7 @@ import qualified Data.Parameterized.List as P import Data.Parameterized.NatRepr import Data.Parameterized.TH.GADT import Data.Parameterized.TraversableFC -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter import Data.Macaw.Types import Data.Macaw.Utils.Pretty @@ -408,15 +408,15 @@ instance TraversableFC App where ------------------------------------------------------------------------ -- App pretty printing -prettyPure :: (Applicative m, Pretty v) => v -> m Doc +prettyPure :: (Applicative m, Pretty v) => v -> m (Doc ann) prettyPure = pure . pretty -- | Pretty print an 'App' as an expression using the given function -- for printing arguments. rendAppA :: Applicative m - => (forall u . f u -> m Doc) + => (forall u . f u -> m (Doc ann)) -> App f tp - -> (String, [m Doc]) + -> (String, [m (Doc ann)]) rendAppA pp a0 = case a0 of Eq x y -> (,) "eq" [ pp x, pp y ] @@ -430,7 +430,7 @@ rendAppA pp a0 = Trunc x w -> (,) "trunc" [ pp x, ppNat w ] SExt x w -> (,) "sext" [ pp x, ppNat w ] UExt x w -> (,) "uext" [ pp x, ppNat w ] - Bitcast x tp -> (,) "bitcast" [ pp x, pure (text (show (widthEqTarget tp))) ] + Bitcast x tp -> (,) "bitcast" [ pp x, pure (viaShow (widthEqTarget tp)) ] BVAdd _ x y -> (,) "bv_add" [ pp x, pp y ] BVAdc _ x y c -> (,) "bv_adc" [ pp x, pp y, pp c ] BVSub _ x y -> (,) "bv_sub" [ pp x, pp y ] @@ -460,16 +460,16 @@ rendAppA pp a0 = -- | Pretty print an 'App' as an expression using the given function -- for printing arguments. ppAppA :: Applicative m - => (forall u . f u -> m Doc) + => (forall u . f u -> m (Doc ann)) -> App f tp - -> m Doc + -> m (Doc ann) ppAppA pp a0 = let (nm,args) = rendAppA pp a0 in sexpr nm <$> sequenceA args -ppApp :: (forall u . f u -> Doc) +ppApp :: (forall u . f u -> Doc ann) -> App f tp - -> Doc + -> Doc ann ppApp pp a0 = runIdentity $ ppAppA (Identity . pp) a0 ------------------------------------------------------------------------ diff --git a/base/src/Data/Macaw/CFG/AssignRhs.hs b/base/src/Data/Macaw/CFG/AssignRhs.hs index 4f4fe68b..d8b8de22 100644 --- a/base/src/Data/Macaw/CFG/AssignRhs.hs +++ b/base/src/Data/Macaw/CFG/AssignRhs.hs @@ -3,6 +3,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilyDependencies #-} {-# LANGUAGE TypeOperators #-} @@ -35,7 +36,7 @@ import Data.Parameterized.NatRepr import Data.Parameterized.TraversableFC (FoldableFC(..)) import Data.Proxy import Numeric.Natural -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>)) +import Prettyprinter -- | Width of register used to store addresses. type family RegAddrWidth (r :: Type -> Kind.Type) :: Nat @@ -110,14 +111,14 @@ data MemRepr (tp :: Type) where -- etc. PackedVecMemRepr :: !(NatRepr n) -> !(MemRepr tp) -> MemRepr (VecType n tp) -ppEndianness :: Endianness -> String +ppEndianness :: Endianness -> Doc ann ppEndianness LittleEndian = "le" ppEndianness BigEndian = "be" instance Pretty (MemRepr tp) where - pretty (BVMemRepr w end) = text "bv" <> text (ppEndianness end) <> text (show w) - pretty (FloatMemRepr f end) = pretty f <> text (ppEndianness end) - pretty (PackedVecMemRepr w r) = text "v" <> text (show w) <> pretty r + pretty (BVMemRepr w end) = "bv" <> ppEndianness end <> viaShow w + pretty (FloatMemRepr f end) = pretty f <> ppEndianness end + pretty (PackedVecMemRepr w r) = "v" <> viaShow w <> pretty r instance Show (MemRepr tp) where show = show . pretty diff --git a/base/src/Data/Macaw/CFG/Block.hs b/base/src/Data/Macaw/CFG/Block.hs index e8588c37..e252943d 100644 --- a/base/src/Data/Macaw/CFG/Block.hs +++ b/base/src/Data/Macaw/CFG/Block.hs @@ -6,6 +6,7 @@ This exports the pre-classification term statement and block data types. -} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE UndecidableInstances #-} module Data.Macaw.CFG.Block @@ -15,8 +16,7 @@ module Data.Macaw.CFG.Block ) where import Data.Text (Text) -import qualified Data.Text as Text -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter import Data.Macaw.CFG.Core @@ -46,13 +46,17 @@ data TermStmt arch ids instance ArchConstraints arch => Pretty (TermStmt arch ids) where pretty (FetchAndExecute s) = - text "fetch_and_execute" <$$> - indent 2 (pretty s) + vcat + [ "fetch_and_execute" + , indent 2 (pretty s) ] pretty (TranslateError s msg) = - text "ERROR: " <+> text (Text.unpack msg) <$$> - indent 2 (pretty s) + vcat + [ "ERROR: " <+> pretty msg + , indent 2 (pretty s) ] pretty (ArchTermStmt ts regs) = - prettyF ts <$$> indent 2 (pretty regs) + vcat + [ prettyF ts + , indent 2 (pretty regs) ] ------------------------------------------------------------------------ -- Block @@ -67,5 +71,5 @@ data Block arch ids -- ^ The last statement in the block. } -ppBlock :: ArchConstraints arch => Block arch ids -> Doc -ppBlock b = vcat (ppStmt (text . show) <$> blockStmts b) <$$> pretty (blockTerm b) +ppBlock :: ArchConstraints arch => Block arch ids -> Doc ann +ppBlock b = vcat [vcat (ppStmt viaShow <$> blockStmts b), pretty (blockTerm b)] diff --git a/base/src/Data/Macaw/CFG/Core.hs b/base/src/Data/Macaw/CFG/Core.hs index 9be7d779..3809703a 100644 --- a/base/src/Data/Macaw/CFG/Core.hs +++ b/base/src/Data/Macaw/CFG/Core.hs @@ -12,6 +12,7 @@ single CFG. {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE PolyKinds #-} @@ -109,12 +110,10 @@ import Data.Parameterized.TraversableFC (FoldableFC(..)) import Data.Set (Set) import qualified Data.Set as Set import Data.Text (Text) -import qualified Data.Text as Text import GHC.TypeLits import Numeric (showHex) import Numeric.Natural -import qualified Text.PrettyPrint.ANSI.Leijen as PP -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>)) +import Prettyprinter as PP import Data.Macaw.CFG.App import Data.Macaw.CFG.AssignRhs @@ -140,23 +139,23 @@ plusPrec = 6 -- | Class for pretty printing with a precedence field. class PrettyPrec v where - prettyPrec :: Int -> v -> Doc + prettyPrec :: Int -> v -> Doc ann -- | Pretty print over all instances of a type. class PrettyF (f :: k -> Kind.Type) where - prettyF :: f tp -> Doc + prettyF :: f tp -> Doc ann -- | Pretty print a document with parens if condition is true -parenIf :: Bool -> Doc -> Doc +parenIf :: Bool -> Doc ann -> Doc ann parenIf True d = parens d parenIf False d = d -bracketsep :: [Doc] -> Doc -bracketsep [] = text "{}" +bracketsep :: [Doc ann] -> Doc ann +bracketsep [] = "{}" bracketsep (h:l) = vcat $ - [text "{" <+> h] - ++ fmap (text "," <+>) l - ++ [text "}"] + [lbrace <+> h] + ++ fmap (comma <+>) l + ++ [rbrace] -- | A type repr for the address width addrWidthTypeRepr :: AddrWidthRepr w -> TypeRepr (BVType w) @@ -173,8 +172,8 @@ addrWidthTypeRepr Addr64 = BVTypeRepr knownNat -- drawn. newtype AssignId (ids :: Kind.Type) (tp :: Type) = AssignId (Nonce ids tp) -ppAssignId :: AssignId ids tp -> Doc -ppAssignId (AssignId w) = text ("r" ++ show (indexValue w)) +ppAssignId :: AssignId ids tp -> Doc ann +ppAssignId (AssignId w) = pretty 'r' <> pretty (indexValue w) instance Eq (AssignId ids tp) where AssignId id1 == AssignId id2 = id1 == id2 @@ -266,21 +265,21 @@ instance Hashable (CValue arch tp) where instance HashableF (CValue arch) where hashWithSaltF = hashWithSalt -ppLit :: NatRepr n -> Integer -> Doc +ppLit :: NatRepr n -> Integer -> Doc ann ppLit w i - | i >= 0 = text ("0x" ++ showHex i "") <+> text "::" <+> brackets (text (show w)) + | i >= 0 = pretty ("0x" ++ showHex i "") <+> "::" <+> brackets (viaShow w) | otherwise = error "ppLit given negative value" -ppCValue :: Prec -> CValue arch tp -> Doc -ppCValue _ (BoolCValue b) = text $ if b then "true" else "false" +ppCValue :: Prec -> CValue arch tp -> Doc ann +ppCValue _ (BoolCValue b) = if b then "true" else "false" ppCValue p (BVCValue w i) | i >= 0 = parenIf (p > colonPrec) $ ppLit w i | otherwise = -- TODO: We may want to report an error here. parenIf (p > colonPrec) $ - text (show i) <+> text "::" <+> brackets (text (show w)) -ppCValue p (RelocatableCValue _ a) = parenIf (p > plusPrec) $ text (show a) -ppCValue _ (SymbolCValue _ a) = text (show a) + pretty i <+> "::" <+> brackets (viaShow w) +ppCValue p (RelocatableCValue _ a) = parenIf (p > plusPrec) $ viaShow a +ppCValue _ (SymbolCValue _ a) = viaShow a instance PrettyPrec (CValue arch tp) where prettyPrec = ppCValue @@ -694,10 +693,10 @@ asStackAddrOffset addr -- Pretty print Assign, AssignRhs, Value operations -- | Pretty print a value. -ppValue :: ShowF (ArchReg arch) => Prec -> Value arch ids tp -> Doc +ppValue :: ShowF (ArchReg arch) => Prec -> Value arch ids tp -> Doc ann ppValue p (CValue c) = ppCValue p c ppValue _ (AssignedValue a) = ppAssignId (assignId a) -ppValue _ (Initial r) = text (showF r) PP.<> text "_0" +ppValue _ (Initial r) = pretty (showF r) PP.<> "_0" instance ShowF (ArchReg arch) => PrettyPrec (Value arch ids tp) where prettyPrec = ppValue @@ -712,18 +711,18 @@ instance ShowF (ArchReg arch) => Show (Value arch ids tp) where class IsArchFn (f :: (Type -> Kind.Type) -> Type -> Kind.Type) where -- | A function for pretty printing an archFn of a given type. ppArchFn :: Applicative m - => (forall u . v u -> m Doc) + => (forall u . v u -> m (Doc ann)) -- ^ Function for pretty printing vlaue. -> f v tp - -> m Doc + -> m (Doc ann) -- | Typeclass for architecture-specific statements class IsArchStmt (f :: (Type -> Kind.Type) -> Kind.Type) where -- | A function for pretty printing an architecture statement of a given type. - ppArchStmt :: (forall u . v u -> Doc) + ppArchStmt :: (forall u . v u -> Doc ann) -- ^ Function for pretty printing value. -> f v - -> Doc + -> Doc ann -- | Constructs expected by architectures type classes. type ArchConstraints arch @@ -739,69 +738,69 @@ type ArchConstraints arch -- | Pretty print an assignment right-hand side using operations parameterized -- over an application to allow side effects. ppAssignRhs :: (Applicative m, ArchConstraints arch) - => (forall u . f u -> m Doc) + => (forall u . f u -> m (Doc ann)) -- ^ Function for pretty printing value. -> AssignRhs arch f tp - -> m Doc + -> m (Doc ann) ppAssignRhs pp (EvalApp a) = ppAppA pp a -ppAssignRhs _ (SetUndefined tp) = pure $ text "undef ::" <+> brackets (text (show tp)) +ppAssignRhs _ (SetUndefined tp) = pure $ "undef ::" <+> brackets (viaShow tp) ppAssignRhs pp (ReadMem a repr) = - (\d -> text "read_mem" <+> d <+> PP.parens (pretty repr)) <$> pp a + (\d -> "read_mem" <+> d <+> PP.parens (pretty repr)) <$> pp a ppAssignRhs pp (CondReadMem repr c a d) = f <$> pp c <*> pp a <*> pp d - where f cd ad dd = text "cond_read_mem" <+> PP.parens (pretty repr) <+> cd <+> ad <+> dd + where f cd ad dd = "cond_read_mem" <+> PP.parens (pretty repr) <+> cd <+> ad <+> dd ppAssignRhs pp (EvalArchFn f _) = ppArchFn pp f instance ArchConstraints arch => Pretty (AssignRhs arch (Value arch ids) tp) where pretty = runIdentity . ppAssignRhs (Identity . ppValue 10) instance ArchConstraints arch => Pretty (Assignment arch ids tp) where - pretty (Assignment lhs rhs) = ppAssignId lhs <+> text ":=" <+> pretty rhs + pretty (Assignment lhs rhs) = ppAssignId lhs <+> ":=" <+> pretty rhs ------------------------------------------------------------------------ -- Pretty print a value assignment -- | Helper type to wrap up a 'Doc' with a dummy type argument; used to put -- 'Doc's into heterogenous maps in the below -newtype DocF (a :: Type) = DocF Doc +newtype DocF ann (a :: Type) = DocF (Doc ann) -- | This pretty prints a value's representation while saving the pretty -- printed repreentation of subvalues in a map. -collectValueRep :: forall arch ids tp +collectValueRep :: forall arch ids tp ann . ArchConstraints arch => Prec -- ^ Outer precedence -> Value arch ids tp - -> State (MapF (AssignId ids) DocF) Doc + -> State (MapF (AssignId ids) (DocF ann)) (Doc ann) collectValueRep _ (AssignedValue a) = do let lhs = assignId a mr <- gets $ MapF.lookup lhs when (isNothing mr) $ do let ppVal :: forall u . Value arch ids u -> - State (MapF (AssignId ids) DocF) Doc + State (MapF (AssignId ids) (DocF ann)) (Doc ann) ppVal = collectValueRep 10 rhs <- ppAssignRhs ppVal (assignRhs a) - let d = ppAssignId lhs <+> text ":=" <+> rhs + let d = ppAssignId lhs <+> ":=" <+> rhs modify $ MapF.insert lhs (DocF d) return () return $! ppAssignId lhs collectValueRep p v = return $ ppValue p v -- | This pretty prints all the history used to create a value. -ppValueAssignments' :: State (MapF (AssignId ids) DocF) Doc -> Doc +ppValueAssignments' :: State (MapF (AssignId ids) (DocF ann)) (Doc ann) -> Doc ann ppValueAssignments' m = case MapF.elems bindings of [] -> rhs (Some (DocF h):r) -> - let first = text "let" PP.<+> h - f (Some (DocF b)) = text " " PP.<> b - in vcat (first:fmap f r) <$$> - text " in" PP.<+> rhs + let first = "let" PP.<+> h + f (Some (DocF b)) = " " PP.<> b + in vcat [ vcat (first:fmap f r) + , " in" PP.<+> rhs ] where (rhs, bindings) = runState m MapF.empty -- | This pretty prints all the history used to create a value. -ppValueAssignments :: ArchConstraints arch => Value arch ids tp -> Doc +ppValueAssignments :: ArchConstraints arch => Value arch ids tp -> Doc ann ppValueAssignments v = ppValueAssignments' (collectValueRep 0 v) -ppValueAssignmentList :: ArchConstraints arch => [Value arch ids tp] -> Doc +ppValueAssignmentList :: ArchConstraints arch => [Value arch ids tp] -> Doc ann ppValueAssignmentList vals = ppValueAssignments' $ do brackets . hcat . punctuate comma @@ -815,11 +814,11 @@ ppValueAssignmentList vals = class PrettyRegValue r (f :: Type -> Kind.Type) where -- | ppValueEq should return a doc if the contents of the given register -- should be printed, and Nothing if the contents should be ignored. - ppValueEq :: r tp -> f tp -> Maybe Doc + ppValueEq :: r tp -> f tp -> Maybe (Doc ann) -ppRegMap :: forall r v . PrettyRegValue r v => MapF.MapF r v -> Doc +ppRegMap :: forall r v ann . PrettyRegValue r v => MapF.MapF r v -> Doc ann ppRegMap m = bracketsep $ catMaybes (f <$> MapF.toList m) - where f :: MapF.Pair r v -> Maybe Doc + where f :: MapF.Pair r v -> Maybe (Doc ann) f (MapF.Pair r v) = ppValueEq r v @@ -839,7 +838,7 @@ instance ( RegisterInfo r ppValueEq r (Initial r') | Just _ <- testEquality r r' = Nothing ppValueEq r v - | otherwise = Just $ text (showF r) <+> text "=" <+> pretty v + | otherwise = Just $ pretty (showF r) <+> "=" <+> pretty v ------------------------------------------------------------------------ -- Stmt @@ -874,33 +873,33 @@ data Stmt arch ids -- execution of the instruction). ppStmt :: ArchConstraints arch - => (ArchAddrWord arch -> Doc) + => (ArchAddrWord arch -> Doc ann) -- ^ Function for pretty printing an instruction address offset -> Stmt arch ids - -> Doc + -> Doc ann ppStmt ppOff stmt = case stmt of AssignStmt a -> pretty a WriteMem a _ rhs -> - text "write_mem" <+> prettyPrec 11 a <+> ppValue 0 rhs + "write_mem" <+> prettyPrec 11 a <+> ppValue 0 rhs CondWriteMem c a _ rhs -> - text "cond_write_mem" <+> prettyPrec 11 c <+> prettyPrec 11 a + "cond_write_mem" <+> prettyPrec 11 c <+> prettyPrec 11 a <+> ppValue 0 rhs - InstructionStart off mnem -> text "#" <+> ppOff off <+> text (Text.unpack mnem) - Comment s -> text $ "# " ++ Text.unpack s + InstructionStart off mnem -> "#" <+> ppOff off <+> pretty mnem + Comment s -> "# " <> pretty s ExecArchStmt s -> ppArchStmt (ppValue 10) s ArchState a m -> - hang (length (show prefix)) (prefix PP.<> PP.semiBraces (MapF.foldrWithKey ppUpdate [] m)) + hang (length (show prefix)) (prefix PP.<> PP.encloseSep PP.lbrace PP.rbrace PP.semi (MapF.foldrWithKey ppUpdate [] m)) where ppAddr addr = case asAbsoluteAddr addr of - Just absAddr -> text (show absAddr) - Nothing -> PP.braces (PP.int (addrBase addr)) PP.<> text "+" PP.<> text (show (addrOffset addr)) - prefix = text "#" <+> ppAddr a PP.<> text ": " - ppUpdate key val acc = text (showF key) <+> text "=>" <+> ppValue 0 val : acc + Just absAddr -> viaShow absAddr + Nothing -> PP.braces (PP.pretty (addrBase addr)) PP.<> "+" PP.<> viaShow (addrOffset addr) + prefix = "#" <+> ppAddr a PP.<> ": " + ppUpdate key val acc = pretty (showF key) <+> "=>" <+> ppValue 0 val : acc instance ArchConstraints arch => Show (Stmt arch ids) where - show = show . ppStmt (\w -> text (show w)) + show = show . ppStmt viaShow ------------------------------------------------------------------------ -- References diff --git a/base/src/Data/Macaw/DebugLogging.hs b/base/src/Data/Macaw/DebugLogging.hs index 048ef6d0..a24531c9 100644 --- a/base/src/Data/Macaw/DebugLogging.hs +++ b/base/src/Data/Macaw/DebugLogging.hs @@ -25,8 +25,9 @@ module Data.Macaw.DebugLogging import Data.IORef import Data.List (find, (\\)) import Debug.Trace +import Prettyprinter +import Prettyprinter.Render.String import System.IO.Unsafe -- For debugKeys -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) #if MIN_VERSION_base(4,9,0) import GHC.Stack #else @@ -93,8 +94,9 @@ debug cl msg x where -- fn = show (getCallStack ?loc) -debug' :: DebugClass -> Doc -> a -> a -debug' cl msg x = debug cl (displayS (renderPretty 0.8 100 msg) "") x +debug' :: DebugClass -> Doc ann -> a -> a +debug' cl msg x = debug cl (renderString (layoutPretty opts msg)) x + where opts = LayoutOptions (AvailablePerLine 100 0.8) {-# INLINE debugM #-} debugM :: (?loc :: CallStack, Monad m) => DebugClass -> String -> m () @@ -107,5 +109,6 @@ debugM cl msg ++ msg) | otherwise = return () -debugM' :: Monad m => DebugClass -> Doc -> m () -debugM' cl msg = debugM cl (displayS (renderPretty 0.8 100 msg) "") +debugM' :: Monad m => DebugClass -> Doc ann -> m () +debugM' cl msg = debugM cl (renderString (layoutPretty opts msg)) + where opts = LayoutOptions (AvailablePerLine 100 0.8) diff --git a/base/src/Data/Macaw/Discovery.hs b/base/src/Data/Macaw/Discovery.hs index 2ef826ab..d63f10dd 100644 --- a/base/src/Data/Macaw/Discovery.hs +++ b/base/src/Data/Macaw/Discovery.hs @@ -95,8 +95,8 @@ import qualified Data.Vector as V import GHC.IO (ioToST) import Numeric import Numeric.Natural +import Prettyprinter (pretty) import System.IO -import Text.PrettyPrint.ANSI.Leijen (pretty) import Text.Printf (printf) #define USE_REWRITER diff --git a/base/src/Data/Macaw/Discovery/State.hs b/base/src/Data/Macaw/Discovery/State.hs index 7f23d623..e30285b5 100644 --- a/base/src/Data/Macaw/Discovery/State.hs +++ b/base/src/Data/Macaw/Discovery/State.hs @@ -52,10 +52,9 @@ import Data.Parameterized.Classes import qualified Data.Parameterized.Map as MapF import Data.Parameterized.Some import Data.Text (Text) -import qualified Data.Text as Text import qualified Data.Vector as V import Numeric (showHex) -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter as PP import Data.Macaw.AbsDomain.AbsState import qualified Data.Macaw.AbsDomain.JumpBounds as Jmp @@ -194,44 +193,54 @@ data ParsedTermStmt arch ids ppTermStmt :: ArchConstraints arch => ParsedTermStmt arch ids - -> Doc + -> Doc ann ppTermStmt tstmt = case tstmt of ParsedCall s Nothing -> - text "tail_call" <$$> - indent 2 (pretty s) + vcat + [ "tail_call" + , indent 2 (pretty s) ] ParsedCall s (Just next) -> - text "call and return to" <+> text (show next) <$$> - indent 2 (pretty s) + vcat + [ "call and return to" <+> viaShow next + , indent 2 (pretty s) ] PLTStub regs addr sym -> - text "call_via_got" <+> text (show sym) <+> "(at" <+> text (show addr) PP.<> ")" <$$> - indent 2 (ppRegMap regs) + vcat + [ "call_via_got" <+> viaShow sym <+> "(at" <+> viaShow addr PP.<> ")" + , indent 2 (ppRegMap regs) ] ParsedJump s addr -> - text "jump" <+> text (show addr) <$$> - indent 2 (pretty s) + vcat + [ "jump" <+> viaShow addr + , indent 2 (pretty s) ] ParsedBranch r c t f -> - text "branch" <+> pretty c <+> text (show t) <+> text (show f) <$$> - indent 2 (pretty r) + vcat + [ "branch" <+> pretty c <+> viaShow t <+> viaShow f + , indent 2 (pretty r) ] ParsedLookupTable s idx entries -> - text "ijump" <+> pretty idx <$$> - indent 2 (vcat (imap (\i v -> int i <+> text ":->" <+> text (show v)) - (V.toList entries))) <$$> - indent 2 (pretty s) + vcat + [ "ijump" <+> pretty idx + , indent 2 (vcat (imap (\i v -> pretty i <+> ":->" <+> viaShow v) + (V.toList entries))) + , indent 2 (pretty s) ] ParsedReturn s -> - text "return" <$$> - indent 2 (pretty s) + vcat + [ "return" + , indent 2 (pretty s) ] ParsedArchTermStmt ts s maddr -> - let addrDoc = case maddr of - Just a -> text ", return to" <+> text (show a) - Nothing -> text "" - in prettyF ts <> addrDoc <$$> - indent 2 (pretty s) + vcat + [ prettyF ts <> addrDoc + , indent 2 (pretty s) ] + where + addrDoc = case maddr of + Just a -> ", return to" <+> viaShow a + Nothing -> "" ParsedTranslateError msg -> - text "translation error" <+> text (Text.unpack msg) + "translation error" <+> pretty msg ClassifyFailure s rsns -> - text "classify failure" <$$> - indent 2 (pretty s) <$$> - indent 2 (vcat (text <$> rsns)) + vcat + [ "classify failure" + , indent 2 (pretty s) + , indent 2 (vcat (pretty <$> rsns)) ] instance ArchConstraints arch => Show (ParsedTermStmt arch ids) where show = show . ppTermStmt @@ -284,10 +293,12 @@ deriving instance (ArchConstraints arch, Show (ArchBlockPrecond arch)) instance ArchConstraints arch => Pretty (ParsedBlock arch ids) where pretty b = - let ppOff o = text (show (incAddr (toInteger o) (segoffAddr (pblockAddr b)))) - in text (show (pblockAddr b)) PP.<> text ":" <$$> - indent 2 (vcat $ (text "; " <+>) <$> Jmp.ppInitJumpBounds (blockJumpBounds b)) <$$> - indent 2 (vcat (ppStmt ppOff <$> pblockStmts b) <$$> ppTermStmt (pblockTermStmt b)) + vcat + [ viaShow (pblockAddr b) PP.<> ":" + , indent 2 (vcat $ ("; " <+>) <$> Jmp.ppInitJumpBounds (blockJumpBounds b)) + , indent 2 (vcat [vcat (ppStmt ppOff <$> pblockStmts b), ppTermStmt (pblockTermStmt b)]) + ] + where ppOff o = viaShow (incAddr (toInteger o) (segoffAddr (pblockAddr b))) ------------------------------------------------------------------------ -- DiscoveryFunInfo @@ -325,11 +336,14 @@ parsedBlocks = lens _parsedBlocks (\s v -> s { _parsedBlocks = v }) instance ArchConstraints arch => Pretty (DiscoveryFunInfo arch ids) where pretty info = - let addr = pretty (show (discoveredFunAddr info)) + vcat + [ "function" <+> nm + , vcat (pretty <$> Map.elems (info^.parsedBlocks)) ] + where + addr = viaShow (discoveredFunAddr info) nm = case discoveredFunSymbol info of - Just sym -> text (BSC.unpack sym) <+> "@" <+> addr + Just sym -> pretty (BSC.unpack sym) <+> "@" <+> addr Nothing -> addr - in text "function" <+> nm <$$> vcat (pretty <$> Map.elems (info^.parsedBlocks)) ------------------------------------------------------------------------ -- NoReturnFunStatus @@ -396,11 +410,10 @@ withDiscoveryArchConstraints :: DiscoveryState arch -> a withDiscoveryArchConstraints dinfo = withArchConstraints (archInfo dinfo) -ppDiscoveryStateBlocks :: DiscoveryState arch - -> Doc +ppDiscoveryStateBlocks :: DiscoveryState arch -> Doc ann ppDiscoveryStateBlocks info = withDiscoveryArchConstraints info $ vcat $ f <$> Map.elems (info^.funInfo) - where f :: ArchConstraints arch => Some (DiscoveryFunInfo arch) -> Doc + where f :: ArchConstraints arch => Some (DiscoveryFunInfo arch) -> Doc ann f (Some v) = pretty v -- | Create empty discovery information. diff --git a/base/src/Data/Macaw/Dwarf.hs b/base/src/Data/Macaw/Dwarf.hs index 4867a07a..fc647fa6 100644 --- a/base/src/Data/Macaw/Dwarf.hs +++ b/base/src/Data/Macaw/Dwarf.hs @@ -92,7 +92,7 @@ import Data.String import qualified Data.Vector as V import Data.Word import Numeric (showHex) -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter import Text.Printf import Data.Macaw.Memory (Endianness(..)) @@ -232,9 +232,9 @@ parseGet bs m = ------------------------------------------------------------------------ -- Range -ppRange :: Range -> Doc +ppRange :: Range -> Doc ann ppRange (Range x y) = - text "low:" <+> text (showHex x "") <+> text "high:" <+> text (showHex y "") + "low:" <+> pretty (showHex x "") <+> "high:" <+> pretty (showHex y "") ------------------------------------------------------------------------ -- DIEParser @@ -370,7 +370,7 @@ instance Show DwarfFilePath where show = BSC.unpack . filePathVal instance Pretty DwarfFilePath where - pretty = text . BSC.unpack . filePathVal + pretty = pretty . BSC.unpack . filePathVal -- | File vector read from line-number information. type FileVec = V.Vector DwarfFilePath @@ -383,12 +383,12 @@ data DeclLoc = DeclLoc { locFile :: !DwarfFilePath instance Pretty DeclLoc where pretty loc = - let file | locFile loc == "" = empty - | otherwise = text "decl_file: " <+> pretty (locFile loc) <> line - lne | locLine loc == 0 = empty - | otherwise = text "decl_line: " <+> text (show (locLine loc)) <> line - col | locColumn loc == 0 = empty - | otherwise = text "decl_column: " <+> text (show (locColumn loc)) <> line + let file | locFile loc == "" = emptyDoc + | otherwise = "decl_file: " <+> pretty (locFile loc) <> line + lne | locLine loc == 0 = emptyDoc + | otherwise = "decl_line: " <+> pretty (locLine loc) <> line + col | locColumn loc == 0 = emptyDoc + | otherwise = "decl_column: " <+> pretty (locColumn loc) <> line in file <> lne <> col instance Show DeclLoc where @@ -420,11 +420,11 @@ parseDeclLoc fileVec = do ------------------------------------------------------------------------ -- DW_OP operations -ppOp :: DW_OP -> Doc -ppOp (DW_OP_addr w) | w >= 0 = text (showHex w "") -ppOp o = text (show o) +ppOp :: DW_OP -> Doc ann +ppOp (DW_OP_addr w) | w >= 0 = pretty (showHex w "") +ppOp o = viaShow o -ppOps :: [DW_OP] -> Doc +ppOps :: [DW_OP] -> Doc ann ppOps l = hsep (ppOp <$> l) ------------------------------------------------------------------------ @@ -437,7 +437,7 @@ instance IsString Name where fromString = Name . BSC.pack instance Pretty Name where - pretty = text . BSC.unpack . nameVal + pretty = pretty . BSC.unpack . nameVal instance Show Name where show = BSC.unpack . nameVal @@ -497,7 +497,7 @@ typeRefFileOffset :: TypeRef -> Word64 typeRefFileOffset (TypeRef o) = dieID o instance Pretty TypeRef where - pretty r = text (showHex (typeRefFileOffset r) "") + pretty r = pretty (showHex (typeRefFileOffset r) "") ------------------------------------------------------------------------ -- Enumerator @@ -898,9 +898,9 @@ attributeAsLocation dr = \case instance Pretty Location where pretty (ComputedLoc (DwarfExpr dr bs)) = case Dwarf.parseDW_OPs dr bs of - Left (_, _, msg) -> text msg + Left (_, _, msg) -> pretty msg Right ops -> ppOps ops - pretty (OffsetLoc w) = text ("offset 0x" ++ showHex w "") + pretty (OffsetLoc w) = pretty ("offset 0x" ++ showHex w "") ------------------------------------------------------------------------ -- Variable @@ -910,7 +910,7 @@ newtype VariableRef = VariableRef DieID deriving (Eq,Ord) instance Pretty VariableRef where - pretty (VariableRef (DieID w)) = text ("0x" ++ showHex w "") + pretty (VariableRef (DieID w)) = pretty ("0x" ++ showHex w "") data Variable = Variable { varDieID :: !DieID , varName :: !Name @@ -927,10 +927,12 @@ data Variable = Variable { varDieID :: !DieID instance Pretty Variable where pretty v = - text "name: " <+> pretty (varName v) <$$> - pretty (varDeclLoc v) <$$> - text "type: " <+> pretty (varType v) <$$> - maybe (text "") (\l -> text "location:" <+> pretty l) (varLocation v) + vcat + [ "name: " <+> pretty (varName v) + , pretty (varDeclLoc v) + , "type: " <+> pretty (varType v) + , maybe ("") (\l -> "location:" <+> pretty l) (varLocation v) + ] instance Show Variable where show = show . pretty @@ -984,7 +986,7 @@ newtype SubprogramRef = SubprogramRef DieID deriving (Eq, Ord) instance Pretty SubprogramRef where - pretty (SubprogramRef (DieID d)) = text ("0x" ++ showHex d "") + pretty (SubprogramRef (DieID d)) = pretty ("0x" ++ showHex d "") data SubprogramDef = SubprogramDef { subLowPC :: !(Maybe Word64) , subHighPC :: !(Maybe Word64) @@ -994,10 +996,10 @@ data SubprogramDef = SubprogramDef { subLowPC :: !(Maybe Word64) instance Pretty SubprogramDef where pretty d = - vcat [ text "low_pc: " <+> text (maybe "UNDEF" (`showHex` "") (subLowPC d)) - , text "high_pc: " <+> text (maybe "UNDEF" (`showHex` "") (subHighPC d)) - , text "frame_base: " <+> text (show (subFrameBase d)) - , text "GNU_all_call_sites: " <+> text (show (subGNUAllCallSites d)) + vcat [ "low_pc: " <+> pretty (maybe "UNDEF" (`showHex` "") (subLowPC d)) + , "high_pc: " <+> pretty (maybe "UNDEF" (`showHex` "") (subHighPC d)) + , "frame_base: " <+> viaShow (subFrameBase d) + , "GNU_all_call_sites: " <+> viaShow (subGNUAllCallSites d) ] -- | Get `DW_AT_GNU_all_tail_call_sites` @@ -1051,14 +1053,14 @@ data Subprogram = Subprogram { subName :: !Name instance Pretty Subprogram where pretty sub = - vcat [ text "name: " <+> pretty (subName sub) - , text "external: " <+> text (show (subExternal sub)) + vcat [ "name: " <+> pretty (subName sub) + , "external: " <+> viaShow (subExternal sub) , pretty (subDeclLoc sub) - , text "prototyped: " <+> text (show (subPrototyped sub)) - , maybe (text "") pretty (subDef sub) + , "prototyped: " <+> viaShow (subPrototyped sub) + , maybe ("") pretty (subDef sub) , ppList "variables" (pretty <$> Map.elems (subVars sub)) , ppList "parameters" (pretty <$> Map.elems (subParamMap sub)) - , text "return type: " <+> pretty (subRetType sub) + , "return type: " <+> pretty (subRetType sub) ] instance Show Subprogram where @@ -1190,19 +1192,19 @@ instance Show CompileUnit where instance Pretty CompileUnit where pretty cu = - vcat [ text "producer: " <+> text (BSC.unpack (cuProducer cu)) - , text "language: " <+> text (show (cuLanguage cu)) - , text "name: " <+> pretty (cuName cu) - , text "comp_dir: " <+> text (BSC.unpack (cuCompDir cu)) - , text "GNU_macros: " <+> text (show (cuGNUMacros cu)) + vcat [ "producer: " <+> pretty (BSC.unpack (cuProducer cu)) + , "language: " <+> viaShow (cuLanguage cu) + , "name: " <+> pretty (cuName cu) + , "comp_dir: " <+> pretty (BSC.unpack (cuCompDir cu)) + , "GNU_macros: " <+> viaShow (cuGNUMacros cu) , ppList "variables" (pretty <$> cuVariables cu) , ppList "subprograms" (pretty <$> cuSubprograms cu) , ppList "ranges" (ppRange <$> cuRanges cu) ] -ppList :: String -> [Doc] -> Doc -ppList nm [] = text nm <> text ": []" -ppList nm l = (text nm <> colon) <$$> indent 2 (vcat l) +ppList :: String -> [Doc ann] -> Doc ann +ppList nm [] = pretty nm <> ": []" +ppList nm l = vcat [pretty nm <> colon, indent 2 (vcat l)] -- Section 7.20 - Address Range Table -- Returns the ranges that belong to a CU diff --git a/base/src/Data/Macaw/Memory.hs b/base/src/Data/Macaw/Memory.hs index eefab02a..537dded8 100644 --- a/base/src/Data/Macaw/Memory.hs +++ b/base/src/Data/Macaw/Memory.hs @@ -9,6 +9,7 @@ Declares 'Memory', a type for representing segmented memory with permissions. {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} @@ -164,7 +165,7 @@ import GHC.Natural import GHC.TypeLits import Language.Haskell.TH.Syntax import Numeric (showHex) -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>)) +import Prettyprinter import Data.Parameterized.Classes import Data.Parameterized.NatRepr @@ -279,7 +280,7 @@ instance Show (MemWord w) where showsPrec _ (MemWord w) = showString "0x" . showHex w instance Pretty (MemWord w) where - pretty = text . show + pretty = viaShow instance Eq (MemWord w) where MemWord x == MemWord y = x == y @@ -428,7 +429,7 @@ instance Hashable (MemInt w) where hashWithSalt s (MemInt w) = s `hashWithSalt` w instance Pretty (MemInt w) where - pretty = text . show . memIntValue + pretty = viaShow . memIntValue instance Show (MemInt w) where showsPrec p (MemInt i) = showsPrec p i @@ -864,12 +865,12 @@ segmentSize :: MemWidth w => MemSegment w -> MemWord w segmentSize = contentsSize . segmentContents -- | Pretty print a memory segment. -ppMemSegment :: MemWidth w => MemSegment w -> Doc +ppMemSegment :: MemWidth w => MemSegment w -> Doc ann ppMemSegment s = - indent 2 $ vcat [ text "base =" <+> text (show (segmentBase s)) - , text "offset =" <+> text (show (segmentOffset s)) - , text "flags =" <+> text (show (segmentFlags s)) - , text "size =" <+> text (show (segmentSize s)) + indent 2 $ vcat [ "base =" <+> viaShow (segmentBase s) + , "offset =" <+> viaShow (segmentOffset s) + , "flags =" <+> viaShow (segmentFlags s) + , "size =" <+> viaShow (segmentSize s) ] instance MemWidth w => Show (MemSegment w) where @@ -1040,7 +1041,7 @@ instance Show (MemAddr w) where . shows off instance Pretty (MemAddr w) where - pretty = text . show + pretty = viaShow -- | Given an absolute address, this returns a segment and offset into the segment. absoluteAddr :: MemWord w -> MemAddr w @@ -1166,7 +1167,7 @@ instance MemWidth w => Show (MemSegmentOff w) where . shows (segmentOffset seg + off) instance MemWidth w => Pretty (MemSegmentOff w) where - pretty = text . show + pretty = viaShow -- | This walks through all the memory regions and looks at each -- address size block of memory that is aligned at a multiple of the diff --git a/base/src/Data/Macaw/Types.hs b/base/src/Data/Macaw/Types.hs index 7950913c..f0227322 100644 --- a/base/src/Data/Macaw/Types.hs +++ b/base/src/Data/Macaw/Types.hs @@ -13,6 +13,7 @@ The type of machine words, including bit vectors and floating point {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE StandaloneDeriving #-} @@ -38,7 +39,7 @@ import Data.Parameterized.TH.GADT import Data.Parameterized.TraversableFC import GHC.TypeLits import qualified Language.Haskell.TH.Syntax as TH -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter -- FIXME: move n0 :: NatRepr 0 @@ -130,7 +131,7 @@ instance Show (FloatInfoRepr fi) where show X86_80FloatRepr = "x87_80" instance Pretty (FloatInfoRepr fi) where - pretty = text . show + pretty = viaShow deriving instance TH.Lift (FloatInfoRepr fi) @@ -231,12 +232,12 @@ type_width (BVTypeRepr n) = n -- Pretty print using an s-expression syntax. instance Pretty (TypeRepr tp) where - pretty BoolTypeRepr = text "bool" - pretty (BVTypeRepr w) = parens (text "bv" <+> text (show w)) - pretty (FloatTypeRepr fi) = text (show fi) + pretty BoolTypeRepr = "bool" + pretty (BVTypeRepr w) = parens ("bv" <+> viaShow w) + pretty (FloatTypeRepr fi) = viaShow fi pretty (TupleTypeRepr z) = - parens (foldlFC (\l tp -> l <+> pretty tp) (text "tuple") z) - pretty (VecTypeRepr c tp) = parens (text "vec" <+> text (show c) <+> pretty tp) + parens (foldlFC (\l tp -> l <+> pretty tp) ("tuple") z) + pretty (VecTypeRepr c tp) = parens ("vec" <+> viaShow c <+> pretty tp) instance Show (TypeRepr tp) where show = show . pretty diff --git a/base/src/Data/Macaw/Utils/Pretty.hs b/base/src/Data/Macaw/Utils/Pretty.hs index a93e6aaa..4c4f755f 100644 --- a/base/src/Data/Macaw/Utils/Pretty.hs +++ b/base/src/Data/Macaw/Utils/Pretty.hs @@ -11,14 +11,14 @@ module Data.Macaw.Utils.Pretty ) where import Data.Parameterized.NatRepr -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>)) +import Prettyprinter -- | Pretty print an operator name and argumetns as an sexpr. -sexpr :: String -> [Doc] -> Doc -sexpr nm d = parens (hsep (text nm : d)) +sexpr :: String -> [Doc ann] -> Doc ann +sexpr nm d = parens (hsep (pretty nm : d)) -sexprA :: Applicative m => String -> [m Doc] -> m Doc +sexprA :: Applicative m => String -> [m (Doc ann)] -> m (Doc ann) sexprA nm d = sexpr nm <$> sequenceA d -ppNat :: Applicative m => NatRepr n -> m Doc -ppNat n = pure (text (show n)) +ppNat :: Applicative m => NatRepr n -> m (Doc ann) +ppNat n = pure (viaShow n) diff --git a/cabal.project.dist.ghc-8.10.2.freeze b/cabal.project.dist.ghc-8.10.2.freeze index 5295f122..ae5e2416 100644 --- a/cabal.project.dist.ghc-8.10.2.freeze +++ b/cabal.project.dist.ghc-8.10.2.freeze @@ -118,7 +118,7 @@ constraints: any.BoundedChan ==1.0.3.0, llvm-pretty-bc-parser -fuzz -regressions, any.located-base ==0.1.1.1, any.logict ==0.7.0.3, - any.lumberjack ==0.1.0.2, + any.lumberjack ==0.1.0.3, any.math-functions ==0.3.4.1, math-functions +system-erf +system-expm1, any.megaparsec ==7.0.5, @@ -144,7 +144,7 @@ constraints: any.BoundedChan ==1.0.3.0, any.pretty ==1.1.3.6, any.pretty-hex ==1.1, any.pretty-show ==1.10, - any.prettyprinter ==1.6.2, + any.prettyprinter ==1.7.0, prettyprinter -buildreadme, any.prettyprinter-ansi-terminal ==1.1.2, any.primitive ==0.7.1.0, diff --git a/cabal.project.dist.ghc-8.6.5.freeze b/cabal.project.dist.ghc-8.6.5.freeze index 639e25f6..623b34a8 100644 --- a/cabal.project.dist.ghc-8.6.5.freeze +++ b/cabal.project.dist.ghc-8.6.5.freeze @@ -120,7 +120,7 @@ constraints: any.BoundedChan ==1.0.3.0, llvm-pretty-bc-parser -fuzz -regressions, any.located-base ==0.1.1.1, any.logict ==0.7.0.3, - any.lumberjack ==0.1.0.2, + any.lumberjack ==0.1.0.3, any.math-functions ==0.3.4.1, math-functions +system-erf +system-expm1, any.megaparsec ==7.0.5, @@ -146,7 +146,7 @@ constraints: any.BoundedChan ==1.0.3.0, any.pretty ==1.1.3.6, any.pretty-hex ==1.1, any.pretty-show ==1.10, - any.prettyprinter ==1.6.2, + any.prettyprinter ==1.7.0, prettyprinter -buildreadme, any.prettyprinter-ansi-terminal ==1.1.2, any.primitive ==0.7.1.0, diff --git a/cabal.project.dist.ghc-8.8.4.freeze b/cabal.project.dist.ghc-8.8.4.freeze index 684c7f5d..c3f41a17 100644 --- a/cabal.project.dist.ghc-8.8.4.freeze +++ b/cabal.project.dist.ghc-8.8.4.freeze @@ -120,7 +120,7 @@ constraints: any.BoundedChan ==1.0.3.0, llvm-pretty-bc-parser -fuzz -regressions, any.located-base ==0.1.1.1, any.logict ==0.7.0.3, - any.lumberjack ==0.1.0.2, + any.lumberjack ==0.1.0.3, any.math-functions ==0.3.4.1, math-functions +system-erf +system-expm1, any.megaparsec ==7.0.5, @@ -146,7 +146,7 @@ constraints: any.BoundedChan ==1.0.3.0, any.pretty ==1.1.3.6, any.pretty-hex ==1.1, any.pretty-show ==1.10, - any.prettyprinter ==1.6.2, + any.prettyprinter ==1.7.0, prettyprinter -buildreadme, any.prettyprinter-ansi-terminal ==1.1.2, any.primitive ==0.7.1.0, @@ -228,4 +228,3 @@ constraints: any.BoundedChan ==1.0.3.0, any.zlib ==0.6.2.2, zlib -bundled-c-zlib -non-blocking-ffi -pkg-config, any.zlib-bindings ==0.1.1.5 -index-state: hackage.haskell.org 2020-09-29T15:11:45Z diff --git a/deps/asl-translator b/deps/asl-translator index 6c7b38cb..943cf7d7 160000 --- a/deps/asl-translator +++ b/deps/asl-translator @@ -1 +1 @@ -Subproject commit 6c7b38cb758816b5b39b9e0c54a28e17af247dbf +Subproject commit 943cf7d724b15c6ae4b650061f96c8bf0b63344a diff --git a/deps/crucible b/deps/crucible index 4ec56743..c1da81f0 160000 --- a/deps/crucible +++ b/deps/crucible @@ -1 +1 @@ -Subproject commit 4ec5674320a0bedb0c5d83b68857a1e4bc5fe030 +Subproject commit c1da81f05e7a8ac80787e2f161ba341a312a6302 diff --git a/deps/elf-edit b/deps/elf-edit index fbaca779..fe018fbf 160000 --- a/deps/elf-edit +++ b/deps/elf-edit @@ -1 +1 @@ -Subproject commit fbaca77900f95b70ddc5961266a963563e758b2b +Subproject commit fe018fbf6c2df56fc3f565d2732780c064228f1b diff --git a/deps/macaw-loader b/deps/macaw-loader index 4797505a..de712a0c 160000 --- a/deps/macaw-loader +++ b/deps/macaw-loader @@ -1 +1 @@ -Subproject commit 4797505a375071791d05cbc1d9b3d8cca5eee52d +Subproject commit de712a0cbd2a71d3e63c47f8bde3d72eb9d4e784 diff --git a/deps/what4 b/deps/what4 index 419ed1d8..3461006b 160000 --- a/deps/what4 +++ b/deps/what4 @@ -1 +1 @@ -Subproject commit 419ed1d89984b10cee8d80c5213098d653c6914c +Subproject commit 3461006b5156904d82dedd32175849a6aa00059f diff --git a/macaw-aarch32/macaw-aarch32.cabal b/macaw-aarch32/macaw-aarch32.cabal index 8029b093..481e7831 100644 --- a/macaw-aarch32/macaw-aarch32.cabal +++ b/macaw-aarch32/macaw-aarch32.cabal @@ -27,7 +27,6 @@ library -- other-modules: -- other-extensions: build-depends: base >=4.10 && <5 - , ansi-wl-pprint , asl-translator , bytestring , bv-sized >= 1.0.1 && < 1.1 @@ -43,6 +42,7 @@ library , mtl , parameterized-utils , pretty + , prettyprinter >= 1.7.0 , semmc , semmc-aarch32 , template-haskell @@ -64,7 +64,6 @@ test-suite macaw-asl-tests , MismatchTests , Shared build-depends: base >=4.10 && <5 - , ansi-wl-pprint , binary , bytestring , containers @@ -76,6 +75,7 @@ test-suite macaw-asl-tests , macaw-base , macaw-aarch32 , parameterized-utils + , prettyprinter >= 1.7.0 , semmc-aarch32 , tasty , tasty-hunit diff --git a/macaw-aarch32/src/Data/Macaw/ARM/ARMReg.hs b/macaw-aarch32/src/Data/Macaw/ARM/ARMReg.hs index 2caba269..98e87db9 100644 --- a/macaw-aarch32/src/Data/Macaw/ARM/ARMReg.hs +++ b/macaw-aarch32/src/Data/Macaw/ARM/ARMReg.hs @@ -36,7 +36,7 @@ import qualified Data.Set as Set import qualified Data.Text as T import GHC.TypeLits import qualified Language.Haskell.TH as TH -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import qualified Prettyprinter as PP import qualified Data.Macaw.CFG as MC import qualified Data.Macaw.Memory as MM @@ -92,7 +92,7 @@ instance ShowF ARMReg where showF = show instance MC.PrettyF ARMReg where - prettyF = PP.text . showF + prettyF = PP.pretty . showF $(return []) -- allow template haskell below to see definitions above diff --git a/macaw-aarch32/src/Data/Macaw/ARM/Arch.hs b/macaw-aarch32/src/Data/Macaw/ARM/Arch.hs index 27264cad..ced7bea3 100644 --- a/macaw-aarch32/src/Data/Macaw/ARM/Arch.hs +++ b/macaw-aarch32/src/Data/Macaw/ARM/Arch.hs @@ -4,6 +4,7 @@ {-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} @@ -38,7 +39,7 @@ import qualified Dismantle.ARM.A32 as ARMDis import qualified Dismantle.ARM.T32 as ThumbDis import GHC.TypeLits import qualified SemMC.Architecture.AArch32 as ARM -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import qualified Prettyprinter as PP import qualified Text.PrettyPrint.HughesPJClass as HPP -- ---------------------------------------------------------------------- @@ -59,8 +60,8 @@ type instance MC.ArchStmt ARM.AArch32 = ARMStmt instance MC.IsArchStmt ARMStmt where ppArchStmt _pp stmt = case stmt of - UninterpretedA32Opcode opc ops -> PP.pretty (show opc) PP.<+> PP.pretty (FCls.toListFC showF ops) - UninterpretedT32Opcode opc ops -> PP.pretty (show opc) PP.<+> PP.pretty (FCls.toListFC showF ops) + UninterpretedA32Opcode opc ops -> PP.viaShow opc PP.<+> PP.pretty (FCls.toListFC showF ops) + UninterpretedT32Opcode opc ops -> PP.viaShow opc PP.<+> PP.pretty (FCls.toListFC showF ops) instance TF.FunctorF ARMStmt where fmapF = TF.fmapFDefault @@ -105,11 +106,11 @@ deriving instance Show (ARMTermStmt ids) type instance MC.ArchTermStmt ARM.AArch32 = ARMTermStmt instance MC.PrettyF ARMTermStmt where - prettyF ts = let dpp2app :: forall a. HPP.Pretty a => a -> PP.Doc - dpp2app = PP.text . show . HPP.pPrint + prettyF ts = let dpp2app :: forall a ann. HPP.Pretty a => a -> PP.Doc ann + dpp2app = PP.viaShow . HPP.pPrint in case ts of - ARMSyscall imm -> PP.text "arm_syscall" PP.<+> dpp2app imm - ThumbSyscall imm -> PP.text "thumb_syscall" PP.<+> dpp2app imm + ARMSyscall imm -> "arm_syscall" PP.<+> dpp2app imm + ThumbSyscall imm -> "thumb_syscall" PP.<+> dpp2app imm rewriteTermStmt :: ARMTermStmt src -> Rewriter ARM.AArch32 s src tgt (ARMTermStmt tgt) rewriteTermStmt s = @@ -296,9 +297,9 @@ data ARMPrimFn (f :: MT.Type -> Type) tp where instance MC.IsArchFn ARMPrimFn where ppArchFn pp f = - let ppUnary s v' = PP.text s PP.<+> v' - ppBinary s v1' v2' = PP.text s PP.<+> v1' PP.<+> v2' - ppTernary s v1' v2' v3' = PP.text s PP.<+> v1' PP.<+> v2' PP.<+> v3' + let ppUnary s v' = s PP.<+> v' + ppBinary s v1' v2' = s PP.<+> v1' PP.<+> v2' + ppTernary s v1' v2' v3' = s PP.<+> v1' PP.<+> v2' PP.<+> v3' in case f of UDiv _ lhs rhs -> ppBinary "arm_udiv" <$> pp lhs <*> pp rhs SDiv _ lhs rhs -> ppBinary "arm_sdiv" <$> pp lhs <*> pp rhs diff --git a/macaw-aarch32/src/Data/Macaw/ARM/BinaryFormat/ELF.hs b/macaw-aarch32/src/Data/Macaw/ARM/BinaryFormat/ELF.hs index c75c0594..098a76c4 100644 --- a/macaw-aarch32/src/Data/Macaw/ARM/BinaryFormat/ELF.hs +++ b/macaw-aarch32/src/Data/Macaw/ARM/BinaryFormat/ELF.hs @@ -10,7 +10,7 @@ import Data.Bits import qualified Data.ByteString.Char8 as C8 import qualified Data.ElfEdit as E import Data.Vector (toList) -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import Prettyprinter getElfSections :: E.ElfHeaderInfo w -> [String] getElfSections e = @@ -18,10 +18,10 @@ getElfSections e = Left (_, msg) -> error $ show msg Right shdrs -> toList $ (C8.unpack . E.shdrName) <$> shdrs -getELFSymbols :: (Show (E.ElfWordType w), Data.Bits.Bits (E.ElfWordType w), Integral (E.ElfWordType w)) => E.ElfHeaderInfo w -> Doc +getELFSymbols :: (Show (E.ElfWordType w), Data.Bits.Bits (E.ElfWordType w), Integral (E.ElfWordType w)) => E.ElfHeaderInfo w -> Doc ann getELFSymbols elf = case E.decodeHeaderSymtab elf of - Nothing -> empty + Nothing -> emptyDoc Just (Left e) -> error (show e) Just (Right symtab) -> E.ppSymbolTableEntries (toList (E.symtabEntries symtab)) diff --git a/macaw-aarch32/tests/ARMTests.hs b/macaw-aarch32/tests/ARMTests.hs index cfa02a68..ebb6ada3 100644 --- a/macaw-aarch32/tests/ARMTests.hs +++ b/macaw-aarch32/tests/ARMTests.hs @@ -29,7 +29,7 @@ import Shared import System.FilePath ( dropExtension, replaceExtension ) import qualified Test.Tasty as T import qualified Test.Tasty.HUnit as T -import Text.PrettyPrint.ANSI.Leijen ( putDoc ) +import Prettyprinter.Util ( putDocW ) import Text.Printf ( PrintfArg, printf ) import Text.Read ( readMaybe ) @@ -131,7 +131,7 @@ testDiscovery32 (funcblocks, ignored) ehdr = do chatty $ "entryPoint: " <> show entryPoint chatty $ "sections = " <> show (ARMELF.getElfSections ehdr) <> "\n" chatty $ "symbols = " - putDoc $ ARMELF.getELFSymbols ehdr + putDocW 80 $ ARMELF.getELFSymbols ehdr chatty "" let discoveryInfo = MD.cfgFromAddrs RO.arm_linux_info mem mempty [entryPoint] [] diff --git a/macaw-ppc/macaw-ppc.cabal b/macaw-ppc/macaw-ppc.cabal index 159083a5..9e2e47cf 100644 --- a/macaw-ppc/macaw-ppc.cabal +++ b/macaw-ppc/macaw-ppc.cabal @@ -44,10 +44,10 @@ library macaw-loader-ppc, lens, macaw-base, - ansi-wl-pprint, cereal, mtl, parameterized-utils, + prettyprinter >= 1.7.0, elf-edit, template-haskell, what4 diff --git a/macaw-ppc/src/Data/Macaw/PPC/Arch.hs b/macaw-ppc/src/Data/Macaw/PPC/Arch.hs index 150fa613..846a6c4f 100644 --- a/macaw-ppc/src/Data/Macaw/PPC/Arch.hs +++ b/macaw-ppc/src/Data/Macaw/PPC/Arch.hs @@ -6,6 +6,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} @@ -30,7 +31,7 @@ import GHC.TypeLits import Control.Lens ( (^.) ) import Data.Bits -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import qualified Prettyprinter as PP import Data.Parameterized.Classes ( knownRepr ) import qualified Data.Parameterized.NatRepr as NR import qualified Data.Parameterized.TraversableFC as FC @@ -83,9 +84,9 @@ type instance MC.ArchTermStmt (SP.AnyPPC v) = PPCTermStmt v instance MC.PrettyF (PPCTermStmt v) where prettyF ts = case ts of - PPCSyscall -> PP.text "ppc_syscall" - PPCTrap -> PP.text "ppc_trap" - PPCTrapdword vb va vto -> PP.text "ppc_trapdword" PP.<+> MC.ppValue 0 vb PP.<+> MC.ppValue 0 va PP.<+> MC.ppValue 0 vto + PPCSyscall -> "ppc_syscall" + PPCTrap -> "ppc_trap" + PPCTrapdword vb va vto -> "ppc_trapdword" PP.<+> MC.ppValue 0 vb PP.<+> MC.ppValue 0 va PP.<+> MC.ppValue 0 vto rewriteTermStmt :: PPCTermStmt v src -> Rewriter (SP.AnyPPC v) s src tgt (PPCTermStmt v tgt) rewriteTermStmt s = @@ -166,27 +167,27 @@ instance TF.TraversableF (PPCStmt v) where instance MC.IsArchStmt (PPCStmt v) where ppArchStmt pp stmt = case stmt of - Attn -> PP.text "ppc_attn" - Sync -> PP.text "ppc_sync" - Isync -> PP.text "ppc_isync" - Dcba ea -> PP.text "ppc_dcba" PP.<+> pp ea - Dcbf ea -> PP.text "ppc_dcbf" PP.<+> pp ea - Dcbi ea -> PP.text "ppc_dcbi" PP.<+> pp ea - Dcbst ea -> PP.text "ppc_dcbst" PP.<+> pp ea - Dcbz ea -> PP.text "ppc_dcbz" PP.<+> pp ea - Dcbzl ea -> PP.text "ppc_dcbzl" PP.<+> pp ea - Dcbt ea th -> PP.text "ppc_dcbt" PP.<+> pp ea PP.<+> pp th - Dcbtst ea th -> PP.text "ppc_dcbtst" PP.<+> pp ea PP.<+> pp th - Icbi ea -> PP.text "ppc_icbi" PP.<+> pp ea - Icbt ea ct -> PP.text "ppc_icbt" PP.<+> pp ea PP.<+> pp ct - Tabort r -> PP.text "ppc_tabort" PP.<+> pp r - Tabortdc r1 r2 v -> PP.text "ppc_tabortdc" PP.<+> pp r1 PP.<+> pp r2 PP.<+> pp v - Tabortdci v1 r v2 -> PP.text "ppc_tabortdci" PP.<+> pp v1 PP.<+> pp r PP.<+> pp v2 - Tabortwc r1 r2 v -> PP.text "ppc_tabortwc" PP.<+> pp r1 PP.<+> pp r2 PP.<+> pp v - Tabortwci v1 r v2 -> PP.text "ppc_tabortwci" PP.<+> pp v1 PP.<+> pp r PP.<+> pp v2 - Tbegin v -> PP.text "ppc_tbegin" PP.<+> pp v - Tcheck v -> PP.text "ppc_tcheck" PP.<+> pp v - Tend v -> PP.text "ppc_tend" PP.<+> pp v + Attn -> "ppc_attn" + Sync -> "ppc_sync" + Isync -> "ppc_isync" + Dcba ea -> "ppc_dcba" PP.<+> pp ea + Dcbf ea -> "ppc_dcbf" PP.<+> pp ea + Dcbi ea -> "ppc_dcbi" PP.<+> pp ea + Dcbst ea -> "ppc_dcbst" PP.<+> pp ea + Dcbz ea -> "ppc_dcbz" PP.<+> pp ea + Dcbzl ea -> "ppc_dcbzl" PP.<+> pp ea + Dcbt ea th -> "ppc_dcbt" PP.<+> pp ea PP.<+> pp th + Dcbtst ea th -> "ppc_dcbtst" PP.<+> pp ea PP.<+> pp th + Icbi ea -> "ppc_icbi" PP.<+> pp ea + Icbt ea ct -> "ppc_icbt" PP.<+> pp ea PP.<+> pp ct + Tabort r -> "ppc_tabort" PP.<+> pp r + Tabortdc r1 r2 v -> "ppc_tabortdc" PP.<+> pp r1 PP.<+> pp r2 PP.<+> pp v + Tabortdci v1 r v2 -> "ppc_tabortdci" PP.<+> pp v1 PP.<+> pp r PP.<+> pp v2 + Tabortwc r1 r2 v -> "ppc_tabortwc" PP.<+> pp r1 PP.<+> pp r2 PP.<+> pp v + Tabortwci v1 r v2 -> "ppc_tabortwci" PP.<+> pp v1 PP.<+> pp r PP.<+> pp v2 + Tbegin v -> "ppc_tbegin" PP.<+> pp v + Tcheck v -> "ppc_tcheck" PP.<+> pp v + Tend v -> "ppc_tend" PP.<+> pp v type instance MC.ArchStmt (SP.AnyPPC v) = PPCStmt v @@ -571,7 +572,7 @@ rewritePrimFn = \case tgtFn <- Vec3 name <$> rewriteValue op1 <*> rewriteValue op2 <*> rewriteValue op3 <*> rewriteValue vscr evalRewrittenArchFn tgtFn -ppPrimFn :: (Applicative m) => (forall u . f u -> m PP.Doc) -> PPCPrimFn v f tp -> m PP.Doc +ppPrimFn :: (Applicative m) => (forall u . f u -> m (PP.Doc ann)) -> PPCPrimFn v f tp -> m (PP.Doc ann) ppPrimFn pp = \case UDiv _ lhs rhs -> ppBinary "ppc_udiv" <$> pp lhs <*> pp rhs SDiv _ lhs rhs -> ppBinary "ppc_sdiv" <$> pp lhs <*> pp rhs @@ -596,20 +597,20 @@ ppPrimFn pp = \case FPFromSBV _fi r x -> ppBinary "ppc_fp_from_sbv" <$> pp r <*> pp x FPFromUBV _fi r x -> ppBinary "ppc_fp_from_ubv" <$> pp r <*> pp x FPCoerce _fi _fi' x -> ppUnary "ppc_fp_coerce" <$> pp x - FPSCR1 n r1 fpscr -> ppBinary ("ppc_fp_un_op_fpscr " ++ n) <$> pp r1 <*> pp fpscr - FPSCR2 n r1 r2 fpscr -> pp3 ("ppc_fp_bin_op_fpscr " ++ n) <$> pp r1 <*> pp r2 <*> pp fpscr - FPSCR3 n r1 r2 r3 fpscr -> pp4 ("ppc_fp_tern_op_fpscr " ++ n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp fpscr - FP1 n r1 fpscr -> ppBinary ("ppc_fp1 " ++ n) <$> pp r1 <*> pp fpscr - FP2 n r1 r2 fpscr -> pp3 ("ppc_fp2 " ++ n) <$> pp r1 <*> pp r2 <*> pp fpscr - FP3 n r1 r2 r3 fpscr -> pp4 ("ppc_fp3 " ++ n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp fpscr - Vec1 n r1 vscr -> ppBinary ("ppc_vec1 " ++ n) <$> pp r1 <*> pp vscr - Vec2 n r1 r2 vscr -> pp3 ("ppc_vec2" ++ n) <$> pp r1 <*> pp r2 <*> pp vscr - Vec3 n r1 r2 r3 vscr -> pp4 ("ppc_vec3" ++ n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp vscr + FPSCR1 n r1 fpscr -> ppBinary ("ppc_fp_un_op_fpscr " <> PP.pretty n) <$> pp r1 <*> pp fpscr + FPSCR2 n r1 r2 fpscr -> pp3 ("ppc_fp_bin_op_fpscr " <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp fpscr + FPSCR3 n r1 r2 r3 fpscr -> pp4 ("ppc_fp_tern_op_fpscr " <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp fpscr + FP1 n r1 fpscr -> ppBinary ("ppc_fp1 " <> PP.pretty n) <$> pp r1 <*> pp fpscr + FP2 n r1 r2 fpscr -> pp3 ("ppc_fp2 " <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp fpscr + FP3 n r1 r2 r3 fpscr -> pp4 ("ppc_fp3 " <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp fpscr + Vec1 n r1 vscr -> ppBinary ("ppc_vec1 " <> PP.pretty n) <$> pp r1 <*> pp vscr + Vec2 n r1 r2 vscr -> pp3 ("ppc_vec2" <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp vscr + Vec3 n r1 r2 r3 vscr -> pp4 ("ppc_vec3" <> PP.pretty n) <$> pp r1 <*> pp r2 <*> pp r3 <*> pp vscr where - ppUnary s v' = PP.text s PP.<+> v' - ppBinary s v1' v2' = PP.text s PP.<+> v1' PP.<+> v2' - pp3 s v1' v2' v3' = PP.text s PP.<+> v1' PP.<+> v2' PP.<+> v3' - pp4 s v1' v2' v3' v4' = PP.text s PP.<+> v1' PP.<+> v2' PP.<+> v3' PP.<+> v4' + ppUnary s v' = s PP.<+> v' + ppBinary s v1' v2' = s PP.<+> v1' PP.<+> v2' + pp3 s v1' v2' v3' = s PP.<+> v1' PP.<+> v2' PP.<+> v3' + pp4 s v1' v2' v3' v4' = s PP.<+> v1' PP.<+> v2' PP.<+> v3' PP.<+> v4' instance MC.IsArchFn (PPCPrimFn v) where ppArchFn = ppPrimFn diff --git a/macaw-ppc/src/Data/Macaw/PPC/Eval.hs b/macaw-ppc/src/Data/Macaw/PPC/Eval.hs index 8078673a..3b51cd31 100644 --- a/macaw-ppc/src/Data/Macaw/PPC/Eval.hs +++ b/macaw-ppc/src/Data/Macaw/PPC/Eval.hs @@ -31,7 +31,7 @@ import qualified Data.Macaw.Memory as MM import qualified Data.Parameterized.Map as MapF import Data.Parameterized.Some ( Some(..) ) import qualified SemMC.Architecture.PPC as SP -import Text.PrettyPrint.ANSI.Leijen ( pretty ) +import Prettyprinter ( pretty ) import qualified Dismantle.PPC as D diff --git a/macaw-ppc/src/Data/Macaw/PPC/PPCReg.hs b/macaw-ppc/src/Data/Macaw/PPC/PPCReg.hs index 933ca6a3..5f3299c5 100644 --- a/macaw-ppc/src/Data/Macaw/PPC/PPCReg.hs +++ b/macaw-ppc/src/Data/Macaw/PPC/PPCReg.hs @@ -34,7 +34,7 @@ import Data.Macaw.Types import Data.Parameterized.Classes import Data.Parameterized.Some ( Some(..) ) import qualified Data.Parameterized.TH.GADT as TH -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import qualified Prettyprinter as PP import qualified Dismantle.PPC as D import qualified SemMC.Architecture.PPC as PPC @@ -73,7 +73,7 @@ instance ShowF (PPCReg v) where showF = show instance MC.PrettyF (PPCReg v) where - prettyF = PP.text . showF + prettyF = PP.pretty . showF $(return []) diff --git a/macaw-semmc/macaw-semmc.cabal b/macaw-semmc/macaw-semmc.cabal index 0049e2dd..96ad7cd1 100644 --- a/macaw-semmc/macaw-semmc.cabal +++ b/macaw-semmc/macaw-semmc.cabal @@ -36,7 +36,6 @@ library macaw-base >= 0.3.2, macaw-symbolic, dismantle-tablegen, - ansi-wl-pprint, semmc, bv-sized, what4 diff --git a/refinement/macaw-refinement.cabal b/refinement/macaw-refinement.cabal index 74448ea4..328298ff 100644 --- a/refinement/macaw-refinement.cabal +++ b/refinement/macaw-refinement.cabal @@ -47,7 +47,6 @@ source-repository head library build-depends: base >= 4 - , ansi-wl-pprint , bv-sized >= 1.0.0 , containers , crucible >= 0.4 @@ -131,7 +130,6 @@ test-suite test-refinements main-is: RefinementTests.hs other-modules: Summary, Initialization, Options build-depends: base >= 4 - , ansi-wl-pprint , bytestring , containers , directory diff --git a/refinement/src/Data/Macaw/Refinement/Path.hs b/refinement/src/Data/Macaw/Refinement/Path.hs index 50f55d39..c918b4e2 100644 --- a/refinement/src/Data/Macaw/Refinement/Path.hs +++ b/refinement/src/Data/Macaw/Refinement/Path.hs @@ -39,8 +39,7 @@ import Data.Macaw.Refinement.FuncBlockUtils ( BlockIdentifier(..) import qualified Data.Macaw.Refinement.FuncBlockUtils as FBU import Data.Maybe ( fromMaybe, mapMaybe ) import qualified Data.Set as S -import Data.Text.Prettyprint.Doc -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import Prettyprinter data CFG arch ids = CFG { cfgFunc :: DiscoveryFunInfo arch ids -- ^ The original function @@ -366,7 +365,7 @@ instance ( MC.MemWidth (ArchAddrWidth arch) ) => looptxt = if null loop then [] else [parens (hsep [ pretty "loops from:" , list ( prettyBlkId <$> loop )])] - prettyBlkId = pretty . show . PP.pretty . biArchSegmentOff + prettyBlkId = pretty . biArchSegmentOff in vsep [ hsep (label <> looptxt) , nest 4 $ vsep (pretty <$> anc) ] diff --git a/symbolic/macaw-symbolic.cabal b/symbolic/macaw-symbolic.cabal index 963eeeba..ab62b214 100644 --- a/symbolic/macaw-symbolic.cabal +++ b/symbolic/macaw-symbolic.cabal @@ -11,7 +11,6 @@ library build-depends: base >= 4, bv-sized >= 1.0.0, - ansi-wl-pprint, containers, IntervalMap >= 0.6 && < 0.7, crucible >= 0.4, @@ -20,6 +19,7 @@ library macaw-base, mtl, parameterized-utils, + prettyprinter >= 1.7.0, text, vector, bytestring, diff --git a/symbolic/src/Data/Macaw/Symbolic/CrucGen.hs b/symbolic/src/Data/Macaw/Symbolic/CrucGen.hs index 7f4924cd..deaeb1a7 100644 --- a/symbolic/src/Data/Macaw/Symbolic/CrucGen.hs +++ b/symbolic/src/Data/Macaw/Symbolic/CrucGen.hs @@ -109,7 +109,7 @@ import qualified Data.Sequence as Seq import qualified Data.Set as Set import qualified Data.Text as Text import qualified Data.Vector as Vec -import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), width) +import Prettyprinter hiding (width) import What4.ProgramLoc as C import qualified What4.Symbol as C @@ -295,7 +295,7 @@ instance C.PrettyApp (MacawExprExtension arch) where BitsToPtr w x -> sexpr ("bits_to_ptr_" ++ show w) [f x] MacawNullPtr _ -> sexpr "null_ptr" [] - MacawBitcast x p -> sexpr "bitcast" [f x, text (show (M.widthEqTarget p))] + MacawBitcast x p -> sexpr "bitcast" [f x, viaShow (M.widthEqTarget p)] addrWidthIsPos :: M.AddrWidthRepr w -> LeqProof 1 w addrWidthIsPos M.Addr32 = LeqProof @@ -484,35 +484,35 @@ instance TraversableFC (MacawArchStmtExtension arch) => FoldableFC (MacawStmtExtension arch) where foldMapFC = foldMapFCDefault -sexpr :: String -> [Doc] -> Doc -sexpr s [] = text s -sexpr s l = parens (text s <+> hsep l) +sexpr :: String -> [Doc ann] -> Doc ann +sexpr s [] = pretty s +sexpr s l = parens (pretty s <+> hsep l) instance (C.PrettyApp (MacawArchStmtExtension arch), M.PrettyF (M.ArchReg arch), M.MemWidth (M.RegAddrWidth (M.ArchReg arch))) => C.PrettyApp (MacawStmtExtension arch) where - ppApp :: forall f - . (forall (x :: C.CrucibleType) . f x -> Doc) - -> (forall (x :: C.CrucibleType) . MacawStmtExtension arch f x -> Doc) + ppApp :: forall f ann + . (forall (x :: C.CrucibleType) . f x -> Doc ann) + -> (forall (x :: C.CrucibleType) . MacawStmtExtension arch f x -> Doc ann) ppApp f a0 = case a0 of MacawReadMem _ r a -> sexpr "macawReadMem" [pretty r, f a] MacawCondReadMem _ r c a d -> sexpr "macawCondReadMem" [pretty r, f c, f a, f d ] MacawWriteMem _ r a v -> sexpr "macawWriteMem" [pretty r, f a, f v] MacawCondWriteMem _ r c a v -> sexpr "macawCondWriteMem" [f c, pretty r, f a, f v] - MacawGlobalPtr _ x -> sexpr "global" [ text (show x) ] + MacawGlobalPtr _ x -> sexpr "global" [ viaShow x ] - MacawFreshSymbolic r -> sexpr "macawFreshSymbolic" [ text (show r) ] + MacawFreshSymbolic r -> sexpr "macawFreshSymbolic" [ viaShow r ] MacawLookupFunctionHandle _ regs -> sexpr "macawLookupFunctionHandle" [ f regs ] MacawArchStmtExtension a -> C.ppApp f a MacawArchStateUpdate addr m -> - let prettyArchStateBinding :: forall tp . M.ArchReg arch tp -> MacawCrucibleValue f tp -> [Doc] -> [Doc] + let prettyArchStateBinding :: forall tp . M.ArchReg arch tp -> MacawCrucibleValue f tp -> [Doc ann] -> [Doc ann] prettyArchStateBinding reg (MacawCrucibleValue val) acc = - (M.prettyF reg <> text " => " <> f val) : acc - in sexpr "macawArchStateUpdate" [pretty addr, semiBraces (MapF.foldrWithKey prettyArchStateBinding [] m)] + (M.prettyF reg <> " => " <> f val) : acc + in sexpr "macawArchStateUpdate" [pretty addr, encloseSep lbrace rbrace semi (MapF.foldrWithKey prettyArchStateBinding [] m)] MacawInstructionStart baddr ioff t -> - sexpr "macawInstructionStart" [ pretty baddr, pretty ioff, text (show t) ] + sexpr "macawInstructionStart" [ pretty baddr, pretty ioff, viaShow t ] PtrEq _ x y -> sexpr "ptr_eq" [ f x, f y ] PtrLt _ x y -> sexpr "ptr_lt" [ f x, f y ] PtrLeq _ x y -> sexpr "ptr_leq" [ f x, f y ] diff --git a/x86/macaw-x86.cabal b/x86/macaw-x86.cabal index 9294cbb6..98fca38e 100644 --- a/x86/macaw-x86.cabal +++ b/x86/macaw-x86.cabal @@ -11,7 +11,6 @@ tested-with: GHC == 8.0.2 library build-depends: base >= 4, - ansi-wl-pprint, bytestring, containers, flexdis86 >= 0.1.2, @@ -19,6 +18,7 @@ library macaw-base >= 0.3.3, mtl, parameterized-utils, + prettyprinter >= 1.7.0, text, vector diff --git a/x86/src/Data/Macaw/X86.hs b/x86/src/Data/Macaw/X86.hs index 3ffd958a..408af5da 100644 --- a/x86/src/Data/Macaw/X86.hs +++ b/x86/src/Data/Macaw/X86.hs @@ -71,7 +71,7 @@ import qualified Data.Set as Set import qualified Data.Text as Text import Data.Word import qualified Flexdis86 as F -import Text.PrettyPrint.ANSI.Leijen (Pretty(..), text) +import Prettyprinter (Pretty(..), viaShow) import Data.Macaw.AbsDomain.AbsState import qualified Data.Macaw.AbsDomain.JumpBounds as Jmp @@ -111,7 +111,7 @@ data ExploreLoc deriving (Eq, Ord) instance Pretty ExploreLoc where - pretty loc = text $ show (loc_ip loc) + pretty loc = viaShow (loc_ip loc) rootLoc :: MemSegmentOff 64 -> ExploreLoc rootLoc ip = ExploreLoc { loc_ip = ip diff --git a/x86/src/Data/Macaw/X86/ArchTypes.hs b/x86/src/Data/Macaw/X86/ArchTypes.hs index 7dd723cb..78126f51 100644 --- a/x86/src/Data/Macaw/X86/ArchTypes.hs +++ b/x86/src/Data/Macaw/X86/ArchTypes.hs @@ -8,6 +8,7 @@ This defines the X86_64 architecture type and the supporting definitions. {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} @@ -52,7 +53,7 @@ import Data.Parameterized.TraversableFC import Data.Word (Word8) import qualified Flexdis86 as F import Numeric.Natural -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter as PP import Data.Macaw.X86.X86Reg @@ -131,9 +132,9 @@ data X86TermStmt ids -- ^ This raises a invalid opcode instruction. instance PrettyF X86TermStmt where - prettyF X86Syscall = text "x86_syscall" - prettyF Hlt = text "hlt" - prettyF UD2 = text "ud2" + prettyF X86Syscall = "x86_syscall" + prettyF Hlt = "hlt" + prettyF UD2 = "ud2" ------------------------------------------------------------------------ -- SSE declarations @@ -845,21 +846,21 @@ instance TraversableFC X86PrimFn where AESNI_AESKeyGenAssist x i -> AESNI_AESKeyGenAssist <$> go x <*> pure i -- | Pretty print a rep value size -ppRepValSize :: RepValSize w -> Doc +ppRepValSize :: RepValSize w -> Doc ann ppRepValSize = pretty . toInteger . repValSizeBitCount instance IsArchFn X86PrimFn where ppArchFn pp f = do - let ppShow :: (Applicative m, Show a) => a -> m Doc - ppShow = pure . text . show + let ppShow :: (Applicative m, Show a) => a -> m (Doc ann) + ppShow = pure . viaShow case f of EvenParity x -> sexprA "even_parity" [ pp x ] - ReadFSBase -> pure $ text "fs.base" - ReadGSBase -> pure $ text "gs.base" + ReadFSBase -> pure $ "fs.base" + ReadGSBase -> pure $ "gs.base" GetSegmentSelector s -> pure $ sexpr "get_segment_selector" [pretty (show s)] CPUID code -> sexprA "cpuid" [ pp code ] CMPXCHG8B a ax bx cx dx -> sexprA "cmpxchg8b" [ pp a, pp ax, pp bx, pp cx, pp dx ] - RDTSC -> pure $ text "rdtsc" + RDTSC -> pure $ "rdtsc" XGetBV code -> sexprA "xgetbv" [ pp code ] PShufb _ x s -> sexprA "pshufb" [ pp x, pp s ] MemCmp sz cnt src dest rev -> sexprA "memcmp" args @@ -1051,15 +1052,15 @@ instance IsArchStmt X86Stmt where ppArchStmt pp stmt = case stmt of SetSegmentSelector s v -> - text "set_segment_selector(" <> text (show s) <> text ", " <> pp v <> text ")" - StoreX87Control addr -> pp addr <+> text ":= x87_control" + "set_segment_selector(" <> viaShow s <> ", " <> pp v <> ")" + StoreX87Control addr -> pp addr <+> ":= x87_control" RepMovs bc dest src cnt dir -> - text "repMovs" <+> parens (hcat $ punctuate comma args) + "repMovs" <+> parens (hcat $ punctuate comma args) where args = [ppRepValSize bc, pp dest, pp src, pp cnt, pp dir] RepStos bc dest val cnt dir -> - text "repStos" <+> parens (hcat $ punctuate comma args) + "repStos" <+> parens (hcat $ punctuate comma args) where args = [ppRepValSize bc, pp dest, pp val, pp cnt, pp dir] - EMMS -> text "emms" + EMMS -> "emms" ------------------------------------------------------------------------ -- X86_64 diff --git a/x86/src/Data/Macaw/X86/Generator.hs b/x86/src/Data/Macaw/X86/Generator.hs index 253d053a..dbdad0a8 100644 --- a/x86/src/Data/Macaw/X86/Generator.hs +++ b/x86/src/Data/Macaw/X86/Generator.hs @@ -88,7 +88,7 @@ import Data.Sequence (Seq) import qualified Data.Sequence as Seq import Data.Text (Text) import qualified Data.Text as Text -import qualified Text.PrettyPrint.ANSI.Leijen as PP +import qualified Prettyprinter as PP import Data.Macaw.X86.ArchTypes import Data.Macaw.X86.X86Reg @@ -103,7 +103,7 @@ data Expr ids tp where -- | An expression that is computed from evaluating subexpressions. AppExpr :: !(App (Expr ids) tp) -> Expr ids tp -collectExpr :: Expr ids tp -> State (MapF (AssignId ids) DocF) PP.Doc +collectExpr :: Expr ids tp -> State (MapF (AssignId ids) (DocF ann)) (PP.Doc ann) collectExpr (ValueExpr v) = collectValueRep 0 v collectExpr (AppExpr a) = ppAppA collectExpr a diff --git a/x86/src/Data/Macaw/X86/Monad.hs b/x86/src/Data/Macaw/X86/Monad.hs index b60299a3..71d23c0c 100644 --- a/x86/src/Data/Macaw/X86/Monad.hs +++ b/x86/src/Data/Macaw/X86/Monad.hs @@ -13,6 +13,7 @@ semantics of X86 instructions. {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RankNTypes #-} @@ -176,7 +177,7 @@ import Data.Parameterized.NatRepr import qualified Flexdis86 as F import Flexdis86.Sizes (SizeConstraint(..)) import GHC.TypeLits as TypeLits -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter as PP import Data.Macaw.X86.ArchTypes @@ -573,20 +574,20 @@ instance Eq addr => Eq (Location addr tp) where -- Going back to pretty names for subregisters is pretty ad hoc; -- see table at http://stackoverflow.com/a/1753627/470844. E.g., -- instead of @%ah@, we produce @%rax[8:16]@. -ppLocation :: forall addr tp. (addr -> Doc) -> Location addr tp -> Doc +ppLocation :: forall addr tp ann. (addr -> Doc ann) -> Location addr tp -> Doc ann ppLocation ppAddr loc = case loc of MemoryAddr addr _tr -> ppAddr addr Register rv -> ppReg rv - FullRegister r -> text $ "%" ++ show r - X87StackRegister i -> text $ "x87_stack@" ++ show i + FullRegister r -> "%" <> viaShow r + X87StackRegister i -> "x87_stack@" <> viaShow i where -- | Print subrange as Python-style slice @[:]@. -- -- The low bit is inclusive and the high bit is exclusive, but I -- can't bring myself to generate @[:)@ :) - ppReg :: RegisterView w n cl -> Doc + ppReg :: RegisterView w n cl -> Doc ann ppReg rv = - text $ "%" ++ show (_registerViewReg rv) ++ + pretty $ "%" ++ show (_registerViewReg rv) ++ if b == 0 && s == (fromIntegral $ intValue (typeWidth $ _registerViewReg rv)) then "" else "[" ++ show b ++ ":" ++ show s ++ "]" diff --git a/x86/src/Data/Macaw/X86/X86Reg.hs b/x86/src/Data/Macaw/X86/X86Reg.hs index 8b8008bc..4f144d7b 100644 --- a/x86/src/Data/Macaw/X86/X86Reg.hs +++ b/x86/src/Data/Macaw/X86/X86Reg.hs @@ -107,7 +107,7 @@ import Data.Set (Set) import qualified Data.Set as Set import qualified Data.Vector as V import qualified Flexdis86 as F -import Text.PrettyPrint.ANSI.Leijen as PP hiding ((<$>)) +import Prettyprinter as PP import qualified Data.Macaw.X86.X86Flag as R @@ -165,7 +165,7 @@ instance ShowF X86Reg where showF = show instance PrettyF X86Reg where - prettyF = text . show + prettyF = viaShow instance TestEquality X86Reg where testEquality x y = orderingIsEqual (compareF x y) diff --git a/x86_symbolic/macaw-x86-symbolic.cabal b/x86_symbolic/macaw-x86-symbolic.cabal index 022d00d4..2cf13982 100644 --- a/x86_symbolic/macaw-x86-symbolic.cabal +++ b/x86_symbolic/macaw-x86-symbolic.cabal @@ -9,7 +9,6 @@ license-file: LICENSE library build-depends: base >= 4, - ansi-wl-pprint, bv-sized >= 1.0.0, crucible >= 0.4, crucible-llvm, @@ -20,6 +19,7 @@ library macaw-x86 >= 0.3.1, mtl, parameterized-utils, + prettyprinter >= 1.7.0, vector, what4 >= 0.4 hs-source-dirs: src diff --git a/x86_symbolic/src/Data/Macaw/X86/Crucible.hs b/x86_symbolic/src/Data/Macaw/X86/Crucible.hs index b471a32d..95a6719e 100644 --- a/x86_symbolic/src/Data/Macaw/X86/Crucible.hs +++ b/x86_symbolic/src/Data/Macaw/X86/Crucible.hs @@ -44,7 +44,7 @@ import Data.Semigroup import qualified Data.Vector as DV import Data.Word (Word8) import GHC.TypeLits (KnownNat) -import Text.PrettyPrint.ANSI.Leijen hiding ( (<$>), (<>), empty ) +import Prettyprinter import What4.Concrete import What4.Interface hiding (IsExpr)