6
6
{-# LANGUAGE TupleSections #-}
7
7
{-# LANGUAGE MultiParamTypeClasses #-}
8
8
{-# LANGUAGE RecordWildCards #-}
9
+ {-# LANGUAGE PatternGuards #-}
9
10
10
11
{- |
11
12
Module : Verifier.SAW.Term.Pretty
@@ -40,6 +41,7 @@ module Verifier.SAW.Term.Pretty
40
41
, ppName
41
42
) where
42
43
44
+ import Data.Char (intToDigit )
43
45
import Data.Maybe (isJust )
44
46
import Control.Monad.Reader
45
47
import Control.Monad.State.Strict as State
@@ -62,6 +64,7 @@ import qualified Data.IntMap.Strict as IntMap
62
64
import Verifier.SAW.Name
63
65
import Verifier.SAW.Term.Functor
64
66
import Verifier.SAW.Utils (panic )
67
+ import Verifier.SAW.Recognizer
65
68
66
69
--------------------------------------------------------------------------------
67
70
-- * Doc annotations
@@ -469,11 +472,28 @@ ppFlatTermF prec tf =
469
472
RecordProj e fld -> ppProj fld <$> ppTerm' PrecArg e
470
473
Sort s h -> return ((if h then pretty (" i" :: String ) else mempty ) <> viaShow s)
471
474
NatLit i -> ppNat <$> (ppOpts <$> ask) <*> return (toInteger i)
475
+ ArrayValue (asBoolType -> Just _) args
476
+ | Just bits <- mapM asBool $ V. toList args ->
477
+ if length bits `mod` 4 == 0 then
478
+ return $ pretty (" 0x" ++ ppBitsToHex bits)
479
+ else
480
+ return $ pretty (" 0b" ++ map (\ b -> if b then ' 1' else ' 0' ) bits)
472
481
ArrayValue _ args ->
473
482
ppArrayValue <$> mapM (ppTerm' PrecTerm ) (V. toList args)
474
483
StringLit s -> return $ viaShow s
475
484
ExtCns cns -> annotate ExtCnsStyle <$> ppBestName (ecName cns)
476
485
486
+ -- | Pretty-print a big endian list of bit values as a hexadecimal number
487
+ ppBitsToHex :: [Bool ] -> String
488
+ ppBitsToHex (b8: b4: b2: b1: bits') =
489
+ intToDigit (8 * toInt b8 + 4 * toInt b4 + 2 * toInt b2 + toInt b1) :
490
+ ppBitsToHex bits'
491
+ where toInt True = 1
492
+ toInt False = 0
493
+ ppBitsToHex [] = " "
494
+ ppBitsToHex bits =
495
+ panic " ppBitsToHex" [" length of bit list is not a multiple of 4" , show bits]
496
+
477
497
-- | Pretty-print a name, using the best unambiguous alias from the
478
498
-- naming environment.
479
499
ppBestName :: NameInfo -> PPM SawDoc
0 commit comments