module Lava.PrimitiveGates (module Lava.PrimitiveGates)
where
import Control.Monad.State
import Lava.Netlist
primitiveGate :: String
-> [(String, Bit)]
-> [String]
-> Maybe (Int, Int)
-> Out [Bit]
primitiveGate gateName inputPorts outputNames maybeSize
= do state <- get
let insts = instances state
oNet = netCount state
instNr = instCount state
placement = if maybeSize /= Nothing && layoutNesting state > 0 then
Placed
else
Unplaced
l = layout state
l' = if layoutNesting state > 0 && placement == Placed then
Tile (w,h) instNr : l
else
l
outputs = zip outputNames [oNet..]
newInst = Instance
(PrimitiveGate inputPorts outputs)
gateName instNr placement maybeSize
put state{instances = newInst:insts,
netCount = oNet + length outputNames,
instCount = instNr +1,
layout = l'}
return [oNet..oNet+length outputNames1]
where
Just (w, h) = maybeSize