{-# LANGUAGE TemplateHaskell #-}
module Clash.Annotations.BitRepresentation.ClashLib
( coreToType'
, bitsToBits
) where
import Clash.Annotations.BitRepresentation.Internal
(Type'(AppTy',ConstTy',LitTy'))
import qualified Clash.Annotations.BitRepresentation.Util as BitRepresentation
import qualified Clash.Core.Type as C
import Clash.Core.Name (nameOcc)
import qualified Clash.Netlist.Types as Netlist
import Clash.Util (curLoc)
coreToType'
:: C.Type
-> Either
String
Type'
coreToType' (C.AppTy t1 t2) =
AppTy' <$> coreToType' t1 <*> coreToType' t2
coreToType' (C.ConstTy (C.TyCon name)) =
return $ ConstTy' (nameOcc name)
coreToType' (C.LitTy (C.NumTy n)) =
return $ LitTy' n
coreToType' e =
Left $ $(curLoc) ++ "Unexpected type: " ++ show e
bitToBit
:: BitRepresentation.Bit
-> Netlist.Bit
bitToBit BitRepresentation.H = Netlist.H
bitToBit BitRepresentation.L = Netlist.L
bitToBit BitRepresentation.U = Netlist.U
bitsToBits
:: [BitRepresentation.Bit]
-> [Netlist.Bit]
bitsToBits = map bitToBit