Skip to content

Commit 1172c0b

Browse files
committed
clash-ffi: Fixup files for formatting compatibility
1 parent fbd7cd8 commit 1172c0b

File tree

13 files changed

+156
-80
lines changed

13 files changed

+156
-80
lines changed

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

+10-1
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

+4
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

+2-2
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

+5-7
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

+31-5
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

+1
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

+1
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

+6
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

clash-ghc/src-ghc/Clash/GHC/ClashFlags.hs

+9-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ parseClashFlags :: IORef ClashOpts -> [Located String]
4343
-> IO ([Located String],[Warn])
4444
parseClashFlags r = parseClashFlagsFull (flagsClash r)
4545

46-
parseClashFlagsFull :: [Flag IO] -> [Located String]
47-
-> IO ([Located String],[Warn])
48-
parseClashFlagsFull flagsAvialable args = do
49-
(leftovers,errs,warns) <- processArgs flagsAvialable args
46+
processGhcArgs :: [Flag IO] -> [Located String] -> IO ([Located String], [Err], [Warn])
5047
#if MIN_VERSION_ghc(9,4,0)
51-
parseResponseFile
48+
processGhcArgs flagsAvailable args = processArgs flagsAvailable args parseResponseFile
49+
#else
50+
processGhcArgs flagsAvailable args = processArgs flagsAvailable args
5251
#endif
5352

53+
parseClashFlagsFull :: [Flag IO] -> [Located String]
54+
-> IO ([Located String],[Warn])
55+
parseClashFlagsFull flagsAvailable args = do
56+
(leftovers,errs,warns) <- processGhcArgs flagsAvailable args
57+
5458
unless (null errs) $ throwGhcExceptionIO $
5559
errorsToGhcException . map (("on the commandline", ) . unLoc . errMsg)
5660
$ errs

clash-ghc/src-ghc/Clash/GHC/Evaluator.hs

+20-15
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,23 @@ instantiate tcm pVal@(PrimVal (PrimInfo{primType}) tys es) ty m
367367

368368
instantiate _ p _ _ = error $ "Evaluator.instantiate: Not a tylambda: " ++ show p
369369

370+
getByteArrayIP :: Integer -> BA.ByteArray#
371+
#if MIN_VERSION_base(4,15,0)
372+
getByteArrayIP !(IP ba0) = ba0
373+
#else
374+
getByteArrayIP !(Jp# !(BN# ba0)) = ba0
375+
#endif
376+
getByteArrayIP _ = error "getByteArrayIP: not IP"
377+
378+
getByteArrayIN :: Integer -> BA.ByteArray#
379+
#if MIN_VERSION_base(4,15,0)
380+
getByteArrayIN !(IN ba0) = ba0
381+
#else
382+
getByteArrayIN !(Jn# !(BN# ba0)) = ba0
383+
#endif
384+
getByteArrayIN _ = error "getByteArrayIN: not IN"
385+
386+
370387
-- | Evaluate a case-expression
371388
scrutinise :: Value -> Type -> [Alt] -> Machine -> Machine
372389
scrutinise v _altTy [] m = setTerm (valToTerm v) m
@@ -390,19 +407,11 @@ scrutinise (Lit l) _altTy alts m = case alts of
390407
1 | l1 >= ((-2)^(63::Int)) && l1 < 2^(63::Int) ->
391408
Just (IntLiteral l1)
392409
2 | l1 >= (2^(63::Int)) ->
393-
#if MIN_VERSION_base(4,15,0)
394-
let !(IP ba0) = l1
395-
#else
396-
let !(Jp# !(BN# ba0)) = l1
397-
#endif
410+
let ba0 = getByteArrayIP l1
398411
ba1 = BA.ByteArray ba0
399412
in Just (ByteArrayLiteral ba1)
400413
3 | l1 < ((-2)^(63::Int)) ->
401-
#if MIN_VERSION_base(4,15,0)
402-
let !(IN ba0) = l1
403-
#else
404-
let !(Jn# !(BN# ba0)) = l1
405-
#endif
414+
let ba0 = getByteArrayIN l1
406415
ba1 = BA.ByteArray ba0
407416
in Just (ByteArrayLiteral ba1)
408417
_ -> Nothing
@@ -415,11 +424,7 @@ scrutinise (Lit l) _altTy alts m = case alts of
415424
1 | l1 >= 0 && l1 < 2^(64::Int) ->
416425
Just (WordLiteral l1)
417426
2 | l1 >= (2^(64::Int)) ->
418-
#if MIN_VERSION_base(4,15,0)
419-
let !(IP ba0) = l1
420-
#else
421-
let !(Jp# !(BN# ba0)) = l1
422-
#endif
427+
let ba0 = getByteArrayIP l1
423428
ba1 = BA.ByteArray ba0
424429
in Just (ByteArrayLiteral ba1)
425430
_ -> Nothing

clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{- FOURMOLU_DISABLE -}
2+
13
{-|
24
Copyright : (C) 2013-2016, University of Twente,
35
2016-2017, Myrtle Software Ltd,

clash-ghc/src-ghc/Clash/GHC/GHC2Core.hs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{- FOURMOLU_DISABLE -}
2+
13
{-|
24
Copyright : (C) 2013-2016, University of Twente,
35
2016-2017, Myrtle Software Ltd,

0 commit comments

Comments
 (0)