aboutsummaryrefslogtreecommitdiffstats
path: root/src/Verismith/Tool/QuartusLight.hs
blob: cab10877d693fdb3188791273f6462fb3f1cae5e (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      : Verismith.Tool.QuartusLight
-- Description : QuartusLight synthesiser implementation.
-- Copyright   : (c) 2019, Yann Herklotz Grave
-- License     : GPL-3
-- Maintainer  : yann [at] yannherklotz [dot] com
-- Stability   : experimental
-- Portability : POSIX
--
-- QuartusLight synthesiser implementation.
module Verismith.Tool.QuartusLight
  ( QuartusLight (..),
    defaultQuartusLight,
  )
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 QuartusLight
  = QuartusLight
      { quartusLightBin :: !(Maybe FilePath),
        quartusLightDesc :: !Text,
        quartusLightOutput :: !FilePath
      }
  deriving (Eq)

instance Tool QuartusLight where
  toText (QuartusLight _ t _) = t

instance Show QuartusLight where
  show t = unpack $ toText t

instance Synthesiser QuartusLight where
  runSynth = runSynthQuartusLight
  synthOutput = quartusLightOutput
  setSynthOutput (QuartusLight a b _) = QuartusLight a b

instance NFData QuartusLight where
  rnf = rwhnf

defaultQuartusLight :: QuartusLight
defaultQuartusLight = QuartusLight Nothing "quartus" "syn_quartus.v"

runSynthQuartusLight :: Show ann => QuartusLight -> (SourceInfo ann) -> ResultSh ()
runSynthQuartusLight sim (SourceInfo top src) = do
  dir <- liftSh pwd
  let ex = execute_ SynthFail dir "quartus"
  liftSh $ do
    writefile inpf $ genSource src
    noPrint $
      run_
        "sed"
        [ "-i",
          "s/^module/(* multstyle = \"logic\" *) module/;",
          toTextIgnore inpf
        ]
    writefile quartusSdc "create_clock -period 5 -name clk [get_ports clock]"
    writefile quartusTcl $ quartusLightSynthConfig sim quartusSdc top inpf
  ex (exec "quartus_sh") ["-t", toTextIgnore quartusTcl]
  liftSh $ do
    cp (fromText "simulation/vcs" </> fromText top <.> "vo") $
      synthOutput sim
    run_
      "sed"
      [ "-ri",
        "s,^// DATE.*,,; s,^tri1 (.*);,wire \\1 = 1;,; /^\\/\\/ +synopsys/ d;",
        toTextIgnore $ synthOutput sim
      ]
  where
    inpf = "rtl.v"
    exec s = maybe (fromText s) (</> fromText s) $ quartusLightBin sim
    quartusTcl = fromText top <.> "tcl"
    quartusSdc = fromText top <.> "sdc"