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