From 98c6701f48d3e06eb0f2fcd590d0330aec8b5a9b Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 13 May 2019 16:32:41 +0100 Subject: Add ResultT to Sh conversion --- src/VeriFuzz/Sim/Internal.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/VeriFuzz/Sim/Internal.hs') diff --git a/src/VeriFuzz/Sim/Internal.hs b/src/VeriFuzz/Sim/Internal.hs index a11fbd3..091520c 100644 --- a/src/VeriFuzz/Sim/Internal.hs +++ b/src/VeriFuzz/Sim/Internal.hs @@ -14,6 +14,7 @@ Class of the simulator and the synthesize tool. module VeriFuzz.Sim.Internal ( ResultSh + , resultSh , Tool(..) , Simulator(..) , Synthesiser(..) @@ -39,6 +40,7 @@ where import Control.Lens import Control.Monad (forM, void) +import Control.Monad.Catch (throwM) import Data.Bits (shiftL) import Data.ByteString (ByteString) import qualified Data.ByteString as B @@ -51,6 +53,7 @@ import Prelude hiding (FilePath) import Shelly import Shelly.Lifted (MonadSh, liftSh) import System.FilePath.Posix (takeBaseName) +import VeriFuzz.Internal import VeriFuzz.Result import VeriFuzz.Verilog.AST @@ -95,6 +98,13 @@ class Tool a => Synthesiser a where -- with also has those instances. type ResultSh = ResultT Failed Sh +resultSh :: ResultSh a -> Sh a +resultSh s = do + result <- runResultT s + case result of + Fail e -> throwM . RunFailed "" [] 1 $ showT e + Pass s' -> return s' + checkPresent :: FilePath -> Text -> Sh (Maybe Text) checkPresent fp t = do errExit False $ run_ "grep" [t, toTextIgnore fp] -- cgit