From ad199f8087642573f4f7daeeb588a43faaa3eab3 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Grave Date: Fri, 1 Mar 2019 19:18:05 +0000 Subject: Add lens to access main module in SourceInfo --- src/VeriFuzz/Internal/Simulator.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/VeriFuzz/Internal/Simulator.hs') diff --git a/src/VeriFuzz/Internal/Simulator.hs b/src/VeriFuzz/Internal/Simulator.hs index 5712709..1454a0f 100644 --- a/src/VeriFuzz/Internal/Simulator.hs +++ b/src/VeriFuzz/Internal/Simulator.hs @@ -12,7 +12,7 @@ Class of the simulator and the synthesize tool. module VeriFuzz.Internal.Simulator where -import Control.Lens ((^.), (^..)) +import Control.Lens import Data.Bits (shiftL) import Data.ByteString (ByteString) import qualified Data.ByteString as B @@ -48,10 +48,19 @@ class (Tool a) => Synthesisor a where data SourceInfo = SourceInfo { runMainModule :: {-# UNPACK #-} !Text , runSource :: !VerilogSrc } + deriving (Eq, Show) -mainModule :: SourceInfo -> ModDecl -mainModule (SourceInfo main src) = head . filter ismain $ src ^.. getModule - where ismain v = v ^. modId . getIdentifier == main +-- | May need to change this to Traversal to be safe. For now it will fail when +-- the main has not been properly set with. +mainModule :: Lens' SourceInfo ModDecl +mainModule = lens get_ set_ + where + set_ (SourceInfo top main) v = + SourceInfo top (main & getModule %~ update top v) + update top v m@(ModDecl (Identifier i) _ _ _) | i == top = v + | otherwise = m + get_ (SourceInfo top main) = head . filter (f top) $ main ^.. getModule + f top (ModDecl (Identifier i) _ _ _) = i == top rootPath :: Sh FilePath rootPath = do -- cgit