X-Git-Url: http://git.lukelau.me/?p=kaleidoscope-hs.git;a=blobdiff_plain;f=Utils.hs;h=cd325a40b3c3c296549e0ea11ad9947b1c9d53a4;hp=3bd3b37e01e54274cf4841b52e18d8d4b2cea97e;hb=refs%2Fheads%2Ftutorial-3;hpb=71d6ead1c5a14f206f5d7c8d4b9d1cbfed4a90db diff --git a/Utils.hs b/Utils.hs index 3bd3b37..cd325a4 100644 --- a/Utils.hs +++ b/Utils.hs @@ -6,6 +6,7 @@ module Utils where import Control.Monad.Trans.State import Data.ByteString.Short (ShortByteString) import Data.Functor.Identity +import Data.List import LLVM.AST import LLVM.IRBuilder.Module import LLVM.IRBuilder.Internal.SnocList @@ -16,6 +17,13 @@ moduleSoFar nm = do let ds = getSnocList (builderDefs s) return $ defaultModule { moduleName = nm, moduleDefinitions = ds } +removeDef :: MonadModuleBuilder m => Definition -> m () +removeDef def = liftModuleState (modify update) + where + update (ModuleBuilderState defs typeDefs) = + let newDefs = SnocList (delete def (getSnocList defs)) + in ModuleBuilderState newDefs typeDefs + mostRecentDef :: Monad m => ModuleBuilderT m Definition mostRecentDef = last . getSnocList . builderDefs <$> liftModuleState get