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 #-}
34module Data.BitCode.Writer.Monad
45 ( nullBuff , addBuff , mkBuff
@@ -45,15 +46,14 @@ import Control.Monad.Fix
4546
4647import GHC.Stack (HasCallStack )
4748
48- import Debug.Trace
49-
5049-- | The position in the stream.
5150type Position = Int
5251
5352bSize :: Int
5453-- ensure the order is correct
5554bToOrder :: BType -> BType
5655bPut :: BType -> Put
56+ bToWord8 :: BType -> [Word8 ]
5757
5858-- Word64
5959type BType = Word64
@@ -206,8 +206,6 @@ toListStream (S w b p) = S (toList w) b p
206206runStreams :: Streams Seq a -> Stream Seq a
207207runStreams (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
224222data BitstreamState = BitstreamState ! SeqStreams ! Position deriving Show
225223
224+ bssPosition :: BitstreamState -> Position
226225bssPosition (BitstreamState _ p) = p
227226
228227newtype 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-
372369emitChar6 :: HasCallStack => Char -> Bitstream ()
373370emitChar6 ' _' = emitBits 6 63
374371emitChar6 ' .' = 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
395392writeFile
396393 :: HasCallStack
0 commit comments