module Data.ABC.Internal.AIG (
Aig_Type_t(..)
, Aig_Man_t_
, Aig_Obj_t_
, Aig_Man_t
, Aig_Obj_t
, aigRegular
, aigNot
, aigNotCond
, aigIsComplement
, aigManCiNum
, aigManCoNum
, aigManObjNumMax
, aigManConst0
, aigManConst1
, aigManCi
, aigManCo
, aigObjId
, aigManStart
, aigManStop
, p_aigManStop
, aigObjCreateCi
, aigObjCreateCo
, CInt
) where
import Foreign
import Foreign.C
import Data.ABC.Internal.VecPtr
data Aig_Type_t = AigObjNone
| AigObjConst1
| AigObjCi
| AigObjCo
| AigObjBuf
| AigObjAnd
| AigObjExor
| AigObjVoid
deriving (Enum,Show,Eq)
data Aig_Man_t_
data Aig_Obj_t_
type Aig_Man_t = Ptr (Aig_Man_t_)
type Aig_Obj_t = Ptr (Aig_Obj_t_)
aigObjWordPtr :: (WordPtr -> WordPtr) -> (Aig_Obj_t -> Aig_Obj_t)
aigObjWordPtr f = wordPtrToPtr . f . ptrToWordPtr
aigRegular :: Aig_Obj_t -> Aig_Obj_t
aigRegular = aigObjWordPtr (`clearBit` 0)
aigNot :: Aig_Obj_t -> Aig_Obj_t
aigNot = aigObjWordPtr (xor (bit 0))
aigNotCond :: Aig_Obj_t -> Bool -> Aig_Obj_t
aigNotCond o b = if b then aigNot o else o
aigIsComplement :: Aig_Obj_t -> Bool
aigIsComplement o = ptrToWordPtr o `testBit` 0
typeCInt :: Aig_Type_t -> CInt
typeCInt = fromIntegral . fromEnum
aigManNObj :: (Aig_Man_t) -> (Aig_Type_t) -> IO ((CInt))
aigManNObj a1 a2 =
let {a1' = id a1} in
let {a2' = typeCInt a2} in
aigManNObj'_ a1' a2' >>= \res ->
let {res' = id res} in
return (res')
aigManCiNum :: Aig_Man_t -> IO CInt
aigManCiNum = flip aigManNObj AigObjCi
aigManCoNum :: Aig_Man_t -> IO CInt
aigManCoNum = flip aigManNObj AigObjCo
aigManObjNumMax :: Aig_Man_t -> IO Int
aigManObjNumMax man =
vecPtrSize =<< (\ptr -> do {peekByteOff ptr 32 ::IO (Vec_Ptr_t)}) man
aigManConst0 :: Aig_Man_t -> IO Aig_Obj_t
aigManConst0 m = aigNot `fmap` aigManConst1 m
aigManConst1 :: Aig_Man_t -> IO Aig_Obj_t
aigManConst1 = (\ptr -> do {peekByteOff ptr 48 ::IO (Aig_Obj_t)})
aigManCi :: (Aig_Man_t) -> (CInt) -> IO ((Aig_Obj_t))
aigManCi a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
aigManCi'_ a1' a2' >>= \res ->
let {res' = id res} in
return (res')
aigManCo :: (Aig_Man_t) -> (CInt) -> IO ((Aig_Obj_t))
aigManCo a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
aigManCo'_ a1' a2' >>= \res ->
let {res' = id res} in
return (res')
aigObjId :: (Aig_Obj_t) -> IO ((CInt))
aigObjId a1 =
let {a1' = id a1} in
aigObjId'_ a1' >>= \res ->
let {res' = id res} in
return (res')
foreign import ccall unsafe "&Aig_ManStop"
p_aigManStop :: FunPtr (Aig_Man_t -> IO ())
foreign import ccall unsafe "Aig_ManStop" aigManStop :: Aig_Man_t -> IO ()
aigManStart :: (CInt) -> IO ((Aig_Man_t))
aigManStart a1 =
let {a1' = id a1} in
aigManStart'_ a1' >>= \res ->
let {res' = id res} in
return (res')
aigObjCreateCi :: (Aig_Man_t) -> IO ((Aig_Obj_t))
aigObjCreateCi a1 =
let {a1' = id a1} in
aigObjCreateCi'_ a1' >>= \res ->
let {res' = id res} in
return (res')
aigObjCreateCo :: (Aig_Man_t) -> (Aig_Obj_t) -> IO ((Aig_Obj_t))
aigObjCreateCo a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
aigObjCreateCo'_ a1' a2' >>= \res ->
let {res' = id res} in
return (res')
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h AbcBridge_Aig_ManNObj"
aigManNObj'_ :: ((Aig_Man_t) -> (CInt -> (IO CInt)))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h AbcBridge_Aig_ManCi"
aigManCi'_ :: ((Aig_Man_t) -> (CInt -> (IO (Aig_Obj_t))))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h AbcBridge_Aig_ManCo"
aigManCo'_ :: ((Aig_Man_t) -> (CInt -> (IO (Aig_Obj_t))))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h AbcBridge_Aig_ObjId"
aigObjId'_ :: ((Aig_Obj_t) -> (IO CInt))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h Aig_ManStart"
aigManStart'_ :: (CInt -> (IO (Aig_Man_t)))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h Aig_ObjCreateCi"
aigObjCreateCi'_ :: ((Aig_Man_t) -> (IO (Aig_Obj_t)))
foreign import ccall safe "Data/ABC/Internal/AIG.chs.h Aig_ObjCreateCo"
aigObjCreateCo'_ :: ((Aig_Man_t) -> ((Aig_Obj_t) -> (IO (Aig_Obj_t))))