Skip to content

Commit b4cdbc1

Browse files
committed
Cleanup
1 parent 8ae2c94 commit b4cdbc1

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

src/Data/BitCode/Abbreviation.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12
module Data.BitCode.Abbreviation
23
( addAbbrev, lookupAbbrev
34
, addGlobalAbbrev, lookupGlobalAbbrev
@@ -8,7 +9,7 @@ where
89

910
import Data.BitCode
1011
import Data.Maybe (fromMaybe)
11-
import Data.Semigroup
12+
import Data.Semigroup (Semigroup, (<>))
1213

1314
newtype AbbrevMap = AbbrevMap [(Code, BitCode)] deriving Show
1415
newtype GlobalAbbrevMap = GlobalAbbrevMap [(BlockId, AbbrevMap)] deriving Show
@@ -34,14 +35,14 @@ addGlobalAbbrev :: GlobalAbbrevMap -> BlockId -> BitCode -> GlobalAbbrevMap
3435
addGlobalAbbrev (GlobalAbbrevMap g) blockId block = GlobalAbbrevMap g'
3536
where g' = go g blockId block
3637
go :: [(BlockId, AbbrevMap)] -> BlockId -> BitCode -> [(BlockId, AbbrevMap)]
37-
go [] id b = [(blockId, addAbbrev mempty block)]
38+
go [] _id _b = [(blockId, addAbbrev mempty block)]
3839
go (gb@(id', bs):g') id block | id == id' = (id, addAbbrev bs block):go g' id block
3940
| otherwise = gb:go g' id block
4041

4142
lookupAbbrev :: AbbrevMap -> Code -> Maybe BitCode
4243
lookupAbbrev (AbbrevMap m) = flip lookup m
4344

4445
addAbbrev :: AbbrevMap -> BitCode -> AbbrevMap
45-
addAbbrev (AbbrevMap m) r@(DefAbbrevRecord ops) = AbbrevMap $ (nextId,r):m
46+
addAbbrev (AbbrevMap m) r@DefAbbrevRecord{} = AbbrevMap $ (nextId,r):m
4647
where nextId = 1 + foldr max 3 (map fst m)
47-
48+
addAbbrev _ r = error $ "invalid Bitcode, expected DefAbbrevRecord: " ++ show r

src/Data/BitCode/Reader/FromBits.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE TupleSections #-}
22
{-# LANGUAGE LambdaCase #-}
3+
{-# OPTIONS_GHC #-}
34
module Data.BitCode.Reader.FromBits where
45

56
import Prelude hiding (fromEnum, toEnum)
@@ -80,7 +81,7 @@ parseBlock n abbrevs = parseLocated (parseSubBlock n <|> parseUnabbrevRecord n <
8081
go id (Located _ r:bs) = go id (r:bs) -- ignore Located blocks, and just recurse to the contained block.
8182
go _ ((UnabbrevRecord 1 [id]):bs) = go (fromIntegral id) bs
8283
go id (r@(DefAbbrevRecord _):bs) = tellGlobalAbbrev id r >> go id bs
83-
go id (b:bs) = fail $ "*** Can not handle block: " ++ show b
84+
go _ (b:_) = fail $ "*** Can not handle block: " ++ show b
8485
parseUnabbrevRecord :: Int -> BitCodeReader BitCode
8586
parseUnabbrevRecord width = do
8687
readFixed width (fromEnum UNABBREV_RECORD)

src/Data/BitCode/Reader/Monad.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns, CPP #-}
2+
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-top-binds -fno-warn-unused-matches #-}
23
module Data.BitCode.Reader.Monad
34
( BitCodeReader
45
, evalBitCodeReader
@@ -11,19 +12,14 @@ module Data.BitCode.Reader.Monad
1112
where
1213

1314
import Prelude hiding (read, readFile)
14-
import Data.Semigroup
15+
import Data.Semigroup (Semigroup, (<>))
1516
-- Utility
1617
import Data.Bits (FiniteBits, setBit, zeroBits)
1718
-- reading from file
1819
import qualified Data.ByteString as B (readFile,unpack)
1920
import Data.Word (Word8)
2021
import Data.Bits (testBit)
21-
-- abbrev map
22-
import Data.Maybe (fromMaybe)
2322
-- for Pretty printing
24-
import qualified Text.PrettyPrint as PP
25-
import Data.ByteString (pack)
26-
import Data.ByteString.Char8 (unpack)
2723

2824
import Control.Monad (MonadPlus(..))
2925
import Control.Applicative (Alternative(..))
@@ -89,7 +85,7 @@ instance Monad BitCodeReader where
8985
-- * MonadPlus
9086
instance MonadPlus BitCodeReader where
9187
mzero = BitCode $ \b -> PairS (Left "") b
92-
m `mplus` n = BitCode $ \b -> let PairS a b' = runBitCodeReader m b
88+
m `mplus` n = BitCode $ \b -> let PairS _ b' = runBitCodeReader m b
9389
in runBitCodeReader n b'
9490

9591
-- * Alternative

src/Data/BitCode/Writer/Monad.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# OPTIONS_GHC -fprof-auto #-}
2+
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-top-binds -fno-warn-unused-matches #-}
23
{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving, KindSignatures, BinaryLiterals, RecursiveDo, LambdaCase, RankNTypes, FlexibleContexts, BangPatterns #-}
34
module Data.BitCode.Writer.Monad
45
( nullBuff, addBuff, mkBuff
@@ -45,15 +46,14 @@ import Control.Monad.Fix
4546

4647
import GHC.Stack (HasCallStack)
4748

48-
import Debug.Trace
49-
5049
-- | The position in the stream.
5150
type Position = Int
5251

5352
bSize :: Int
5453
-- ensure the order is correct
5554
bToOrder :: BType -> BType
5655
bPut :: BType -> Put
56+
bToWord8 :: BType -> [Word8]
5757

5858
-- Word64
5959
type BType = Word64
@@ -206,8 +206,6 @@ toListStream (S w b p) = S (toList w) b p
206206
runStreams :: Streams Seq a -> Stream Seq a
207207
runStreams (Streams ss _) = foldl' mappend mempty ss
208208

209-
{-# SPECIALIZE runStreams :: Streams Seq a -> Stream Seq a #-}
210-
211209
-- So we have Streams, which are Sequences of Stream.
212210
-- S0 # # # # # # # # # # # # # # # # # # # +
213211
-- S1 # # # # #
@@ -223,6 +221,7 @@ fs b (x:xs) = let !(S w b'@(Buff n _) _) = b <> x in
223221

224222
data BitstreamState = BitstreamState !SeqStreams !Position deriving Show
225223

224+
bssPosition :: BitstreamState -> Position
226225
bssPosition (BitstreamState _ p) = p
227226

228227
newtype Bitstream a = Bitstream { unBitstream :: State BitstreamState a }
@@ -367,8 +366,6 @@ emitVBR_slow !n !w =do
367366
then emitBit False
368367
else emitBit True >> emitVBR n tail
369368

370-
where logBase2 x = finiteBitSize x - 1 - countLeadingZeros x
371-
372369
emitChar6 :: HasCallStack => Char -> Bitstream ()
373370
emitChar6 '_' = emitBits 6 63
374371
emitChar6 '.' = emitBits 6 62
@@ -390,7 +387,7 @@ alignWord32 = flip mod 32 <$> loc >>= \case
390387
x | 32 - x < 8 -> emitBits (32 - x) 0
391388
x | 32 - x < 16 -> emitWord8 0 >> emitBits (24 - x) 0
392389
x | 32 - x < 24 -> emitWord8 0 >> emitWord8 0 >> emitBits (16 - x) 0
393-
x | 32 - x < 32 -> emitWord8 0 >> emitWord8 0 >> emitWord8 0 >> emitBits (8 - x) 0
390+
| otherwise -> emitWord8 0 >> emitWord8 0 >> emitWord8 0 >> emitBits (8 - x) 0
394391

395392
writeFile
396393
:: HasCallStack

src/Data/BitCode/Writer/ToBits.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# OPTIONS_GHC -fprof-auto #-}
2+
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-top-binds -fno-warn-unused-matches #-}
23
{-# LANGUAGE TupleSections, RecursiveDo, FlexibleInstances #-}
34
module Data.BitCode.Writer.ToBits
45
(module Data.BitCode.Writer.Monad

0 commit comments

Comments
 (0)