From bf08551fb9f37056eabaea9578d857c5de9489a3 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sat, 9 Mar 2024 00:58:52 +0300 Subject: [PATCH 01/22] replace toml to yaml --- app/Main.hs | 17 +++----- examples/microarch.toml | 46 --------------------- examples/microarch.yml | 32 ++++++++++++++ nitta.cabal | 8 ++-- package.yaml | 2 +- src/NITTA/Model/Microarchitecture/Config.hs | 39 ++++++++++++----- src/NITTA/Project/Template.hs | 32 +++++--------- src/NITTA/Utils.hs | 21 ---------- templates/Icarus/template.toml | 11 ----- templates/Icarus/template.yml | 7 ++++ 10 files changed, 88 insertions(+), 127 deletions(-) delete mode 100644 examples/microarch.toml create mode 100644 examples/microarch.yml delete mode 100644 templates/Icarus/template.toml create mode 100644 templates/Icarus/template.yml diff --git a/app/Main.hs b/app/Main.hs index 862a37efc..488fc190d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -40,7 +40,6 @@ import NITTA.Synthesis (TargetSynthesis (..), mlScoreKeyPrefix, noSynthesis, sta import NITTA.Synthesis.MlBackend.ServerInstance import NITTA.UIBackend import NITTA.UIBackend.Types (BackendCtx, mlBackendGetter, nodeScores, outputPath, receivedValues, root) -import NITTA.Utils import Paths_nitta import System.Console.CmdArgs hiding (def) import System.Exit @@ -199,8 +198,6 @@ nittaArgs = getNittaArgs :: IO Nitta getNittaArgs = cmdArgs nittaArgs -fromConf toml s = getFromTomlSection s =<< toml - main = do ( Nitta filename @@ -230,9 +227,7 @@ main = do -- it's critical for successful parsing of NITTA's stdout in python scripts hSetBuffering stdout LineBuffering - toml <- case uarch of - Nothing -> return Nothing - Just path -> Just . getToml <$> T.readFile path + conf <- parseConfig $ fromJust uarch let exactFrontendType = identifyFrontendType filename frontend_language @@ -241,17 +236,17 @@ main = do let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = translate exactFrontendType src received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] - ioSync = fromJust $ io_sync <|> fromConf toml "ioSync" <|> Just Sync - confMa = toml >>= Just . mkMicroarchitecture ioSync + ioSync_ = fromJust $ io_sync <|> Just (ioSync' conf) <|> Just Sync + confMa = Just (mkMicroarchitecture conf) ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma | auto_uarch && isJust confMa = error $ "auto_uarch flag means that an empty uarch with default prototypes will be used. " <> "Remove uarch flag or specify prototypes list in config file and remove auto_uarch." - | auto_uarch = microarchWithProtos ioSync + | auto_uarch = microarchWithProtos ioSync_ | isJust confMa = fromJust confMa - | otherwise = defMicroarch ioSync + | otherwise = defMicroarch ioSync_ infoM "NITTA" $ "will trace: " <> S.join ", " (map (show . tvVar) frTrace) @@ -302,7 +297,7 @@ main = do exitSuccess ) $ parseFX . fromJust - $ type_ <|> fromConf toml "type" <|> Just "fx32.32" + $ type_ <|> Just (T.unpack $ type' conf) <|> Just "fx32.32" parseFX input = let typePattern = mkRegex "fx([0-9]+).([0-9]+)" diff --git a/examples/microarch.toml b/examples/microarch.toml deleted file mode 100644 index 8ed5cfcf5..000000000 --- a/examples/microarch.toml +++ /dev/null @@ -1,46 +0,0 @@ -type = "fx32.32" -ioSync = "Sync" - -[[networks]] -name = "net1" - -# Array of PUs - -[[networks.pus]] -type = "SPI" -name = "spi" -mosi = "mosi" -miso = "miso" -sclk = "sclk" -cs = "cs" -isSlave = true -bufferSize = 6 -bounceFilter = 0 - -# Array of PU prototypes - -[[networks.protos]] -type = "Fram" -name = "fram{x}" # If you want a PU can be allocated only once, remove {x} from the PU name. -size = 32 - -[[networks.protos]] -type = "Shift" -name = "shift{x}" -sRight = true - -[[networks.protos]] -type = "Multiplier" -name = "mul{x}" -mock = true - -[[networks.protos]] -type = "Accum" -name = "accum{x}" -isInt = true - -[[networks.protos]] -type = "Divider" -name = "div{x}" -mock = true -pipeline = 4 diff --git a/examples/microarch.yml b/examples/microarch.yml new file mode 100644 index 000000000..84c269ce6 --- /dev/null +++ b/examples/microarch.yml @@ -0,0 +1,32 @@ +type: fx32.32 +ioSync: Sync +networks: + - name: net1 + pus: + - type: SPI + name: spi + mosi: mosi + miso: miso + sclk: sclk + cs: cs + isSlave: true + bufferSize: 6 + bounceFilter: 0 + protos: + - type: Fram + name: fram{x} # If you want a PU can be allocated only once, remove {x} from the PU name. + size: 32 + - type: Shift + name: shift{x} + sRight: true + - type: Multiplier + name: mul{x} + mock: true + - type: Accum + name: accum{x} + isInt: true + - type: Divider + name: div{x} + mock: true + pipeline: 4 + diff --git a/nitta.cabal b/nitta.cabal index 7c1e3ba5a..47b73944b 100644 --- a/nitta.cabal +++ b/nitta.cabal @@ -148,7 +148,6 @@ library , hashable , heap , hslogger - , htoml , http-api-data , http-conduit , hxt @@ -178,6 +177,7 @@ library , wai-app-static , wai-cors , warp + , yaml default-language: Haskell2010 executable nitta @@ -211,7 +211,6 @@ executable nitta , ginger , heap , hslogger - , htoml , intervals , mtl , nitta @@ -223,6 +222,7 @@ executable nitta , tostring , unordered-containers , wai-app-static + , yaml default-language: Haskell2010 executable nitta-api-gen @@ -259,7 +259,6 @@ executable nitta-api-gen , ginger , heap , hslogger - , htoml , intervals , mtl , nitta @@ -271,6 +270,7 @@ executable nitta-api-gen , tostring , unordered-containers , wai-app-static + , yaml default-language: Haskell2010 test-suite nitta-test @@ -337,7 +337,6 @@ test-suite nitta-test , genvalidity-property , ginger , heap - , htoml , hxt , intervals , language-lua @@ -359,4 +358,5 @@ test-suite nitta-test , tostring , unordered-containers , wai-app-static + , yaml default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 689b5f03d..1278107f5 100644 --- a/package.yaml +++ b/package.yaml @@ -61,7 +61,7 @@ dependencies: - data-default - filepath - ginger - - htoml + - yaml - intervals - mtl - prettyprinter diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 60f32e85b..5df6eb139 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -3,20 +3,26 @@ {-# LANGUAGE PartialTypeSignatures #-} module NITTA.Model.Microarchitecture.Config ( + MicroarchitectureConf (type', ioSync'), + parseConfig, mkMicroarchitecture, ) where import Data.Aeson ( - FromJSON (parseJSON), Options (sumEncoding), SumEncoding (TaggedObject, contentsFieldName, tagFieldName), - ToJSON (toJSON), defaultOptions, genericParseJSON, genericToJSON, ) import Data.Default (Default (def)) -import Data.HashMap.Internal.Strict (HashMap) +import Data.Yaml ( + decodeFileThrow, + (.:), + Value (Object), + FromJSON (parseJSON), + ToJSON (toJSON), + ) import Data.Text qualified as T import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) @@ -30,7 +36,6 @@ import NITTA.Model.Networks.Bus ( ) import NITTA.Model.Networks.Types (IOSynchronization) import NITTA.Model.ProcessorUnits qualified as PU -import NITTA.Utils (getFromToml) data PUConf = Accum @@ -86,16 +91,28 @@ data NetworkConf = NetworkConf instance FromJSON NetworkConf instance ToJSON NetworkConf -newtype MicroarchitectureConf = MicroarchitectureConf - { networks :: [NetworkConf] +data MicroarchitectureConf = MicroarchitectureConf + { type' :: T.Text + , ioSync' :: IOSynchronization + , networks :: [NetworkConf] } deriving (Generic, Show) -instance FromJSON MicroarchitectureConf +instance FromJSON MicroarchitectureConf where + parseJSON (Object v) = do + type' <- v .: "type" + ioSync' <- v .: "ioSync" + networks <- v .: "networks" + return MicroarchitectureConf { type' = type', ioSync' = ioSync', networks = networks } + parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf -mkMicroarchitecture :: (Val v, Var x, ToJSON a, ToJSON x) => IOSynchronization -> HashMap T.Text a -> BusNetwork T.Text x v Int -mkMicroarchitecture ioSync toml = +parseConfig :: FilePath -> IO MicroarchitectureConf +parseConfig path = do + decodeFileThrow path :: IO MicroarchitectureConf + +mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int +mkMicroarchitecture conf = let addPU proto | proto = addCustomPrototype | otherwise = addCustom @@ -125,8 +142,8 @@ mkMicroarchitecture ioSync toml = , master_sclk = PU.OutputPortTag sclk , master_cs = PU.OutputPortTag cs } - nets = networks (getFromToml toml :: MicroarchitectureConf) - mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name ioSync) (build net) + nets = networks conf + mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name $ ioSync' conf) (build net) in case nets of [n] -> mkNetwork n _ -> error "multi-networks are not currently supported" diff --git a/src/NITTA/Project/Template.hs b/src/NITTA/Project/Template.hs index f7311341c..5d362b332 100644 --- a/src/NITTA/Project/Template.hs +++ b/src/NITTA/Project/Template.hs @@ -31,6 +31,7 @@ import Data.Maybe import Data.String.Interpolate import Data.Text qualified as T import Data.Text.IO qualified as T +import Data.Yaml import GHC.Generics hiding (moduleName) import NITTA.Project.Context import NITTA.Project.Types @@ -39,13 +40,15 @@ import System.FilePath import System.Log.Logger import System.Path.WildMatch import Text.Ginger -import Text.Toml data Conf = Conf { template :: TemplateConf , signals :: M.HashMap T.Text T.Text } - deriving (Show) + deriving (Generic, Show) + +instance FromJSON Conf +instance ToJSON Conf data TemplateConf = TemplateConf { nittaPath :: Maybe FilePath @@ -54,7 +57,7 @@ data TemplateConf = TemplateConf deriving (Generic, Show) defNittaPath = "." -templateConfFileName = "template.toml" +templateConfFileName = "template.yml" instance Default TemplateConf where def = @@ -86,26 +89,11 @@ collectNittaPath templates = do where getNittaPath = fromMaybe (error "internal error") . nittaPath . template +readTemplateConfDef :: FilePath -> IO Conf readTemplateConfDef fn = do - text <- - doesFileExist fn >>= \case - True -> T.readFile fn - False -> return "" - let conf = either (error . show) id $ parseTomlDoc (fn <> ": parse error: ") text - return - Conf - { template = confLookup fn "template" conf - , signals = confLookup fn "signals" conf - } - -confLookup fn sec conf = - maybe - def - (unwrap (fn <> " in section [" <> T.unpack sec <> "]: ") . fromJSON . toJSON) - $ M.lookup sec conf - where - unwrap _prefix (Success a) = a - unwrap prefix (Error msg) = error $ prefix <> msg + doesFileExist fn >>= \case + True -> decodeFileThrow fn :: IO Conf + False -> return Conf{template = def, signals = def} applyCustomSignal signals diff --git a/src/NITTA/Utils.hs b/src/NITTA/Utils.hs index 440a2ed2a..951960d1b 100644 --- a/src/NITTA/Utils.hs +++ b/src/NITTA/Utils.hs @@ -33,16 +33,9 @@ module NITTA.Utils ( getIntermediates, isInstruction, module NITTA.Utils.Base, - - -- * Toml - getToml, - getFromToml, - getFromTomlSection, ) where -import Data.Aeson import Data.Bits (setBit, testBit) -import Data.HashMap.Strict qualified as HM import Data.List (sortOn) import Data.Maybe import Data.String.Utils qualified as S @@ -56,7 +49,6 @@ import Numeric.Interval.NonEmpty (inf, sup, (...)) import Numeric.Interval.NonEmpty qualified as I import Prettyprinter import Prettyprinter.Render.Text -import Text.Toml (parseTomlDoc) type Verilog = Doc () doc2text :: Verilog -> T.Text @@ -129,16 +121,3 @@ stepsInterval ss = in a ... b stepStart Step{pInterval} = I.inf pInterval - -getToml text = either (error . show) id $ parseTomlDoc "parse error: " text - -getFromToml toml = getFromTomlSection T.empty toml - -getFromTomlSection section toml - | section == T.empty = unwrap $ fromJSON $ toJSON toml - | otherwise = case HM.lookup section toml of - Just s -> unwrap $ fromJSON $ toJSON s - Nothing -> error $ "section not found - " <> T.unpack section - where - unwrap (Success conf) = conf - unwrap (Error msg) = error msg diff --git a/templates/Icarus/template.toml b/templates/Icarus/template.toml deleted file mode 100644 index 5a8c6403e..000000000 --- a/templates/Icarus/template.toml +++ /dev/null @@ -1,11 +0,0 @@ -# section for general parameters of template. -[template] -# subpath of nitta implementation (default: '.') -nittaPath = "." -# list of template files, which should be ignored (default: ['template.toml']) -ignore = ['template.toml'] - -# external signal names used in nitta instance -[signals] -rst = "rst" -clk = "clk" diff --git a/templates/Icarus/template.yml b/templates/Icarus/template.yml new file mode 100644 index 000000000..15b685341 --- /dev/null +++ b/templates/Icarus/template.yml @@ -0,0 +1,7 @@ +template: + nittaPath: "." + ignore: + - 'template.yml' +signals: + rst: rst + clk: clk \ No newline at end of file From e34fd57c01230a22765296cc7ed8c873c577fce3 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 17 Mar 2024 19:29:00 +0300 Subject: [PATCH 02/22] replace toml to yaml --- app/Main.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 488fc190d..f8b167569 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -226,8 +226,10 @@ main = do -- force line buffering (always, not just when stdout is connected to a tty), -- it's critical for successful parsing of NITTA's stdout in python scripts hSetBuffering stdout LineBuffering - - conf <- parseConfig $ fromJust uarch + + conf <- case uarch of + Nothing -> return Nothing + Just path -> return . Just =<< parseConfig path let exactFrontendType = identifyFrontendType filename frontend_language @@ -236,17 +238,17 @@ main = do let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = translate exactFrontendType src received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] - ioSync_ = fromJust $ io_sync <|> Just (ioSync' conf) <|> Just Sync - confMa = Just (mkMicroarchitecture conf) + ioSync = fromJust $ io_sync <|> (Just . ioSync' =<< conf) <|> Just Sync + confMa = Just . mkMicroarchitecture =<< conf ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma | auto_uarch && isJust confMa = error $ "auto_uarch flag means that an empty uarch with default prototypes will be used. " <> "Remove uarch flag or specify prototypes list in config file and remove auto_uarch." - | auto_uarch = microarchWithProtos ioSync_ + | auto_uarch = microarchWithProtos ioSync | isJust confMa = fromJust confMa - | otherwise = defMicroarch ioSync_ + | otherwise = defMicroarch ioSync infoM "NITTA" $ "will trace: " <> S.join ", " (map (show . tvVar) frTrace) @@ -297,7 +299,7 @@ main = do exitSuccess ) $ parseFX . fromJust - $ type_ <|> Just (T.unpack $ type' conf) <|> Just "fx32.32" + $ type_ <|> (Just . T.unpack . type' =<< conf) <|> Just "fx32.32" parseFX input = let typePattern = mkRegex "fx([0-9]+).([0-9]+)" From 1ee11fc12092dff272a18d8a4ab46c670df7156d Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 17 Mar 2024 19:53:08 +0300 Subject: [PATCH 03/22] clean up --- src/NITTA/Model/Microarchitecture/Config.hs | 14 +++++++------- src/NITTA/Project/Template.hs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 5df6eb139..38e5c29d1 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -16,14 +16,14 @@ import Data.Aeson ( genericToJSON, ) import Data.Default (Default (def)) +import Data.Text qualified as T import Data.Yaml ( - decodeFileThrow, - (.:), - Value (Object), FromJSON (parseJSON), ToJSON (toJSON), + Value (Object), + decodeFileThrow, + (.:), ) -import Data.Text qualified as T import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) import NITTA.Intermediate.Variable (Var) @@ -98,17 +98,17 @@ data MicroarchitectureConf = MicroarchitectureConf } deriving (Generic, Show) -instance FromJSON MicroarchitectureConf where +instance FromJSON MicroarchitectureConf where parseJSON (Object v) = do type' <- v .: "type" ioSync' <- v .: "ioSync" networks <- v .: "networks" - return MicroarchitectureConf { type' = type', ioSync' = ioSync', networks = networks } + return MicroarchitectureConf{type' = type', ioSync' = ioSync', networks = networks} parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf parseConfig :: FilePath -> IO MicroarchitectureConf -parseConfig path = do +parseConfig path = do decodeFileThrow path :: IO MicroarchitectureConf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int diff --git a/src/NITTA/Project/Template.hs b/src/NITTA/Project/Template.hs index 5d362b332..050bcda41 100644 --- a/src/NITTA/Project/Template.hs +++ b/src/NITTA/Project/Template.hs @@ -46,7 +46,7 @@ data Conf = Conf , signals :: M.HashMap T.Text T.Text } deriving (Generic, Show) - + instance FromJSON Conf instance ToJSON Conf From 48a2a43de033397d24375ae0e096025e643445cb Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 17 Mar 2024 19:55:13 +0300 Subject: [PATCH 04/22] clean up --- app/Main.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index f8b167569..8d6c083a7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -226,10 +226,9 @@ main = do -- force line buffering (always, not just when stdout is connected to a tty), -- it's critical for successful parsing of NITTA's stdout in python scripts hSetBuffering stdout LineBuffering - conf <- case uarch of - Nothing -> return Nothing - Just path -> return . Just =<< parseConfig path + Nothing -> return Nothing + Just path -> return . Just =<< parseConfig path let exactFrontendType = identifyFrontendType filename frontend_language From dc9c38c254cfbcf24d971dea849e787a4f4d164e Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 17 Mar 2024 20:09:22 +0300 Subject: [PATCH 05/22] clean up --- app/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 8d6c083a7..5bcc9dc5f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -228,7 +228,7 @@ main = do hSetBuffering stdout LineBuffering conf <- case uarch of Nothing -> return Nothing - Just path -> return . Just =<< parseConfig path + Just path -> Just <$> parseConfig path let exactFrontendType = identifyFrontendType filename frontend_language @@ -237,8 +237,8 @@ main = do let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = translate exactFrontendType src received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] - ioSync = fromJust $ io_sync <|> (Just . ioSync' =<< conf) <|> Just Sync - confMa = Just . mkMicroarchitecture =<< conf + ioSync = fromJust $ io_sync <|> ioSync' <$> conf <|> Just Sync + confMa = mkMicroarchitecture <$> conf ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma | auto_uarch && isJust confMa = @@ -298,7 +298,7 @@ main = do exitSuccess ) $ parseFX . fromJust - $ type_ <|> (Just . T.unpack . type' =<< conf) <|> Just "fx32.32" + $ type_ <|> T.unpack . type' <$> conf <|> Just "fx32.32" parseFX input = let typePattern = mkRegex "fx([0-9]+).([0-9]+)" From 0a4056d6789ded71fc311f68c4a57b6a69f07f0e Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 24 Mar 2024 20:52:55 +0300 Subject: [PATCH 06/22] fixes --- app/Main.hs | 4 ++-- src/NITTA/Model/Microarchitecture/Config.hs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 5bcc9dc5f..10e4fd8ce 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -237,7 +237,7 @@ main = do let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = translate exactFrontendType src received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] - ioSync = fromJust $ io_sync <|> ioSync' <$> conf <|> Just Sync + ioSync = fromJust $ io_sync <|> valueIoSync <$> conf <|> Just Sync confMa = mkMicroarchitecture <$> conf ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma @@ -298,7 +298,7 @@ main = do exitSuccess ) $ parseFX . fromJust - $ type_ <|> T.unpack . type' <$> conf <|> Just "fx32.32" + $ type_ <|> T.unpack . valueType <$> conf <|> Just "fx32.32" parseFX input = let typePattern = mkRegex "fx([0-9]+).([0-9]+)" diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 38e5c29d1..f92e0da13 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -3,7 +3,7 @@ {-# LANGUAGE PartialTypeSignatures #-} module NITTA.Model.Microarchitecture.Config ( - MicroarchitectureConf (type', ioSync'), + MicroarchitectureConf (valueType, valueIoSync), parseConfig, mkMicroarchitecture, ) where @@ -92,18 +92,18 @@ instance FromJSON NetworkConf instance ToJSON NetworkConf data MicroarchitectureConf = MicroarchitectureConf - { type' :: T.Text - , ioSync' :: IOSynchronization + { valueType :: T.Text + , valueIoSync :: IOSynchronization , networks :: [NetworkConf] } deriving (Generic, Show) instance FromJSON MicroarchitectureConf where parseJSON (Object v) = do - type' <- v .: "type" - ioSync' <- v .: "ioSync" + valueType <- v .: "type" + valueIoSync <- v .: "ioSync" networks <- v .: "networks" - return MicroarchitectureConf{type' = type', ioSync' = ioSync', networks = networks} + return MicroarchitectureConf{valueType, valueIoSync, networks} parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf @@ -143,7 +143,7 @@ mkMicroarchitecture conf = , master_cs = PU.OutputPortTag cs } nets = networks conf - mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name $ ioSync' conf) (build net) + mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name $ valueIoSync conf) (build net) in case nets of [n] -> mkNetwork n _ -> error "multi-networks are not currently supported" From 7240f352ceccdd7f6be35f2b61e9b71a5250d8a6 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sun, 24 Mar 2024 22:04:00 +0300 Subject: [PATCH 07/22] fixes --- examples/microarch.yml | 2 +- src/NITTA/Model/Microarchitecture/Config.hs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/microarch.yml b/examples/microarch.yml index 84c269ce6..ce721a9f1 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -1,7 +1,7 @@ type: fx32.32 ioSync: Sync networks: - - name: net1 + net1: pus: - type: SPI name: spi diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index f92e0da13..eb9594246 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -24,6 +24,10 @@ import Data.Yaml ( decodeFileThrow, (.:), ) +import Data.Map as M ( + Map, + toList + ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) import NITTA.Intermediate.Variable (Var) @@ -82,8 +86,7 @@ instance FromJSON PUConf where parseJSON = genericParseJSON puConfJsonOptions data NetworkConf = NetworkConf - { name :: T.Text - , pus :: [PUConf] + { pus :: [PUConf] , protos :: [PUConf] } deriving (Generic, Show) @@ -94,7 +97,7 @@ instance ToJSON NetworkConf data MicroarchitectureConf = MicroarchitectureConf { valueType :: T.Text , valueIoSync :: IOSynchronization - , networks :: [NetworkConf] + , networks :: Map T.Text NetworkConf } deriving (Generic, Show) @@ -143,7 +146,7 @@ mkMicroarchitecture conf = , master_cs = PU.OutputPortTag cs } nets = networks conf - mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name $ valueIoSync conf) (build net) - in case nets of - [n] -> mkNetwork n + mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync conf) (build net) + in case M.toList nets of + [(name, net)] -> mkNetwork name net _ -> error "multi-networks are not currently supported" From 627affd38ed1bbb7ba1644c8e76de608b3ce4856 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 16:07:34 +0300 Subject: [PATCH 08/22] fixes --- src/NITTA/Model/Microarchitecture/Config.hs | 26 +++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index eb9594246..a82944d52 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -41,6 +41,16 @@ import NITTA.Model.Networks.Bus ( import NITTA.Model.Networks.Types (IOSynchronization) import NITTA.Model.ProcessorUnits qualified as PU +data PULibrary = PULibrary + { isSlave :: Bool + , bufferSize :: Maybe Int + , bounceFilter :: Int + } + deriving (Generic, Show) + +instance FromJSON PULibrary +instance ToJSON PULibrary + data PUConf = Accum { name :: T.Text @@ -64,9 +74,6 @@ data PUConf , miso :: T.Text , sclk :: T.Text , cs :: T.Text - , isSlave :: Bool - , bufferSize :: Maybe Int - , bounceFilter :: Int } | Shift { name :: T.Text @@ -97,6 +104,7 @@ instance ToJSON NetworkConf data MicroarchitectureConf = MicroarchitectureConf { valueType :: T.Text , valueIoSync :: IOSynchronization + , puLibrary :: PULibrary , networks :: Map T.Text NetworkConf } deriving (Generic, Show) @@ -105,8 +113,9 @@ instance FromJSON MicroarchitectureConf where parseJSON (Object v) = do valueType <- v .: "type" valueIoSync <- v .: "ioSync" + puLibrary <- v .: "puLibrary" networks <- v .: "networks" - return MicroarchitectureConf{valueType, valueIoSync, networks} + return MicroarchitectureConf{valueType, valueIoSync, puLibrary, networks} parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf @@ -119,6 +128,9 @@ mkMicroarchitecture conf = let addPU proto | proto = addCustomPrototype | otherwise = addCustom + isSlave_ = isSlave . puLibrary $ conf + bufferSize_ = bufferSize . puLibrary $ conf + bounceFilter_ = bounceFilter . puLibrary $ conf build NetworkConf{pus, protos} = do mapM_ (configure False) pus mapM_ (configure True) protos @@ -128,9 +140,9 @@ mkMicroarchitecture conf = configure proto Multiplier{name, mock} = addPU proto name (PU.multiplier mock) PU.MultiplierIO configure proto Fram{name, size} = addPU proto name (PU.framWithSize size) PU.FramIO configure proto Shift{name, sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO - configure proto SPI{name, mosi, miso, sclk, cs, isSlave, bounceFilter, bufferSize} = - addPU proto name (PU.anySPI bounceFilter bufferSize) $ - if isSlave + configure proto SPI{name, mosi, miso, sclk, cs} = + addPU proto name (PU.anySPI bounceFilter_ bufferSize_) $ + if isSlave_ then PU.SPISlave { slave_mosi = PU.InputPortTag mosi From c2e82e195d91b441149b33d6963be52bcec5af52 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 18:11:48 +0300 Subject: [PATCH 09/22] fixes --- examples/microarch.yml | 10 +++++----- src/NITTA/Model/Microarchitecture/Config.hs | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/microarch.yml b/examples/microarch.yml index ce721a9f1..8cafe24dc 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -1,5 +1,10 @@ +mock: true type: fx32.32 ioSync: Sync +puLibrary: + isSlave: true + bufferSize: 6 + bounceFilter: 0 networks: net1: pus: @@ -9,9 +14,6 @@ networks: miso: miso sclk: sclk cs: cs - isSlave: true - bufferSize: 6 - bounceFilter: 0 protos: - type: Fram name: fram{x} # If you want a PU can be allocated only once, remove {x} from the PU name. @@ -21,12 +23,10 @@ networks: sRight: true - type: Multiplier name: mul{x} - mock: true - type: Accum name: accum{x} isInt: true - type: Divider name: div{x} - mock: true pipeline: 4 diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index a82944d52..0072d6ffa 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -58,11 +58,9 @@ data PUConf | Divider { name :: T.Text , pipeline :: Int - , mock :: Bool } | Multiplier { name :: T.Text - , mock :: Bool } | Fram { name :: T.Text @@ -102,7 +100,8 @@ instance FromJSON NetworkConf instance ToJSON NetworkConf data MicroarchitectureConf = MicroarchitectureConf - { valueType :: T.Text + { mock :: Bool + , valueType :: T.Text , valueIoSync :: IOSynchronization , puLibrary :: PULibrary , networks :: Map T.Text NetworkConf @@ -111,11 +110,12 @@ data MicroarchitectureConf = MicroarchitectureConf instance FromJSON MicroarchitectureConf where parseJSON (Object v) = do + mock <- v .: "mock" valueType <- v .: "type" valueIoSync <- v .: "ioSync" puLibrary <- v .: "puLibrary" networks <- v .: "networks" - return MicroarchitectureConf{valueType, valueIoSync, puLibrary, networks} + return MicroarchitectureConf{mock, valueType, valueIoSync, puLibrary, networks} parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf @@ -128,6 +128,7 @@ mkMicroarchitecture conf = let addPU proto | proto = addCustomPrototype | otherwise = addCustom + mock_ = mock conf isSlave_ = isSlave . puLibrary $ conf bufferSize_ = bufferSize . puLibrary $ conf bounceFilter_ = bounceFilter . puLibrary $ conf @@ -136,8 +137,8 @@ mkMicroarchitecture conf = mapM_ (configure True) protos where configure proto Accum{name} = addPU proto name def PU.AccumIO - configure proto Divider{name, pipeline, mock} = addPU proto name (PU.divider pipeline mock) PU.DividerIO - configure proto Multiplier{name, mock} = addPU proto name (PU.multiplier mock) PU.MultiplierIO + configure proto Divider{name, pipeline} = addPU proto name (PU.divider pipeline mock_) PU.DividerIO + configure proto Multiplier{name} = addPU proto name (PU.multiplier mock_) PU.MultiplierIO configure proto Fram{name, size} = addPU proto name (PU.framWithSize size) PU.FramIO configure proto Shift{name, sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO configure proto SPI{name, mosi, miso, sclk, cs} = From 7238f8146a7f9c89af18d5e7d6d474de3ec211cc Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 20:31:33 +0300 Subject: [PATCH 10/22] fixes --- examples/microarch.yml | 24 +++++----- src/NITTA/Model/Microarchitecture/Config.hs | 51 +++++++++------------ 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/examples/microarch.yml b/examples/microarch.yml index 8cafe24dc..b4201745b 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -8,25 +8,25 @@ puLibrary: networks: net1: pus: - - type: SPI - name: spi + spi: + type: SPI mosi: mosi miso: miso sclk: sclk cs: cs protos: - - type: Fram - name: fram{x} # If you want a PU can be allocated only once, remove {x} from the PU name. + fram{x}: # If you want a PU can be allocated only once, remove {x} from the PU name. + type: Fram size: 32 - - type: Shift - name: shift{x} + shift{x}: + type: Shift sRight: true - - type: Multiplier - name: mul{x} - - type: Accum - name: accum{x} + mul{x}: + type: Multiplier + accum{x}: + type: Accum isInt: true - - type: Divider - name: div{x} + div{x}: + type: Divider pipeline: 4 diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 0072d6ffa..938f7580e 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -53,29 +53,21 @@ instance ToJSON PULibrary data PUConf = Accum - { name :: T.Text - } | Divider - { name :: T.Text - , pipeline :: Int + { pipeline :: Int } | Multiplier - { name :: T.Text - } | Fram - { name :: T.Text - , size :: Int + { size :: Int } | SPI - { name :: T.Text - , mosi :: T.Text + { mosi :: T.Text , miso :: T.Text , sclk :: T.Text , cs :: T.Text } | Shift - { name :: T.Text - , sRight :: Maybe Bool + { sRight :: Maybe Bool } deriving (Generic, Show) @@ -91,8 +83,8 @@ instance FromJSON PUConf where parseJSON = genericParseJSON puConfJsonOptions data NetworkConf = NetworkConf - { pus :: [PUConf] - , protos :: [PUConf] + { pus :: Map T.Text PUConf + , protos :: Map T.Text PUConf } deriving (Generic, Show) @@ -124,24 +116,24 @@ parseConfig path = do decodeFileThrow path :: IO MicroarchitectureConf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int -mkMicroarchitecture conf = +mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks} = let addPU proto | proto = addCustomPrototype | otherwise = addCustom - mock_ = mock conf - isSlave_ = isSlave . puLibrary $ conf - bufferSize_ = bufferSize . puLibrary $ conf - bounceFilter_ = bounceFilter . puLibrary $ conf + isSlave_ = isSlave puLibrary + bufferSize_ = bufferSize puLibrary + bounceFilter_ = bounceFilter puLibrary build NetworkConf{pus, protos} = do - mapM_ (configure False) pus - mapM_ (configure True) protos + mapM_ (configure_ False) $ M.toList pus + mapM_ (configure_ True) $ M.toList protos where - configure proto Accum{name} = addPU proto name def PU.AccumIO - configure proto Divider{name, pipeline} = addPU proto name (PU.divider pipeline mock_) PU.DividerIO - configure proto Multiplier{name} = addPU proto name (PU.multiplier mock_) PU.MultiplierIO - configure proto Fram{name, size} = addPU proto name (PU.framWithSize size) PU.FramIO - configure proto Shift{name, sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO - configure proto SPI{name, mosi, miso, sclk, cs} = + configure_ proto (name, pu) = configure proto name pu + configure proto name Accum = addPU proto name def PU.AccumIO + configure proto name Divider{pipeline} = addPU proto name (PU.divider pipeline mock) PU.DividerIO + configure proto name Multiplier = addPU proto name (PU.multiplier mock) PU.MultiplierIO + configure proto name Fram{size} = addPU proto name (PU.framWithSize size) PU.FramIO + configure proto name Shift{sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO + configure proto name SPI{mosi, miso, sclk, cs} = addPU proto name (PU.anySPI bounceFilter_ bufferSize_) $ if isSlave_ then @@ -158,8 +150,7 @@ mkMicroarchitecture conf = , master_sclk = PU.OutputPortTag sclk , master_cs = PU.OutputPortTag cs } - nets = networks conf - mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync conf) (build net) - in case M.toList nets of + mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync) (build net) + in case M.toList networks of [(name, net)] -> mkNetwork name net _ -> error "multi-networks are not currently supported" From c77c8bdb6ab4ace70a87b1c4492b96db65289627 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 20:44:54 +0300 Subject: [PATCH 11/22] fixes --- src/NITTA/Model/Microarchitecture/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 938f7580e..d67f321cb 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -26,7 +26,7 @@ import Data.Yaml ( ) import Data.Map as M ( Map, - toList + toList, ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) From f63c40e41fd7950dae085314172c2fef183ff22e Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 23:17:03 +0300 Subject: [PATCH 12/22] fixes --- src/NITTA/Model/Microarchitecture/Config.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index d67f321cb..702e9474b 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -16,6 +16,10 @@ import Data.Aeson ( genericToJSON, ) import Data.Default (Default (def)) +import Data.Map as M ( + Map, + toList, + ) import Data.Text qualified as T import Data.Yaml ( FromJSON (parseJSON), @@ -24,10 +28,6 @@ import Data.Yaml ( decodeFileThrow, (.:), ) -import Data.Map as M ( - Map, - toList, - ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) import NITTA.Intermediate.Variable (Var) From ebd687b97729c88cb5804d99bd5392b1f9d59dc1 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Mon, 1 Apr 2024 23:26:14 +0300 Subject: [PATCH 13/22] fixes --- src/NITTA/Model/Microarchitecture/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 702e9474b..062258112 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -150,7 +150,7 @@ mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks , master_sclk = PU.OutputPortTag sclk , master_cs = PU.OutputPortTag cs } - mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync) (build net) + mkNetwork name net = modifyNetwork (busNetwork name valueIoSync) (build net) in case M.toList networks of [(name, net)] -> mkNetwork name net _ -> error "multi-networks are not currently supported" From 56e93fc97223fb7ce62674d1f997349dc4d056a9 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Sat, 13 Apr 2024 18:45:30 +0300 Subject: [PATCH 14/22] maybe nets --- src/NITTA/Model/Microarchitecture/Config.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 062258112..b01bad3b7 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -20,6 +20,7 @@ import Data.Map as M ( Map, toList, ) +import Data.Maybe (fromMaybe) import Data.Text qualified as T import Data.Yaml ( FromJSON (parseJSON), @@ -83,8 +84,8 @@ instance FromJSON PUConf where parseJSON = genericParseJSON puConfJsonOptions data NetworkConf = NetworkConf - { pus :: Map T.Text PUConf - , protos :: Map T.Text PUConf + { pus :: Maybe (Map T.Text PUConf) + , protos :: Maybe (Map T.Text PUConf) } deriving (Generic, Show) @@ -124,8 +125,8 @@ mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks bufferSize_ = bufferSize puLibrary bounceFilter_ = bounceFilter puLibrary build NetworkConf{pus, protos} = do - mapM_ (configure_ False) $ M.toList pus - mapM_ (configure_ True) $ M.toList protos + mapM_ (configure_ False) $ M.toList $ fromMaybe def pus + mapM_ (configure_ True) $ M.toList $ fromMaybe def protos where configure_ proto (name, pu) = configure proto name pu configure proto name Accum = addPU proto name def PU.AccumIO From 129f99b962eb55fa65b369b75637d748385c29bd Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 23 Apr 2024 21:30:06 +0300 Subject: [PATCH 15/22] fixes --- app/Main.hs | 8 ++-- examples/microarch.yml | 9 ++--- src/NITTA/Model/Microarchitecture/Config.hs | 41 +++++---------------- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 10e4fd8ce..4724878ad 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -32,7 +32,7 @@ import NITTA.Frontends import NITTA.Intermediate.Simulation import NITTA.Intermediate.Types import NITTA.Model.Microarchitecture.Config -import NITTA.Model.Networks.Bus +import NITTA.Model.Networks.Bus hiding (ioSync) import NITTA.Model.Networks.Types import NITTA.Model.ProcessorUnits import NITTA.Project (TestbenchReport (..), defProjectTemplates, runTestbench) @@ -237,7 +237,7 @@ main = do let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = translate exactFrontendType src received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] - ioSync = fromJust $ io_sync <|> valueIoSync <$> conf <|> Just Sync + ioSync_ = fromJust $ io_sync <|> ioSync <$> conf <|> Just Sync confMa = mkMicroarchitecture <$> conf ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma @@ -245,9 +245,9 @@ main = do error $ "auto_uarch flag means that an empty uarch with default prototypes will be used. " <> "Remove uarch flag or specify prototypes list in config file and remove auto_uarch." - | auto_uarch = microarchWithProtos ioSync + | auto_uarch = microarchWithProtos ioSync_ | isJust confMa = fromJust confMa - | otherwise = defMicroarch ioSync + | otherwise = defMicroarch ioSync_ infoM "NITTA" $ "will trace: " <> S.join ", " (map (show . tvVar) frTrace) diff --git a/examples/microarch.yml b/examples/microarch.yml index b4201745b..79db12eab 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -1,10 +1,6 @@ mock: true -type: fx32.32 ioSync: Sync -puLibrary: - isSlave: true - bufferSize: 6 - bounceFilter: 0 +valueType: fx32.32 networks: net1: pus: @@ -14,6 +10,9 @@ networks: miso: miso sclk: sclk cs: cs + isSlave: true + bufferSize: 6 + bounceFilter: 0 protos: fram{x}: # If you want a PU can be allocated only once, remove {x} from the PU name. type: Fram diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index b01bad3b7..c38247248 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -3,7 +3,7 @@ {-# LANGUAGE PartialTypeSignatures #-} module NITTA.Model.Microarchitecture.Config ( - MicroarchitectureConf (valueType, valueIoSync), + MicroarchitectureConf (valueType, ioSync), parseConfig, mkMicroarchitecture, ) where @@ -25,9 +25,7 @@ import Data.Text qualified as T import Data.Yaml ( FromJSON (parseJSON), ToJSON (toJSON), - Value (Object), decodeFileThrow, - (.:), ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) @@ -42,16 +40,6 @@ import NITTA.Model.Networks.Bus ( import NITTA.Model.Networks.Types (IOSynchronization) import NITTA.Model.ProcessorUnits qualified as PU -data PULibrary = PULibrary - { isSlave :: Bool - , bufferSize :: Maybe Int - , bounceFilter :: Int - } - deriving (Generic, Show) - -instance FromJSON PULibrary -instance ToJSON PULibrary - data PUConf = Accum | Divider @@ -66,6 +54,9 @@ data PUConf , miso :: T.Text , sclk :: T.Text , cs :: T.Text + , isSlave :: Bool + , bufferSize :: Maybe Int + , bounceFilter :: Int } | Shift { sRight :: Maybe Bool @@ -94,22 +85,13 @@ instance ToJSON NetworkConf data MicroarchitectureConf = MicroarchitectureConf { mock :: Bool + , ioSync :: IOSynchronization , valueType :: T.Text - , valueIoSync :: IOSynchronization - , puLibrary :: PULibrary , networks :: Map T.Text NetworkConf } deriving (Generic, Show) instance FromJSON MicroarchitectureConf where - parseJSON (Object v) = do - mock <- v .: "mock" - valueType <- v .: "type" - valueIoSync <- v .: "ioSync" - puLibrary <- v .: "puLibrary" - networks <- v .: "networks" - return MicroarchitectureConf{mock, valueType, valueIoSync, puLibrary, networks} - parseJSON v = fail $ show v instance ToJSON MicroarchitectureConf parseConfig :: FilePath -> IO MicroarchitectureConf @@ -117,13 +99,10 @@ parseConfig path = do decodeFileThrow path :: IO MicroarchitectureConf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int -mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks} = +mkMicroarchitecture MicroarchitectureConf{mock, ioSync, networks} = let addPU proto | proto = addCustomPrototype | otherwise = addCustom - isSlave_ = isSlave puLibrary - bufferSize_ = bufferSize puLibrary - bounceFilter_ = bounceFilter puLibrary build NetworkConf{pus, protos} = do mapM_ (configure_ False) $ M.toList $ fromMaybe def pus mapM_ (configure_ True) $ M.toList $ fromMaybe def protos @@ -134,9 +113,9 @@ mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks configure proto name Multiplier = addPU proto name (PU.multiplier mock) PU.MultiplierIO configure proto name Fram{size} = addPU proto name (PU.framWithSize size) PU.FramIO configure proto name Shift{sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO - configure proto name SPI{mosi, miso, sclk, cs} = - addPU proto name (PU.anySPI bounceFilter_ bufferSize_) $ - if isSlave_ + configure proto name SPI{mosi, miso, sclk, cs, isSlave, bufferSize, bounceFilter} = + addPU proto name (PU.anySPI bounceFilter bufferSize) $ + if isSlave then PU.SPISlave { slave_mosi = PU.InputPortTag mosi @@ -151,7 +130,7 @@ mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks , master_sclk = PU.OutputPortTag sclk , master_cs = PU.OutputPortTag cs } - mkNetwork name net = modifyNetwork (busNetwork name valueIoSync) (build net) + mkNetwork name net = modifyNetwork (busNetwork name ioSync) (build net) in case M.toList networks of [(name, net)] -> mkNetwork name net _ -> error "multi-networks are not currently supported" From 4ffe9bd3f274fa23f2fcb9a187d47bf0eb164670 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 23 Apr 2024 21:34:03 +0300 Subject: [PATCH 16/22] pu library --- examples/microarch.yml | 13 +++++++------ src/NITTA/Model/Microarchitecture/Config.hs | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/microarch.yml b/examples/microarch.yml index 79db12eab..d225533f2 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -1,6 +1,13 @@ mock: true ioSync: Sync valueType: fx32.32 +library: + fram{x}: # If you want a PU can be allocated only once, remove {x} from the PU name. + type: Fram + size: 32 + accum{x}: + type: Accum + isInt: true networks: net1: pus: @@ -14,17 +21,11 @@ networks: bufferSize: 6 bounceFilter: 0 protos: - fram{x}: # If you want a PU can be allocated only once, remove {x} from the PU name. - type: Fram - size: 32 shift{x}: type: Shift sRight: true mul{x}: type: Multiplier - accum{x}: - type: Accum - isInt: true div{x}: type: Divider pipeline: 4 diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index c38247248..18fc3f036 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -87,6 +87,7 @@ data MicroarchitectureConf = MicroarchitectureConf { mock :: Bool , ioSync :: IOSynchronization , valueType :: T.Text + , library :: Maybe (Map T.Text PUConf) , networks :: Map T.Text NetworkConf } deriving (Generic, Show) @@ -99,13 +100,14 @@ parseConfig path = do decodeFileThrow path :: IO MicroarchitectureConf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int -mkMicroarchitecture MicroarchitectureConf{mock, ioSync, networks} = +mkMicroarchitecture MicroarchitectureConf{mock, ioSync, library, networks} = let addPU proto | proto = addCustomPrototype | otherwise = addCustom build NetworkConf{pus, protos} = do mapM_ (configure_ False) $ M.toList $ fromMaybe def pus mapM_ (configure_ True) $ M.toList $ fromMaybe def protos + mapM_ (configure_ True) $ M.toList $ fromMaybe def library where configure_ proto (name, pu) = configure proto name pu configure proto name Accum = addPU proto name def PU.AccumIO From a1c49049f32a6e6f01ac884fdfc7878f1a0487a0 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 23 Apr 2024 21:57:21 +0300 Subject: [PATCH 17/22] save march --- app/Main.hs | 4 ++++ examples/microarch.yml | 3 +-- src/NITTA/Model/Microarchitecture/Config.hs | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 4724878ad..67f449d30 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -229,6 +229,10 @@ main = do conf <- case uarch of Nothing -> return Nothing Just path -> Just <$> parseConfig path + + case conf of + Nothing -> return () + Just conf_ -> saveConfig output_path conf_ let exactFrontendType = identifyFrontendType filename frontend_language diff --git a/examples/microarch.yml b/examples/microarch.yml index d225533f2..26169acb0 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -28,5 +28,4 @@ networks: type: Multiplier div{x}: type: Divider - pipeline: 4 - + pipeline: 4 \ No newline at end of file diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 18fc3f036..77197e48b 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -5,6 +5,7 @@ module NITTA.Model.Microarchitecture.Config ( MicroarchitectureConf (valueType, ioSync), parseConfig, + saveConfig, mkMicroarchitecture, ) where @@ -26,6 +27,7 @@ import Data.Yaml ( FromJSON (parseJSON), ToJSON (toJSON), decodeFileThrow, + encodeFile ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) @@ -99,6 +101,10 @@ parseConfig :: FilePath -> IO MicroarchitectureConf parseConfig path = do decodeFileThrow path :: IO MicroarchitectureConf +saveConfig :: FilePath -> MicroarchitectureConf -> IO () +saveConfig path conf = do + encodeFile (path <> "/microarch.yml") conf + mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int mkMicroarchitecture MicroarchitectureConf{mock, ioSync, library, networks} = let addPU proto From 9757aa022729c932749d3268f5c461fa5fd4bcc8 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 23 Apr 2024 22:38:10 +0300 Subject: [PATCH 18/22] march --- app/Main.hs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 67f449d30..25280386d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -61,8 +61,8 @@ data SynthesisMethodArg -- | Command line interface. data Nitta = Nitta { filename :: FilePath - , uarch :: Maybe FilePath - , auto_uarch :: Bool + , march :: Maybe FilePath + , auto_march :: Bool , type_ :: Maybe String , io_sync :: Maybe IOSynchronization , port :: Int @@ -95,17 +95,17 @@ nittaArgs = -1 &= help "Run nitta server for UI on specific port (by default - not run)" &= groupname "Common flags" - , uarch = + , march = Nothing &= typ "PATH" &= help "Microarchitecture configuration file" &= explicit - &= name "uarch" + &= name "march" &= groupname "Target system configuration" - , auto_uarch = + , auto_march = False &= help "Use empty microarchitecture and allocate PUs during synthesis process." - &= name "auto-uarch" + &= name "auto-march" &= groupname "Target system configuration" , type_ = Nothing @@ -201,8 +201,8 @@ getNittaArgs = cmdArgs nittaArgs main = do ( Nitta filename - uarch - auto_uarch + march + auto_march type_ io_sync port @@ -226,7 +226,7 @@ main = do -- force line buffering (always, not just when stdout is connected to a tty), -- it's critical for successful parsing of NITTA's stdout in python scripts hSetBuffering stdout LineBuffering - conf <- case uarch of + conf <- case march of Nothing -> return Nothing Just path -> Just <$> parseConfig path @@ -245,11 +245,11 @@ main = do confMa = mkMicroarchitecture <$> conf ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int ma - | auto_uarch && isJust confMa = + | auto_march && isJust confMa = error $ - "auto_uarch flag means that an empty uarch with default prototypes will be used. " - <> "Remove uarch flag or specify prototypes list in config file and remove auto_uarch." - | auto_uarch = microarchWithProtos ioSync_ + "auto_march flag means that an empty march with default prototypes will be used. " + <> "Remove march flag or specify prototypes list in config file and remove auto_march." + | auto_march = microarchWithProtos ioSync_ | isJust confMa = fromJust confMa | otherwise = defMicroarch ioSync_ From 8c8f454a361b673d1f7c95418f6d650473c445cf Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 30 Apr 2024 14:30:27 +0300 Subject: [PATCH 19/22] test --- README.md | 4 +- app/Main.hs | 5 +- examples/microarch.yml | 1 - nitta.cabal | 1 + src/NITTA/Model/Microarchitecture/Config.hs | 6 ++- src/NITTA/Model/Networks/Bus.hs | 2 +- test/NITTA/Model/Config/Tests.hs | 55 +++++++++++++++++++++ test/Spec.hs | 2 + 8 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 test/NITTA/Model/Config/Tests.hs diff --git a/README.md b/README.md index ec88f6763..1521b0ed3 100644 --- a/README.md +++ b/README.md @@ -217,8 +217,8 @@ nitta v0.0.0.1 - tool for hard real-time CGRA processors nitta [OPTIONS] FILE Target system configuration: - --uarch=PATH Microarchitecture configuration file - -a --auto-uarch Use empty microarchitecture and + --march=PATH Microarchitecture configuration file + -a --auto-march Use empty microarchitecture and allocate PUs during synthesis process. -t --type=fxM.B Overrides data type specified in config file diff --git a/app/Main.hs b/app/Main.hs index 25280386d..24b6ff623 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -21,6 +21,7 @@ import Control.Exception import Control.Monad (when) import Data.ByteString.Lazy.Char8 qualified as BS import Data.Default (def) +import Data.Foldable (forM_) import Data.Maybe import Data.Proxy import Data.String.Utils qualified as S @@ -230,9 +231,7 @@ main = do Nothing -> return Nothing Just path -> Just <$> parseConfig path - case conf of - Nothing -> return () - Just conf_ -> saveConfig output_path conf_ + forM_ conf $ saveConfig output_path let exactFrontendType = identifyFrontendType filename frontend_language diff --git a/examples/microarch.yml b/examples/microarch.yml index 26169acb0..0517417f7 100644 --- a/examples/microarch.yml +++ b/examples/microarch.yml @@ -7,7 +7,6 @@ library: size: 32 accum{x}: type: Accum - isInt: true networks: net1: pus: diff --git a/nitta.cabal b/nitta.cabal index 47b73944b..f57406b74 100644 --- a/nitta.cabal +++ b/nitta.cabal @@ -285,6 +285,7 @@ test-suite nitta-test NITTA.Intermediate.Simulation.Tests NITTA.Intermediate.Tests.Functions NITTA.Intermediate.Value.Tests + NITTA.Model.Config.Tests NITTA.Model.Problems.Refactor.Accum.Tests NITTA.Model.Problems.Refactor.ConstantFolding.Tests NITTA.Model.Problems.Refactor.Tests diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 77197e48b..5048cc40c 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -3,7 +3,9 @@ {-# LANGUAGE PartialTypeSignatures #-} module NITTA.Model.Microarchitecture.Config ( - MicroarchitectureConf (valueType, ioSync), + MicroarchitectureConf (..), + NetworkConf (..), + PUConf (..), parseConfig, saveConfig, mkMicroarchitecture, @@ -103,7 +105,7 @@ parseConfig path = do saveConfig :: FilePath -> MicroarchitectureConf -> IO () saveConfig path conf = do - encodeFile (path <> "/microarch.yml") conf + encodeFile (path <> "/microarch.yml") conf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int mkMicroarchitecture MicroarchitectureConf{mock, ioSync, library, networks} = diff --git a/src/NITTA/Model/Networks/Bus.hs b/src/NITTA/Model/Networks/Bus.hs index 556db771e..aa91b134c 100644 --- a/src/NITTA/Model/Networks/Bus.hs +++ b/src/NITTA/Model/Networks/Bus.hs @@ -189,7 +189,7 @@ instance (UnitTag tag, VarValTime v x t) => ProcessorUnit (BusNetwork tag v x t) | any (allowToProcess f) (M.elems bnPus) = Right net{bnRemains = f : bnRemains} -- TODO: -- There are several issues that need to be addressed: see https://github.com/ryukzak/nitta/pull/195#discussion_r853486450 - -- 1) Now the binding of functions to the network is hardcoded, that prevents use of an empty uarch at the start + -- 1) Now the binding of functions to the network is hardcoded, that prevents use of an empty march at the start -- 2) If Allocation options are independent of the bnRemains, then they are present in all synthesis states, which means no leaves in the synthesis tree | any (\PUPrototype{pProto} -> allowToProcess f pProto) (M.elems bnPUPrototypes) = Right net{bnRemains = f : bnRemains} tryBind f BusNetwork{bnPus} = diff --git a/test/NITTA/Model/Config/Tests.hs b/test/NITTA/Model/Config/Tests.hs new file mode 100644 index 000000000..9c635056c --- /dev/null +++ b/test/NITTA/Model/Config/Tests.hs @@ -0,0 +1,55 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE IncoherentInstances #-} +{-# LANGUAGE PartialTypeSignatures #-} + +{- | +Module : NITTA.Model.Config.Tests +Description : +Copyright : (c) Valerii Butorin, 2024 +License : BSD3 +Maintainer : aleksandr.penskoi@gmail.com +Stability : experimental +-} +module NITTA.Model.Config.Tests ( + tests, +) where + +import Data.Maybe +import Data.Map as M +import Data.Text qualified as T +import NITTA.Model.Microarchitecture.Config as Conf +import Test.Tasty (testGroup) +import Test.Tasty.HUnit + +tests = + testGroup + "Configuration parsing" + [ testCase "parse config common" $ do + conf <- parseConfig "examples/microarch.yml" + let + lib = fromJust $ library conf + fram = fromJust $ M.lookup (T.pack "fram{x}") lib + nets = networks conf + net = fromJust $ M.lookup (T.pack "net1") nets + spi = fromJust $ M.lookup (T.pack "spi") (fromJust $ pus net) + proros_ = fromJust $ protos net + shift = fromJust $ M.lookup (T.pack "shift{x}") proros_ + div_ = fromJust $ M.lookup (T.pack "div{x}") proros_ + + "Sync" @=? show (ioSync conf) + True @=? mock conf + "fx32.32" @=? T.unpack (valueType conf) + 2 @=? M.size (fromJust $ library conf) + + 32 @=? Conf.size fram + Just True @=? Conf.sRight shift + 4 @=? Conf.pipeline div_ + + "mosi" @=? T.unpack (mosi spi) + "miso" @=? T.unpack (miso spi) + "sclk" @=? T.unpack (sclk spi) + "cs" @=? T.unpack (cs spi) + True @=? isSlave spi + Just 6 @=? bufferSize spi + 0 @=? bounceFilter spi + ] diff --git a/test/Spec.hs b/test/Spec.hs index 83043cee2..14227d66a 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -20,6 +20,7 @@ import NITTA.Frontends.XMILE.MathParserTests qualified import NITTA.Intermediate.Functions.Accum.Tests qualified import NITTA.Intermediate.Simulation.Tests qualified import NITTA.Intermediate.Value.Tests qualified +import NITTA.Model.Config.Tests qualified import NITTA.Model.Problems.Refactor.Accum.Tests qualified import NITTA.Model.Problems.Refactor.ConstantFolding.Tests qualified import NITTA.Model.Problems.Refactor.Tests qualified @@ -61,6 +62,7 @@ main = do , NITTA.Model.ProcessorUnits.Accum.Tests.tests , NITTA.Model.ProcessorUnits.Shift.Tests.tests , NITTA.Model.ProcessorUnits.Tests.DSL.Tests.tests + , NITTA.Model.Config.Tests.tests , NITTA.Tests.tests , NITTA.Utils.Tests.tests ] From f109211c2a3581ac385145f5b6408a00f4e59c65 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 30 Apr 2024 14:38:09 +0300 Subject: [PATCH 20/22] fix --- src/NITTA/Model/Microarchitecture/Config.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 5048cc40c..6a3e98e2f 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -24,7 +24,8 @@ import Data.Map as M ( toList, ) import Data.Maybe (fromMaybe) -import Data.Text qualified as T +import Data.Text + qualified as T import Data.Yaml ( FromJSON (parseJSON), ToJSON (toJSON), @@ -43,6 +44,7 @@ import NITTA.Model.Networks.Bus ( ) import NITTA.Model.Networks.Types (IOSynchronization) import NITTA.Model.ProcessorUnits qualified as PU +import System.Directory (createDirectoryIfMissing) data PUConf = Accum @@ -105,6 +107,7 @@ parseConfig path = do saveConfig :: FilePath -> MicroarchitectureConf -> IO () saveConfig path conf = do + createDirectoryIfMissing True path encodeFile (path <> "/microarch.yml") conf mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int From 6a61a5a26cb06f817a63518226ff74e70963c4d7 Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 30 Apr 2024 14:54:18 +0300 Subject: [PATCH 21/22] fix --- app/Main.hs | 2 +- src/NITTA/Model/Microarchitecture/Config.hs | 7 +++---- test/NITTA/Model/Config/Tests.hs | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 24b6ff623..95b1dda49 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -230,7 +230,7 @@ main = do conf <- case march of Nothing -> return Nothing Just path -> Just <$> parseConfig path - + forM_ conf $ saveConfig output_path let exactFrontendType = identifyFrontendType filename frontend_language diff --git a/src/NITTA/Model/Microarchitecture/Config.hs b/src/NITTA/Model/Microarchitecture/Config.hs index 6a3e98e2f..51cf16682 100644 --- a/src/NITTA/Model/Microarchitecture/Config.hs +++ b/src/NITTA/Model/Microarchitecture/Config.hs @@ -24,13 +24,12 @@ import Data.Map as M ( toList, ) import Data.Maybe (fromMaybe) -import Data.Text - qualified as T +import Data.Text qualified as T import Data.Yaml ( FromJSON (parseJSON), ToJSON (toJSON), decodeFileThrow, - encodeFile + encodeFile, ) import GHC.Generics (Generic) import NITTA.Intermediate.Value (Val) @@ -98,7 +97,7 @@ data MicroarchitectureConf = MicroarchitectureConf } deriving (Generic, Show) -instance FromJSON MicroarchitectureConf where +instance FromJSON MicroarchitectureConf instance ToJSON MicroarchitectureConf parseConfig :: FilePath -> IO MicroarchitectureConf diff --git a/test/NITTA/Model/Config/Tests.hs b/test/NITTA/Model/Config/Tests.hs index 9c635056c..f4873381f 100644 --- a/test/NITTA/Model/Config/Tests.hs +++ b/test/NITTA/Model/Config/Tests.hs @@ -14,8 +14,8 @@ module NITTA.Model.Config.Tests ( tests, ) where -import Data.Maybe import Data.Map as M +import Data.Maybe import Data.Text qualified as T import NITTA.Model.Microarchitecture.Config as Conf import Test.Tasty (testGroup) @@ -32,9 +32,9 @@ tests = nets = networks conf net = fromJust $ M.lookup (T.pack "net1") nets spi = fromJust $ M.lookup (T.pack "spi") (fromJust $ pus net) - proros_ = fromJust $ protos net - shift = fromJust $ M.lookup (T.pack "shift{x}") proros_ - div_ = fromJust $ M.lookup (T.pack "div{x}") proros_ + protos_ = fromJust $ protos net + shift = fromJust $ M.lookup (T.pack "shift{x}") protos_ + div_ = fromJust $ M.lookup (T.pack "div{x}") protos_ "Sync" @=? show (ioSync conf) True @=? mock conf From ae753ce2242edc396776ffd87184c08c7165dd1e Mon Sep 17 00:00:00 2001 From: Valerii Butorin Date: Tue, 30 Apr 2024 14:56:37 +0300 Subject: [PATCH 22/22] fix --- app/Main.hs | 2 +- test/NITTA/Model/Config/Tests.hs | 37 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 95b1dda49..0ad4d9fa6 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -230,7 +230,7 @@ main = do conf <- case march of Nothing -> return Nothing Just path -> Just <$> parseConfig path - + forM_ conf $ saveConfig output_path let exactFrontendType = identifyFrontendType filename frontend_language diff --git a/test/NITTA/Model/Config/Tests.hs b/test/NITTA/Model/Config/Tests.hs index f4873381f..d97cf35b9 100644 --- a/test/NITTA/Model/Config/Tests.hs +++ b/test/NITTA/Model/Config/Tests.hs @@ -24,9 +24,9 @@ import Test.Tasty.HUnit tests = testGroup "Configuration parsing" - [ testCase "parse config common" $ do - conf <- parseConfig "examples/microarch.yml" - let + [ testCase "parse config common" $ do + conf <- parseConfig "examples/microarch.yml" + let lib = fromJust $ library conf fram = fromJust $ M.lookup (T.pack "fram{x}") lib nets = networks conf @@ -35,21 +35,18 @@ tests = protos_ = fromJust $ protos net shift = fromJust $ M.lookup (T.pack "shift{x}") protos_ div_ = fromJust $ M.lookup (T.pack "div{x}") protos_ - - "Sync" @=? show (ioSync conf) - True @=? mock conf - "fx32.32" @=? T.unpack (valueType conf) - 2 @=? M.size (fromJust $ library conf) - - 32 @=? Conf.size fram - Just True @=? Conf.sRight shift - 4 @=? Conf.pipeline div_ - - "mosi" @=? T.unpack (mosi spi) - "miso" @=? T.unpack (miso spi) - "sclk" @=? T.unpack (sclk spi) - "cs" @=? T.unpack (cs spi) - True @=? isSlave spi - Just 6 @=? bufferSize spi - 0 @=? bounceFilter spi + "Sync" @=? show (ioSync conf) + True @=? mock conf + "fx32.32" @=? T.unpack (valueType conf) + 2 @=? M.size (fromJust $ library conf) + 32 @=? Conf.size fram + Just True @=? Conf.sRight shift + 4 @=? Conf.pipeline div_ + "mosi" @=? T.unpack (mosi spi) + "miso" @=? T.unpack (miso spi) + "sclk" @=? T.unpack (sclk spi) + "cs" @=? T.unpack (cs spi) + True @=? isSlave spi + Just 6 @=? bufferSize spi + 0 @=? bounceFilter spi ]