@@ -8,12 +8,12 @@ module Data.BitCode where
88import Prelude hiding (fromEnum , toEnum )
99import qualified Prelude as P
1010
11- import Data.Word (Word32 , Word64 )
11+ import Data.Word (Word64 )
1212import Data.Maybe (catMaybes )
1313import Data.Bits (FiniteBits , finiteBitSize , countLeadingZeros )
1414
1515import GHC.Generics (Generic )
16- import Data.Binary (Binary , decodeFile )
16+ import Data.Binary (Binary )
1717
1818--- Bit Codes ------------------------------------------------------------------
1919-- see BitCodes.h (e.g. http://llvm.org/docs/doxygen/html/BitCodes_8h_source.html)
@@ -116,11 +116,11 @@ idOrCode (NRec i _) = i
116116
117117normalize :: BitCode -> Maybe NBitCode
118118normalize (Block 0 _ _) = Nothing
119- normalize (Block id _ b) = Just (NBlock id (catMaybes . map normalize $ b))
119+ normalize (Block ident _ b) = Just (NBlock ident (catMaybes . map normalize $ b))
120120normalize (DefAbbrevRecord {}) = Nothing
121121normalize (Located _ bs) = normalize bs
122122normalize (UnabbrevRecord c vs) = Just (NRec (fromIntegral c) vs)
123- normalize (AbbrevRecord _ flds) = let (code: ops) = map toVal . filter (not . isControl) $ flds
123+ normalize (AbbrevRecord _ flds) = let (code: ops) = map toVal' . filter (not . isControl) $ flds
124124 in Just (NRec (fromIntegral code) ops)
125125 where
126126 -- As Abbreviated records can contain arrays, and
@@ -134,24 +134,24 @@ normalize (AbbrevRecord _ flds) = let (code:ops) = map toVal . filter (not . isC
134134 isControl (Len _) = True
135135 isControl _ = False
136136
137- toVal :: Field -> Val
138- toVal (Vbr _ n) = n
139- toVal (Fix _ n) = n
140- toVal (Len _) = error " Len is a control op"
141- toVal (Chr c) = fromIntegral . fromEnum $ c
142- toVal (W64 v) = v
137+ toVal' :: Field -> Val
138+ toVal' (Vbr _ n) = n
139+ toVal' (Fix _ n) = n
140+ toVal' (Len _) = error " Len is a control op"
141+ toVal' (Chr c) = fromIntegral . fromEnum $ c
142+ toVal' (W64 v) = v
143143
144144bitWidth :: (FiniteBits a ) => a -> Int
145145bitWidth x = finiteBitSize x - countLeadingZeros x
146146
147147-- | Extract the id or the code for a BitCode element
148148denormalize :: NBitCode -> BitCode
149- denormalize (NBlock id bs) = let bs' = map denormalize bs
150- ids = map idOrCode bs
151- abbrevWidth = fromIntegral $ if null ids
152- then 2
153- else max 2 (bitWidth (maximum ids))
154- in Block id abbrevWidth ( map denormalize bs)
149+ denormalize (NBlock ident bs) = let bs' = map denormalize bs
150+ ids = map idOrCode bs
151+ abbrevWidth = fromIntegral $ if null ids
152+ then 2
153+ else max 2 (bitWidth (maximum ids))
154+ in Block ident abbrevWidth bs'
155155denormalize (NRec c vs) = UnabbrevRecord (fromIntegral c) vs
156156
157157records :: (Enum a ) => [NBitCode ] -> [(a , [Val ])]
0 commit comments