{-# 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 :: BlackBoxFunction
wordTF = Text
-> (Bool -> [Either Term Type] -> Int -> (BlackBoxMeta, BlackBox))
-> BlackBoxFunction
literalTF Text
"GHC.Word.W" Bool -> [Either Term Type] -> Int -> (BlackBoxMeta, BlackBox)
wordTF'
wordTF'
:: Bool
-> [Either Term Type]
-> Int
-> (BlackBoxMeta, BlackBox)
wordTF' :: Bool -> [Either Term Type] -> Int -> (BlackBoxMeta, BlackBox)
wordTF' Bool
False [Left (Literal (WordLiteral Integer
n))] Int
wordSize =
( BlackBoxMeta
emptyBlackBoxMeta
, BlackBoxTemplate -> BlackBox
BBTemplate [Int -> Integer -> Element
unsignedLiteral Int
wordSize Integer
n])
wordTF' Bool
True [Left (Literal (WordLiteral Integer
n))] Int
wordSize =
( BlackBoxMeta
emptyBlackBoxMeta
, BlackBoxTemplate -> BlackBox
BBTemplate (Element -> BlackBoxTemplate -> BlackBoxTemplate
assign (Bool -> Element
Result Bool
False) [Int -> Integer -> Element
unsignedLiteral Int
wordSize Integer
n]))
wordTF' Bool
_isDecl [Either Term Type]
_args Int
_wordSize =
( BlackBoxMeta
emptyBlackBoxMeta {bbKind :: TemplateKind
bbKind = TemplateKind
TDecl }
, BlackBoxTemplate -> BlackBox
BBTemplate (Element -> BlackBoxTemplate -> BlackBoxTemplate
assign (Bool -> Element
Result Bool
False) (Element -> BlackBoxTemplate
unsigned (Bool -> Int -> Element
Arg Bool
False Int
0))))