-- GENERATED by C->Haskell Compiler, version 0.20.1 The shapeless maps, 31 Oct 2014 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Data/ABC/Internal/GiaAig.chs" #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

{- |
Module      : Data.ABC.Internal.GiaAig
Copyright   : Galois, Inc. 2010
License     : BSD3
Maintainer  : jhendrix@galois.com
Stability   : experimental
Portability : non-portable (c2hs, language extensions)

Comprehensive binding of @aig\/gia\/giaAig.h@ for
converting between AIGs (new-style, not ABC) and GIAs.

-}

module Data.ABC.Internal.GiaAig (
      Gia_AigMap_t
    , withGiaAigMap
    , aigDupGiaLit
    , giaManToAig
    ) where

import Control.Exception (bracket)
import Foreign
import Foreign.C

import Data.ABC.Internal.GIA
{-# LINE 27 "src/Data/ABC/Internal/GiaAig.chs" #-}

import Data.ABC.Internal.AIG
{-# LINE 28 "src/Data/ABC/Internal/GiaAig.chs" #-}




giaManToAig :: (Gia_Man_t) -> (CInt) -> IO ((Aig_Man_t))
giaManToAig a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  giaManToAig'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 35 "src/Data/ABC/Internal/GiaAig.chs" #-}


type Gia_AigMap_t = Ptr Aig_Obj_t

-- | Create a new map for storing all nodes in GIA
newGiaAigMap :: Gia_Man_t -> IO Gia_AigMap_t
newGiaAigMap m = do
  n <- giaManObjNum m
  newArray (replicate (fromIntegral n) nullPtr)

withGiaAigMap :: Gia_Man_t -> (Gia_AigMap_t -> IO a) -> IO a
withGiaAigMap m = bracket (newGiaAigMap m) free

aigDupGiaLit :: Aig_Man_t -> Gia_AigMap_t -> Gia_Man_t -> GiaLit -> IO Aig_Obj_t
aigDupGiaLit aig m gia l = aigDupGiaLit' aig m gia (unGiaLit l)

foreign import ccall unsafe "AbcBridge_Aig_DupGiaLit"
  aigDupGiaLit' :: Ptr Aig_Man_t_ -> Gia_AigMap_t -> Gia_Man_t -> CInt -> IO Aig_Obj_t

foreign import ccall safe "Data/ABC/Internal/GiaAig.chs.h Gia_ManToAig"
  giaManToAig'_ :: ((Gia_Man_t) -> (CInt -> (IO (Aig_Man_t))))