module Verismith.Tool.Vivado
( Vivado (..),
defaultVivado,
)
where
import Control.DeepSeq (NFData, rnf, rwhnf)
import Data.Text (Text, unpack)
import Shelly
import Shelly.Lifted (liftSh)
import Verismith.Tool.Internal
import Verismith.Tool.Template
import Verismith.Verilog.AST
import Verismith.Verilog.CodeGen
import Prelude hiding (FilePath)
data Vivado = Vivado
{ Vivado -> Maybe FilePath
vivadoBin :: !(Maybe FilePath),
Vivado -> Text
vivadoDesc :: !Text,
Vivado -> FilePath
vivadoOutput :: !FilePath
}
deriving (Vivado -> Vivado -> Bool
(Vivado -> Vivado -> Bool)
-> (Vivado -> Vivado -> Bool) -> Eq Vivado
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Vivado -> Vivado -> Bool
== :: Vivado -> Vivado -> Bool
$c/= :: Vivado -> Vivado -> Bool
/= :: Vivado -> Vivado -> Bool
Eq)
instance Tool Vivado where
toText :: Vivado -> Text
toText (Vivado Maybe FilePath
_ Text
t FilePath
_) = Text
t
instance Show Vivado where
show :: Vivado -> FilePath
show Vivado
t = Text -> FilePath
unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ Vivado -> Text
forall a. Tool a => a -> Text
toText Vivado
t
instance Synthesiser Vivado where
runSynth :: forall ann. Show ann => Vivado -> SourceInfo ann -> ResultSh ()
runSynth = Vivado -> SourceInfo ann -> ResultSh ()
forall ann. Show ann => Vivado -> SourceInfo ann -> ResultSh ()
runSynthVivado
synthOutput :: Vivado -> FilePath
synthOutput = Vivado -> FilePath
vivadoOutput
setSynthOutput :: Vivado -> FilePath -> Vivado
setSynthOutput (Vivado Maybe FilePath
a Text
b FilePath
_) = Maybe FilePath -> Text -> FilePath -> Vivado
Vivado Maybe FilePath
a Text
b
instance NFData Vivado where
rnf :: Vivado -> ()
rnf = Vivado -> ()
forall a. a -> ()
rwhnf
defaultVivado :: Vivado
defaultVivado :: Vivado
defaultVivado = Maybe FilePath -> Text -> FilePath -> Vivado
Vivado Maybe FilePath
forall a. Maybe a
Nothing Text
"vivado" FilePath
"syn_vivado.v"
runSynthVivado :: (Show ann) => Vivado -> (SourceInfo ann) -> ResultSh ()
runSynthVivado :: forall ann. Show ann => Vivado -> SourceInfo ann -> ResultSh ()
runSynthVivado Vivado
sim (SourceInfo Text
top Verilog ann
src) = do
FilePath
dir <- Sh FilePath -> ResultT Failed Sh FilePath
forall a. Sh a -> ResultT Failed Sh a
forall (m :: * -> *) a. MonadSh m => Sh a -> m a
liftSh Sh FilePath
pwd
Sh () -> ResultSh ()
forall a. Sh a -> ResultT Failed Sh a
forall (m :: * -> *) a. MonadSh m => Sh a -> m a
liftSh (Sh () -> ResultSh ()) -> Sh () -> ResultSh ()
forall a b. (a -> b) -> a -> b
$ do
FilePath -> Text -> Sh ()
writefile FilePath
vivadoTcl (Text -> Sh ()) -> (FilePath -> Text) -> FilePath -> Sh ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
vivadoSynthConfig Text
top (Text -> Text) -> (FilePath -> Text) -> FilePath -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
toTextIgnore (FilePath -> Sh ()) -> FilePath -> Sh ()
forall a b. (a -> b) -> a -> b
$
Vivado -> FilePath
forall a. Synthesiser a => a -> FilePath
synthOutput
Vivado
sim
FilePath -> Text -> Sh ()
writefile FilePath
"rtl.v" (Text -> Sh ()) -> Text -> Sh ()
forall a b. (a -> b) -> a -> b
$ Verilog ann -> Text
forall a. Source a => a -> Text
genSource Verilog ann
src
FilePath -> [Text] -> Sh ()
run_
FilePath
"sed"
[ Text
"s/^module/(* use_dsp48=\"no\" *) (* use_dsp=\"no\" *) module/;",
Text
"-i",
Text
"rtl.v"
]
let exec_ :: Text -> [Text] -> ResultT Failed m ()
exec_ Text
n =
Failed
-> FilePath -> Text -> FilePath -> [Text] -> ResultT Failed m ()
forall (m :: * -> *).
(MonadSh m, Monad m) =>
Failed
-> FilePath -> Text -> FilePath -> [Text] -> ResultT Failed m ()
execute_
Failed
SynthFail
FilePath
dir
Text
"vivado"
(FilePath -> ShowS -> Maybe FilePath -> FilePath
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> FilePath
fromText Text
n) (FilePath -> ShowS
forall filepath1 filepath2.
(ToFilePath filepath1, ToFilePath filepath2) =>
filepath1 -> filepath2 -> FilePath
</> Text -> FilePath
fromText Text
n) (Maybe FilePath -> FilePath) -> Maybe FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ Vivado -> Maybe FilePath
vivadoBin Vivado
sim)
Text -> [Text] -> ResultSh ()
forall {m :: * -> *}.
MonadSh m =>
Text -> [Text] -> ResultT Failed m ()
exec_ Text
"vivado" [Text
"-mode", Text
"batch", Text
"-source", FilePath -> Text
toTextIgnore FilePath
vivadoTcl]
where
vivadoTcl :: FilePath
vivadoTcl = Text -> FilePath
fromText (Text
"vivado_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
top) FilePath -> Text -> FilePath
forall filepath.
ToFilePath filepath =>
filepath -> Text -> FilePath
<.> Text
"tcl"