Skip to content

Commit 58f6995

Browse files
committed
clash-ffi: Fixup files for formatting compatibility
1 parent ec0432a commit 58f6995

File tree

8 files changed

+60
-15
lines changed

8 files changed

+60
-15
lines changed

clash-ffi/src/Clash/FFI/VPI/Callback.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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
1617
module 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

clash-ffi/src/Clash/FFI/VPI/Callback/Reason.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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 -}
6970
data 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

152154
type 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 -}
497500
instance 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 -}

clash-ffi/src/Clash/FFI/VPI/Control.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

clash-ffi/src/Clash/FFI/VPI/Object.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ newtype Object
8686
#if defined(VERILOG)
8787
foreign 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)
9092
foreign 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

clash-ffi/src/Clash/FFI/VPI/Object/Type.hs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff 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)
2526
data 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

3644
type instance CRepr ObjectType = CInt
3745

46+
#if defined(VERILOG_2001)
3847
instance 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)
6886
instance 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

clash-ffi/src/Clash/FFI/VPI/Object/Value.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{- FOURMOLU_DISABLE -}
12
{-|
23
Copyright: (C) 2022 Google Inc.
34
License: BSD2 (see the file LICENSE)

clash-ffi/src/Clash/FFI/VPI/Object/Value/Format.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{- FOURMOLU_DISABLE -}
12
{-|
23
Copyright: (C) 2022 Google Inc.
34
License: BSD2 (see the file LICENSE)

clash-ffi/tests/Clash/FFI/Test/Instances.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ instance TShow CallbackReason where
267267
<> pShow t
268268
#endif
269269

270+
{- FOURMOLU_DISABLE -}
271+
270272
instance 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

316320
instance TShow Control
@@ -398,6 +402,7 @@ instance Monad m => Serial m (Property CInt) where
398402
instance Monad m => Serial m (Property CString) where
399403
series = foldl (\/) (pure Name) $ map pure [FullName, File]
400404

405+
{- FOURMOLU_DISABLE -}
401406
instance 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

0 commit comments

Comments
 (0)