Skip to content

Commit 714339f

Browse files
committed
Add Binary instances; and benchmark data.
1 parent 6502a30 commit 714339f

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

bench/data/HelloWorld.mod

29.7 KB
Binary file not shown.

bench/data/HelloWorld2.mod

51.5 KB
Binary file not shown.

data-bitcode.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ library
4242
base >= 4.7 && < 5
4343
, pretty >= 1.1
4444
, bytestring >= 0.10
45+
, binary >= 0.8
4546
, base16-bytestring
4647
default-language: Haskell2010

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
- base >= 4.7 && < 5
1414
- pretty >= 1.1
1515
- bytestring >= 0.10
16+
- binary >= 0.8
1617
- base16-bytestring
1718

1819
library:

src/Data/BitCode.hs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{-# LANGUAGE UndecidableInstances #-}
22
{-# LANGUAGE FlexibleInstances #-}
33
{-# LANGUAGE RankNTypes #-}
4+
{-# LANGUAGE DeriveGeneric #-}
45
module Data.BitCode where
56

67
import Data.Word (Word32, Word64)
78
import Data.Maybe (catMaybes)
89
import Data.Bits (FiniteBits, finiteBitSize, countLeadingZeros)
910

11+
import GHC.Generics (Generic)
12+
import Data.Binary (Binary)
1013

1114
--- Bit Codes ------------------------------------------------------------------
1215
-- see BitCodes.h (e.g. http://llvm.org/docs/doxygen/html/BitCodes_8h_source.html)
@@ -29,12 +32,16 @@ data EncVal = Fixed !Val -- code 1 fixed value
2932
-- when reading an array, the first is a vbr6 field indicating the length.
3033
| Char6 -- code 4 6-bit char
3134
| Blob -- code 5 note: the value for this is: [vbr6:val,pad32bit,8bit array,pad32bit]
32-
deriving Show
35+
deriving (Show, Generic)
36+
37+
instance Binary EncVal
3338

3439
-- | Operators for abbreviated records, are encoded as either literal (1) or encoded value (0).
3540
data Op = Lit !Val -- [1,vbr8:val]
3641
| Enc !EncVal -- [0,f3:enc(,vbr5:val)?], vbr5 value only if given.
37-
deriving Show
42+
deriving (Show, Generic)
43+
44+
instance Binary Op
3845

3946
-- | The Fields contained in an abbreviated record can be one of the following.
4047
data Field = Vbr !Int !Val
@@ -47,7 +54,9 @@ data Field = Vbr !Int !Val
4754
-- abbreviated record matches the def abbrev. This could be considered
4855
-- a TODO, as it would be an improvement to enforce the that AbbrevRecord
4956
-- matches the actuall DefAbbrev.
50-
deriving Show
57+
deriving (Show, Generic)
58+
59+
instance Binary Field
5160

5261
-- | Bit Code Data consists of a series of blocks. Their interpretation is dependent
5362
-- on the container they are in. The top level blocks are emitted with an abbreviation
@@ -73,7 +82,9 @@ data BitCode
7382
, aRecordFields :: ![Field]
7483
}
7584
| Located { srcLoc :: (Loc, Loc), unLoc :: !BitCode }
76-
deriving Show
85+
deriving (Show, Generic)
86+
87+
instance Binary BitCode
7788

7889
-- | BitCode contains some additional control information,
7990
-- like abbreviation records, or the BLOCKINFO block, which
@@ -85,7 +96,9 @@ data BitCode
8596
data NBitCode
8697
= NBlock !BlockId ![NBitCode]
8798
| NRec !Code ![Val]
88-
deriving Show
99+
deriving (Show, Generic)
100+
101+
instance Binary NBitCode
89102

90103
idOrCode :: NBitCode -> Int
91104
idOrCode (NBlock i _) = i

0 commit comments

Comments
 (0)