From 48f556ffcb33f5e7a0f0c9d8cd4383cf4502e1ab Mon Sep 17 00:00:00 2001 From: Tristan Ravitch Date: Wed, 4 Oct 2017 09:49:17 -0700 Subject: [PATCH] Add some more helpers for the Generator monad --- macaw-ppc/src/Data/Macaw/PPC/Generator.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/macaw-ppc/src/Data/Macaw/PPC/Generator.hs b/macaw-ppc/src/Data/Macaw/PPC/Generator.hs index 67ee2d96..ea45b4ff 100644 --- a/macaw-ppc/src/Data/Macaw/PPC/Generator.hs +++ b/macaw-ppc/src/Data/Macaw/PPC/Generator.hs @@ -11,6 +11,8 @@ module Data.Macaw.PPC.Generator ( PPCGenerator, runGenerator, execGenerator, + evalGenerator, + genResult, Expr(..), BlockSeq(..), PreBlock(..), @@ -160,6 +162,16 @@ runGenerator s0 act = ET.runExceptT (St.runStateT (runGen act) s0) execGenerator :: GenState ppc s -> PPCGenerator ppc s () -> ST s (Either GeneratorError (GenState ppc s)) execGenerator s0 act = ET.runExceptT (St.execStateT (runGen act) s0) +evalGenerator :: GenState ppc s -> PPCGenerator ppc s a -> ST s (Either GeneratorError a) +evalGenerator s0 act = ET.runExceptT (St.evalStateT (runGen act) s0) + +genResult :: PPCGenerator ppc s (GenResult ppc s) +genResult = do + s <- St.get + return GenResult { resBlockSeq = blockSeq s + , resState = Just (s ^. blockState) + } + addStmt :: Stmt ppc s -> PPCGenerator ppc s () addStmt stmt = (blockState . pBlockStmts) %= (Seq.|> stmt)