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>
13
13
{-# OPTIONS_GHC -fplugin=Foreign.Storable.Generic.Plugin #-}
14
14
{-# OPTIONS_GHC -fplugin-opt=Foreign.Storable.Generic.Plugin:-v0 #-}
15
15
16
+ #ifndef IVERILOG
16
17
module Clash.FFI.VPI.Callback
17
18
( CCallbackInfo (.. )
18
19
, CallbackInfo (.. )
19
20
, Callback (.. )
20
21
, registerCallback
21
22
, removeCallback
22
- #ifndef IVERILOG
23
23
, getCallbackInfo
24
24
, withCallbackInfo
25
25
, unsafeReceiveCallbackInfo
26
26
, receiveCallbackInfo
27
+ , module Clash.FFI.VPI.Callback.Reason
28
+ ) where
27
29
#endif
30
+
31
+ module Clash.FFI.VPI.Callback
32
+ ( CCallbackInfo (.. )
33
+ , CallbackInfo (.. )
34
+ , Callback (.. )
35
+ , registerCallback
36
+ , removeCallback
28
37
, module Clash.FFI.VPI.Callback.Reason
29
38
) where
30
39
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ obviously unchecked / unsafe, so must be performed carefully.
66
66
-- for a compliant VPI implementation but a feature is optional and may not
67
67
-- be implemented in all tools.
68
68
--
69
+ {- FOURMOLU_DISABLE -}
69
70
data CallbackReason
70
71
= forall a . Coercible a Object => AfterValueChange a TimeType ValueFormat
71
72
-- ^ Triggered after the value of the object @a@ changes.
@@ -148,6 +149,7 @@ data CallbackReason
148
149
-- ^ Triggered after non-blocking events in a time step are executed, but
149
150
-- before read-only events are processed.
150
151
#endif
152
+ {- FOURMOLU_ENABLE -}
151
153
152
154
type instance CRepr CallbackReason = (CInt , Object , Ptr CTime , Ptr CValue )
153
155
@@ -494,6 +496,7 @@ instance Show UnknownCallbackReason where
494
496
, prettyCallStack c
495
497
]
496
498
499
+ {- FOURMOLU_DISABLE -}
497
500
instance UnsafeReceive CallbackReason where
498
501
unsafeReceive (creason, object, ctime, cvalue) =
499
502
let mObject = if isNullObject object then Nothing else Just object in
@@ -737,3 +740,4 @@ instance Receive CallbackReason where
737
740
#endif
738
741
739
742
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>
7
7
{-# LANGUAGE CPP #-}
8
8
{-# LANGUAGE TypeFamilies #-}
9
9
10
- module Clash.FFI.VPI.Control
11
10
#if defined(VERILOG_2001)
11
+ module Clash.FFI.VPI.Control
12
12
( Control (.. )
13
13
, StopValue (.. )
14
14
, DiagnosticLevel (.. )
@@ -115,5 +115,5 @@ controlSimulator control = do
115
115
throwIO $ CouldNotControl control callStack
116
116
117
117
#else
118
- () where
118
+ module Clash.FFI.VPI.Control () where
119
119
#endif
Original file line number Diff line number Diff line change @@ -86,9 +86,13 @@ newtype Object
86
86
#if defined(VERILOG)
87
87
foreign import ccall " vpi_user.h vpi_free_object"
88
88
c_vpi_free_object :: Object -> IO CInt
89
+ c_vpi_release :: Object -> IO CInt
90
+ c_vpi_release = c_vpi_free_object
89
91
#elif defined(SYSTEMVERILOG)
90
92
foreign import ccall " vpi_user.h vpi_release_handle"
91
93
c_vpi_release_handle :: Object -> IO CInt
94
+ c_vpi_release :: Object -> IO CInt
95
+ c_vpi_release = c_vpi_release_handle
92
96
#else
93
97
#error "Neither VERILOG or SYSTEMVERILOG is defined in VPI implementation"
94
98
#endif
@@ -135,13 +139,7 @@ instance IsObject Object where
135
139
freeObject obj =
136
140
Monad. unless (isNullObject obj)
137
141
. 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
145
143
146
144
compareObjects =
147
145
c_vpi_compare_objects
Original file line number Diff line number Diff line change @@ -22,19 +22,28 @@ import Clash.FFI.View
22
22
-- queried using the @vpiType@ property, and the value used to identify when
23
23
-- it is safe to coerce into a type in the higher-level VPI API.
24
24
--
25
+ #if defined(VERILOG_2001)
25
26
data ObjectType
26
27
= ObjModule
27
28
| ObjNet
28
29
| ObjParameter
29
30
| ObjPort
30
31
| ObjReg
31
- #if defined(VERILOG_2001)
32
32
| ObjCallback
33
- #endif
34
33
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
35
43
36
44
type instance CRepr ObjectType = CInt
37
45
46
+ #if defined(VERILOG_2001)
38
47
instance Send ObjectType where
39
48
send =
40
49
pure . \ case
@@ -43,8 +52,16 @@ instance Send ObjectType where
43
52
ObjParameter -> 41
44
53
ObjPort -> 44
45
54
ObjReg -> 48
46
- #if defined(VERILOG_2001)
47
55
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
48
65
#endif
49
66
50
67
-- | An exception thrown when decoding an object type if an invalid value is
@@ -65,14 +82,23 @@ instance Show UnknownObjectType where
65
82
, prettyCallStack c
66
83
]
67
84
85
+ #if defined(VERILOG_2001)
68
86
instance Receive ObjectType where
69
87
receive = \ case
70
88
32 -> pure ObjModule
71
89
36 -> pure ObjNet
72
90
41 -> pure ObjParameter
73
91
44 -> pure ObjPort
74
92
48 -> pure ObjReg
75
- #if defined(VERILOG_2001)
76
93
107 -> pure ObjCallback
77
- #endif
78
94
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 -}
1
2
{-|
2
3
Copyright: (C) 2022 Google Inc.
3
4
License: BSD2 (see the file LICENSE)
Original file line number Diff line number Diff line change
1
+ {- FOURMOLU_DISABLE -}
1
2
{-|
2
3
Copyright: (C) 2022 Google Inc.
3
4
License: BSD2 (see the file LICENSE)
Original file line number Diff line number Diff line change @@ -267,6 +267,8 @@ instance TShow CallbackReason where
267
267
<> pShow t
268
268
#endif
269
269
270
+ {- FOURMOLU_DISABLE -}
271
+
270
272
instance Monad m => Serial m CallbackReason where
271
273
series =
272
274
(AfterValueChange <$> obj <~> series <~> series)
@@ -311,6 +313,8 @@ instance Monad m => Serial m CallbackReason where
311
313
mObj :: Series m (Maybe Object )
312
314
mObj = series
313
315
316
+ {- FOURMOLU_ENABLE -}
317
+
314
318
-- Additional Clash.FFI.VPI.Control.Control Instances
315
319
316
320
instance TShow Control
@@ -398,6 +402,7 @@ instance Monad m => Serial m (Property CInt) where
398
402
instance Monad m => Serial m (Property CString ) where
399
403
series = foldl (\/) (pure Name ) $ map pure [FullName , File ]
400
404
405
+ {- FOURMOLU_DISABLE -}
401
406
instance Monad m => Serial m (Property Bool ) where
402
407
series =
403
408
foldl (\/) (pure IsScalar ) $ map pure
@@ -407,6 +412,7 @@ instance Monad m => Serial m (Property Bool) where
407
412
, IsLocalParam
408
413
#endif
409
414
]
415
+ {- FOURMOLU_ENABLE -}
410
416
411
417
-- Additional Clash.FFI.VPI.Object.Time.TimeType Instances
412
418
You can’t perform that action at this time.
0 commit comments