Giter VIP home page Giter VIP logo

aig's People

Contributors

david-christiansen avatar kquick avatar ntc2 avatar robdockins avatar ryanglscott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aig's Issues

Bug with `ror`?

In the definition of ror, there is a call to rolC, which I very much suspect is a typo/bug.

@brianhuffman, can you take a look: I'm not confident I understand the rotation circuits you've built.

Replace `binary-parsers` dependency with `attoparsec`?

Currently, aig cannot be built with GHC 9.2 because of its dependency on binary-parsers, as binary-parsers imposes an upper bounds of bytestring < 0.11. I've submitted a PR upstream at winterland1989/binary-parsers#6, but it hasn't been merged for over a month. Moreover, it's unclear if binary-parsers is still maintained, as there have not been any new commits to the repo for about three years.

Perhaps we should just replace the binary-parsers dependency with attoparsec, which provides similar parsing functionality. I think the following should work:

diff --git a/aig.cabal b/aig.cabal
diff --git a/aig.cabal b/aig.cabal
index 22e9202..3c49362 100644
--- a/aig.cabal
+++ b/aig.cabal
@@ -36,10 +36,9 @@ library
   default-Language: Haskell2010
   ghc-options:      -Wall -fno-ignore-asserts
   build-depends:
+    attoparsec,
     base >= 4.9 && < 4.17,
     bimap,
-    binary,
-    binary-parsers,
     bytestring,
     containers >= 0.5.5,
     mtl,
diff --git a/src/Data/AIG/CompactGraph.hs b/src/Data/AIG/CompactGraph.hs
index 3282f85..cb3063d 100644
--- a/src/Data/AIG/CompactGraph.hs
+++ b/src/Data/AIG/CompactGraph.hs
@@ -24,8 +24,9 @@ module Data.AIG.CompactGraph
   ) where
 
 import Control.Monad (forM_, replicateM)
-import Data.Binary.Get
-import qualified Data.Binary.Parser as BP
+import Data.Attoparsec.ByteString (Parser)
+import qualified Data.Attoparsec.ByteString.Char8 as AttoC8
+import qualified Data.Attoparsec.ByteString.Lazy as AttoL
 import Data.Bits (shiftL, shiftR, (.&.), (.|.), xor, testBit)
 import Data.IORef (IORef, newIORef, modifyIORef', readIORef, writeIORef)
 import Data.List (elemIndex, intersperse)
@@ -256,44 +257,44 @@ encodeDifference w@(fromIntegral -> b)
 ------------------------------------------------------------------
 -- AIG parsing
 
-spaces :: Get ()
-spaces = BP.skipWhile BP.isHorizontalSpace
+spaces :: Parser ()
+spaces = AttoL.skipWhile AttoC8.isHorizontalSpace
 
-getIntWords :: Get [Int]
-getIntWords = BP.decimal `BP.sepBy` spaces
+getIntWords :: Parser [Int]
+getIntWords = AttoC8.decimal `AttoL.sepBy` spaces
 
-getIntWordsLine :: Get [Int]
-getIntWordsLine = getIntWords <* BP.skipWhile BP.isEndOfLine
+getIntWordsLine :: Parser [Int]
+getIntWordsLine = getIntWords <* AttoL.skipWhile AttoC8.isEndOfLine
 
-getHeader :: Get (Int, Int, Int, Int, Int)
+getHeader :: Parser (Int, Int, Int, Int, Int)
 getHeader =
-  do BP.string (modeString Binary)
+  do _ <- AttoL.string (modeString Binary)
      spaces
      ns <- getIntWordsLine
      case ns of
        [m, i, l, o, a] -> return (m, i, l, o, a)
        _ -> fail $ "Invalid AIG header: " ++ show ns
 
-getOutput :: Get (CompactLit s)
+getOutput :: Parser (CompactLit s)
 getOutput =
   do ns <- getIntWordsLine
      case ns of
        [n] -> return (CompactLit (fromIntegral n))
        _ -> fail $ "Invalid output line: " ++ show ns
 
-getDifference :: Get Word32
+getDifference :: Parser Word32
 getDifference = go 0 0
   where
     addByte x b i = x .|. (((fromIntegral b) .&. 0x7f) `shiftL` (7*i))
     go x i =
-      do b <- getWord8
+      do b <- AttoL.anyWord8
          let x' = addByte x b i
          if b .&. 0x80 /= 0 then go x' (i + 1) else return x'
 
-getDifferences :: Get (Word32, Word32)
+getDifferences :: Parser (Word32, Word32)
 getDifferences = (,) <$> getDifference <*> getDifference
 
-getGraph :: Get (Var, [Var], [CompactLit s], Bimap Var (CompactLit s, CompactLit s))
+getGraph :: Parser (Var, [Var], [CompactLit s], Bimap Var (CompactLit s, CompactLit s))
 getGraph =
   do (maxvar, ninputs, nlatches, nouts, nands) <- getHeader
      outputs <- replicateM (nlatches + nouts) getOutput
@@ -352,7 +353,8 @@ instance IsAIG CompactLit CompactGraph where
   withNewGraph _proxy k = k =<< newCompactGraph
 
   aigerNetwork _proxy fp =
-    do (maxv, inps, outs, gates) <- runGet getGraph <$> LBS.readFile fp
+    do res <- AttoL.parseOnly getGraph <$> LBS.readFile fp
+       (maxv, inps, outs, gates) <- either fail pure res
        maxVar  <- newIORef maxv
        inputs  <- newIORef inps
        andMap  <- newIORef gates

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.