-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Add ClashFloPoCo #23
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
* Add Lattice Semi SB_IO primitive | ||
* Add UART core | ||
* Add CRC core | ||
* Add Clash FloPoCo library |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ packages: | |
clash-cores.cabal | ||
hdl-tests | ||
|
||
|
||
package clash-cores | ||
ghc-options: +RTS -qn4 -A128M -RTS -j4 | ||
|
||
|
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. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -59,6 +59,7 @@ common basic-config | |||||
default-language: Haskell2010 | ||||||
|
||||||
default-extensions: | ||||||
BangPatterns | ||||||
BinaryLiterals | ||||||
DataKinds | ||||||
DefaultSignatures | ||||||
|
@@ -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) | ||||||
|
@@ -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: | ||||||
|
@@ -194,6 +203,7 @@ library | |||||
other-modules: | ||||||
Data.Text.Extra | ||||||
|
||||||
|
||||||
ghc-options: | ||||||
-fexpose-all-unfoldings | ||||||
-fno-worker-wrapper | ||||||
|
@@ -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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add version bounds
Suggested change
|
||||||
|
||||||
test-suite unit-tests | ||||||
import: basic-config | ||||||
|
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
|
||||||
-- 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 |
There was a problem hiding this comment.
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