Skip to content

Commit b242d02

Browse files
authored
Merge pull request #2558 from clash-lang/clash-ffi-update
Ditch `ContT` from `clash-ffi`
2 parents 63b90ce + d9f0a45 commit b242d02

File tree

26 files changed

+787
-953
lines changed

26 files changed

+787
-953
lines changed

clash-ffi/clash-ffi.cabal

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.2
22

33
name: clash-ffi
4-
version: 1.5.0
4+
version: 1.7.0
55
synopsis: Interact with Simulators from Clash
66
description: Interact with Simulators from Clash
77
bug-reports: https://github.com/clash-lang/clash-compiler/issues
@@ -41,14 +41,15 @@ library
4141
DeriveGeneric
4242
DerivingStrategies
4343
GeneralizedNewtypeDeriving
44+
LambdaCase
45+
RecordWildCards
46+
TupleSections
4447
build-depends:
4548
derive-storable >= 0.3 && < 0.4,
4649
derive-storable-plugin >= 0.2 && < 0.3,
47-
mtl >= 2.2 && < 2.4,
4850
hs-source-dirs: src
4951
c-sources: cbits/entry_vpi.c
5052
exposed-modules:
51-
Clash.FFI.Monad
5253
Clash.FFI.View
5354
Clash.FFI.VPI.Callback
5455
Clash.FFI.VPI.Callback.Reason

clash-ffi/example/Simulate.hs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Data.Bits (complement)
99
import Data.List (intercalate, zip5)
1010
import Control.Exception (SomeException, try)
1111
import Control.Monad (void)
12-
import Control.Monad.IO.Class (liftIO)
1312
import Foreign.C.String (newCString)
1413
import Foreign.Marshal.Alloc (free)
1514

@@ -20,7 +19,6 @@ import Clash.Prelude
2019
, low, high, pack, unpack, resize
2120
)
2221

23-
import Clash.FFI.Monad
2422
import Clash.FFI.VPI.Info
2523
import Clash.FFI.VPI.IO
2624
import Clash.FFI.VPI.Callback
@@ -49,7 +47,7 @@ foreign export ccall "clash_ffi_main"
4947
ffiMain :: IO ()
5048

5149
ffiMain :: IO ()
52-
ffiMain = runSimAction $ do
50+
ffiMain = do
5351
--------------------------
5452
-- print simulator info --
5553
--------------------------
@@ -122,7 +120,7 @@ ffiMain = runSimAction $ do
122120
4 -> "<=>" -- mixed input-output
123121
_ -> "x" -- no direction
124122

125-
assignInputs :: (?state :: State) => SimAction ()
123+
assignInputs :: (?state :: State) => IO ()
126124
assignInputs = do
127125
SimTime time <- receiveTime Sim $ Just top
128126

@@ -163,7 +161,7 @@ assignInputs = do
163161
sendValue port (BitVectorVal SNat $ pack v) $ InertialDelay $ SimTime 0
164162
return $ Just v
165163

166-
readOutputs :: (?state :: State) => SimAction ()
164+
readOutputs :: (?state :: State) => IO ()
167165
readOutputs = do
168166
SimTime time <- receiveTime Sim $ Just top
169167
receiveValue VectorFmt dataOut >>= \case
@@ -174,14 +172,14 @@ readOutputs = do
174172
}
175173
_ -> return ()
176174

177-
if (steps > 0) then do
175+
if steps > 0 then do
178176
let ?state = ?state { steps = steps - 1 }
179177
nextCB ReadWriteSynch 1 assignInputs
180178
else do
181179
putStrLn ""
182180
putStrLn "[ Simulation done ]"
183181

184-
liftIO $ void $ try @SomeException $ runSimAction
182+
void $ try @SomeException
185183
$ controlSimulator $ Finish NoDiagnostics
186184

187185
where
@@ -226,31 +224,31 @@ updates = Updates 0 Nothing Nothing Nothing Nothing Nothing
226224
nextCB ::
227225
(Maybe Object -> Time -> CallbackReason) ->
228226
Int64 ->
229-
SimAction () ->
230-
SimAction ()
227+
IO () ->
228+
IO ()
231229
nextCB reason time action =
232230
void $ registerCallback
233231
CallbackInfo
234232
{ cbReason = reason Nothing (SimTime time)
235-
, cbRoutine = const (runSimAction action >> return 0)
233+
, cbRoutine = const (action >> return 0)
236234
, cbIndex = 0
237235
, cbData = B.empty
238236
}
239237

240238
getByName ::
241239
(Coercible a Object, Show a, Typeable a, Coercible Object b) =>
242-
Maybe a -> B.ByteString -> SimCont o b
240+
Maybe a -> B.ByteString -> IO b
243241
getByName m name = do
244-
ref <- liftIO $ newCString $ B.unpack name
242+
ref <- newCString $ B.unpack name
245243
obj <- getChild ref m
246-
liftIO $ free ref
244+
free ref
247245
return obj
248246

249-
putStr :: String -> SimAction ()
247+
putStr :: String -> IO ()
250248
putStr = simPutStr . B.pack
251249

252-
putStrLn :: String -> SimAction ()
250+
putStrLn :: String -> IO ()
253251
putStrLn = simPutStrLn . B.pack
254252

255-
print :: Show a => a -> SimAction ()
253+
print :: Show a => a -> IO ()
256254
print = simPutStrLn . B.pack . show

clash-ffi/src/Clash/FFI/Monad.hs

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)