aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Sim/XST.hs
blob: b5b1b8b267ef9d7d43a231e4c97322584a260561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-|
Module      : VeriFuzz.Sim.XST
Description : XST (ise) simulator implementation.
Copyright   : (c) 2018-2019, Yann Herklotz
License     : BSD-3
Maintainer  : ymherklotz [at] gmail [dot] com
Stability   : experimental
Portability : POSIX

XST (ise) simulator implementation.
-}

{-# LANGUAGE QuasiQuotes #-}

module VeriFuzz.Sim.XST
    ( XST(..)
    , defaultXST
    )
where

import           Prelude                  hiding (FilePath)
import           Shelly
import           Shelly.Lifted            (liftSh)
import           Text.Shakespeare.Text    (st)
import           VeriFuzz.Sim.Internal
import           VeriFuzz.Sim.Template
import           VeriFuzz.Verilog.AST
import           VeriFuzz.Verilog.CodeGen

data XST = XST { xstPath    :: {-# UNPACK #-} !FilePath
               , netgenPath :: {-# UNPACK #-} !FilePath
               , xstOutput  :: {-# UNPACK #-} !FilePath
               }
         deriving (Eq)

instance Show XST where
    show _ = "xst"

instance Tool XST where
    toText _ = "xst"

instance Synthesiser XST where
    runSynth = runSynthXST
    synthOutput = xstOutput
    setSynthOutput (XST a b _) f = XST a b f

defaultXST :: XST
defaultXST = XST "xst" "netgen" "xst/syn_xst.v"

runSynthXST :: XST -> SourceInfo -> FilePath -> ResultSh ()
runSynthXST sim (SourceInfo top src) outf = do
    dir <- liftSh pwd
    let exec = execute_ SynthFail dir "xst"
    liftSh $ do
        writefile xstFile $ xstSynthConfig top
        writefile prjFile [st|verilog work "rtl.v"|]
        writefile "rtl.v" $ genSource src
        echoP "XST: run"
    exec (xstPath sim) ["-ifn", toTextIgnore xstFile]
    liftSh $ echoP "XST: netgen"
    exec
        (netgenPath sim)
        [ "-w"
        , "-ofmt"
        , "verilog"
        , toTextIgnore $ modFile <.> "ngc"
        , toTextIgnore outf
        ]
    liftSh $ do
        echoP "XST: clean"
        noPrint $ run_
            "sed"
            [ "-i"
            , "/^`ifndef/,/^`endif/ d; s/ *Timestamp: .*//;"
            , toTextIgnore outf
            ]
        echoP "XST: done"
  where
    modFile = fromText $ "xst_" <> top
    xstFile = modFile <.> "xst"
    prjFile = modFile <.> "prj"