Skip to content

Commit

Permalink
Remove special casing for BiSignalOut
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan committed Nov 7, 2019
1 parent cd62969 commit e1ac22b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 63 deletions.
1 change: 1 addition & 0 deletions clash-lib/prims/systemverilog/Clash_Signal_BiSignal.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ { "BlackBox" :
{ "name" : "Clash.Signal.BiSignal.writeToBiSignal#",
"kind" : "Declaration",
"renderVoid": "RenderVoid",
"type" :
"writeToBiSignal#
:: HasCallStack -- ARG[0]
Expand Down
1 change: 1 addition & 0 deletions clash-lib/prims/verilog/Clash_Signal_BiSignal.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ { "BlackBox" :
{ "name" : "Clash.Signal.BiSignal.writeToBiSignal#",
"kind" : "Declaration",
"renderVoid": "RenderVoid",
"type" :
"writeToBiSignal#
:: HasCallStack -- ARG[0]
Expand Down
1 change: 1 addition & 0 deletions clash-lib/prims/vhdl/Clash_Signal_BiSignal.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ { "BlackBox" :
{ "name" : "Clash.Signal.BiSignal.writeToBiSignal#",
"kind" : "Declaration",
"renderVoid": "RenderVoid",
"type" :
"writeToBiSignal#
:: HasCallStack -- ARG[0]
Expand Down
83 changes: 26 additions & 57 deletions clash-lib/src/Clash/Netlist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -331,39 +331,19 @@ mkNetDecl (id_,tm) = preserveVarEnv $ do
go _ _ = return Nothing


isWriteToBiSignalPrimitive :: Term -> Bool
isWriteToBiSignalPrimitive e = case collectArgs e of
(Prim nm _,_) -> nm == StrictText.pack "Clash.Signal.BiSignal.writeToBiSignal#"
_ -> False

-- | Generate a list of Declarations for a let-binder, return an empty list
-- if the bound expression is a BiSignalOut
mkDeclarations
:: HasCallStack
=> Id
-- ^ LHS of the let-binder
-> Term
-- ^ RHS of the let-binder
-> NetlistMonad [Declaration]
mkDeclarations bndr e = do
hty <- unsafeCoreTypeToHWTypeM' $(curLoc) (varType bndr)
if isBiSignalOut hty
then return []
else mkDeclarations' bndr e

-- | Generate a list of Declarations for a let-binder
mkDeclarations'
mkDeclarations
:: HasCallStack
=> Id
-- ^ LHS of the let-binder
-> Term
-- ^ RHS of the let-binder
-> NetlistMonad [Declaration]
mkDeclarations' bndr (collectTicks -> (Var v,ticks)) =
mkDeclarations bndr (collectTicks -> (Var v,ticks)) =
withTicks ticks $ \tickDecls -> do
mkFunApp (id2identifier bndr) v [] tickDecls

mkDeclarations' _ e@(collectTicks -> (Case _ _ [],_)) = do
mkDeclarations _ e@(collectTicks -> (Case _ _ [],_)) = do
(_,sp) <- Lens.use curCompNm
throw $ ClashException
sp
Expand All @@ -374,11 +354,11 @@ mkDeclarations' _ e@(collectTicks -> (Case _ _ [],_)) = do
])
Nothing

mkDeclarations' bndr (collectTicks -> (Case scrut altTy alts@(_:_:_),ticks)) =
mkDeclarations bndr (collectTicks -> (Case scrut altTy alts@(_:_:_),ticks)) =
withTicks ticks $ \tickDecls -> do
mkSelection (Right bndr) scrut altTy alts tickDecls

mkDeclarations' bndr app = do
mkDeclarations bndr app = do
let (appF,args0,ticks) = collectArgsTicks app
(args,tyArgs) = partitionEithers args0
case appF of
Expand All @@ -387,39 +367,28 @@ mkDeclarations' bndr app = do
| otherwise -> do
(_,sp) <- Lens.use curCompNm
throw (ClashException sp ($(curLoc) ++ "Not in normal form: Var-application with Type arguments:\n\n" ++ showPpr app) Nothing)
-- Do not generate any assignments writing to a BiSignalOut, as these
-- do not have any significance in a HDL. The single exception occurs
-- when writing to a BiSignal using the primitive 'writeToBiSignal'. In
-- the generate HDL it will write to an inout port, NOT the variable
-- having the actual type BiSignalOut.
-- _ | isBiSignalOut (id2type bndr) && (not $ isWriteToBiSignalPrimitive app) ->
-- return []
_ -> do
hwTy <- unsafeCoreTypeToHWTypeM' $(curLoc) (id2type bndr)
if isBiSignalOut hwTy && not (isWriteToBiSignalPrimitive app)
then return []
else do
(exprApp,declsApp0) <- mkExpr False (Right bndr) (varType bndr) app
let dstId = id2identifier bndr
assn =
case exprApp of
Identifier _ Nothing ->
-- Supplied 'bndr' was used to assign a result to, so we
-- don't have to manually turn it into a declaration
[]
Noop ->
-- Rendered expression rendered a "noop" - a list of
-- declarations without a result. Used for things like
-- mealy IO / inline assertions.
[]
_ ->
-- Turn returned expression into declaration by assigning
-- it to 'dstId'
[Assignment dstId exprApp]
declsApp1 <- if null declsApp0
then withTicks ticks return
else pure declsApp0
return (declsApp1 ++ assn)
(exprApp,declsApp0) <- mkExpr False (Right bndr) (varType bndr) app
let dstId = id2identifier bndr
assn =
case exprApp of
Identifier _ Nothing ->
-- Supplied 'bndr' was used to assign a result to, so we
-- don't have to manually turn it into a declaration
[]
Noop ->
-- Rendered expression rendered a "noop" - a list of
-- declarations without a result. Used for things like
-- mealy IO / inline assertions.
[]
_ ->
-- Turn returned expression into declaration by assigning
-- it to 'dstId'
[Assignment dstId exprApp]
declsApp1 <- if null declsApp0
then withTicks ticks return
else pure declsApp0
return (declsApp1 ++ assn)

-- | Generate a declaration that selects an alternative based on the value of
-- the scrutinee
Expand Down
6 changes: 0 additions & 6 deletions clash-lib/src/Clash/Netlist/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ isVoidHwType _ = False
isFilteredVoid :: FilteredHWType -> Bool
isFilteredVoid = isVoidHwType . stripFiltered

isBiSignalOut :: HWType -> Bool
isBiSignalOut (Void (Just (BiDirectional Out _))) = True
isBiSignalOut (Vector n ty) | n /= 0 = isBiSignalOut ty
isBiSignalOut (RTree _ ty) = isBiSignalOut ty
isBiSignalOut _ = False

mkIdentifier :: IdType -> Identifier -> NetlistMonad Identifier
mkIdentifier typ nm = Lens.use mkIdentifierFn <*> pure typ <*> pure nm

Expand Down

0 comments on commit e1ac22b

Please sign in to comment.