Skip to content

Commit

Permalink
Build add cell
Browse files Browse the repository at this point in the history
  • Loading branch information
dopamane committed Jun 6, 2024
1 parent 33450d7 commit 2390861
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Bayeux/Rtlil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Bayeux.Rtlil
, MemoryOption(..)
, -- ** Cells
Cell(..)
, add
, CellStmt(..)
, CellId(..)
, CellType(..)
Expand Down Expand Up @@ -168,7 +169,7 @@ instance Pretty ModuleBody where

initial
:: FiniteBits output
=> Text -- ^ output identifier
=> Text -- ^ output identifier
-> output
-> [ModuleBody]
initial outputIdent output =
Expand Down Expand Up @@ -301,6 +302,35 @@ instance Pretty Cell where
, pretty e
]

add
:: CellId
-> Bool -- ^ \\A_SIGNED
-> Integer -- ^ \\A_WIDTH
-> Bool -- ^ \\B_SIGNED
-> Integer -- ^ \\B_WIDTH
-> Integer -- ^ \\Y_WIDTH
-> SigSpec -- ^ A
-> SigSpec -- ^ B
-> WireId -- ^ Y
-> Cell
add n aSigned aWidth bSigned bWidth yWidth a b y = Cell
[]
(CellStmt "$add" n)
[ CellParameter Nothing "\\A_SIGNED" $ ConstantInteger $ fromBool aSigned
, CellParameter Nothing "\\A_WIDTH" $ ConstantInteger aWidth
, CellParameter Nothing "\\B_SIGNED" $ ConstantInteger $ fromBool bSigned
, CellParameter Nothing "\\B_WIDTH" $ ConstantInteger bWidth
, CellParameter Nothing "\\Y_WIDTH" $ ConstantInteger yWidth
, CellConnect "\\A" a
, CellConnect "\\B" b
, CellConnect "\\Y" $ SigSpecWireId y
]
CellEndStmt
where
fromBool :: Bool -> Integer
fromBool True = 1
fromBool False = 0

data CellStmt = CellStmt CellType CellId
deriving (Eq, Read, Show)

Expand Down
1 change: 1 addition & 0 deletions test/Test/Bayeux/Rtlil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tests =
[ prettyTest "led" rtlilLed
, prettyTest "sbRgbaDrv" sbRgbaDrv
, prettyTest "fiatLux" fiatLux
, prettyTest "add" $ add "\\adder" False 32 False 32 33 (SigSpecWireId "\\a") (SigSpecWireId "\\b") "\\y"
]
, testGroup "synth"
[ synthTest "led" rtlilLed
Expand Down
12 changes: 12 additions & 0 deletions test/Test/Bayeux/Rtlil/pretty-add.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cell $add \adder

parameter \A_SIGNED 0
parameter \A_WIDTH 32
parameter \B_SIGNED 0
parameter \B_WIDTH 32
parameter \Y_WIDTH 33
connect \A \a
connect \B \b
connect \Y \y

end

0 comments on commit 2390861

Please sign in to comment.