File tree Expand file tree Collapse file tree 8 files changed +60
-15
lines changed
Expand file tree Collapse file tree 8 files changed +60
-15
lines changed Original file line number Diff line number Diff line change @@ -13,18 +13,27 @@ Maintainer: QBayLogic B.V. <devops@qbaylogic.com>
1313{-# OPTIONS_GHC -fplugin=Foreign.Storable.Generic.Plugin #-}
1414{-# OPTIONS_GHC -fplugin-opt=Foreign.Storable.Generic.Plugin:-v0 #-}
1515
16+ #ifndef IVERILOG
1617module Clash.FFI.VPI.Callback
1718 ( CCallbackInfo (.. )
1819 , CallbackInfo (.. )
1920 , Callback (.. )
2021 , registerCallback
2122 , removeCallback
22- #ifndef IVERILOG
2323 , getCallbackInfo
2424 , withCallbackInfo
2525 , unsafeReceiveCallbackInfo
2626 , receiveCallbackInfo
27+ , module Clash.FFI.VPI.Callback.Reason
28+ ) where
2729#endif
30+
31+ module Clash.FFI.VPI.Callback
32+ ( CCallbackInfo (.. )
33+ , CallbackInfo (.. )
34+ , Callback (.. )
35+ , registerCallback
36+ , removeCallback
2837 , module Clash.FFI.VPI.Callback.Reason
2938 ) where
3039
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ obviously unchecked / unsafe, so must be performed carefully.
6666-- for a compliant VPI implementation but a feature is optional and may not
6767-- be implemented in all tools.
6868--
69+ {- FOURMOLU_DISABLE -}
6970data CallbackReason
7071 = forall a . Coercible a Object => AfterValueChange a TimeType ValueFormat
7172 -- ^ Triggered after the value of the object @a@ changes.
@@ -148,6 +149,7 @@ data CallbackReason
148149 -- ^ Triggered after non-blocking events in a time step are executed, but
149150 -- before read-only events are processed.
150151#endif
152+ {- FOURMOLU_ENABLE -}
151153
152154type instance CRepr CallbackReason = (CInt , Object , Ptr CTime , Ptr CValue )
153155
@@ -494,6 +496,7 @@ instance Show UnknownCallbackReason where
494496 , prettyCallStack c
495497 ]
496498
499+ {- FOURMOLU_DISABLE -}
497500instance UnsafeReceive CallbackReason where
498501 unsafeReceive (creason, object, ctime, cvalue) =
499502 let mObject = if isNullObject object then Nothing else Just object in
@@ -737,3 +740,4 @@ instance Receive CallbackReason where
737740#endif
738741
739742 n -> throwIO $ UnknownCallbackReason n callStack
743+ {- FOURMOLU_ENABLE -}
Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ Maintainer: QBayLogic B.V. <devops@qbaylogic.com>
77{-# LANGUAGE CPP #-}
88{-# LANGUAGE TypeFamilies #-}
99
10- module Clash.FFI.VPI.Control
1110#if defined(VERILOG_2001)
11+ module Clash.FFI.VPI.Control
1212 ( Control (.. )
1313 , StopValue (.. )
1414 , DiagnosticLevel (.. )
@@ -115,5 +115,5 @@ controlSimulator control = do
115115 throwIO $ CouldNotControl control callStack
116116
117117#else
118- () where
118+ module Clash.FFI.VPI.Control () where
119119#endif
Original file line number Diff line number Diff line change @@ -86,9 +86,13 @@ newtype Object
8686#if defined(VERILOG)
8787foreign import ccall " vpi_user.h vpi_free_object"
8888 c_vpi_free_object :: Object -> IO CInt
89+ c_vpi_release :: Object -> IO CInt
90+ c_vpi_release = c_vpi_free_object
8991#elif defined(SYSTEMVERILOG)
9092foreign import ccall " vpi_user.h vpi_release_handle"
9193 c_vpi_release_handle :: Object -> IO CInt
94+ c_vpi_release :: Object -> IO CInt
95+ c_vpi_release = c_vpi_release_handle
9296#else
9397#error "Neither VERILOG or SYSTEMVERILOG is defined in VPI implementation"
9498#endif
@@ -135,13 +139,7 @@ instance IsObject Object where
135139 freeObject obj =
136140 Monad. unless (isNullObject obj)
137141 . Monad. void
138- #if defined(VERILOG)
139- $ c_vpi_free_object obj
140- #elif defined(SYSTEMVERILOG)
141- $ c_vpi_release_handle obj
142- #else
143- #error "Neither VERILOG or SYSTEMVERILOG is defined in VPI implementation"
144- #endif
142+ $ c_vpi_release obj
145143
146144 compareObjects =
147145 c_vpi_compare_objects
Original file line number Diff line number Diff line change @@ -22,19 +22,28 @@ import Clash.FFI.View
2222-- queried using the @vpiType@ property, and the value used to identify when
2323-- it is safe to coerce into a type in the higher-level VPI API.
2424--
25+ #if defined(VERILOG_2001)
2526data ObjectType
2627 = ObjModule
2728 | ObjNet
2829 | ObjParameter
2930 | ObjPort
3031 | ObjReg
31- #if defined(VERILOG_2001)
3232 | ObjCallback
33- #endif
3433 deriving stock (Eq , Show )
34+ #else
35+ data ObjectType
36+ = ObjModule
37+ | ObjNet
38+ | ObjParameter
39+ | ObjPort
40+ | ObjReg
41+ deriving stock (Eq , Show )
42+ #endif
3543
3644type instance CRepr ObjectType = CInt
3745
46+ #if defined(VERILOG_2001)
3847instance Send ObjectType where
3948 send =
4049 pure . \ case
@@ -43,8 +52,16 @@ instance Send ObjectType where
4352 ObjParameter -> 41
4453 ObjPort -> 44
4554 ObjReg -> 48
46- #if defined(VERILOG_2001)
4755 ObjCallback -> 107
56+ #else
57+ instance Send ObjectType where
58+ send =
59+ pure . \ case
60+ ObjModule -> 32
61+ ObjNet -> 36
62+ ObjParameter -> 41
63+ ObjPort -> 44
64+ ObjReg -> 48
4865#endif
4966
5067-- | An exception thrown when decoding an object type if an invalid value is
@@ -65,14 +82,23 @@ instance Show UnknownObjectType where
6582 , prettyCallStack c
6683 ]
6784
85+ #if defined(VERILOG_2001)
6886instance Receive ObjectType where
6987 receive = \ case
7088 32 -> pure ObjModule
7189 36 -> pure ObjNet
7290 41 -> pure ObjParameter
7391 44 -> pure ObjPort
7492 48 -> pure ObjReg
75- #if defined(VERILOG_2001)
7693 107 -> pure ObjCallback
77- #endif
7894 ty -> throwIO $ UnknownObjectType ty callStack
95+ #else
96+ instance Receive ObjectType where
97+ receive = \ case
98+ 32 -> pure ObjModule
99+ 36 -> pure ObjNet
100+ 41 -> pure ObjParameter
101+ 44 -> pure ObjPort
102+ 48 -> pure ObjReg
103+ ty -> throwIO $ UnknownObjectType ty callStack
104+ #endif
Original file line number Diff line number Diff line change 1+ {- FOURMOLU_DISABLE -}
12{-|
23Copyright: (C) 2022 Google Inc.
34License: BSD2 (see the file LICENSE)
Original file line number Diff line number Diff line change 1+ {- FOURMOLU_DISABLE -}
12{-|
23Copyright: (C) 2022 Google Inc.
34License: BSD2 (see the file LICENSE)
Original file line number Diff line number Diff line change @@ -267,6 +267,8 @@ instance TShow CallbackReason where
267267 <> pShow t
268268#endif
269269
270+ {- FOURMOLU_DISABLE -}
271+
270272instance Monad m => Serial m CallbackReason where
271273 series =
272274 (AfterValueChange <$> obj <~> series <~> series)
@@ -311,6 +313,8 @@ instance Monad m => Serial m CallbackReason where
311313 mObj :: Series m (Maybe Object )
312314 mObj = series
313315
316+ {- FOURMOLU_ENABLE -}
317+
314318-- Additional Clash.FFI.VPI.Control.Control Instances
315319
316320instance TShow Control
@@ -398,6 +402,7 @@ instance Monad m => Serial m (Property CInt) where
398402instance Monad m => Serial m (Property CString ) where
399403 series = foldl (\/) (pure Name ) $ map pure [FullName , File ]
400404
405+ {- FOURMOLU_DISABLE -}
401406instance Monad m => Serial m (Property Bool ) where
402407 series =
403408 foldl (\/) (pure IsScalar ) $ map pure
@@ -407,6 +412,7 @@ instance Monad m => Serial m (Property Bool) where
407412 , IsLocalParam
408413#endif
409414 ]
415+ {- FOURMOLU_ENABLE -}
410416
411417-- Additional Clash.FFI.VPI.Object.Time.TimeType Instances
412418
You can’t perform that action at this time.
0 commit comments