Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClashFloPoCo #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* Add Lattice Semi SB_IO primitive
* Add UART core
* Add CRC core
* Add Clash FloPoCo library
1 change: 1 addition & 0 deletions cabal.project-common
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
clash-cores.cabal
hdl-tests


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra whitespace can be removed

package clash-cores
ghc-options: +RTS -qn4 -A128M -RTS -j4

Expand Down
24 changes: 24 additions & 0 deletions cabal.project-flopoco
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- This is add for VHDL block generation used by ClashFloPoCo library
source-repository-package
type: git
location: https://github.com/clash-lang/clash-compiler.git
tag: 5706eafca799ae04fda0ee7d666a40b6c0e7f22b
subdir: clash-prelude

source-repository-package
type: git
location: https://github.com/clash-lang/clash-compiler.git
tag: 5706eafca799ae04fda0ee7d666a40b6c0e7f22b
subdir: clash-ghc

source-repository-package
type: git
location: https://github.com/clash-lang/clash-compiler.git
tag: 5706eafca799ae04fda0ee7d666a40b6c0e7f22b
subdir: clash-lib
source-repository-package
type: git
location: https://github.com/clash-lang/clash-compiler.git
tag: 5706eafca799ae04fda0ee7d666a40b6c0e7f22b
subdir: tests
-- Eliminates the need for `--enable-tests`, which is needed for HLS.
11 changes: 11 additions & 0 deletions clash-cores.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ common basic-config
default-language: Haskell2010

default-extensions:
BangPatterns
BinaryLiterals
DataKinds
DefaultSignatures
Expand All @@ -75,6 +76,7 @@ common basic-config
TypeApplications
TypeFamilies
TypeOperators
QuasiQuotes

-- See https://github.com/clash-lang/clash-compiler/pull/2511
if impl(ghc >= 9.4)
Expand Down Expand Up @@ -177,6 +179,13 @@ library
Clash.Cores.Xilinx.Xpm.Cdc.Pulse
Clash.Cores.Xilinx.Xpm.Cdc.Single
Clash.Cores.Xilinx.Xpm.Cdc.SyncRst
Clash.Cores.ClashFloPoCo.FloPoCoCall
Clash.Cores.ClashFloPoCo.GenTemDSL
Clash.Cores.ClashFloPoCo.InfoEn
Clash.Cores.ClashFloPoCo.Lexer
Clash.Cores.ClashFloPoCo.Help,
Clash.Cores.ClashFloPoCo.Helpargs,
Clash.Cores.ClashFloPoCo.FloPoCoExample

if !flag(clash-18)
exposed-modules:
Expand All @@ -194,6 +203,7 @@ library
other-modules:
Data.Text.Extra


ghc-options:
-fexpose-all-unfoldings
-fno-worker-wrapper
Expand All @@ -210,6 +220,7 @@ library
text >= 1.2.2 && < 2.2,
constraints >= 0.9 && < 1.0,
template-haskell >= 2.12.0.0 && < 2.23,
process,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add version bounds

Suggested change
process,
process >= 1.6.5.0 && < 1.7,


test-suite unit-tests
import: basic-config
Expand Down
72 changes: 72 additions & 0 deletions src/Clash/Cores/ClashFloPoCo/FloPoCoCall.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- |
-- Copyright : (C) 2024, Hoang Minh Le <[email protected]>.
-- License : BSD2
-- Maintainer : QBayLogic B.V. <[email protected]>
module Clash.Cores.ClashFloPoCo.FloPoCoCall
( callFloPoCoWithInput, -- add this line to export the function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
( callFloPoCoWithInput, -- add this line to export the function
( callFloPoCoWithInput

)
where

import qualified Control.Monad.Fail as Fail
import Control.Monad.IO.Class (MonadIO, liftIO)
import System.IO (hClose, hFlush, hGetContents, hPutStrLn)
import System.Info (os)
import System.Process
import Prelude

-- | This function is to call FloPoCo to generate VHDL files from provided input
-- Work on Linux. For Window users, it can be used to call FloPoCo
-- directly from WSL without modification
--
-- Example usage with IO:
--
-- > main::IO
-- > main = do
-- > _ <- callFloPoCoWithInput "/home/user/flopoco/build/bin/flopoco"
-- > ["frequency=300", "target=Zynq7000", "FPAdd", "wE=8", "wF=23", "name=SinglePrecisionFPAdd", "registerLargeTables=1"]
-- > ""
-- > return ()
callFloPoCoWithInput ::
(MonadIO m, Fail.MonadFail m) =>
-- | The path where FloPoCo is installed or built
String ->
-- | List of input for FloPoCo
[String] ->
-- | Dummy input
String ->
-- | Return the output generated by FloPoCo
m String
callFloPoCoWithInput floPoCoPath args dummyinput = do
let (command, finalArgs) =
if os == "mingw32"
then ("wsl", floPoCoPath : args) -- On Windows, prepend "wsl"
else (floPoCoPath, args) -- On Linux, use the binary directly

-- Create the process with stdin, stdout, stderr pipes
(Just hin, Just hout, Just herr, _) <-
liftIO $
createProcess
(proc command finalArgs)
{ std_in = CreatePipe,
std_out = CreatePipe,
std_err = CreatePipe
}

-- Feed input to the process
liftIO $ do
hPutStrLn hin dummyinput
hFlush hin
hClose hin
Comment on lines +55 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed since you're only passing it dummy input. Then you can probably remove the dummyInput argument from the function definition also.


-- Read output from stdout
output <- liftIO $ hGetContents hout

-- Optionally print the output (for debugging purposes)
-- liftIO $ putStrLn output

-- Read error output from stderr (optional, for debugging)
errOutput <- liftIO $ hGetContents herr
liftIO $ putStrLn errOutput

-- Return the actual output as the result
return output
Loading