X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=Utils.hs;fp=Utils.hs;h=cd325a40b3c3c296549e0ea11ad9947b1c9d53a4;hb=b380cc6f6b84c17af96be39f42b879f86f41c468;hp=3bd3b37e01e54274cf4841b52e18d8d4b2cea97e;hpb=3b94bc147412cd0fc3d14b68ac0720f3d2ea7a1b;p=kaleidoscope-hs.git 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