{-# LANGUAGE OverloadedStrings #-}
module Clash.Primitives.GHC.Word (wordTF) where
import Clash.Core.Literal (Literal(WordLiteral))
import Clash.Core.Term (Term(Literal))
import Clash.Core.Type (Type)
import Clash.Primitives.GHC.Literal
(literalTF, unsigned, unsignedLiteral, assign)
import Clash.Netlist.Types (BlackBox(BBTemplate))
import Clash.Netlist.BlackBox.Types
(BlackBoxFunction, Element(Arg, Result), emptyBlackBoxMeta
,BlackBoxMeta, bbKind, TemplateKind(TDecl))
wordTF :: BlackBoxFunction
wordTF = literalTF "GHC.Word.W" wordTF'
wordTF'
:: Bool
-> [Either Term Type]
-> Int
-> (BlackBoxMeta, BlackBox)
wordTF' False [Left (Literal (WordLiteral n))] wordSize =
( emptyBlackBoxMeta
, BBTemplate [unsignedLiteral wordSize n])
wordTF' True [Left (Literal (WordLiteral n))] wordSize =
( emptyBlackBoxMeta
, BBTemplate (assign (Result False) [unsignedLiteral wordSize n]))
wordTF' _isDecl _args _wordSize =
( emptyBlackBoxMeta {bbKind = TDecl }
, BBTemplate (assign (Result False) (unsigned (Arg False 0))))