From d821bbe66596b402a93c3189d5497e4d287f6a83 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 14 Nov 2019 19:48:38 +0000 Subject: Support proper Quartus Pro version --- bugs/quartus_12.md | 2 +- src/Verismith/Config.hs | 30 +++++++++------ src/Verismith/Report.hs | 68 ++++++++++++++++++++------------- src/Verismith/Tool.hs | 4 ++ src/Verismith/Tool/QuartusLight.hs | 78 ++++++++++++++++++++++++++++++++++++++ src/Verismith/Tool/Template.hs | 26 +++++++++++-- verismith.cabal | 1 + 7 files changed, 168 insertions(+), 41 deletions(-) create mode 100644 src/Verismith/Tool/QuartusLight.hs diff --git a/bugs/quartus_12.md b/bugs/quartus_12.md index 24469ce..ff4bef0 100644 --- a/bugs/quartus_12.md +++ b/bugs/quartus_12.md @@ -4,7 +4,7 @@ ## Affected versions -- Quartus 19.1 +- Quartus Prime Light 19.1 ## Description diff --git a/src/Verismith/Config.hs b/src/Verismith/Config.hs index decf1fb..66a8560 100644 --- a/src/Verismith/Config.hs +++ b/src/Verismith/Config.hs @@ -36,6 +36,7 @@ module Verismith.Config , fromYosys , fromVivado , fromQuartus + , fromQuartusLight , configProbability , configProperty , configSimulators @@ -79,20 +80,21 @@ module Verismith.Config ) where -import Control.Applicative (Alternative) -import Control.Lens hiding ((.=)) -import Data.List.NonEmpty (NonEmpty (..)) -import Data.Maybe (fromMaybe) -import Data.Text (Text, pack) -import qualified Data.Text.IO as T -import Data.Version (showVersion) +import Control.Applicative (Alternative) +import Control.Lens hiding ((.=)) +import Data.List.NonEmpty (NonEmpty (..)) +import Data.Maybe (fromMaybe) +import Data.Text (Text, pack) +import qualified Data.Text.IO as T +import Data.Version (showVersion) import Development.GitRev -import Hedgehog.Internal.Seed (Seed) -import Paths_verismith (version) -import Shelly (toTextIgnore) -import Toml (TomlCodec, (.=)) +import Hedgehog.Internal.Seed (Seed) +import Paths_verismith (version) +import Shelly (toTextIgnore) +import Toml (TomlCodec, (.=)) import qualified Toml import Verismith.Tool.Quartus +import Verismith.Tool.QuartusLight import Verismith.Tool.Vivado import Verismith.Tool.XST import Verismith.Tool.Yosys @@ -287,6 +289,12 @@ fromQuartus (Quartus a b c) = SynthDescription "quartus" (Just b) (Just $ toTextIgnore c) +fromQuartusLight :: QuartusLight -> SynthDescription +fromQuartusLight (QuartusLight a b c) = SynthDescription "quartuslight" + (toTextIgnore <$> a) + (Just b) + (Just $ toTextIgnore c) + defaultConfig :: Config defaultConfig = Config (Info (pack $(gitHash)) (pack $ showVersion version)) diff --git a/src/Verismith/Report.hs b/src/Verismith/Report.hs index dbaf613..e2707ea 100644 --- a/src/Verismith/Report.hs +++ b/src/Verismith/Report.hs @@ -35,6 +35,7 @@ module Verismith.Report , defaultYosysSynth , defaultXSTSynth , defaultQuartusSynth + , defaultQuartusLightSynth , defaultIdentitySynth , descriptionToSim , descriptionToSynth @@ -76,47 +77,54 @@ data SynthTool = XSTSynth {-# UNPACK #-} !XST | VivadoSynth {-# UNPACK #-} !Vivado | YosysSynth {-# UNPACK #-} !Yosys | QuartusSynth {-# UNPACK #-} !Quartus + | QuartusLightSynth {-# UNPACK #-} !QuartusLight | IdentitySynth {-# UNPACK #-} !Identity deriving (Eq) instance NFData SynthTool where - rnf (XSTSynth a) = rnf a - rnf (VivadoSynth a) = rnf a - rnf (YosysSynth a) = rnf a - rnf (QuartusSynth a) = rnf a - rnf (IdentitySynth a) = rnf a + rnf (XSTSynth a) = rnf a + rnf (VivadoSynth a) = rnf a + rnf (YosysSynth a) = rnf a + rnf (QuartusSynth a) = rnf a + rnf (QuartusLightSynth a) = rnf a + rnf (IdentitySynth a) = rnf a instance Show SynthTool where - show (XSTSynth xst) = show xst - show (VivadoSynth vivado) = show vivado - show (YosysSynth yosys) = show yosys - show (QuartusSynth quartus) = show quartus - show (IdentitySynth identity) = show identity + show (XSTSynth xst) = show xst + show (VivadoSynth vivado) = show vivado + show (YosysSynth yosys) = show yosys + show (QuartusSynth quartus) = show quartus + show (QuartusLightSynth quartus) = show quartus + show (IdentitySynth identity) = show identity instance Tool SynthTool where - toText (XSTSynth xst) = toText xst - toText (VivadoSynth vivado) = toText vivado - toText (YosysSynth yosys) = toText yosys - toText (QuartusSynth quartus) = toText quartus - toText (IdentitySynth identity) = toText identity + toText (XSTSynth xst) = toText xst + toText (VivadoSynth vivado) = toText vivado + toText (YosysSynth yosys) = toText yosys + toText (QuartusSynth quartus) = toText quartus + toText (QuartusLightSynth quartus) = toText quartus + toText (IdentitySynth identity) = toText identity instance Synthesiser SynthTool where - runSynth (XSTSynth xst) = runSynth xst - runSynth (VivadoSynth vivado) = runSynth vivado - runSynth (YosysSynth yosys) = runSynth yosys - runSynth (QuartusSynth quartus) = runSynth quartus - runSynth (IdentitySynth identity) = runSynth identity - - synthOutput (XSTSynth xst) = synthOutput xst - synthOutput (VivadoSynth vivado) = synthOutput vivado - synthOutput (YosysSynth yosys) = synthOutput yosys - synthOutput (QuartusSynth quartus) = synthOutput quartus - synthOutput (IdentitySynth identity) = synthOutput identity + runSynth (XSTSynth xst) = runSynth xst + runSynth (VivadoSynth vivado) = runSynth vivado + runSynth (YosysSynth yosys) = runSynth yosys + runSynth (QuartusSynth quartus) = runSynth quartus + runSynth (QuartusLightSynth quartus) = runSynth quartus + runSynth (IdentitySynth identity) = runSynth identity + + synthOutput (XSTSynth xst) = synthOutput xst + synthOutput (VivadoSynth vivado) = synthOutput vivado + synthOutput (YosysSynth yosys) = synthOutput yosys + synthOutput (QuartusSynth quartus) = synthOutput quartus + synthOutput (QuartusLightSynth quartus) = synthOutput quartus + synthOutput (IdentitySynth identity) = synthOutput identity setSynthOutput (YosysSynth yosys) = YosysSynth . setSynthOutput yosys setSynthOutput (XSTSynth xst) = XSTSynth . setSynthOutput xst setSynthOutput (VivadoSynth vivado) = VivadoSynth . setSynthOutput vivado setSynthOutput (QuartusSynth quartus) = QuartusSynth . setSynthOutput quartus + setSynthOutput (QuartusLightSynth quartus) = QuartusLightSynth . setSynthOutput quartus setSynthOutput (IdentitySynth identity) = IdentitySynth . setSynthOutput identity defaultYosysSynth :: SynthTool @@ -125,6 +133,9 @@ defaultYosysSynth = YosysSynth defaultYosys defaultQuartusSynth :: SynthTool defaultQuartusSynth = QuartusSynth defaultQuartus +defaultQuartusLightSynth :: SynthTool +defaultQuartusLightSynth = QuartusLightSynth defaultQuartusLight + defaultVivadoSynth :: SynthTool defaultVivadoSynth = VivadoSynth defaultVivado @@ -228,6 +239,11 @@ descriptionToSynth (SynthDescription "quartus" bin desc out) = . Quartus (fromText <$> bin) (fromMaybe (quartusDesc defaultQuartus) desc) $ maybe (quartusOutput defaultQuartus) fromText out +descriptionToSynth (SynthDescription "quartuslight" bin desc out) = + QuartusLightSynth + . QuartusLight (fromText <$> bin) + (fromMaybe (quartusDesc defaultQuartus) desc) + $ maybe (quartusOutput defaultQuartus) fromText out descriptionToSynth (SynthDescription "identity" _ desc out) = IdentitySynth . Identity (fromMaybe (identityDesc defaultIdentity) desc) diff --git a/src/Verismith/Tool.hs b/src/Verismith/Tool.hs index 7e41180..a9a153d 100644 --- a/src/Verismith/Tool.hs +++ b/src/Verismith/Tool.hs @@ -29,6 +29,9 @@ module Verismith.Tool -- ** Quartus , Quartus(..) , defaultQuartus + -- ** Quartus Light + , QuartusLight(..) + , defaultQuartusLight -- ** Identity , Identity(..) , defaultIdentity @@ -46,6 +49,7 @@ import Verismith.Tool.Icarus import Verismith.Tool.Identity import Verismith.Tool.Internal import Verismith.Tool.Quartus +import Verismith.Tool.QuartusLight import Verismith.Tool.Vivado import Verismith.Tool.XST import Verismith.Tool.Yosys diff --git a/src/Verismith/Tool/QuartusLight.hs b/src/Verismith/Tool/QuartusLight.hs new file mode 100644 index 0000000..86c9a3a --- /dev/null +++ b/src/Verismith/Tool/QuartusLight.hs @@ -0,0 +1,78 @@ +{-| +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 Prelude hiding (FilePath) +import Shelly +import Shelly.Lifted (liftSh) +import Verismith.Tool.Internal +import Verismith.Tool.Template +import Verismith.Verilog.AST +import Verismith.Verilog.CodeGen + +data QuartusLight = QuartusLight { quartusLightBin :: !(Maybe FilePath) + , quartusLightDesc :: {-# UNPACK #-} !Text + , quartusLightOutput :: {-# UNPACK #-} !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 :: QuartusLight -> SourceInfo -> 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 $ quartusSynthConfig 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" diff --git a/src/Verismith/Tool/Template.hs b/src/Verismith/Tool/Template.hs index 5402702..3bd5a2d 100644 --- a/src/Verismith/Tool/Template.hs +++ b/src/Verismith/Tool/Template.hs @@ -16,6 +16,7 @@ module Verismith.Tool.Template ( yosysSynthConfigStd , yosysSatConfig , yosysSimConfig + , quartusLightSynthConfig , quartusSynthConfig , xstSynthConfig , vivadoSynthConfig @@ -77,10 +78,10 @@ yosysSimConfig = [st|read_verilog rtl.v; proc;; rename mod mod_rtl |] -quartusSynthConfig :: Synthesiser a => a -> FilePath -> Text -> FilePath -> Text -quartusSynthConfig q sdc top fp = [st|load_package flow +quartusLightSynthConfig :: Synthesiser a => a -> FilePath -> Text -> FilePath -> Text +quartusLightSynthConfig q sdc top fp = [st|load_package flow -project_new #{top} +project_new -overwrite #{top} set_global_assignment -name FAMILY "Cyclone V" set_global_assignment -name SYSTEMVERILOG_FILE #{toTextIgnore fp} @@ -98,6 +99,25 @@ execute_module -tool eda -args "--simulation --tool=vcs" project_close |] +quartusSynthConfig :: Synthesiser a => a -> FilePath -> Text -> FilePath -> Text +quartusSynthConfig q sdc top fp = [st|load_package flow + +project_new -overwrite #{top} + +set_global_assignment -name FAMILY "Cyclone 10 GX" +set_global_assignment -name SYSTEMVERILOG_FILE #{toTextIgnore fp} +set_global_assignment -name TOP_LEVEL_ENTITY #{top} +set_global_assignment -name SDC_FILE #{toTextIgnore sdc} +set_global_assignment -name INI_VARS "qatm_force_vqm=on;" +set_global_assignment -name NUM_PARALLEL_PROCESSORS 2 +set_instance_assignment -name VIRTUAL_PIN ON -to * + +execute_module -tool syn +execute_module -tool eda -args "--simulation --tool=vcs" + +project_close +|] + xstSynthConfig :: Text -> Text xstSynthConfig top = [st|run -ifn #{top}.prj -ofn #{top} -p artix7 -top #{top} diff --git a/verismith.cabal b/verismith.cabal index 76fc97b..57849c1 100644 --- a/verismith.cabal +++ b/verismith.cabal @@ -60,6 +60,7 @@ library , Verismith.Tool.Identity , Verismith.Tool.Internal , Verismith.Tool.Quartus + , Verismith.Tool.QuartusLight , Verismith.Tool.Template , Verismith.Tool.Vivado , Verismith.Tool.XST -- cgit